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; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 26 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 27 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 28 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 29 | import android.app.Activity; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 30 | import android.app.IServiceConnection; |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 31 | import android.app.KeyguardManager; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 32 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 33 | import android.content.ComponentName; |
| 34 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 35 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 36 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 37 | import android.content.ServiceConnection; |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 38 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 41 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 42 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 43 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 44 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 45 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 46 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 47 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 49 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 50 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 52 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 53 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 54 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 55 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 56 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 57 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 58 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 59 | import android.util.Log; |
| 60 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 61 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 62 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 63 | |
| 64 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 65 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 66 | import java.lang.annotation.Retention; |
| 67 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 68 | import java.net.InetSocketAddress; |
| 69 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 70 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 71 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 72 | import java.security.PrivateKey; |
| 73 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 74 | import java.security.cert.CertificateException; |
| 75 | import java.security.cert.CertificateFactory; |
| 76 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 77 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 78 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 79 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 80 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 81 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 82 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 85 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 86 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 87 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 88 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 89 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 90 | * application calling an api may only pass as an argument a device administrator component it |
| 91 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 92 | * <div class="special reference"> |
| 93 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 94 | * <p> |
| 95 | * For more information about managing policies for device administration, read the <a href= |
| 96 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 97 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | */ |
| 99 | public class DevicePolicyManager { |
| 100 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 101 | |
| 102 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 103 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 104 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 105 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 106 | /** @hide */ |
| 107 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 108 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 111 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 113 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 114 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | mContext = context; |
| 116 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 117 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | /** @hide test will override it. */ |
| 121 | @VisibleForTesting |
| 122 | protected int myUserId() { |
| 123 | return UserHandle.myUserId(); |
| 124 | } |
| 125 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 126 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 127 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 128 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 129 | * <p>A managed profile allows data separation for example for the usage of a |
| 130 | * device as a personal and corporate device. The user which provisioning is started from and |
| 131 | * the managed profile share a launcher. |
| 132 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 133 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 134 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 135 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 136 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 137 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 138 | * {@link #isProvisioningAllowed(String)}. |
| 139 | * |
| 140 | * <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] | 141 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 142 | * 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] | 143 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 144 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 145 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 146 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 147 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 148 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 149 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 150 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 152 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 153 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 154 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 155 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 156 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 157 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 158 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 159 | * <p>When managed provisioning has completed, broadcasts are sent to the application specified |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 160 | * in the provisioning intent. The |
| 161 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 162 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 163 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 164 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 165 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 166 | * completed, along with the above broadcast, activity intent |
| 167 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 168 | * the provisioning intent. |
| 169 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 170 | * <p>If provisioning fails, the managedProfile is removed so the device returns to its |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 171 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 172 | * |
| 173 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 174 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 175 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 176 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 177 | * 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] | 178 | */ |
| 179 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 180 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 181 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 182 | |
| 183 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 184 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 185 | * |
| 186 | * <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] | 187 | * 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] | 188 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 189 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 190 | * allowed. |
| 191 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 192 | * <p>The intent contains the following extras: |
| 193 | * <ul> |
| 194 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 195 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 196 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 197 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 198 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 199 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 200 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 201 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 202 | * |
| 203 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 204 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 205 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 206 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 207 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 208 | * |
| 209 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 210 | */ |
| 211 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 212 | public static final String ACTION_PROVISION_MANAGED_USER |
| 213 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 214 | |
| 215 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 216 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 217 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 218 | * |
| 219 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 220 | * A device owner has full control over the device. The device owner can not be modified by the |
| 221 | * user. |
| 222 | * |
| 223 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 224 | * employee or client. |
| 225 | * |
| 226 | * <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] | 227 | * It is possible to check if provisioning is allowed or not by querying the method |
| 228 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 229 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 230 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 231 | * <ul> |
| 232 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 233 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 234 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 235 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 236 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 237 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 238 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | * </ul> |
| 240 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 241 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 242 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 243 | * device owner. |
| 244 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 245 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 246 | * completed, along with the above broadcast, activity intent |
| 247 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 248 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 249 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 250 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 251 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 252 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 253 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 254 | * 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] | 255 | */ |
| 256 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 257 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 258 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 259 | |
| 260 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 261 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 262 | * |
| 263 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 264 | * the device. A device owner has full control over the device. The device owner can not be |
| 265 | * modified by the user and the only way of resetting the device is via factory reset. |
| 266 | * |
| 267 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 268 | * employee or client. |
| 269 | * |
| 270 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 271 | * |
| 272 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 273 | * by a privileged app with the permission |
| 274 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 275 | * |
| 276 | * <p>The provisioning intent contains the following properties: |
| 277 | * <ul> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 282 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 283 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 284 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 286 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 288 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 290 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 291 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 292 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 293 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 294 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 295 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 296 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 297 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 298 | * |
| 299 | * @hide |
| 300 | */ |
| 301 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 302 | @SystemApi |
| 303 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 304 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 305 | |
| 306 | /** |
| 307 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 308 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 309 | * |
| 310 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 311 | * management state that is distinct from that reached by |
| 312 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 313 | * user, and only has control over device-wide policies, not individual users and their data. |
| 314 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 315 | * this form of device management. |
| 316 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 317 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 318 | * A device owner has full control over the device. The device owner can not be modified by the |
| 319 | * user. |
| 320 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 321 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 322 | * employee or client. |
| 323 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 324 | * <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] | 325 | * It is possible to check if provisioning is allowed or not by querying the method |
| 326 | * {@link #isProvisioningAllowed(String)}. |
| 327 | * |
| 328 | * <p>The intent contains the following extras: |
| 329 | * <ul> |
| 330 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 331 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 332 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 333 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 334 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 335 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 336 | * </ul> |
| 337 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 338 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 339 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 340 | * device owner. |
| 341 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 342 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 343 | * completed, along with the above broadcast, activity intent |
| 344 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 345 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 346 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 347 | * |
| 348 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 349 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 350 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 351 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 352 | * |
| 353 | * @hide |
| 354 | */ |
| 355 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 356 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 357 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 358 | |
| 359 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 360 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 361 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 362 | * <ul> |
| 363 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 364 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 365 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 366 | * </ul> |
| 367 | * |
| 368 | * @hide |
| 369 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 370 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 371 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 372 | public static final String ACTION_PROVISION_FINALIZATION |
| 373 | = "android.app.action.PROVISION_FINALIZATION"; |
| 374 | |
| 375 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 376 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 377 | * |
| 378 | * @hide |
| 379 | */ |
| 380 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 381 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 382 | |
| 383 | /** |
| 384 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 385 | * |
| 386 | * @hide |
| 387 | */ |
| 388 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 389 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 390 | |
| 391 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 392 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 393 | * |
| 394 | * @hide |
| 395 | */ |
| 396 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 397 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 398 | |
| 399 | /** |
| 400 | * Extra for shared bugreport's SHA-256 hash. |
| 401 | * |
| 402 | * @hide |
| 403 | */ |
| 404 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 405 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 406 | |
| 407 | /** |
| 408 | * Extra for remote bugreport notification shown type. |
| 409 | * |
| 410 | * @hide |
| 411 | */ |
| 412 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 413 | "android.app.extra.bugreport_notification_type"; |
| 414 | |
| 415 | /** |
| 416 | * Notification type for a started remote bugreport flow. |
| 417 | * |
| 418 | * @hide |
| 419 | */ |
| 420 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 421 | |
| 422 | /** |
| 423 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 424 | * being taken. |
| 425 | * |
| 426 | * @hide |
| 427 | */ |
| 428 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 429 | |
| 430 | /** |
| 431 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 432 | * |
| 433 | * @hide |
| 434 | */ |
| 435 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 436 | |
| 437 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 438 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 439 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 440 | * |
| 441 | * @hide |
| 442 | */ |
| 443 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 444 | |
| 445 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 446 | * 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] | 447 | * allows a mobile device management application or NFC programmer application which starts |
| 448 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 449 | * <p> |
| 450 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 451 | * sends the intent to pass data to itself on the newly created profile. |
| 452 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 453 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 454 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 455 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 456 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 457 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 458 | * management application after provisioning. |
| 459 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 460 | * <p> |
| 461 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 462 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 463 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 464 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 465 | */ |
| 466 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 467 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 468 | |
| 469 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 470 | * A String extra holding the package name of the mobile device management application that |
| 471 | * will be set as the profile owner or device owner. |
| 472 | * |
| 473 | * <p>If an application starts provisioning directly via an intent with action |
| 474 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 475 | * application that started provisioning. The package will be set as profile owner in that case. |
| 476 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 477 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 478 | * 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] | 479 | * |
| 480 | * <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] | 481 | * This receiver will be set as the profile or device owner and active admin. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 482 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 483 | * @see DeviceAdminReceiver |
| 484 | * @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] | 485 | * supported, but only if there is only one device admin receiver in the package that requires |
| 486 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 487 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 488 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 489 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 490 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 491 | |
| 492 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 493 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 494 | * application that will be set as the profile owner or device owner and active admin. |
| 495 | * |
| 496 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 497 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 498 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 499 | * 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] | 500 | * |
| 501 | * <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] | 502 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 503 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 504 | * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 505 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 506 | * |
| 507 | * @see DeviceAdminReceiver |
| 508 | */ |
| 509 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 510 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 511 | |
| 512 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 513 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 514 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 515 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 516 | * |
| 517 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 518 | */ |
| 519 | |
| 520 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 521 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 522 | |
| 523 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 524 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 525 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 526 | * the account will not be removed from the primary user after it is migrated to the newly |
| 527 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 528 | * |
| 529 | * <p> Defaults to {@code false} |
| 530 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 531 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 532 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 533 | */ |
| 534 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 535 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 536 | |
| 537 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 538 | * A String extra that, holds the email address of the account which a managed profile is |
| 539 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 540 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 541 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 542 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 543 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 544 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 545 | * contains this extra, it is forwarded in the |
| 546 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 547 | * device management application that was set as the profile owner during provisioning. |
| 548 | * 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] | 549 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 550 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 551 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 552 | |
| 553 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 554 | * A integer extra indicating the predominant color to show during the provisioning. |
| 555 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 556 | * |
| 557 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 558 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 559 | */ |
| 560 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 561 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 562 | |
| 563 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 564 | * 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] | 565 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 566 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 567 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 568 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 569 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 570 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 571 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 572 | |
| 573 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 574 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 575 | * will be set to. |
| 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_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 581 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | |
| 583 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 584 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 585 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 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_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 591 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 595 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 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_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 601 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | |
| 603 | /** |
| 604 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 605 | * owner provisioning for downloading the mobile device management application. |
| 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_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 611 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | |
| 613 | /** |
| 614 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 615 | * is hidden or not. |
| 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_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 621 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 625 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 626 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 627 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 628 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 629 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 630 | */ |
| 631 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 632 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * A String extra holding the password of the wifi network in |
| 636 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 637 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 638 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 639 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 640 | */ |
| 641 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 642 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | |
| 644 | /** |
| 645 | * A String extra holding the proxy host for the wifi network in |
| 646 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 647 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 648 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 649 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 650 | */ |
| 651 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 652 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * An int extra holding the proxy port for the wifi network in |
| 656 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 657 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 658 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 659 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 660 | */ |
| 661 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 662 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 663 | |
| 664 | /** |
| 665 | * A String extra holding the proxy bypass for the wifi network in |
| 666 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 667 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 668 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 669 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 670 | */ |
| 671 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 672 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 673 | |
| 674 | /** |
| 675 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 676 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 677 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 678 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 679 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 680 | */ |
| 681 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 682 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 683 | |
| 684 | /** |
| 685 | * A String extra holding a url that specifies the download location of the device admin |
| 686 | * package. When not provided it is assumed that the device admin package is already installed. |
| 687 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 688 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 689 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 690 | */ |
| 691 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 692 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 693 | |
| 694 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 695 | * A String extra holding the localized name of the organization under management. |
| 696 | * |
| 697 | * The name is displayed only during provisioning. |
| 698 | * |
| 699 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 700 | * |
| 701 | * @hide |
| 702 | */ |
| 703 | @SystemApi |
| 704 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 705 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 706 | |
| 707 | /** |
| 708 | * A String extra holding a url to the website of the device's provider. The website can be |
| 709 | * opened in a browser during provisioning. |
| 710 | * |
| 711 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 712 | * |
| 713 | * @hide |
| 714 | */ |
| 715 | @SystemApi |
| 716 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 717 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 718 | |
| 719 | /** |
| 720 | * A String extra holding the localized name of the device admin package. It should be the same |
| 721 | * as the app label of the package. |
| 722 | * |
| 723 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 724 | * |
| 725 | * @hide |
| 726 | */ |
| 727 | @SystemApi |
| 728 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 729 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 730 | |
| 731 | /** |
| 732 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 733 | * shown during the provisioning. |
| 734 | * <h5>The following URI schemes are accepted:</h5> |
| 735 | * <ul> |
| 736 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 737 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 738 | * </ul> |
| 739 | * |
| 740 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 741 | * pixel density for the device. |
| 742 | * |
| 743 | * <p> If a content: URI is passed, the intent should have the flag |
| 744 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 745 | * {@link android.content.ClipData} of the intent too. |
| 746 | * |
| 747 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 748 | * |
| 749 | * @hide |
| 750 | */ |
| 751 | @SystemApi |
| 752 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 753 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 754 | |
| 755 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 756 | * An int extra holding a minimum required version code for the device admin package. If the |
| 757 | * device admin is already installed on the device, it will only be re-downloaded from |
| 758 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 759 | * installed package is less than this version code. |
| 760 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 761 | * <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] | 762 | * provisioning via an NFC bump. |
| 763 | */ |
| 764 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 765 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 766 | |
| 767 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 768 | * A String extra holding a http cookie header which should be used in the http request to the |
| 769 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 770 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 771 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 772 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 773 | */ |
| 774 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 775 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 776 | |
| 777 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 778 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 779 | * the file at download location specified in |
| 780 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 781 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 782 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 783 | * present. The provided checksum must match the checksum of the file at the download |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 784 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 785 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 786 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 787 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 788 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 789 | * |
| 790 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 791 | * 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] | 792 | * 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] | 793 | * 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] | 794 | */ |
| 795 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 796 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 797 | |
| 798 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 799 | * 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] | 800 | * android package archive at the download location specified in {@link |
| 801 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 802 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 803 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 804 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 805 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 806 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 807 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 808 | * present. The provided checksum must match the checksum of any signature of the file at |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 809 | * the download location. If the checksum does not match an error will be shown to the user and |
| 810 | * the user will be asked to factory reset the device. |
| 811 | * |
| 812 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 813 | * provisioning via an NFC bump. |
| 814 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 815 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 816 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 817 | |
| 818 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 819 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 820 | * has completed successfully. |
| 821 | * |
| 822 | * <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] | 823 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 824 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 825 | * <p>This intent will contain the following extras |
| 826 | * <ul> |
| 827 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 828 | * profile.</li> |
| 829 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 830 | * be migrated at provisioning time, if any.</li> |
| 831 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 832 | */ |
| 833 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 834 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 835 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 836 | |
| 837 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 838 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 839 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 840 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 841 | * delivered faster as it's an activity intent. |
| 842 | * |
| 843 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 844 | * the device owner case the profile is the primary user. |
| 845 | * |
| 846 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 847 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 848 | */ |
| 849 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 850 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 851 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 852 | |
| 853 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 854 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 855 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 856 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 857 | * <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] | 858 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 859 | * |
| 860 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 861 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 862 | */ |
| 863 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 864 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 865 | |
| 866 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 867 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 868 | * provisioning. If this extra is not passed, a default image will be shown. |
| 869 | * <h5>The following URI schemes are accepted:</h5> |
| 870 | * <ul> |
| 871 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 872 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 873 | * </ul> |
| 874 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 875 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 876 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 877 | * |
| 878 | * <p> If a content: URI is passed, the intent should have the flag |
| 879 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 880 | * {@link android.content.ClipData} of the intent too. |
| 881 | * |
| 882 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 883 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 884 | */ |
| 885 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 886 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 887 | |
| 888 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 889 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 890 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 891 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 892 | * content. |
| 893 | * |
| 894 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 895 | * management application (MDM), and one disclaimer from the organization. |
| 896 | * |
| 897 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 898 | * |
| 899 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 900 | * |
| 901 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 902 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 903 | */ |
| 904 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 905 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 906 | |
| 907 | /** |
| 908 | * A String extra of localized disclaimer header. |
| 909 | * |
| 910 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 911 | * or the organization name. |
| 912 | * |
| 913 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 914 | * |
| 915 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 916 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 917 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 918 | * |
| 919 | * <pre> |
| 920 | * <meta-data |
| 921 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 922 | * android:resource="@string/disclaimer_header" |
| 923 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 924 | */ |
| 925 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 926 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 927 | |
| 928 | /** |
| 929 | * A {@link Uri} extra pointing to disclaimer content. |
| 930 | * |
| 931 | * <h5>The following URI schemes are accepted:</h5> |
| 932 | * <ul> |
| 933 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 934 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 935 | * </ul> |
| 936 | * |
| 937 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 938 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 939 | * {@link android.widget.TextView}. |
| 940 | * |
| 941 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 942 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 943 | * {@link android.content.ClipData} of the intent too. |
| 944 | * |
| 945 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 946 | * |
| 947 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 948 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 949 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 950 | * |
| 951 | * <pre> |
| 952 | * <meta-data |
| 953 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 954 | * android:resource="@string/disclaimer_content" |
| 955 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 956 | */ |
| 957 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 958 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 959 | |
| 960 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 961 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 962 | * during setup-wizard. |
| 963 | * |
| 964 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 965 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 966 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 967 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 968 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 969 | * |
| 970 | * @hide |
| 971 | */ |
| 972 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 973 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 974 | |
| 975 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 976 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 977 | * skipped. If unspecified, defaults to {@code false}. |
| 978 | * |
| 979 | * It can only be used by an existing device owner trying to create a managed profile via |
| 980 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 981 | */ |
| 982 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 983 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 984 | |
| 985 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 986 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 987 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 988 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 989 | * A device owner has full control over the device. The device owner can not be modified by the |
| 990 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 991 | * reset. |
| 992 | * |
| 993 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 994 | * employee or client. |
| 995 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 996 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 997 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 998 | * <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] | 999 | * contains the following properties: |
| 1000 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1001 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1002 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1003 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1004 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1005 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1006 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1007 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1008 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1009 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1010 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1011 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1012 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1013 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1014 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1015 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1016 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1017 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1018 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1019 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1020 | * 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] | 1021 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1022 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1023 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1024 | */ |
| 1025 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1026 | = "application/com.android.managedprovisioning"; |
| 1027 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1028 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1029 | * Activity action: ask the user to add a new device administrator to the system. |
| 1030 | * The desired policy is the ComponentName of the policy in the |
| 1031 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1032 | * bring the user through adding the device administrator to the system (or |
| 1033 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1034 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1035 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1036 | * field to provide the user with additional explanation (in addition |
| 1037 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1038 | * |
| 1039 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1040 | * user intervention). However, if your administrator has been updated and is requesting |
| 1041 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1042 | * 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] | 1043 | */ |
| 1044 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1045 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1046 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1047 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1048 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1049 | * @hide |
| 1050 | * 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] | 1051 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1052 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1053 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1054 | * 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] | 1055 | * to remotely control restrictions on the user. |
| 1056 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1057 | * <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] | 1058 | * result of whether or not the user approved the action. If approved, the result will |
| 1059 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1060 | * as a profile owner. |
| 1061 | * |
| 1062 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1063 | * field to provide the user with additional explanation (in addition |
| 1064 | * to your component's description) about what is being added. |
| 1065 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1066 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1067 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1068 | */ |
| 1069 | @SystemApi |
| 1070 | public static final String ACTION_SET_PROFILE_OWNER |
| 1071 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1072 | |
| 1073 | /** |
| 1074 | * @hide |
| 1075 | * Name of the profile owner admin that controls the user. |
| 1076 | */ |
| 1077 | @SystemApi |
| 1078 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1079 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1080 | |
| 1081 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1082 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1083 | * 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] | 1084 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1085 | * @hide |
| 1086 | */ |
| 1087 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1088 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1089 | |
| 1090 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1091 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1092 | * |
| 1093 | * This broadcast is sent only to the primary user. |
| 1094 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1095 | */ |
| 1096 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1097 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1098 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1099 | |
| 1100 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1101 | * The ComponentName of the administrator component. |
| 1102 | * |
| 1103 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1104 | */ |
| 1105 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1106 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1107 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1108 | * An optional CharSequence providing additional explanation for why the |
| 1109 | * admin is being added. |
| 1110 | * |
| 1111 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1112 | */ |
| 1113 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1114 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1115 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1116 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1117 | * {@link #createAdminSupportIntent(String)}. |
| 1118 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1119 | */ |
| 1120 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1121 | |
| 1122 | /** |
| 1123 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1124 | * {@link #createAdminSupportIntent(String)}. |
| 1125 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1126 | */ |
| 1127 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1128 | |
| 1129 | /** |
| 1130 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1131 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1132 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1133 | * @see #createAdminSupportIntent(String) |
| 1134 | * @hide |
| 1135 | */ |
| 1136 | @TestApi |
| 1137 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1138 | |
| 1139 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1140 | * Activity action: have the user enter a new password. This activity should |
| 1141 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1142 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1143 | * enter a new password that meets the current requirements. You can use |
| 1144 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1145 | * have the user select a new password in order to meet the current |
| 1146 | * constraints. Upon being resumed from this activity, you can check the new |
| 1147 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1148 | * |
| 1149 | * If the intent is launched from within a managed profile with a profile |
| 1150 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1151 | * this will trigger entering a new password for the parent of the profile. |
| 1152 | * For all other cases it will trigger entering a new password for the user |
| 1153 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1154 | * |
| 1155 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1156 | */ |
| 1157 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1158 | public static final String ACTION_SET_NEW_PASSWORD |
| 1159 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1160 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1161 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1162 | * Activity action: have the user enter a new password for the parent profile. |
| 1163 | * If the intent is launched from within a managed profile, this will trigger |
| 1164 | * entering a new password for the parent of the profile. In all other cases |
| 1165 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1166 | */ |
| 1167 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1168 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1169 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1170 | |
| 1171 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1172 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1173 | * Network logging was enabled and the user tapped the notification. |
| 1174 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1175 | * @hide |
| 1176 | */ |
| 1177 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1178 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1179 | |
| 1180 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1181 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1182 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1183 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1184 | * |
| 1185 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1186 | */ |
| 1187 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1188 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1189 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1190 | |
| 1191 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1192 | * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1193 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1194 | */ |
| 1195 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1196 | |
| 1197 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1198 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1199 | * the parent profile to access intents sent from the managed profile. |
| 1200 | * That is, when an app in the managed profile calls |
| 1201 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1202 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1203 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1204 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1205 | |
| 1206 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1207 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1208 | * the managed profile to access intents sent from the parent profile. |
| 1209 | * That is, when an app in the parent profile calls |
| 1210 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1211 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1212 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1213 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1214 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1215 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1216 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1217 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1218 | */ |
| 1219 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1220 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1221 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1222 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1223 | /** |
| 1224 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1225 | * Already granted or denied permissions are not affected by this. |
| 1226 | */ |
| 1227 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1228 | |
| 1229 | /** |
| 1230 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1231 | * Already granted or denied permissions are not affected by this. |
| 1232 | */ |
| 1233 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1234 | |
| 1235 | /** |
| 1236 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1237 | * Already granted or denied permissions are not affected by this. |
| 1238 | */ |
| 1239 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1240 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1241 | /** |
| 1242 | * Runtime permission state: The user can manage the permission |
| 1243 | * through the UI. |
| 1244 | */ |
| 1245 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1246 | |
| 1247 | /** |
| 1248 | * Runtime permission state: The permission is granted to the app |
| 1249 | * and the user cannot manage the permission through the UI. |
| 1250 | */ |
| 1251 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1252 | |
| 1253 | /** |
| 1254 | * Runtime permission state: The permission is denied to the app |
| 1255 | * and the user cannot manage the permission through the UI. |
| 1256 | */ |
| 1257 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1258 | |
| 1259 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1260 | * Delegation of certificate installation and management. This scope grants access to the |
| 1261 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1262 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1263 | */ |
| 1264 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1265 | |
| 1266 | /** |
| 1267 | * Delegation of application restrictions management. This scope grants access to the |
| 1268 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1269 | */ |
| 1270 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1271 | |
| 1272 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1273 | * Delegation of application uninstall block. This scope grants access to the |
| 1274 | * {@link #setUninstallBlocked} API. |
| 1275 | */ |
| 1276 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1277 | |
| 1278 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1279 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1280 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1281 | * and {@link #setPermissionGrantState} APIs. |
| 1282 | */ |
| 1283 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1284 | |
| 1285 | /** |
| 1286 | * Delegation of package access state. This scope grants access to the |
| 1287 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1288 | * {@link #setPackagesSuspended} APIs. |
| 1289 | */ |
| 1290 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1291 | |
| 1292 | /** |
| 1293 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1294 | * API. |
| 1295 | */ |
| 1296 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1297 | |
| 1298 | /** |
| 1299 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1300 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1301 | * @hide |
| 1302 | */ |
| 1303 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1304 | "delegation-keep-uninstalled-packages"; |
| 1305 | |
| 1306 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1307 | * No management for current user in-effect. This is the default. |
| 1308 | * @hide |
| 1309 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1310 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1311 | public static final int STATE_USER_UNMANAGED = 0; |
| 1312 | |
| 1313 | /** |
| 1314 | * Management partially setup, user setup needs to be completed. |
| 1315 | * @hide |
| 1316 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1317 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1318 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1319 | |
| 1320 | /** |
| 1321 | * Management partially setup, user setup completed. |
| 1322 | * @hide |
| 1323 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1324 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1325 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1326 | |
| 1327 | /** |
| 1328 | * Management setup and active on current user. |
| 1329 | * @hide |
| 1330 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1331 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1332 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1333 | |
| 1334 | /** |
| 1335 | * Management partially setup on a managed profile. |
| 1336 | * @hide |
| 1337 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1338 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1339 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1340 | |
| 1341 | /** |
| 1342 | * @hide |
| 1343 | */ |
| 1344 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1345 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1346 | @Retention(RetentionPolicy.SOURCE) |
| 1347 | public @interface UserProvisioningState {} |
| 1348 | |
| 1349 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1350 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1351 | * |
| 1352 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1353 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1354 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1355 | * |
| 1356 | * @hide |
| 1357 | */ |
| 1358 | public static final int CODE_OK = 0; |
| 1359 | |
| 1360 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1361 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1362 | * |
| 1363 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1364 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1365 | * owner. |
| 1366 | * |
| 1367 | * @hide |
| 1368 | */ |
| 1369 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1370 | |
| 1371 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1372 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1373 | * |
| 1374 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1375 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1376 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1377 | * |
| 1378 | * @hide |
| 1379 | */ |
| 1380 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1381 | |
| 1382 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1383 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1384 | * |
| 1385 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1386 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1387 | * |
| 1388 | * @hide |
| 1389 | */ |
| 1390 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1391 | |
| 1392 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1393 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1394 | * |
| 1395 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1396 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1397 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1398 | * |
| 1399 | * @hide |
| 1400 | */ |
| 1401 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1402 | |
| 1403 | /** |
| 1404 | * Code used to indicate that the device also has a user other than the system user. |
| 1405 | * |
| 1406 | * @hide |
| 1407 | */ |
| 1408 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1409 | |
| 1410 | /** |
| 1411 | * Code used to indicate that device has an account that prevents provisioning. |
| 1412 | * |
| 1413 | * @hide |
| 1414 | */ |
| 1415 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1416 | |
| 1417 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1418 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1419 | * |
| 1420 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1421 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1422 | * |
| 1423 | * @hide |
| 1424 | */ |
| 1425 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1426 | |
| 1427 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1428 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1429 | * |
| 1430 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1431 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1432 | * when the device is a watch and is already paired. |
| 1433 | * |
| 1434 | * @hide |
| 1435 | */ |
| 1436 | public static final int CODE_HAS_PAIRED = 8; |
| 1437 | |
| 1438 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1439 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1440 | * |
| 1441 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1442 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1443 | * |
| 1444 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1445 | * @hide |
| 1446 | */ |
| 1447 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1448 | |
| 1449 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1450 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1451 | * |
| 1452 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1453 | * |
| 1454 | * @hide |
| 1455 | */ |
| 1456 | public static final int CODE_SYSTEM_USER = 10; |
| 1457 | |
| 1458 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1459 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1460 | * |
| 1461 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1462 | * managed profiles. |
| 1463 | * |
| 1464 | * @hide |
| 1465 | */ |
| 1466 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1467 | |
| 1468 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1469 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1470 | * |
| 1471 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1472 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1473 | * user. |
| 1474 | * |
| 1475 | * @hide |
| 1476 | */ |
| 1477 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1478 | |
| 1479 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1480 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1481 | * |
| 1482 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1483 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1484 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1485 | * admins. |
| 1486 | * |
| 1487 | * @hide |
| 1488 | */ |
| 1489 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1490 | |
| 1491 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1492 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1493 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1494 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1495 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1496 | * |
| 1497 | * @hide |
| 1498 | */ |
| 1499 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1500 | |
| 1501 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1502 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1503 | * |
| 1504 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1505 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1506 | * |
| 1507 | * @hide |
| 1508 | */ |
| 1509 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1510 | |
| 1511 | /** |
| 1512 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1513 | * conditions. |
| 1514 | * |
| 1515 | * @hide |
| 1516 | */ |
| 1517 | @Retention(RetentionPolicy.SOURCE) |
| 1518 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1519 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1520 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1521 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1522 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1523 | public @interface ProvisioningPreCondition {} |
| 1524 | |
| 1525 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1526 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1527 | * |
| 1528 | * @param admin The administrator component to check for. |
| 1529 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1530 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1531 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1532 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1533 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1534 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /** |
| 1538 | * @see #isAdminActive(ComponentName) |
| 1539 | * @hide |
| 1540 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1541 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1542 | if (mService != null) { |
| 1543 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1544 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1545 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1546 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | return false; |
| 1550 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1551 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1552 | /** |
| 1553 | * Return true if the given administrator component is currently being removed |
| 1554 | * for the user. |
| 1555 | * @hide |
| 1556 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1557 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1558 | if (mService != null) { |
| 1559 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1560 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1561 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1562 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | return false; |
| 1566 | } |
| 1567 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1568 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1569 | * Return a list of all currently active device administrators' component |
| 1570 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1571 | * returned. |
| 1572 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1573 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1574 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1575 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * @see #getActiveAdmins() |
| 1580 | * @hide |
| 1581 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1582 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1583 | if (mService != null) { |
| 1584 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1585 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1586 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1587 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1588 | } |
| 1589 | } |
| 1590 | return null; |
| 1591 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1592 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1593 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1594 | * Used by package administration code to determine if a package can be stopped |
| 1595 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1596 | * @hide |
| 1597 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1598 | @SystemApi |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1599 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1600 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * Used by package administration code to determine if a package can be stopped |
| 1605 | * or uninstalled. |
| 1606 | * @hide |
| 1607 | */ |
| 1608 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1609 | if (mService != null) { |
| 1610 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1611 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1612 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1613 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | return false; |
| 1617 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1618 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1619 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1620 | * Remove a current administration component. This can only be called |
| 1621 | * by the application that owns the administration component; if you |
| 1622 | * try to remove someone else's component, a security exception will be |
| 1623 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1624 | * |
| 1625 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1626 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1627 | * |
| 1628 | * @param admin The administration compononent to remove. |
| 1629 | * @throws SecurityException if the caller is not in the owner application of {@code admin}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1630 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1631 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1632 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1633 | if (mService != null) { |
| 1634 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1635 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1636 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1637 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1641 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1642 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1643 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1644 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1645 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1646 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1647 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1648 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1649 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1650 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1651 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1652 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1653 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1654 | if (mService != null) { |
| 1655 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1656 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1657 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1658 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1659 | } |
| 1660 | } |
| 1661 | return false; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1665 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1666 | * |
| 1667 | * @hide |
| 1668 | */ |
| 1669 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1670 | if (mService != null) { |
| 1671 | try { |
| 1672 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1673 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1674 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | return false; |
| 1678 | } |
| 1679 | |
| 1680 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1681 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1682 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1683 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1684 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1685 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1686 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1687 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1688 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1689 | * recognition technology. This implies technologies that can recognize the identity of |
| 1690 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1691 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1692 | */ |
| 1693 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1694 | |
| 1695 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1696 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1697 | * 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] | 1698 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1699 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1700 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1701 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1702 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1703 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1704 | * password containing at least numeric characters. Note that quality |
| 1705 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1706 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1707 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1708 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1709 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1710 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1711 | * password containing at least numeric characters with no repeating (4444) |
| 1712 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1713 | * constants are ordered so that higher values are more restrictive. |
| 1714 | */ |
| 1715 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1716 | |
| 1717 | /** |
| 1718 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1719 | * password containing at least alphabetic (or other symbol) characters. |
| 1720 | * Note that quality constants are ordered so that higher values are more |
| 1721 | * restrictive. |
| 1722 | */ |
| 1723 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1724 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1725 | /** |
| 1726 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1727 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1728 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1729 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1730 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1731 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1732 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1733 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1734 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1735 | * password containing at least a letter, a numerical digit and a special |
| 1736 | * symbol, by default. With this password quality, passwords can be |
| 1737 | * restricted to contain various sets of characters, like at least an |
| 1738 | * uppercase letter, etc. These are specified using various methods, |
| 1739 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1740 | * that quality constants are ordered so that higher values are more |
| 1741 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1742 | */ |
| 1743 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1744 | |
| 1745 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1746 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1747 | * modify password. In case this password quality is set, the password is |
| 1748 | * managed by a profile owner. The profile owner can set any password, |
| 1749 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1750 | * that quality constants are ordered so that higher values are more |
| 1751 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1752 | * the highest. |
| 1753 | * @hide |
| 1754 | */ |
| 1755 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1756 | |
| 1757 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1758 | * @hide |
| 1759 | * |
| 1760 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1761 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1762 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1763 | * used by authenticator to exempt their accounts from this: |
| 1764 | * |
| 1765 | * <ul> |
| 1766 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1767 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1768 | * <application> tag in the manifest. |
| 1769 | * |
| 1770 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1771 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1772 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1773 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1774 | * if any of the accounts have it. |
| 1775 | * </ul> |
| 1776 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1777 | @SystemApi |
| 1778 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1779 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1780 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1781 | |
| 1782 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1783 | @SystemApi |
| 1784 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1785 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1786 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1787 | |
| 1788 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1789 | * Called by an application that is administering the device to set the password restrictions it |
| 1790 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1791 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1792 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1793 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1794 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1795 | * <p> |
| 1796 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1797 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1798 | * considerations) is the one that is in effect. |
| 1799 | * <p> |
| 1800 | * The calling device admin must have requested |
| 1801 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1802 | * not, a security exception will be thrown. |
| 1803 | * <p> |
| 1804 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1805 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1806 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1807 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1808 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1809 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1810 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1811 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1812 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1813 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1814 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1815 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1816 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1817 | if (mService != null) { |
| 1818 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1819 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1820 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1821 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1825 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1826 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1827 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1828 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1829 | * a separate challenge are not taken into account. |
| 1830 | * |
| 1831 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1832 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1833 | * restrictions on the parent profile. |
| 1834 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1835 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1836 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1837 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1838 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1839 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1843 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1844 | if (mService != null) { |
| 1845 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1846 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1847 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1848 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1849 | } |
| 1850 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1851 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1852 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1853 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1854 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1855 | * Called by an application that is administering the device to set the minimum allowed password |
| 1856 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1857 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1858 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1859 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1860 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1861 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1862 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1863 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1864 | * {@link #setPasswordQuality}. |
| 1865 | * <p> |
| 1866 | * The calling device admin must have requested |
| 1867 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1868 | * not, a security exception will be thrown. |
| 1869 | * <p> |
| 1870 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1871 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1872 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1873 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1874 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1875 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1876 | * restriction. |
| 1877 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1878 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1879 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1880 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1881 | if (mService != null) { |
| 1882 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1883 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1884 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1885 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1886 | } |
| 1887 | } |
| 1888 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1889 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1890 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1891 | * Retrieve the current minimum password length for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1892 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1893 | * a separate challenge are not taken into account. |
| 1894 | * |
| 1895 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1896 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1897 | * restrictions on the parent profile. |
| 1898 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1899 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1900 | * @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] | 1901 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1902 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1903 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1904 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1908 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1909 | if (mService != null) { |
| 1910 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1911 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1912 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1913 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | return 0; |
| 1917 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1918 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1919 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1920 | * Called by an application that is administering the device to set the minimum number of upper |
| 1921 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1922 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1923 | * current password will remain until the user has set a new one, so the change does not take |
| 1924 | * place immediately. To prompt the user for a new password, use |
| 1925 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1926 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1927 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1928 | * <p> |
| 1929 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1930 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1931 | * not, a security exception will be thrown. |
| 1932 | * <p> |
| 1933 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1934 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1935 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1936 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1937 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1938 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1939 | * A value of 0 means there is no restriction. |
| 1940 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1941 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1942 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1943 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1944 | if (mService != null) { |
| 1945 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1946 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1947 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1948 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1954 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1955 | * for a particular admin or all admins that set restrictions on this user and |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1956 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1957 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1958 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1959 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1960 | * and only applies when the password quality is |
| 1961 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1962 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1963 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1964 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1965 | * restrictions on the parent profile. |
| 1966 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1967 | * @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] | 1968 | * aggregate all admins. |
| 1969 | * @return The minimum number of upper case letters required in the |
| 1970 | * password. |
| 1971 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1972 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1973 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1977 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1978 | if (mService != null) { |
| 1979 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1980 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1981 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1982 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | return 0; |
| 1986 | } |
| 1987 | |
| 1988 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1989 | * Called by an application that is administering the device to set the minimum number of lower |
| 1990 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1991 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1992 | * current password will remain until the user has set a new one, so the change does not take |
| 1993 | * place immediately. To prompt the user for a new password, use |
| 1994 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1995 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1996 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1997 | * <p> |
| 1998 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1999 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2000 | * not, a security exception will be thrown. |
| 2001 | * <p> |
| 2002 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2003 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2004 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2005 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2006 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2007 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2008 | * A value of 0 means there is no restriction. |
| 2009 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2010 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2011 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2012 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2013 | if (mService != null) { |
| 2014 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2015 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2016 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2017 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2023 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2024 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2025 | * and its participating profiles. Restrictions on profiles that have |
| 2026 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2027 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2028 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2029 | * and only applies when the password quality is |
| 2030 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2031 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2032 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2033 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2034 | * restrictions on the parent profile. |
| 2035 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2036 | * @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] | 2037 | * aggregate all admins. |
| 2038 | * @return The minimum number of lower case letters required in the |
| 2039 | * password. |
| 2040 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2041 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2042 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2046 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2047 | if (mService != null) { |
| 2048 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2049 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2050 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2051 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2058 | * Called by an application that is administering the device to set the minimum number of |
| 2059 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2060 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2061 | * password will remain until the user has set a new one, so the change does not take place |
| 2062 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2063 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2064 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2065 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2066 | * <p> |
| 2067 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2068 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2069 | * not, a security exception will be thrown. |
| 2070 | * <p> |
| 2071 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2072 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2073 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2074 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2075 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2076 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2077 | * 0 means there is no restriction. |
| 2078 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2079 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2080 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2081 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2082 | if (mService != null) { |
| 2083 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2084 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2085 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2086 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2092 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2093 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2094 | * and its participating profiles. Restrictions on profiles that have |
| 2095 | * a separate challenge are not taken into account. |
| 2096 | * This is the same value as set by |
| 2097 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2098 | * and only applies when the password quality is |
| 2099 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2100 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2101 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2102 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2103 | * restrictions on the parent profile. |
| 2104 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2105 | * @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] | 2106 | * aggregate all admins. |
| 2107 | * @return The minimum number of letters required in the password. |
| 2108 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2109 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2110 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2114 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2115 | if (mService != null) { |
| 2116 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2117 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2118 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2119 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | return 0; |
| 2123 | } |
| 2124 | |
| 2125 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2126 | * Called by an application that is administering the device to set the minimum number of |
| 2127 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2128 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2129 | * current password will remain until the user has set a new one, so the change does not take |
| 2130 | * place immediately. To prompt the user for a new password, use |
| 2131 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2132 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2133 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2134 | * <p> |
| 2135 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2136 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2137 | * not, a security exception will be thrown. |
| 2138 | * <p> |
| 2139 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2140 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2141 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2142 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2143 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2144 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2145 | * value of 0 means there is no restriction. |
| 2146 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2147 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2148 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2149 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2150 | if (mService != null) { |
| 2151 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2152 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2153 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2154 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2155 | } |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | /** |
| 2160 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2161 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2162 | * and its participating profiles. Restrictions on profiles that have |
| 2163 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2164 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2165 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2166 | * and only applies when the password quality is |
| 2167 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2168 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2169 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2170 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2171 | * restrictions on the parent profile. |
| 2172 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2173 | * @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] | 2174 | * aggregate all admins. |
| 2175 | * @return The minimum number of numerical digits required in the password. |
| 2176 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2177 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2178 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2182 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2183 | if (mService != null) { |
| 2184 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2185 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2186 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2187 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2188 | } |
| 2189 | } |
| 2190 | return 0; |
| 2191 | } |
| 2192 | |
| 2193 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2194 | * Called by an application that is administering the device to set the minimum number of |
| 2195 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2196 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2197 | * password will remain until the user has set a new one, so the change does not take place |
| 2198 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2199 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2200 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2201 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2202 | * <p> |
| 2203 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2204 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2205 | * not, a security exception will be thrown. |
| 2206 | * <p> |
| 2207 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2208 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2209 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2210 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2211 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2212 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2213 | * 0 means there is no restriction. |
| 2214 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2215 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2216 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2217 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2218 | if (mService != null) { |
| 2219 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2220 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2221 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2222 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2228 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2229 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2230 | * and its participating profiles. Restrictions on profiles that have |
| 2231 | * a separate challenge are not taken into account. This is the same value as |
| 2232 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2233 | * and only applies when the password quality is |
| 2234 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2235 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2236 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2237 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2238 | * restrictions on the parent profile. |
| 2239 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2240 | * @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] | 2241 | * aggregate all admins. |
| 2242 | * @return The minimum number of symbols required in the password. |
| 2243 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2244 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2245 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2249 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2250 | if (mService != null) { |
| 2251 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2252 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2253 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2254 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | return 0; |
| 2258 | } |
| 2259 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2260 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2261 | * Called by an application that is administering the device to set the minimum number of |
| 2262 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2263 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2264 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2265 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2266 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2267 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2268 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2269 | * <p> |
| 2270 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2271 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2272 | * not, a security exception will be thrown. |
| 2273 | * <p> |
| 2274 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2275 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2276 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2277 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2278 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2279 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2280 | * 0 means there is no restriction. |
| 2281 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2282 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2283 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2284 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2285 | if (mService != null) { |
| 2286 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2287 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2288 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2289 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2295 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2296 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2297 | * and its participating profiles. Restrictions on profiles that have |
| 2298 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2299 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2300 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2301 | * and only applies when the password quality is |
| 2302 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2303 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2304 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2305 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2306 | * restrictions on the parent profile. |
| 2307 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2308 | * @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] | 2309 | * aggregate all admins. |
| 2310 | * @return The minimum number of letters required in the password. |
| 2311 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2312 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2313 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2317 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2318 | if (mService != null) { |
| 2319 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2320 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2321 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2322 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | return 0; |
| 2326 | } |
| 2327 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2328 | /** |
| 2329 | * Called by an application that is administering the device to set the length of the password |
| 2330 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2331 | * same as any password in the history. Note that the current password will remain until the |
| 2332 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2333 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2334 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2335 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2336 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2337 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2338 | * <p> |
| 2339 | * The calling device admin must have requested |
| 2340 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2341 | * not, a security exception will be thrown. |
| 2342 | * <p> |
| 2343 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2344 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2345 | * profile. |
| 2346 | * |
| 2347 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2348 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2349 | * restriction. |
| 2350 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2351 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2352 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2353 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2354 | if (mService != null) { |
| 2355 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2356 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2357 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2358 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2364 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2365 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2366 | * device password (for all admins). |
| 2367 | * <p> |
| 2368 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2369 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2370 | * 432000000 ms for timeout. |
| 2371 | * <p> |
| 2372 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2373 | * <p> |
| 2374 | * The calling device admin must have requested |
| 2375 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2376 | * not, a security exception will be thrown. |
| 2377 | * <p> |
| 2378 | * Note that setting the password will automatically reset the expiration time for all active |
| 2379 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2380 | * <p> |
| 2381 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2382 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2383 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2384 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2385 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2386 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2387 | * there is no restriction (unlimited). |
| 2388 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2389 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2390 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2391 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2392 | if (mService != null) { |
| 2393 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2394 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2395 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2396 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2402 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2403 | * recurring expiration timeout provided in the call to |
| 2404 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2405 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2406 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2407 | * |
| 2408 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2409 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2410 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2411 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2412 | * @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] | 2413 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2414 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2415 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2416 | if (mService != null) { |
| 2417 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2418 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2419 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2420 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | return 0; |
| 2424 | } |
| 2425 | |
| 2426 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2427 | * Get the current password expiration time for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2428 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2429 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2430 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2431 | * |
| 2432 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2433 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2434 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2435 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2436 | * @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] | 2437 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2438 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2439 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2440 | if (mService != null) { |
| 2441 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2442 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2443 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2444 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2445 | } |
| 2446 | } |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
| 2450 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2451 | * Retrieve the current password history length for a particular admin or all admins that |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2452 | * set restrictions on this user and its participating profiles. Restrictions on profiles that |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2453 | * have a separate challenge are not taken into account. |
| 2454 | * |
| 2455 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2456 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2457 | * restrictions on the parent profile. |
| 2458 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2459 | * @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] | 2460 | * all admins. |
| 2461 | * @return The length of the password history |
| 2462 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2463 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2464 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2468 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2469 | if (mService != null) { |
| 2470 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2471 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2472 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2473 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | return 0; |
| 2477 | } |
| 2478 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2479 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2480 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2481 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2482 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2483 | * @return Returns the maximum length that the user can enter. |
| 2484 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2485 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2486 | // Kind-of arbitrary. |
| 2487 | return 16; |
| 2488 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2489 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2490 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2491 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2492 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2493 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2494 | * are not taken into account. The user must be unlocked in order to perform the check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2495 | * <p> |
| 2496 | * The calling device admin must have requested |
| 2497 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2498 | * not, a security exception will be thrown. |
| 2499 | * <p> |
| 2500 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2501 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2502 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2503 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2504 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2505 | * @throws SecurityException if the calling application does not own an active administrator |
| 2506 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2507 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2508 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2509 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2510 | if (mService != null) { |
| 2511 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2512 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2513 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2514 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2515 | } |
| 2516 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2517 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2518 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2519 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2520 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2521 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2522 | * 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] | 2523 | * requested by the admins of the parent user and its profiles. |
| 2524 | * |
| 2525 | * @param userHandle the userId of the profile to check the password for. |
| 2526 | * @return Returns true if the password would meet the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2527 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2528 | * @hide |
| 2529 | */ |
| 2530 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2531 | if (mService != null) { |
| 2532 | try { |
| 2533 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2534 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2535 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | return false; |
| 2539 | } |
| 2540 | |
| 2541 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2542 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2543 | * successful password entry. |
| 2544 | * <p> |
| 2545 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2546 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2547 | * password attemts for the parent user. |
| 2548 | * <p> |
| 2549 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2550 | * to be able to call this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2551 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2552 | * @return The number of times user has entered an incorrect password since the last correct |
| 2553 | * password entry. |
| 2554 | * @throws SecurityException if the calling application does not own an active administrator |
| 2555 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2556 | */ |
| 2557 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2558 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2559 | } |
| 2560 | |
| 2561 | /** |
| 2562 | * Retrieve the number of times the given user has failed at entering a |
| 2563 | * password since that last successful password entry. |
| 2564 | * |
| 2565 | * <p>The calling device admin must have requested |
| 2566 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2567 | * not and it is not the system uid, a security exception will be thrown. |
| 2568 | * |
| 2569 | * @hide |
| 2570 | */ |
| 2571 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2572 | if (mService != null) { |
| 2573 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2574 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2575 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2576 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | return -1; |
| 2580 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2581 | |
| 2582 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2583 | * 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] | 2584 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2585 | * @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] | 2586 | * @hide |
| 2587 | */ |
| 2588 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2589 | if (mService != null) { |
| 2590 | try { |
| 2591 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2592 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2593 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | return false; |
| 2597 | } |
| 2598 | |
| 2599 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2600 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2601 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2602 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2603 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2604 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2605 | * <p> |
| 2606 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2607 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2608 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2609 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2610 | * immediately, and your callback will not be invoked. |
| 2611 | * <p> |
| 2612 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2613 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2614 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2615 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2616 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2617 | * @param num The number of failed password attempts at which point the device or profile will |
| 2618 | * be wiped. |
| 2619 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2620 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2621 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2622 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2623 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2624 | if (mService != null) { |
| 2625 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2626 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2627 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2628 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2632 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2633 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2634 | * Retrieve the current maximum number of login attempts that are allowed before the device |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2635 | * or profile is wiped, for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2636 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2637 | * not taken into account. |
| 2638 | * |
| 2639 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2640 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2641 | * the value for the parent profile. |
| 2642 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2643 | * @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] | 2644 | * all admins. |
| 2645 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2646 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2647 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2651 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2652 | if (mService != null) { |
| 2653 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2654 | return mService.getMaximumFailedPasswordsForWipe( |
| 2655 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2656 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2657 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2658 | } |
| 2659 | } |
| 2660 | return 0; |
| 2661 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2662 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2663 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2664 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2665 | * for the given user. So for primary user, it might return the primary or |
| 2666 | * a managed profile. For a secondary user, it would be the same as the |
| 2667 | * user passed in. |
| 2668 | * @hide Used only by Keyguard |
| 2669 | */ |
| 2670 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2671 | if (mService != null) { |
| 2672 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2673 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2674 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2675 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2676 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2677 | } |
| 2678 | } |
| 2679 | return UserHandle.USER_NULL; |
| 2680 | } |
| 2681 | |
| 2682 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2683 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2684 | * the password again until the user has entered it. |
| 2685 | */ |
| 2686 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2687 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2688 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2689 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2690 | * If the flag is set, the device can be booted without asking for user password. |
| 2691 | * The absence of this flag does not change the current boot requirements. This flag |
| 2692 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2693 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2694 | * device to factory defaults. |
| 2695 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2696 | 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] | 2697 | |
| 2698 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2699 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2700 | * individual accounts) on the user. This takes effect immediately. |
| 2701 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2702 | * <em>For device owner and profile owners targeting SDK level |
| 2703 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 2704 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 2705 | * instead. </em> |
| 2706 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2707 | * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2708 | * device admins that are not device owner and not profile owner. |
| 2709 | * The password can now only be changed if there is currently no password set. Device owner |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2710 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2711 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2712 | * <p> |
| 2713 | * The given password must be sufficient for the current password quality and length constraints |
| 2714 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2715 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2716 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2717 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2718 | * case the currently active quality will be increased to match. |
| 2719 | * <p> |
| 2720 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
Robin Lee | ce5c400 | 2016-03-23 17:05:03 +0000 | [diff] [blame] | 2721 | * current password constraints allow it. <em>Note: This will not work in |
| 2722 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2723 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2724 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2725 | * <p> |
| 2726 | * The calling device admin must have requested |
| 2727 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2728 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2729 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2730 | * @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] | 2731 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2732 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2733 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2734 | * current constraints or if the user has not been decrypted yet. |
| 2735 | * @throws SecurityException if the calling application does not own an active administrator |
| 2736 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2737 | * @throws IllegalStateException if the calling user is locked or has a managed profile. |
Andrew Scull | 3f81f4e | 2016-07-29 16:29:58 +0100 | [diff] [blame] | 2738 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2739 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2740 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2741 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2742 | if (mService != null) { |
| 2743 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2744 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2745 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2746 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2747 | } |
| 2748 | } |
| 2749 | return false; |
| 2750 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2751 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2752 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2753 | * Called by a profile or device owner to provision a token which can later be used to reset the |
| 2754 | * device lockscreen password (if called by device owner), or work challenge (if called by |
| 2755 | * profile owner), via {@link #resetPasswordWithToken}. |
| 2756 | * <p> |
| 2757 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 2758 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 2759 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 2760 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 2761 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 2762 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 2763 | * the device reboots. In this case a new token needs to be provisioned again. |
| 2764 | * <p> |
| 2765 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 2766 | * or clears the lockscreen password. |
| 2767 | * <p> |
| 2768 | * <em>This token is highly sensitive and should be treated at the same level as user |
| 2769 | * credentials. In particular, NEVER store this token on device in plaintext, especially in |
| 2770 | * Device-Encrypted storage if the token will be used to reset password on FBE devices before |
| 2771 | * user unlocks. |
| 2772 | * </em> |
| 2773 | * |
| 2774 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2775 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 2776 | * cryptographically strong random number generator. |
| 2777 | * @return true if the operation is successful, false otherwise. |
| 2778 | * @throws IllegalArgumentException if the supplied token is invalid. |
| 2779 | * @throws SecurityException |
| 2780 | */ |
| 2781 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 2782 | throwIfParentInstance("setResetPasswordToken"); |
| 2783 | if (mService != null) { |
| 2784 | try { |
| 2785 | return mService.setResetPasswordToken(admin, token); |
| 2786 | } catch (RemoteException e) { |
| 2787 | throw e.rethrowFromSystemServer(); |
| 2788 | } |
| 2789 | } |
| 2790 | return false; |
| 2791 | } |
| 2792 | |
| 2793 | /** |
| 2794 | * Called by a profile or device owner to revoke the current password reset token. |
| 2795 | * |
| 2796 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2797 | * @return true if the operation is successful, false otherwise. |
| 2798 | */ |
| 2799 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 2800 | throwIfParentInstance("clearResetPasswordToken"); |
| 2801 | if (mService != null) { |
| 2802 | try { |
| 2803 | return mService.clearResetPasswordToken(admin); |
| 2804 | } catch (RemoteException e) { |
| 2805 | throw e.rethrowFromSystemServer(); |
| 2806 | } |
| 2807 | } |
| 2808 | return false; |
| 2809 | } |
| 2810 | |
| 2811 | /** |
| 2812 | * Called by a profile or device owner to check if the current reset password token is active. |
| 2813 | * |
| 2814 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2815 | * @return true if the token is active, false otherwise. |
| 2816 | * @throws IllegalStateException if no token has been set. |
| 2817 | */ |
| 2818 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 2819 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 2820 | if (mService != null) { |
| 2821 | try { |
| 2822 | return mService.isResetPasswordTokenActive(admin); |
| 2823 | } catch (RemoteException e) { |
| 2824 | throw e.rethrowFromSystemServer(); |
| 2825 | } |
| 2826 | } |
| 2827 | return false; |
| 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * Called by device or profile owner to force set a new device unlock password or a work profile |
| 2832 | * challenge on current user. This takes effect immediately. |
| 2833 | * <p> |
| 2834 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 2835 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 2836 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 2837 | * <p> |
| 2838 | * The given password must be sufficient for the current password quality and length constraints |
| 2839 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2840 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2841 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2842 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2843 | * case the currently active quality will be increased to match. |
| 2844 | * <p> |
| 2845 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
| 2846 | * current password constraints allow it. |
| 2847 | * |
| 2848 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2849 | * @param password The new password for the user. Null or empty clears the password. |
| 2850 | * @param token the password reset token previously provisioned by #setResetPasswordToken. |
| 2851 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
| 2852 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2853 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2854 | * current constraints. |
| 2855 | * @throws SecurityException if the calling application does not own an active administrator |
| 2856 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
| 2857 | * @throws IllegalStateException if the provided token is not valid. |
| 2858 | * @throws IllegalArgumentException if the password does not meet system requirements. |
| 2859 | */ |
| 2860 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 2861 | byte[] token, int flags) { |
| 2862 | throwIfParentInstance("resetPassword"); |
| 2863 | if (mService != null) { |
| 2864 | try { |
| 2865 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 2866 | } catch (RemoteException e) { |
| 2867 | throw e.rethrowFromSystemServer(); |
| 2868 | } |
| 2869 | } |
| 2870 | return false; |
| 2871 | } |
| 2872 | |
| 2873 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2874 | * Called by an application that is administering the device to set the maximum time for user |
| 2875 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2876 | * effect immediately. |
| 2877 | * <p> |
| 2878 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2879 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2880 | * <p> |
| 2881 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2882 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2883 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2884 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2885 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2886 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2887 | * is no restriction. |
| 2888 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2889 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2890 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2891 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2892 | if (mService != null) { |
| 2893 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2894 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2895 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2896 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2897 | } |
| 2898 | } |
| 2899 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2900 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2901 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2902 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2903 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2904 | * a separate challenge are not taken into account. |
| 2905 | * |
| 2906 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2907 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2908 | * restrictions on the parent profile. |
| 2909 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2910 | * @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] | 2911 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2912 | * @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] | 2913 | * 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] | 2914 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2915 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2916 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2920 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2921 | if (mService != null) { |
| 2922 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2923 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2924 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2925 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | return 0; |
| 2929 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2930 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2931 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2932 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2933 | * do not have a separate timeout to lock for work challenge only. |
| 2934 | * |
| 2935 | * @hide |
| 2936 | */ |
| 2937 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2938 | if (mService != null) { |
| 2939 | try { |
| 2940 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2941 | } catch (RemoteException e) { |
| 2942 | throw e.rethrowFromSystemServer(); |
| 2943 | } |
| 2944 | } |
| 2945 | return 0; |
| 2946 | } |
| 2947 | |
| 2948 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2949 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2950 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2951 | * authentication method like password, pin or pattern. |
| 2952 | * |
| 2953 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2954 | * specified timeout each time it has been successfully used. |
| 2955 | * |
| 2956 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2957 | * |
| 2958 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2959 | * |
| 2960 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2961 | * a {@link SecurityException} will be thrown. |
| 2962 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2963 | * <p>The calling device admin can verify the value it has set by calling |
| 2964 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2965 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2966 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2967 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2968 | * profile. |
| 2969 | * |
| 2970 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2971 | * @param timeoutMs The new timeout, after which the user will have to unlock with strong |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2972 | * authentication method. A value of 0 means the admin is not participating in |
| 2973 | * controlling the timeout. |
| 2974 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2975 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2976 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2977 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2978 | * |
| 2979 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2980 | */ |
| 2981 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2982 | long timeoutMs) { |
| 2983 | if (mService != null) { |
| 2984 | try { |
| 2985 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2986 | } catch (RemoteException e) { |
| 2987 | throw e.rethrowFromSystemServer(); |
| 2988 | } |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | /** |
| 2993 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2994 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2995 | * After the returned timeout the user is required to use strong authentication method. |
| 2996 | * |
| 2997 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2998 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2999 | * restrictions on the parent profile. |
| 3000 | * |
| 3001 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 3002 | * accross all participating admins. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3003 | * @return The timeout or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3004 | */ |
| 3005 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3006 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3007 | } |
| 3008 | |
| 3009 | /** @hide per-user version */ |
| 3010 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3011 | if (mService != null) { |
| 3012 | try { |
| 3013 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3014 | } catch (RemoteException e) { |
| 3015 | throw e.rethrowFromSystemServer(); |
| 3016 | } |
| 3017 | } |
| 3018 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3019 | } |
| 3020 | |
| 3021 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3022 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3023 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3024 | * credential encryption key that will be stored back in the keyring for future use. |
| 3025 | * <p> |
| 3026 | * This flag can only be used by a profile owner when locking a managed profile on an FBE |
| 3027 | * device. |
| 3028 | * <p> |
| 3029 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3030 | * until they are next run to perform further actions. |
| 3031 | */ |
| 3032 | public static final int FLAG_EVICT_CE_KEY = 1; |
| 3033 | |
| 3034 | /** @hide */ |
| 3035 | @Retention(RetentionPolicy.SOURCE) |
| 3036 | @IntDef(flag=true, value={FLAG_EVICT_CE_KEY}) |
| 3037 | public @interface LockNowFlag {} |
| 3038 | |
| 3039 | /** |
| 3040 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3041 | * this call. |
| 3042 | * <p> |
| 3043 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3044 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3045 | * <p> |
| 3046 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3047 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3048 | * <p> |
| 3049 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3050 | * |
| 3051 | * @throws SecurityException if the calling application does not own an active administrator |
| 3052 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3053 | */ |
| 3054 | public void lockNow() { |
| 3055 | lockNow(0); |
| 3056 | } |
| 3057 | |
| 3058 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3059 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3060 | * this call. |
| 3061 | * <p> |
| 3062 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3063 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3064 | * <p> |
| 3065 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3066 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3067 | * |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3068 | * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3069 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3070 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
| 3071 | * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile |
| 3072 | * owner of a managed profile. |
| 3073 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when |
| 3074 | * locking the parent profile. |
| 3075 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a |
| 3076 | * non-FBE device. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3077 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3078 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3079 | if (mService != null) { |
| 3080 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3081 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3082 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3083 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3084 | } |
| 3085 | } |
| 3086 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3087 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3088 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3089 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3090 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3091 | */ |
| 3092 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3093 | |
| 3094 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3095 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3096 | * data. |
| 3097 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3098 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3099 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3100 | */ |
| 3101 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3102 | |
| 3103 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3104 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3105 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3106 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3107 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3108 | * <p> |
| 3109 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3110 | * be able to call this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3111 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3112 | * @param flags Bit mask of additional options: currently supported flags are |
| 3113 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3114 | * @throws SecurityException if the calling application does not own an active administrator |
| 3115 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3116 | */ |
| 3117 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3118 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3119 | if (mService != null) { |
| 3120 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3121 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3122 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3123 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3127 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3128 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3129 | * Called by an application that is administering the device to set the |
| 3130 | * global proxy and exclusion list. |
| 3131 | * <p> |
| 3132 | * The calling device admin must have requested |
| 3133 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3134 | * this method; if it has not, a security exception will be thrown. |
| 3135 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3136 | * 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] | 3137 | * 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] | 3138 | * be returned. |
| 3139 | * The method can be called repeatedly by the device admin alrady setting the |
| 3140 | * proxy to update the proxy and exclusion list. |
| 3141 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3142 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3143 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3144 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3145 | * @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] | 3146 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3147 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3148 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3149 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3150 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3151 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3152 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3153 | if (proxySpec == null) { |
| 3154 | throw new NullPointerException(); |
| 3155 | } |
| 3156 | if (mService != null) { |
| 3157 | try { |
| 3158 | String hostSpec; |
| 3159 | String exclSpec; |
| 3160 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3161 | hostSpec = null; |
| 3162 | exclSpec = null; |
| 3163 | } else { |
| 3164 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3165 | throw new IllegalArgumentException(); |
| 3166 | } |
| 3167 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3168 | String hostName = sa.getHostName(); |
| 3169 | int port = sa.getPort(); |
| 3170 | StringBuilder hostBuilder = new StringBuilder(); |
| 3171 | hostSpec = hostBuilder.append(hostName) |
| 3172 | .append(":").append(Integer.toString(port)).toString(); |
| 3173 | if (exclusionList == null) { |
| 3174 | exclSpec = ""; |
| 3175 | } else { |
| 3176 | StringBuilder listBuilder = new StringBuilder(); |
| 3177 | boolean firstDomain = true; |
| 3178 | for (String exclDomain : exclusionList) { |
| 3179 | if (!firstDomain) { |
| 3180 | listBuilder = listBuilder.append(","); |
| 3181 | } else { |
| 3182 | firstDomain = false; |
| 3183 | } |
| 3184 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3185 | } |
| 3186 | exclSpec = listBuilder.toString(); |
| 3187 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3188 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3189 | != android.net.Proxy.PROXY_VALID) |
| 3190 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3191 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3192 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3193 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3194 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | return null; |
| 3198 | } |
| 3199 | |
| 3200 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3201 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3202 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3203 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3204 | * proxy is not accessible, you may break HTTP using this. |
| 3205 | * <p> |
| 3206 | * This method requires the caller to be the device owner. |
| 3207 | * <p> |
| 3208 | * This proxy is only a recommendation and it is possible that some apps will ignore it. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3209 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3210 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3211 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3212 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3213 | * {@code null} value will clear the global HTTP proxy. |
| 3214 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3215 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3216 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3217 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3218 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3219 | if (mService != null) { |
| 3220 | try { |
| 3221 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3222 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3223 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3229 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3230 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3231 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3232 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3233 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3234 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3235 | if (mService != null) { |
| 3236 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3237 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3238 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3239 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3240 | } |
| 3241 | } |
| 3242 | return null; |
| 3243 | } |
| 3244 | |
| 3245 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3246 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3247 | * indicating that encryption is not supported. |
| 3248 | */ |
| 3249 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3250 | |
| 3251 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3252 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3253 | * indicating that encryption is supported, but is not currently active. |
| 3254 | */ |
| 3255 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3256 | |
| 3257 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3258 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3259 | * indicating that encryption is not currently active, but is currently |
| 3260 | * being activated. This is only reported by devices that support |
| 3261 | * encryption of data and only when the storage is currently |
| 3262 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3263 | * to become encrypted will never return this value. |
| 3264 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3265 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3266 | |
| 3267 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3268 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3269 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3270 | * <p> |
| 3271 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3272 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3273 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3274 | |
| 3275 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3276 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3277 | * indicating that encryption is active, but an encryption key has not |
| 3278 | * been set by the user. |
| 3279 | */ |
| 3280 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3281 | |
| 3282 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3283 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3284 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3285 | * <p> |
| 3286 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3287 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3288 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3289 | */ |
| 3290 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3291 | |
| 3292 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3293 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3294 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3295 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3296 | * to check encryption status. However, on some devices this activity may never return, as |
| 3297 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3298 | */ |
| 3299 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3300 | public static final String ACTION_START_ENCRYPTION |
| 3301 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3302 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3303 | * Widgets are enabled in keyguard |
| 3304 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3305 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3306 | |
| 3307 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3308 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3309 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3310 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3311 | |
| 3312 | /** |
| 3313 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3314 | */ |
| 3315 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3316 | |
| 3317 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3318 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3319 | */ |
| 3320 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3321 | |
| 3322 | /** |
| 3323 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3324 | */ |
| 3325 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3326 | |
| 3327 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3328 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3329 | * (e.g. PIN/Pattern/Password). |
| 3330 | */ |
| 3331 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3332 | |
| 3333 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3334 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3335 | */ |
| 3336 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3337 | |
| 3338 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3339 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3340 | */ |
| 3341 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3342 | |
| 3343 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3344 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3345 | */ |
| 3346 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3347 | |
| 3348 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3349 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3350 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3351 | * {@link DevicePolicyManager} instance. |
| 3352 | * |
| 3353 | * @hide |
| 3354 | */ |
| 3355 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3356 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
| 3357 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3358 | |
| 3359 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3360 | * Called by an application that is administering the device to request that the storage system |
| 3361 | * be encrypted. |
| 3362 | * <p> |
| 3363 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3364 | * supported setting will always be used. If any device administrator requests device |
| 3365 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3366 | * device encryption while another device administrator has enabled it, the call to disable will |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3367 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3368 | * <p> |
| 3369 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3370 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3371 | * control the encryption of any other storage areas. There is one exception: If |
| 3372 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3373 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3374 | * written to disk within the encrypted storage area. |
| 3375 | * <p> |
| 3376 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3377 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3378 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3379 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3380 | * |
| 3381 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3382 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3383 | * @return the new request status (for all active admins) - will be one of |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3384 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3385 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3386 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3387 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3388 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3389 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3390 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3391 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3392 | if (mService != null) { |
| 3393 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3394 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3395 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3396 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3397 | } |
| 3398 | } |
| 3399 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3400 | } |
| 3401 | |
| 3402 | /** |
| 3403 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3404 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3405 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3406 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3407 | * this will return the requested encryption setting as an aggregate of all active |
| 3408 | * administrators. |
| 3409 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3410 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3411 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3412 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3413 | if (mService != null) { |
| 3414 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3415 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3416 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3417 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3418 | } |
| 3419 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3420 | return false; |
| 3421 | } |
| 3422 | |
| 3423 | /** |
| 3424 | * Called by an application that is administering the device to |
| 3425 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3426 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3427 | * Depending on the returned status code, the caller may proceed in different |
| 3428 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3429 | * storage system does not support encryption. If the |
| 3430 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3431 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3432 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3433 | * storage system has enabled encryption but no password is set so further action |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3434 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3435 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3436 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3437 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3438 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3439 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3440 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3441 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3442 | */ |
| 3443 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3444 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3445 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | /** @hide per-user version */ |
| 3449 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3450 | if (mService != null) { |
| 3451 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3452 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3453 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3454 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3455 | } |
| 3456 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3457 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3458 | } |
| 3459 | |
| 3460 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3461 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3462 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3463 | * keep the certificate on the device. |
| 3464 | * |
| 3465 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3466 | * this certificate. |
| 3467 | * |
| 3468 | * @hide |
| 3469 | */ |
| 3470 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3471 | if (mService != null) { |
| 3472 | try { |
| 3473 | return mService.approveCaCert(alias, userHandle, approval); |
| 3474 | } catch (RemoteException e) { |
| 3475 | throw e.rethrowFromSystemServer(); |
| 3476 | } |
| 3477 | } |
| 3478 | return false; |
| 3479 | } |
| 3480 | |
| 3481 | /** |
| 3482 | * Check whether a CA certificate has been approved by the device user. |
| 3483 | * |
| 3484 | * @hide |
| 3485 | */ |
| 3486 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3487 | if (mService != null) { |
| 3488 | try { |
| 3489 | return mService.isCaCertApproved(alias, userHandle); |
| 3490 | } catch (RemoteException e) { |
| 3491 | throw e.rethrowFromSystemServer(); |
| 3492 | } |
| 3493 | } |
| 3494 | return false; |
| 3495 | } |
| 3496 | |
| 3497 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3498 | * Installs the given certificate as a user CA. |
| 3499 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3500 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3501 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3502 | * security exception will be thrown. |
| 3503 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3504 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3505 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3506 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3507 | * |
| 3508 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3509 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3510 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3511 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3512 | * @see #setDelegatedScopes |
| 3513 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3514 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3515 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3516 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3517 | if (mService != null) { |
| 3518 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3519 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3520 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3521 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3522 | } |
| 3523 | } |
| 3524 | return false; |
| 3525 | } |
| 3526 | |
| 3527 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3528 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3529 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3530 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3531 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3532 | * security exception will be thrown. |
| 3533 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3534 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3535 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3536 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3537 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3538 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3539 | * @see #setDelegatedScopes |
| 3540 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3541 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3542 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3543 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3544 | if (mService != null) { |
| 3545 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3546 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3547 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3548 | } catch (CertificateException e) { |
| 3549 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3550 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3551 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3552 | } |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3557 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3558 | * If a user has installed any certificates by other means than device policy these will be |
| 3559 | * included too. |
| 3560 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3561 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3562 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3563 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3564 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3565 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3566 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3567 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3568 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3569 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3570 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3571 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3572 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3573 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3574 | for (String alias : certStore.userAliases()) { |
| 3575 | try { |
| 3576 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3577 | } catch (CertificateException ce) { |
| 3578 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3579 | } |
| 3580 | } |
| 3581 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3582 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3589 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3590 | * means other than device policy will also be removed, except for system CA certificates. |
| 3591 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3592 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3593 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3594 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3595 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3596 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3597 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3598 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3599 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3600 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3601 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3602 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3603 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3604 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | /** |
| 3610 | * Returns whether this certificate is installed as a trusted CA. |
| 3611 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3612 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3613 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3614 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3615 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3616 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3617 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3618 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3619 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3620 | if (mService != null) { |
| 3621 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3622 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3623 | return getCaCertAlias(certBuffer) != null; |
| 3624 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3625 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3626 | } catch (CertificateException ce) { |
| 3627 | Log.w(TAG, "Could not parse certificate", ce); |
| 3628 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3629 | } |
| 3630 | return false; |
| 3631 | } |
| 3632 | |
| 3633 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3634 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3635 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3636 | * the certificate and use the private key, given direct user approval. |
| 3637 | * |
| 3638 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3639 | * direct user approval. This is for security - should a certificate installer become |
| 3640 | * compromised, certificates it had already installed will be protected. |
| 3641 | * |
| 3642 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3643 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3644 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3645 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3646 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3647 | * @param privKey The private key to install. |
| 3648 | * @param cert The certificate to install. |
| 3649 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3650 | * with that alias already exists, it will be overwritten. |
| 3651 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3652 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3653 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3654 | * @see #setDelegatedScopes |
| 3655 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3656 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3657 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3658 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3659 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * Called by a device or profile owner, or delegated certificate installer, to install a |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3664 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3665 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3666 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3667 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3668 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3669 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3670 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3671 | * |
| 3672 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3673 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3674 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3675 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3676 | * certificate and include the chain of trust in order. This will be returned by |
| 3677 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3678 | * @param alias The private key alias under which to install the certificate. If a certificate |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3679 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3680 | * @param requestAccess {@code true} to request that the calling app be granted access to the |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3681 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3682 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3683 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3684 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3685 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3686 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3687 | * @see #setDelegatedScopes |
| 3688 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3689 | */ |
| 3690 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3691 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3692 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3693 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3694 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3695 | byte[] pemChain = null; |
| 3696 | if (certs.length > 1) { |
| 3697 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3698 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3699 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3700 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3701 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3702 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3703 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3704 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3705 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3706 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3707 | } catch (CertificateException | IOException e) { |
| 3708 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3709 | } |
| 3710 | return false; |
| 3711 | } |
| 3712 | |
| 3713 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3714 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3715 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3716 | * |
| 3717 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3718 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3719 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3720 | * @return {@code true} if the private key alias no longer exists, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3721 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3722 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3723 | * @see #setDelegatedScopes |
| 3724 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3725 | */ |
| 3726 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3727 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3728 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3729 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3730 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3731 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3732 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3736 | * @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] | 3737 | * doesn't exist. |
| 3738 | */ |
| 3739 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3740 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3741 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3742 | new ByteArrayInputStream(certBuffer)); |
| 3743 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3744 | } |
| 3745 | |
| 3746 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3747 | * 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] | 3748 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3749 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3750 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3751 | * <p> |
| 3752 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3753 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3754 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3755 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3756 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3757 | * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3758 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3759 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3760 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3761 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3762 | * @param installerPackage The package name of the certificate installer which will be given |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3763 | * access. If {@code null} is given the current package will be cleared. |
| 3764 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3765 | * |
| 3766 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3767 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3768 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3769 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3770 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3771 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3772 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3773 | if (mService != null) { |
| 3774 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3775 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3776 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3777 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3778 | } |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3783 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3784 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3785 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3786 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3787 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3788 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3789 | * none is set. |
| 3790 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3791 | * |
| 3792 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3793 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3794 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3795 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3796 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3797 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3798 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3799 | if (mService != null) { |
| 3800 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3801 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3802 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3803 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | return null; |
| 3807 | } |
| 3808 | |
| 3809 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3810 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3811 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3812 | * constants. |
| 3813 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3814 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3815 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3816 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3817 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3818 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3819 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3820 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3821 | * {@code delegatePackage}. |
| 3822 | * |
| 3823 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3824 | * @param delegatePackage The package name of the app which will be given access. |
| 3825 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3826 | * {@code delegatedPackage}. |
| 3827 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3828 | */ |
| 3829 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3830 | @NonNull List<String> scopes) { |
| 3831 | throwIfParentInstance("setDelegatedScopes"); |
| 3832 | if (mService != null) { |
| 3833 | try { |
| 3834 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3835 | } catch (RemoteException e) { |
| 3836 | throw e.rethrowFromSystemServer(); |
| 3837 | } |
| 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | /** |
| 3842 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3843 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3844 | * passing {@code null} for {@code admin} and their own package name as |
| 3845 | * {@code delegatedPackage}. |
| 3846 | * |
| 3847 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3848 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3849 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3850 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3851 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3852 | */ |
| 3853 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3854 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3855 | @NonNull String delegatedPackage) { |
| 3856 | throwIfParentInstance("getDelegatedScopes"); |
| 3857 | if (mService != null) { |
| 3858 | try { |
| 3859 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3860 | } catch (RemoteException e) { |
| 3861 | throw e.rethrowFromSystemServer(); |
| 3862 | } |
| 3863 | } |
| 3864 | return null; |
| 3865 | } |
| 3866 | |
| 3867 | /** |
| 3868 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3869 | * granted a delegation scope. |
| 3870 | * |
| 3871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3872 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3873 | * @return A list of package names of the current delegated packages for |
| 3874 | {@code delegationScope}. |
| 3875 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3876 | */ |
| 3877 | @Nullable |
| 3878 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3879 | @NonNull String delegationScope) { |
| 3880 | throwIfParentInstance("getDelegatePackages"); |
| 3881 | if (mService != null) { |
| 3882 | try { |
| 3883 | return mService.getDelegatePackages(admin, delegationScope); |
| 3884 | } catch (RemoteException e) { |
| 3885 | throw e.rethrowFromSystemServer(); |
| 3886 | } |
| 3887 | } |
| 3888 | return null; |
| 3889 | } |
| 3890 | |
| 3891 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3892 | * Called by a device or profile owner to configure an always-on VPN connection through a |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3893 | * specific application for the current user. |
| 3894 | * |
| 3895 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3896 | * TODO: delete once there are no longer any live references. |
| 3897 | * @hide |
| 3898 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3899 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3900 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3901 | throws NameNotFoundException, UnsupportedOperationException { |
| 3902 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3903 | } |
| 3904 | |
| 3905 | /** |
| 3906 | * Called by a device or profile owner to configure an always-on VPN connection through a |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3907 | * specific application for the current user. This connection is automatically granted and |
| 3908 | * persisted after a reboot. |
| 3909 | * <p> |
| 3910 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3911 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3912 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3913 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3914 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3915 | * remove an existing always-on VPN configuration. |
| 3916 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3917 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3918 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3919 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3920 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3921 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3922 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3923 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3924 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3925 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3926 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3927 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3928 | if (mService != null) { |
| 3929 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3930 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3931 | throw new NameNotFoundException(vpnPackage); |
| 3932 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3933 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3934 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3935 | } |
| 3936 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | /** |
| 3940 | * Called by a device or profile owner to read the name of the package administering an |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3941 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3942 | * VPN is provided by the system instead of by an application, {@code null} will be returned. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3943 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3944 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3945 | * is set. |
| 3946 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3947 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3948 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3949 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3950 | if (mService != null) { |
| 3951 | try { |
| 3952 | return mService.getAlwaysOnVpnPackage(admin); |
| 3953 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3954 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3955 | } |
| 3956 | } |
| 3957 | return null; |
| 3958 | } |
| 3959 | |
| 3960 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3961 | * Called by an application that is administering the device to disable all cameras on the |
| 3962 | * device, for this user. After setting this, no applications running as this user will be able |
| 3963 | * to access any cameras on the device. |
| 3964 | * <p> |
| 3965 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3966 | * <p> |
| 3967 | * The calling device admin must have requested |
| 3968 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3969 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3970 | * |
| 3971 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3972 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3973 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3974 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3975 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3976 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3977 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3978 | if (mService != null) { |
| 3979 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3980 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3981 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3982 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3988 | * 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] | 3989 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3990 | * @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] | 3991 | * have disabled the camera |
| 3992 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3993 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3994 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3995 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3999 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4000 | if (mService != null) { |
| 4001 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4002 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4003 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4004 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4005 | } |
| 4006 | } |
| 4007 | return false; |
| 4008 | } |
| 4009 | |
| 4010 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4011 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4012 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4013 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 4014 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 4015 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4016 | * |
| 4017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4018 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4019 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4020 | * bugreport is still running or waiting for the user to share or decline) |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4021 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 4022 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4023 | */ |
| 4024 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4025 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4026 | if (mService != null) { |
| 4027 | try { |
| 4028 | return mService.requestBugreport(admin); |
| 4029 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4030 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4031 | } |
| 4032 | } |
| 4033 | return false; |
| 4034 | } |
| 4035 | |
| 4036 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4037 | * Determine whether or not creating a guest user has been disabled for the device |
| 4038 | * |
| 4039 | * @hide |
| 4040 | */ |
| 4041 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4042 | // Currently guest users can always be created if multi-user is enabled |
| 4043 | // TODO introduce a policy for guest user creation |
| 4044 | return false; |
| 4045 | } |
| 4046 | |
| 4047 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4048 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4049 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4050 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4051 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4052 | * <p> |
| 4053 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4054 | * exception will be thrown. |
| 4055 | * <p> |
| 4056 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4057 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4058 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4059 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4060 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4061 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4062 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4063 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4064 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4065 | if (mService != null) { |
| 4066 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4067 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4068 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4069 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4070 | } |
| 4071 | } |
| 4072 | } |
| 4073 | |
| 4074 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4075 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4076 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4077 | * @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] | 4078 | * have disabled screen capture. |
| 4079 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4080 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4081 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4082 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4086 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4087 | if (mService != null) { |
| 4088 | try { |
| 4089 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4090 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4091 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | return false; |
| 4095 | } |
| 4096 | |
| 4097 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4098 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4099 | * required, no user will be able set the date and time and network date and time will be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4100 | * <p> |
| 4101 | * Note: if auto time is required the user can still manually set the time zone. |
| 4102 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4103 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4104 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4105 | * |
| 4106 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4107 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4108 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4109 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4110 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4111 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4112 | if (mService != null) { |
| 4113 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4114 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4115 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4116 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4117 | } |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | /** |
| 4122 | * @return true if auto time is required. |
| 4123 | */ |
| 4124 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4125 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4126 | if (mService != null) { |
| 4127 | try { |
| 4128 | return mService.getAutoTimeRequired(); |
| 4129 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4130 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4131 | } |
| 4132 | } |
| 4133 | return false; |
| 4134 | } |
| 4135 | |
| 4136 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4137 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4138 | * <p> |
| 4139 | * The system user is exempt from this policy - it is never ephemeral. |
| 4140 | * <p> |
| 4141 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4142 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4143 | * |
| 4144 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4145 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4146 | * subsequently created users will be ephemeral. |
| 4147 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4148 | * @hide |
| 4149 | */ |
| 4150 | public void setForceEphemeralUsers( |
| 4151 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4152 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4153 | if (mService != null) { |
| 4154 | try { |
| 4155 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4156 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4157 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | /** |
| 4163 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4164 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4165 | * @hide |
| 4166 | */ |
| 4167 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4168 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4169 | if (mService != null) { |
| 4170 | try { |
| 4171 | return mService.getForceEphemeralUsers(admin); |
| 4172 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4173 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4174 | } |
| 4175 | } |
| 4176 | return false; |
| 4177 | } |
| 4178 | |
| 4179 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4180 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4181 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4182 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4183 | * <p> |
| 4184 | * The calling device admin must have requested |
| 4185 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4186 | * if it has not, a security exception will be thrown. |
| 4187 | * <p> |
| 4188 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4189 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4190 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4191 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4192 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4193 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4194 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4195 | * there is one, or the parent user otherwise. |
| 4196 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4197 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4198 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4199 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4200 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4201 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4202 | * profile. |
| 4203 | * <p> |
| 4204 | * Requests to disable other features on a managed profile will be ignored. |
| 4205 | * <p> |
| 4206 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4207 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4208 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4209 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4210 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4211 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4212 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4213 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4214 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4215 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4216 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4217 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4218 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4219 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4220 | if (mService != null) { |
| 4221 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4222 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4223 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4224 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4230 | * Determine whether or not features have been disabled in keyguard either by the calling |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 4231 | * admin, if specified, or all admins that set restrictions on this user and its participating |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4232 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4233 | * |
| 4234 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4235 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4236 | * restrictions on the parent profile. |
| 4237 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4238 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4239 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4240 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4241 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4242 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4243 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4244 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4248 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4249 | if (mService != null) { |
| 4250 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4251 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4252 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4253 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4254 | } |
| 4255 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4256 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4260 | * @hide |
| 4261 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4262 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4263 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4264 | if (mService != null) { |
| 4265 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4266 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4267 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4268 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4269 | } |
| 4270 | } |
| 4271 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4272 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4273 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4274 | * @hide |
| 4275 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4276 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4277 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4281 | * @hide |
| 4282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4283 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4284 | if (mService != null) { |
| 4285 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4286 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4287 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4288 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4289 | } |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | /** |
| 4294 | * @hide |
| 4295 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4296 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4297 | if (mService != null) { |
| 4298 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4299 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4300 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4301 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4302 | } |
| 4303 | } |
| 4304 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4305 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4306 | /** |
| 4307 | * @hide |
| 4308 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4309 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4310 | if (mService != null) { |
| 4311 | try { |
| 4312 | mService.reportPasswordChanged(userId); |
| 4313 | } catch (RemoteException e) { |
| 4314 | throw e.rethrowFromSystemServer(); |
| 4315 | } |
| 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | /** |
| 4320 | * @hide |
| 4321 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4322 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4323 | if (mService != null) { |
| 4324 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4325 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4326 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4327 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4328 | } |
| 4329 | } |
| 4330 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4331 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4332 | /** |
| 4333 | * @hide |
| 4334 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4335 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4336 | if (mService != null) { |
| 4337 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4338 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4339 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4340 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4341 | } |
| 4342 | } |
| 4343 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4344 | |
| 4345 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4346 | * @hide |
| 4347 | */ |
| 4348 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4349 | if (mService != null) { |
| 4350 | try { |
| 4351 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4352 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4353 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4354 | } |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * @hide |
| 4360 | */ |
| 4361 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4362 | if (mService != null) { |
| 4363 | try { |
| 4364 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4365 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4366 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4372 | * Should be called when keyguard has been dismissed. |
| 4373 | * @hide |
| 4374 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4375 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4376 | if (mService != null) { |
| 4377 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4378 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4379 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4380 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | /** |
| 4386 | * Should be called when keyguard view has been shown to the user. |
| 4387 | * @hide |
| 4388 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4389 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4390 | if (mService != null) { |
| 4391 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4392 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4393 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4394 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4395 | } |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4400 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4401 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4402 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4403 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4404 | * @return whether the package was successfully registered as the device owner. |
| 4405 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4406 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4407 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4408 | public boolean setDeviceOwner(ComponentName who) { |
| 4409 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | /** |
| 4413 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4414 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4415 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4416 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | /** |
| 4420 | * @hide |
| 4421 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4422 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4423 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | /** |
| 4427 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4428 | * Sets the given package as the device owner. The package must already be installed. There |
| 4429 | * must not already be a device owner. |
| 4430 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4431 | * this method. |
| 4432 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4433 | * 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] | 4434 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4435 | * @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] | 4436 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4437 | * @return whether the package was successfully registered as the device owner. |
| 4438 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4439 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4440 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4441 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4442 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4443 | if (mService != null) { |
| 4444 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4445 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4446 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4447 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4448 | } |
| 4449 | } |
| 4450 | return false; |
| 4451 | } |
| 4452 | |
| 4453 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4454 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4455 | * 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] | 4456 | * 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] | 4457 | * package is currently registered as the device owner app, pass in the package name from |
| 4458 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4459 | * 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] | 4460 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4461 | * the setup process. |
| 4462 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4463 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4464 | * @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] | 4465 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4466 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4467 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4468 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4469 | } |
| 4470 | |
| 4471 | /** |
| 4472 | * @return true if a package is registered as device owner, only when it's running on the |
| 4473 | * calling user. |
| 4474 | * |
| 4475 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4476 | * @hide |
| 4477 | */ |
| 4478 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4479 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4480 | } |
| 4481 | |
| 4482 | /** |
| 4483 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4484 | * user. |
| 4485 | * |
| 4486 | * <p>Requires the MANAGE_USERS permission. |
| 4487 | * |
| 4488 | * @hide |
| 4489 | */ |
| 4490 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4491 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4492 | } |
| 4493 | |
| 4494 | /** |
| 4495 | * @return device owner component name, only when it's running on the calling user. |
| 4496 | * |
| 4497 | * @hide |
| 4498 | */ |
| 4499 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4500 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4501 | } |
| 4502 | |
| 4503 | /** |
| 4504 | * @return device owner component name, even if it's running on a different user. |
| 4505 | * |
| 4506 | * <p>Requires the MANAGE_USERS permission. |
| 4507 | * |
| 4508 | * @hide |
| 4509 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4510 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4511 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4512 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4513 | } |
| 4514 | |
| 4515 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4516 | if (packageName == null) { |
| 4517 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4518 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4519 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4520 | if (deviceOwner == null) { |
| 4521 | return false; |
| 4522 | } |
| 4523 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4526 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4527 | if (mService != null) { |
| 4528 | try { |
| 4529 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4530 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4531 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4537 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4538 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4539 | * no device owner. |
| 4540 | * |
| 4541 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4542 | * |
| 4543 | * @hide |
| 4544 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4545 | public int getDeviceOwnerUserId() { |
| 4546 | if (mService != null) { |
| 4547 | try { |
| 4548 | return mService.getDeviceOwnerUserId(); |
| 4549 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4550 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4551 | } |
| 4552 | } |
| 4553 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4557 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4558 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4559 | * a part of device setup, before it completes. |
| 4560 | * <p> |
| 4561 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 4562 | * a best-effort process and some other policies will still remain in place after the device |
| 4563 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4564 | * |
| 4565 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4566 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4567 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4568 | * |
| 4569 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 4570 | * will lose control of the device and its data after calling it. In order to protect any |
| 4571 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 4572 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4573 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4574 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4575 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4576 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4577 | if (mService != null) { |
| 4578 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4579 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4580 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4581 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | } |
| 4585 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4586 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4587 | * Returns the device owner package name, only if it's running on the calling user. |
| 4588 | * |
| 4589 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4590 | * |
| 4591 | * @hide |
| 4592 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4593 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4594 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4595 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4596 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4597 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4601 | * Called by the system to find out whether the device is managed by a Device Owner. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4602 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4603 | * @return whether the device is managed by a Device Owner. |
| 4604 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4605 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4606 | * |
| 4607 | * @hide |
| 4608 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4609 | @SystemApi |
| 4610 | @TestApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4611 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4612 | try { |
| 4613 | return mService.hasDeviceOwner(); |
| 4614 | } catch (RemoteException re) { |
| 4615 | throw re.rethrowFromSystemServer(); |
| 4616 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | /** |
| 4620 | * Returns the device owner name. Note this method *will* return the device owner |
| 4621 | * name when it's running on a different user. |
| 4622 | * |
| 4623 | * <p>Requires the MANAGE_USERS permission. |
| 4624 | * |
| 4625 | * @hide |
| 4626 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4627 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4628 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4629 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4630 | if (mService != null) { |
| 4631 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4632 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4633 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4634 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4635 | } |
| 4636 | } |
| 4637 | return null; |
| 4638 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4639 | |
| 4640 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4641 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4642 | * @deprecated Do not use |
| 4643 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4644 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4645 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4646 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4647 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4648 | return null; |
| 4649 | } |
| 4650 | |
| 4651 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4652 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4653 | * @deprecated Do not use |
| 4654 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4655 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4656 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4657 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4658 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4659 | return null; |
| 4660 | } |
| 4661 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4662 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4663 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4664 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4665 | * Sets the given component as an active admin and registers the package as the profile |
| 4666 | * owner for this user. The package must already be installed and there shouldn't be |
| 4667 | * an existing profile owner registered for this user. Also, this method must be called |
| 4668 | * before the user setup has been completed. |
| 4669 | * <p> |
| 4670 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4671 | * MANAGE_DEVICE_ADMINS permission. |
| 4672 | * @param admin The component to register as an active admin and profile owner. |
| 4673 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4674 | * @return whether the admin was successfully registered as the profile owner. |
| 4675 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4676 | * the user has already been set up. |
| 4677 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4678 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4679 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4680 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4681 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4682 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4683 | if (mService != null) { |
| 4684 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4685 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4686 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4687 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4688 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4689 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | return false; |
| 4693 | } |
| 4694 | |
| 4695 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4696 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 4697 | * a SecurityException will be thrown. This method is not available to managed profile owners. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4698 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4699 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 4700 | * a best-effort process and some other policies will still remain in place after the profile |
| 4701 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4702 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4703 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4704 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 4705 | * being called from a managed profile. |
| 4706 | * |
| 4707 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 4708 | * will lose control of the user and its data after calling it. In order to protect any |
| 4709 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 4710 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4711 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4712 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4713 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4714 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4715 | if (mService != null) { |
| 4716 | try { |
| 4717 | mService.clearProfileOwner(admin); |
| 4718 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4719 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4720 | } |
| 4721 | } |
| 4722 | } |
| 4723 | |
| 4724 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4725 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4726 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4727 | */ |
| 4728 | public boolean hasUserSetupCompleted() { |
| 4729 | if (mService != null) { |
| 4730 | try { |
| 4731 | return mService.hasUserSetupCompleted(); |
| 4732 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4733 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4734 | } |
| 4735 | } |
| 4736 | return true; |
| 4737 | } |
| 4738 | |
| 4739 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4740 | * @hide |
| 4741 | * 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] | 4742 | * already be installed. There must not already be a profile owner for this user. |
| 4743 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4744 | * this method. |
| 4745 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4746 | * - the caller is SYSTEM_UID. |
| 4747 | * - 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] | 4748 | * @param admin the component name to be registered as profile owner. |
| 4749 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4750 | * @param userHandle the userId to set the profile owner for. |
| 4751 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4752 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4753 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4754 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4755 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4756 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4757 | if (mService != null) { |
| 4758 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4759 | if (ownerName == null) { |
| 4760 | ownerName = ""; |
| 4761 | } |
| 4762 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4763 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4764 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4765 | } |
| 4766 | } |
| 4767 | return false; |
| 4768 | } |
| 4769 | |
| 4770 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4771 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4772 | * <p> |
| 4773 | * If the device owner information is {@code null} or empty then the device owner info is |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4774 | * cleared and the user owner info is shown on the lock screen if it is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4775 | * <p> |
| 4776 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4777 | * will be blank and the user will not be allowed to change it. |
| 4778 | * <p> |
| 4779 | * If the device owner information needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 4780 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4781 | * and set a new version of this string accordingly. |
| 4782 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4783 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4784 | * @param info Device owner information which will be displayed instead of the user owner info. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4785 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4786 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4787 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4788 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4789 | if (mService != null) { |
| 4790 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4791 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4792 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4793 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4794 | } |
| 4795 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | /** |
| 4799 | * @return The device owner information. If it is not set returns {@code null}. |
| 4800 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4801 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4802 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4803 | if (mService != null) { |
| 4804 | try { |
| 4805 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4806 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4807 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4808 | } |
| 4809 | } |
| 4810 | return null; |
| 4811 | } |
| 4812 | |
| 4813 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4814 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4815 | * called by a device owner, profile owner, or by a delegate given the |
| 4816 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4817 | * <p> |
| 4818 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4819 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4820 | * device. |
| 4821 | * <p> |
| 4822 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4823 | * package will no longer be suspended. The admin can block this by using |
Kenny Guy | 871f3eb | 2016-03-09 20:06:16 +0000 | [diff] [blame] | 4824 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4825 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4826 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4827 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4828 | * @param packageNames The package names to suspend or unsuspend. |
| 4829 | * @param suspended If set to {@code true} than the packages will be suspended, if set to |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4830 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4831 | * @return an array of package names for which the suspended status is not set as requested in |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4832 | * this method. |
| 4833 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4834 | * @see #setDelegatedScopes |
| 4835 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4836 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4837 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4838 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4839 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4840 | if (mService != null) { |
| 4841 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4842 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4843 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4844 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4845 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4846 | } |
| 4847 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4848 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4852 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4853 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4854 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4855 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4856 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4857 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4858 | * @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] | 4859 | * @return {@code true} if the package is suspended or {@code false} if the package is not |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4860 | * suspended, could not be found or an error occurred. |
| 4861 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4862 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4863 | * @see #setDelegatedScopes |
| 4864 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4865 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4866 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4867 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4868 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4869 | if (mService != null) { |
| 4870 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4871 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4872 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4873 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4874 | } catch (IllegalArgumentException ex) { |
| 4875 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | return false; |
| 4879 | } |
| 4880 | |
| 4881 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4882 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4883 | * be used. Only the profile owner can call this. |
| 4884 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4885 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4886 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4887 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4888 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4889 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4890 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4891 | if (mService != null) { |
| 4892 | try { |
| 4893 | mService.setProfileEnabled(admin); |
| 4894 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4895 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4896 | } |
| 4897 | } |
| 4898 | } |
| 4899 | |
| 4900 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4901 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4902 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4903 | * by the profile or device owner, the name will be set to default values. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4904 | * |
| 4905 | * @see #isProfileOwnerApp |
| 4906 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4907 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4908 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4909 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4910 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4911 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4912 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4913 | if (mService != null) { |
| 4914 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4915 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4916 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4917 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4918 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4919 | } |
| 4920 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4921 | |
| 4922 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4923 | * 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] | 4924 | * 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] | 4925 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4926 | * |
| 4927 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4928 | * @return Whether or not the package is registered as the profile owner. |
| 4929 | */ |
| 4930 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4931 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4932 | if (mService != null) { |
| 4933 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4934 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4935 | return profileOwner != null |
| 4936 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4937 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4938 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4939 | } |
| 4940 | } |
| 4941 | return false; |
| 4942 | } |
| 4943 | |
| 4944 | /** |
| 4945 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4946 | * @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] | 4947 | * owner has been set for that user. |
| 4948 | * @throws IllegalArgumentException if the userId is invalid. |
| 4949 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4950 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4951 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4952 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4953 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * @see #getProfileOwner() |
| 4958 | * @hide |
| 4959 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4960 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4961 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4962 | if (mService != null) { |
| 4963 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4964 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4965 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4966 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4967 | } |
| 4968 | } |
| 4969 | return null; |
| 4970 | } |
| 4971 | |
| 4972 | /** |
| 4973 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4974 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4975 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4976 | * @throws IllegalArgumentException if the userId is invalid. |
| 4977 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4978 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4979 | if (mService != null) { |
| 4980 | try { |
| 4981 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4982 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4983 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4984 | } |
| 4985 | } |
| 4986 | return null; |
| 4987 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4988 | |
| 4989 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4990 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4991 | * @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] | 4992 | * @return the human readable name of the organisation associated with this profile owner or |
| 4993 | * null if one is not set. |
| 4994 | * @throws IllegalArgumentException if the userId is invalid. |
| 4995 | */ |
| 4996 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4997 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4998 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4999 | if (mService != null) { |
| 5000 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5001 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5002 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5003 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5004 | } |
| 5005 | } |
| 5006 | return null; |
| 5007 | } |
| 5008 | |
| 5009 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5010 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 5011 | * intents that match a certain intent filter. This activity will remain the default intent |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5012 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 5013 | * intent preferences are reset. |
| 5014 | * <p> |
| 5015 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5016 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5017 | * the filter. |
| 5018 | * <p> |
| 5019 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5020 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5021 | * |
| 5022 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5023 | * @param filter The IntentFilter for which a default handler is added. |
| 5024 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5025 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5026 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5027 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5028 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5029 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5030 | if (mService != null) { |
| 5031 | try { |
| 5032 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5033 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5034 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5035 | } |
| 5036 | } |
| 5037 | } |
| 5038 | |
| 5039 | /** |
| 5040 | * 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] | 5041 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5042 | * <p> |
| 5043 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5044 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5045 | * |
| 5046 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5047 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5048 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5049 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5050 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5051 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5052 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5053 | if (mService != null) { |
| 5054 | try { |
| 5055 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5056 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5057 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5058 | } |
| 5059 | } |
| 5060 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5061 | |
| 5062 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5063 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5064 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5065 | * {@link #getApplicationRestrictions}. |
| 5066 | * <p> |
| 5067 | * This permission is persistent until it is later cleared by calling this method with a |
| 5068 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5069 | * <p> |
| 5070 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5071 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5072 | * |
| 5073 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5074 | * @param packageName The package name which will be given access to application restrictions |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5075 | * APIs. If {@code null} is given the current package will be cleared. |
| 5076 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5077 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5078 | * |
| 5079 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5080 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5081 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5082 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5083 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5084 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5085 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5086 | if (mService != null) { |
| 5087 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5088 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5089 | throw new NameNotFoundException(packageName); |
| 5090 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5091 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5092 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | } |
| 5096 | |
| 5097 | /** |
| 5098 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5099 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5100 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5101 | * |
| 5102 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5103 | * @return The package name allowed to manage application restrictions on the current user, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5104 | * {@code null} if none is set. |
| 5105 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5106 | * |
| 5107 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 5108 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5109 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5110 | @Deprecated |
| 5111 | @Nullable |
| 5112 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5113 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5114 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5115 | if (mService != null) { |
| 5116 | try { |
| 5117 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5118 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5119 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5120 | } |
| 5121 | } |
| 5122 | return null; |
| 5123 | } |
| 5124 | |
| 5125 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5126 | * Called by any application to find out whether it has been granted permission via |
| 5127 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5128 | * for the calling user. |
| 5129 | * |
| 5130 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5131 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5132 | * |
| 5133 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5134 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5135 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5136 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5137 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5138 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5139 | if (mService != null) { |
| 5140 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5141 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5142 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5143 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5144 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5145 | } |
| 5146 | } |
| 5147 | return false; |
| 5148 | } |
| 5149 | |
| 5150 | /** |
| 5151 | * Sets the application restrictions for a given target application running in the calling user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5152 | * <p> |
| 5153 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5154 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5155 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5156 | * <p> |
| 5157 | * The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 5158 | * <ul> |
| 5159 | * <li>{@code boolean} |
| 5160 | * <li>{@code int} |
| 5161 | * <li>{@code String} or {@code String[]} |
| 5162 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5163 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5164 | * <p> |
| 5165 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5166 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5167 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5168 | * <p> |
| 5169 | * The application restrictions are only made visible to the target application via |
| 5170 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5171 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5172 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5173 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5174 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5175 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5176 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5177 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5178 | * @param packageName The name of the package to update restricted settings for. |
| 5179 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5180 | * set of active restrictions. |
| 5181 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5182 | * @see #setDelegatedScopes |
| 5183 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5184 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5185 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5186 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5187 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5188 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5189 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5190 | if (mService != null) { |
| 5191 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5192 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5193 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5194 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5195 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | |
| 5200 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5201 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5202 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5203 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5204 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5205 | * <p> |
| 5206 | * The calling device admin must have requested |
| 5207 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5208 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5209 | * <p> |
| 5210 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5211 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5212 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5213 | * |
| 5214 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5215 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5216 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5217 | * strictly disabled according to the state of the |
| 5218 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5219 | * <p> |
| 5220 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5221 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5222 | * device admins. |
| 5223 | * <p> |
| 5224 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5225 | * parameters. |
| 5226 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5227 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5228 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5229 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5230 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5231 | if (mService != null) { |
| 5232 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5233 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5234 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5235 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5241 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5242 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5243 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5244 | * <p> |
| 5245 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5246 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5247 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5248 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5249 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5250 | * this function returns a list of configurations for all admins that declare |
| 5251 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5252 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5253 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5254 | * 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] | 5255 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5256 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5257 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5258 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5259 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5260 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5264 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5265 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5266 | if (mService != null) { |
| 5267 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5268 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5269 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5270 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5271 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5272 | } |
| 5273 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5274 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5278 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5279 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5280 | * <p> |
| 5281 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5282 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5283 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5284 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5285 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5286 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5287 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5288 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5289 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5290 | if (mService != null) { |
| 5291 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5292 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5293 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5294 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5295 | } |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5300 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5301 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5302 | * <p> |
| 5303 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5304 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5305 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5306 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5307 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5308 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5309 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5310 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5311 | if (mService != null) { |
| 5312 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5313 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5314 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5315 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | return false; |
| 5319 | } |
| 5320 | |
| 5321 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5322 | * Determine whether or not caller-Id information has been disabled. |
| 5323 | * |
| 5324 | * @param userHandle The user for whom to check the caller-id permission |
| 5325 | * @hide |
| 5326 | */ |
| 5327 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5328 | if (mService != null) { |
| 5329 | try { |
| 5330 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5331 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5332 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | return false; |
| 5336 | } |
| 5337 | |
| 5338 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5339 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5340 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5341 | * <p> |
| 5342 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5343 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5344 | * |
| 5345 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5346 | * @param disabled If true contacts search in the managed profile is not displayed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5347 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5348 | */ |
| 5349 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5350 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5351 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5352 | if (mService != null) { |
| 5353 | try { |
| 5354 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5355 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5356 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | } |
| 5360 | |
| 5361 | /** |
| 5362 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5363 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5364 | * <p> |
| 5365 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5366 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5367 | * |
| 5368 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5369 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5370 | */ |
| 5371 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5372 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5373 | if (mService != null) { |
| 5374 | try { |
| 5375 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5376 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5377 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5378 | } |
| 5379 | } |
| 5380 | return false; |
| 5381 | } |
| 5382 | |
| 5383 | |
| 5384 | /** |
| 5385 | * Determine whether or not contacts search has been disabled. |
| 5386 | * |
| 5387 | * @param userHandle The user for whom to check the contacts search permission |
| 5388 | * @hide |
| 5389 | */ |
| 5390 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5391 | if (mService != null) { |
| 5392 | try { |
| 5393 | return mService |
| 5394 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5395 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5396 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | return false; |
| 5400 | } |
| 5401 | |
| 5402 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5403 | * 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] | 5404 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5405 | * @hide |
| 5406 | */ |
| 5407 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5408 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5409 | if (mService != null) { |
| 5410 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5411 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5412 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5413 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5414 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5415 | } |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5420 | * 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] | 5421 | * @hide |
| 5422 | */ |
| 5423 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5424 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5425 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5426 | originalIntent); |
| 5427 | } |
| 5428 | |
| 5429 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5430 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5431 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5432 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5433 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5434 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5435 | * <p> |
| 5436 | * This API works on managed profile only. |
| 5437 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5438 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5439 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5440 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5441 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5442 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5443 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5444 | if (mService != null) { |
| 5445 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5446 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5447 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5448 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5449 | } |
| 5450 | } |
| 5451 | } |
| 5452 | |
| 5453 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5454 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5455 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5456 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5457 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5458 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5459 | * <p> |
| 5460 | * This API works on managed profile only. |
| 5461 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5462 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5463 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5464 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5465 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5466 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5467 | if (mService != null) { |
| 5468 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5469 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5470 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5471 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | return true; |
| 5475 | } |
| 5476 | |
| 5477 | /** |
| 5478 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5479 | * <p> |
| 5480 | * This API works on managed profile UserHandle only. |
| 5481 | * |
| 5482 | * @param userHandle The user for whom to check the caller-id permission |
| 5483 | * @hide |
| 5484 | */ |
| 5485 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5486 | if (mService != null) { |
| 5487 | try { |
| 5488 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5489 | .getIdentifier()); |
| 5490 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5491 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5492 | } |
| 5493 | } |
| 5494 | return true; |
| 5495 | } |
| 5496 | |
| 5497 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5498 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5499 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5500 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5501 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5502 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5503 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5504 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5505 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5506 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5507 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5508 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5509 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5510 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5511 | if (mService != null) { |
| 5512 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5513 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5514 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5515 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5516 | } |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5521 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5522 | * 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] | 5523 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5524 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5525 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5526 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5527 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5528 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5529 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5530 | if (mService != null) { |
| 5531 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5532 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5533 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5534 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5535 | } |
| 5536 | } |
| 5537 | } |
| 5538 | |
| 5539 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5540 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5541 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5542 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5543 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5544 | * the list and not part of the system can not be enabled by the user. |
| 5545 | * <p> |
| 5546 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5547 | * used, calling with an empty list only allows the builtin system's services. |
| 5548 | * <p> |
| 5549 | * System accesibility services are always available to the user the list can't modify this. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5550 | * |
| 5551 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5552 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5553 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5554 | * accessibility services enabled, that are not in the list. |
| 5555 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5556 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5557 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5558 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5559 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5560 | if (mService != null) { |
| 5561 | try { |
| 5562 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5563 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5564 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5565 | } |
| 5566 | } |
| 5567 | return false; |
| 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * Returns the list of permitted accessibility services set by this device or profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5572 | * <p> |
| 5573 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5574 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5575 | * |
| 5576 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5577 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5578 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5579 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5580 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5581 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5582 | if (mService != null) { |
| 5583 | try { |
| 5584 | return mService.getPermittedAccessibilityServices(admin); |
| 5585 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5586 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | return null; |
| 5590 | } |
| 5591 | |
| 5592 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5593 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5594 | * |
| 5595 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5596 | * @param packageName Accessibility service package name that needs to be checked. |
| 5597 | * @param userHandle user id the admin is running as. |
| 5598 | * @return true if the accessibility service is permitted, otherwise false. |
| 5599 | * |
| 5600 | * @hide |
| 5601 | */ |
| 5602 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5603 | @NonNull String packageName, int userHandle) { |
| 5604 | if (mService != null) { |
| 5605 | try { |
| 5606 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5607 | userHandle); |
| 5608 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5609 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5610 | } |
| 5611 | } |
| 5612 | return false; |
| 5613 | } |
| 5614 | |
| 5615 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5616 | * Returns the list of accessibility services permitted by the device or profiles |
| 5617 | * owners of this user. |
| 5618 | * |
| 5619 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5620 | * it will contain the intersection of the permitted lists for any device or profile |
| 5621 | * owners that apply to this user. It will also include any system accessibility services. |
| 5622 | * |
| 5623 | * @param userId which user to check for. |
| 5624 | * @return List of accessiblity service package names. |
| 5625 | * @hide |
| 5626 | */ |
| 5627 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5628 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5629 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5630 | if (mService != null) { |
| 5631 | try { |
| 5632 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5633 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5634 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | return null; |
| 5638 | } |
| 5639 | |
| 5640 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5641 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5642 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5643 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5644 | * When zero or more packages have been added, input method that are not in the list and not |
| 5645 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5646 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5647 | * <p> |
| 5648 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5649 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5650 | * <p> |
| 5651 | * System input methods are always available to the user this method can't modify this. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5652 | * |
| 5653 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5654 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5655 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5656 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5657 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5658 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5659 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5660 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5661 | if (mService != null) { |
| 5662 | try { |
| 5663 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5664 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5665 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5666 | } |
| 5667 | } |
| 5668 | return false; |
| 5669 | } |
| 5670 | |
| 5671 | |
| 5672 | /** |
| 5673 | * Returns the list of permitted input methods set by this device or profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5674 | * <p> |
| 5675 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5676 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5677 | * |
| 5678 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5679 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5680 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5681 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5682 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5683 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5684 | if (mService != null) { |
| 5685 | try { |
| 5686 | return mService.getPermittedInputMethods(admin); |
| 5687 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5688 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5689 | } |
| 5690 | } |
| 5691 | return null; |
| 5692 | } |
| 5693 | |
| 5694 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5695 | * Called by the system to check if a specific input method is disabled by admin. |
| 5696 | * |
| 5697 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5698 | * @param packageName Input method package name that needs to be checked. |
| 5699 | * @param userHandle user id the admin is running as. |
| 5700 | * @return true if the input method is permitted, otherwise false. |
| 5701 | * |
| 5702 | * @hide |
| 5703 | */ |
| 5704 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5705 | @NonNull String packageName, int userHandle) { |
| 5706 | if (mService != null) { |
| 5707 | try { |
| 5708 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5709 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5710 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5711 | } |
| 5712 | } |
| 5713 | return false; |
| 5714 | } |
| 5715 | |
| 5716 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5717 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5718 | * 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] | 5719 | * |
| 5720 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5721 | * it will contain the intersection of the permitted lists for any device or profile |
| 5722 | * owners that apply to this user. It will also include any system input methods. |
| 5723 | * |
| 5724 | * @return List of input method package names. |
| 5725 | * @hide |
| 5726 | */ |
| 5727 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5728 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5729 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5730 | if (mService != null) { |
| 5731 | try { |
| 5732 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5733 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5734 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5735 | } |
| 5736 | } |
| 5737 | return null; |
| 5738 | } |
| 5739 | |
| 5740 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5741 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5742 | * function can be called by a device owner or by a delegate given the |
| 5743 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5744 | * <p> |
| 5745 | * Please note that packages returned in this method are not automatically pre-cached. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5746 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5747 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5748 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5749 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5750 | * @see #setDelegatedScopes |
| 5751 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5752 | * @hide |
| 5753 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5754 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5755 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5756 | if (mService != null) { |
| 5757 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5758 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5759 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5760 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5761 | } |
| 5762 | } |
| 5763 | return null; |
| 5764 | } |
| 5765 | |
| 5766 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5767 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5768 | * function can be called by a device owner or by a delegate given the |
| 5769 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5770 | * |
| 5771 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5772 | * automatically pre-cached.</p> |
| 5773 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5774 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5775 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5776 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5777 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5778 | * @see #setDelegatedScopes |
| 5779 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5780 | * @hide |
| 5781 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5782 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5783 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5784 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5785 | if (mService != null) { |
| 5786 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5787 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5788 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5789 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5790 | } |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5795 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5796 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5797 | * created. If you need to persist an identifier for this user, use |
| 5798 | * {@link UserManager#getSerialNumberForUser}. |
| 5799 | * |
| 5800 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5801 | * @param name the user's name |
| 5802 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5803 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5804 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5805 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5806 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5807 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5808 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5809 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5810 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5811 | return null; |
| 5812 | } |
| 5813 | |
| 5814 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5815 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5816 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5817 | * created. If you need to persist an identifier for this user, use |
| 5818 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5819 | * immediately. |
| 5820 | * |
| 5821 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5822 | * as registered as an active admin on the new user. The profile owner package will be |
| 5823 | * installed on the new user if it already is installed on the device. |
| 5824 | * |
| 5825 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5826 | * profileOwnerComponent when onEnable is called. |
| 5827 | * |
| 5828 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5829 | * @param name the user's name |
| 5830 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5831 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5832 | * the user. |
| 5833 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5834 | * on the new user. |
| 5835 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5836 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5837 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5838 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5839 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5840 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5841 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5842 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5843 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5844 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5845 | return null; |
| 5846 | } |
| 5847 | |
| 5848 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5849 | * 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] | 5850 | */ |
| 5851 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5852 | |
| 5853 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5854 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5855 | * ephemeral. |
| 5856 | * @hide |
| 5857 | */ |
| 5858 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5859 | |
| 5860 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5861 | * Called by a device owner to create a user with the specified name and a given component of |
| 5862 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5863 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5864 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5865 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5866 | * <p> |
| 5867 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5868 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5869 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5870 | * on the new user. |
| 5871 | * <p> |
| 5872 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5873 | * for the first time. Then the extras will be passed to the admin when onEnable is called. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5874 | * |
| 5875 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5876 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5877 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5878 | * same package as admin, otherwise no user is created and an |
| 5879 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5880 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5881 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5882 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5883 | * @see UserHandle |
| 5884 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5885 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5886 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5887 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5888 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5889 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5890 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5891 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5892 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5893 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5894 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5895 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5896 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5897 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5901 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5902 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5903 | * |
| 5904 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5905 | * @param userHandle the user to remove. |
| 5906 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5907 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5908 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5909 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5910 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5911 | try { |
| 5912 | return mService.removeUser(admin, userHandle); |
| 5913 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5914 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5919 | * Called by a device owner to switch the specified user to the foreground. |
| 5920 | * |
| 5921 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5922 | * @param userHandle the user to switch to; null will switch to primary. |
| 5923 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5924 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5925 | * @see Intent#ACTION_USER_FOREGROUND |
| 5926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5927 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5928 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5929 | try { |
| 5930 | return mService.switchUser(admin, userHandle); |
| 5931 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5932 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5937 | * Retrieves the application restrictions for a given target application running in the calling |
| 5938 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5939 | * <p> |
| 5940 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5941 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5942 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5943 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5944 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5945 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5946 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5947 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5948 | * @param packageName The name of the package to fetch restricted settings of. |
| 5949 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5950 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5951 | * {@link Bundle} if no restrictions have been set. |
| 5952 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5953 | * @see #setDelegatedScopes |
| 5954 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5955 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5956 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5957 | public @NonNull Bundle getApplicationRestrictions( |
| 5958 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5959 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5960 | if (mService != null) { |
| 5961 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5962 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 5963 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5964 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5965 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | return null; |
| 5969 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5970 | |
| 5971 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5972 | * 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] | 5973 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5974 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5975 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5976 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5977 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5978 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5979 | * for the list of keys. |
| 5980 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5981 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5982 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5983 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5984 | if (mService != null) { |
| 5985 | try { |
| 5986 | mService.setUserRestriction(admin, key, true); |
| 5987 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5988 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5989 | } |
| 5990 | } |
| 5991 | } |
| 5992 | |
| 5993 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5994 | * 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] | 5995 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5996 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5997 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5998 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5999 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6000 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6001 | * for the list of keys. |
| 6002 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6003 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6004 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6005 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6006 | if (mService != null) { |
| 6007 | try { |
| 6008 | mService.setUserRestriction(admin, key, false); |
| 6009 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6010 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6011 | } |
| 6012 | } |
| 6013 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6014 | |
| 6015 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6016 | * Called by a profile or device owner to get user restrictions set with |
| 6017 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6018 | * <p> |
| 6019 | * The target user may have more restrictions set by the system or other device owner / profile |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6020 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6021 | * {@link UserManager#getUserRestrictions()}. |
| 6022 | * |
| 6023 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6024 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6025 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6026 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6027 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6028 | Bundle ret = null; |
| 6029 | if (mService != null) { |
| 6030 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6031 | ret = mService.getUserRestrictions(admin); |
| 6032 | } catch (RemoteException e) { |
| 6033 | throw e.rethrowFromSystemServer(); |
| 6034 | } |
| 6035 | } |
| 6036 | return ret == null ? new Bundle() : ret; |
| 6037 | } |
| 6038 | |
| 6039 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6040 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6041 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6042 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6043 | * was disabled by an admin, and include a link for more information. The default content of |
| 6044 | * the dialog can be changed by the restricting admin via |
| 6045 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6046 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6047 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6048 | * user restriction from {@link UserManager}, e.g. |
| 6049 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 6050 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 6051 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6052 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6053 | */ |
| 6054 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6055 | throwIfParentInstance("createAdminSupportIntent"); |
| 6056 | if (mService != null) { |
| 6057 | try { |
| 6058 | return mService.createAdminSupportIntent(restriction); |
| 6059 | } catch (RemoteException e) { |
| 6060 | throw e.rethrowFromSystemServer(); |
| 6061 | } |
| 6062 | } |
| 6063 | return null; |
| 6064 | } |
| 6065 | |
| 6066 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6067 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 6068 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 6069 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6070 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6071 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6072 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6073 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6074 | * @param packageName The name of the package to hide or unhide. |
| 6075 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6076 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6077 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6078 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6079 | * @see #setDelegatedScopes |
| 6080 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6081 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6082 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6083 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6084 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6085 | if (mService != null) { |
| 6086 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6087 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 6088 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6089 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6090 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6091 | } |
| 6092 | } |
| 6093 | return false; |
| 6094 | } |
| 6095 | |
| 6096 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6097 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 6098 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6099 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6100 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6101 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6102 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6103 | * @param packageName The name of the package to retrieve the hidden status of. |
| 6104 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6105 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6106 | * @see #setDelegatedScopes |
| 6107 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6108 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6109 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6110 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6111 | if (mService != null) { |
| 6112 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6113 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6114 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6115 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6116 | } |
| 6117 | } |
| 6118 | return false; |
| 6119 | } |
| 6120 | |
| 6121 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6122 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 6123 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6124 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6125 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6126 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6127 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6128 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6129 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6130 | * @see #setDelegatedScopes |
| 6131 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6132 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6133 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6134 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6135 | if (mService != null) { |
| 6136 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6137 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6138 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6139 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6140 | } |
| 6141 | } |
| 6142 | } |
| 6143 | |
| 6144 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6145 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 6146 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 6147 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6148 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6149 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6150 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6151 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6152 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6153 | * @return int The number of activities that matched the intent and were installed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6154 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6155 | * @see #setDelegatedScopes |
| 6156 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6157 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6158 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6159 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6160 | if (mService != null) { |
| 6161 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6162 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6163 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6164 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6165 | } |
| 6166 | } |
| 6167 | return 0; |
| 6168 | } |
| 6169 | |
| 6170 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6171 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6172 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6173 | * <p> |
| 6174 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6175 | * exception will be thrown. |
| 6176 | * <p> |
| 6177 | * When account management is disabled for an account type, adding or removing an account of |
| 6178 | * that type will not be possible. |
| 6179 | * <p> |
| 6180 | * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 6181 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6182 | * management for a specific type is disabled. |
| 6183 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6184 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6185 | * @param accountType For which account management is disabled or enabled. |
| 6186 | * @param disabled The boolean indicating that account management will be disabled (true) or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6187 | * enabled (false). |
| 6188 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6189 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6190 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6191 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6192 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6193 | if (mService != null) { |
| 6194 | try { |
| 6195 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6196 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6197 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6198 | } |
| 6199 | } |
| 6200 | } |
| 6201 | |
| 6202 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6203 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6204 | * |
| 6205 | * <p> Account management can be disabled/enabled by calling |
| 6206 | * {@link #setAccountManagementDisabled}. |
| 6207 | * |
| 6208 | * @return a list of account types for which account management has been disabled. |
| 6209 | * |
| 6210 | * @see #setAccountManagementDisabled |
| 6211 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6212 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6213 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6214 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | /** |
| 6218 | * @see #getAccountTypesWithManagementDisabled() |
| 6219 | * @hide |
| 6220 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6221 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6222 | if (mService != null) { |
| 6223 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6224 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6225 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6226 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6227 | } |
| 6228 | } |
| 6229 | |
| 6230 | return null; |
| 6231 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6232 | |
| 6233 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6234 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6235 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6236 | * Any packages that share uid with an allowed package will also be allowed to activate lock |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6237 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6238 | * package list results in locked tasks belonging to those packages to be finished. |
| 6239 | * <p> |
| 6240 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6241 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6242 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6243 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6244 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6245 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6246 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6247 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6248 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6249 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6250 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6251 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6252 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6253 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6254 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6255 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6256 | if (mService != null) { |
| 6257 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6258 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6259 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6260 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6261 | } |
| 6262 | } |
| 6263 | } |
| 6264 | |
| 6265 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6266 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6267 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6268 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6269 | * an affiliated user or profile. |
| 6270 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6271 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6272 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6273 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6274 | if (mService != null) { |
| 6275 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6276 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6277 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6278 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6279 | } |
| 6280 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6281 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | /** |
| 6285 | * This function lets the caller know whether the given component is allowed to start the |
| 6286 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6287 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6288 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6289 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6290 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6291 | if (mService != null) { |
| 6292 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6293 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6294 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6295 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | return false; |
| 6299 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6300 | |
| 6301 | /** |
| 6302 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 6303 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6304 | * <p> |
| 6305 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6306 | * <ul> |
| 6307 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 6308 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 6309 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6310 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6311 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6312 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6313 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 6314 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 6315 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 6316 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 6317 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6318 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6319 | * <p> |
| 6320 | * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6321 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6322 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 6323 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6324 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6325 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6326 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 6327 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6328 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6329 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 6330 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6331 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6332 | * |
| 6333 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6334 | * @param setting The name of the setting to update. |
| 6335 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6336 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6337 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6338 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6339 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6340 | if (mService != null) { |
| 6341 | try { |
| 6342 | mService.setGlobalSetting(admin, setting, value); |
| 6343 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6344 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6345 | } |
| 6346 | } |
| 6347 | } |
| 6348 | |
| 6349 | /** |
| 6350 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 6351 | * that the value of the setting is in the correct form for the setting type should be performed |
| 6352 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6353 | * <p> |
| 6354 | * 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] | 6355 | * <ul> |
| 6356 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 6357 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 6358 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6359 | * <p> |
| 6360 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6361 | * <ul> |
| 6362 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 6363 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6364 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 6365 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 6366 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 6367 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 6368 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 6369 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 6370 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 6371 | * an {@link UnsupportedOperationException} is thrown. |
| 6372 | * </strong> |
| 6373 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6374 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6375 | * @param setting The name of the setting to update. |
| 6376 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6377 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6378 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6379 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6380 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6381 | if (mService != null) { |
| 6382 | try { |
| 6383 | mService.setSecureSetting(admin, setting, value); |
| 6384 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6385 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6386 | } |
| 6387 | } |
| 6388 | } |
| 6389 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6390 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6391 | * Designates a specific service component as the provider for making permission requests of a |
| 6392 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6393 | * <p/> |
| 6394 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6395 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6396 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6397 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6398 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6399 | * provider previously assigned. |
| 6400 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6401 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6402 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6403 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6404 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6405 | if (mService != null) { |
| 6406 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6407 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6408 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6409 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6410 | } |
| 6411 | } |
| 6412 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6413 | |
| 6414 | /** |
| 6415 | * Called by profile or device owners to set the master volume mute on or off. |
Nicolas Prevot | aef3ce2 | 2016-09-22 12:00:25 +0100 | [diff] [blame] | 6416 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6417 | * |
| 6418 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6419 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6420 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6421 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6422 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6423 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6424 | if (mService != null) { |
| 6425 | try { |
| 6426 | mService.setMasterVolumeMuted(admin, on); |
| 6427 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6428 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6429 | } |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | /** |
| 6434 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6435 | * |
| 6436 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6437 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6438 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6439 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6440 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6441 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6442 | if (mService != null) { |
| 6443 | try { |
| 6444 | return mService.isMasterVolumeMuted(admin); |
| 6445 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6446 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6447 | } |
| 6448 | } |
| 6449 | return false; |
| 6450 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6451 | |
| 6452 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6453 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6454 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6455 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6456 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6457 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6458 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6459 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6460 | * @param uninstallBlocked true if the user shouldn't be able to uninstall the package. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6461 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6462 | * @see #setDelegatedScopes |
| 6463 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6464 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6465 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6466 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6467 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6468 | if (mService != null) { |
| 6469 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6470 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6471 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6472 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6473 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6479 | * 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] | 6480 | * 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] | 6481 | * <p> |
| 6482 | * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6483 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6484 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6485 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6486 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6487 | * @param admin The name of the admin component whose blocking policy will be checked, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6488 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6489 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6490 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6491 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6492 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6493 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6494 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6495 | if (mService != null) { |
| 6496 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6497 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6498 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6499 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6500 | } |
| 6501 | } |
| 6502 | return false; |
| 6503 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6504 | |
| 6505 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6506 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6507 | * package to be available in the parent profile. As a result the user will be able to add |
| 6508 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6509 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6510 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6511 | * <p> |
| 6512 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6513 | * |
| 6514 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6515 | * @param packageName The package from which widget providers are white-listed. |
| 6516 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6517 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6518 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6519 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6520 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6521 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6522 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6523 | if (mService != null) { |
| 6524 | try { |
| 6525 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6526 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6527 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6528 | } |
| 6529 | } |
| 6530 | return false; |
| 6531 | } |
| 6532 | |
| 6533 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6534 | * Called by the profile owner of a managed profile to disable widget providers from a given |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6535 | * package to be available in the parent profile. For this method to take effect the package |
| 6536 | * should have been added via |
| 6537 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6538 | * <p> |
| 6539 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6540 | * |
| 6541 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6542 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6543 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6544 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6545 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6546 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6547 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6548 | public boolean removeCrossProfileWidgetProvider( |
| 6549 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6550 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6551 | if (mService != null) { |
| 6552 | try { |
| 6553 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6554 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6555 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6556 | } |
| 6557 | } |
| 6558 | return false; |
| 6559 | } |
| 6560 | |
| 6561 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6562 | * 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] | 6563 | * available in the parent profile. |
| 6564 | * |
| 6565 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6566 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6567 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6568 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6569 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6570 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6571 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6572 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6573 | if (mService != null) { |
| 6574 | try { |
| 6575 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6576 | if (providers != null) { |
| 6577 | return providers; |
| 6578 | } |
| 6579 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6580 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6581 | } |
| 6582 | } |
| 6583 | return Collections.emptyList(); |
| 6584 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6585 | |
| 6586 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6587 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6588 | * |
| 6589 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6590 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6591 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6592 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6593 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6594 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6595 | try { |
| 6596 | mService.setUserIcon(admin, icon); |
| 6597 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6598 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6599 | } |
| 6600 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6601 | |
| 6602 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6603 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6604 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6605 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6606 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6607 | * components in the device owner package can set system update policies and the most |
| 6608 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6609 | * @param policy the new policy, or {@code null} to clear the current policy. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6610 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6611 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6612 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6613 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6614 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6615 | if (mService != null) { |
| 6616 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6617 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6618 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6619 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6620 | } |
| 6621 | } |
| 6622 | } |
| 6623 | |
| 6624 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6625 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6626 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6627 | * @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] | 6628 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6629 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6630 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6631 | if (mService != null) { |
| 6632 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6633 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6634 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6635 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6636 | } |
| 6637 | } |
| 6638 | return null; |
| 6639 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6640 | |
| 6641 | /** |
| 6642 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6643 | * <p> |
| 6644 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6645 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6646 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6647 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6648 | * |
| 6649 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6650 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6651 | * @return {@code false} if attempting to disable the keyguard while a lock password was in |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6652 | * place. {@code true} otherwise. |
| 6653 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6654 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6655 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6656 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6657 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6658 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6659 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6660 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6661 | } |
| 6662 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6663 | |
| 6664 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6665 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6666 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6667 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6668 | * |
| 6669 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6670 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6671 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6672 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6673 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6674 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6675 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6676 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6677 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6678 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6679 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6680 | } |
| 6681 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6682 | |
| 6683 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6684 | * Called by the system update service to notify device and profile owners of pending system |
| 6685 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6686 | * |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6687 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6688 | * permission. This method should only be used when it is unknown whether the pending system |
| 6689 | * update is a security patch. Otherwise, use |
| 6690 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6691 | * |
| 6692 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6693 | * indicating when the current pending update was first available. {@code -1} if no |
| 6694 | * update is available. |
| 6695 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6696 | * @hide |
| 6697 | */ |
| 6698 | @SystemApi |
| 6699 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6700 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6701 | if (mService != null) { |
| 6702 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6703 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6704 | } catch (RemoteException re) { |
| 6705 | throw re.rethrowFromSystemServer(); |
| 6706 | } |
| 6707 | } |
| 6708 | } |
| 6709 | |
| 6710 | /** |
| 6711 | * Called by the system update service to notify device and profile owners of pending system |
| 6712 | * updates. |
| 6713 | * |
| 6714 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6715 | * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
| 6716 | * when it is known whether the pending system update is a security patch. |
| 6717 | * |
| 6718 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6719 | * indicating when the current pending update was first available. {@code -1} if no |
| 6720 | * update is available. |
| 6721 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6722 | * {@code false} if not. |
| 6723 | * @see #notifyPendingSystemUpdate(long) |
| 6724 | * @hide |
| 6725 | */ |
| 6726 | @SystemApi |
| 6727 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6728 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6729 | if (mService != null) { |
| 6730 | try { |
| 6731 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6732 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6733 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6734 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6735 | } |
| 6736 | } |
| 6737 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6738 | |
| 6739 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6740 | * Called by device or profile owners to get information about a pending system update. |
| 6741 | * |
| 6742 | * @param admin Which profile or device owner this request is associated with. |
| 6743 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6744 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6745 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6746 | */ |
| 6747 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6748 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6749 | try { |
| 6750 | return mService.getPendingSystemUpdate(admin); |
| 6751 | } catch (RemoteException re) { |
| 6752 | throw re.rethrowFromSystemServer(); |
| 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6757 | * Set the default response for future runtime permission requests by applications. This |
| 6758 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6759 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6760 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6761 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6762 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6763 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6764 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6765 | * <p/> |
| 6766 | * 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] | 6767 | * 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] | 6768 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6769 | * @param admin Which profile or device owner this request is associated with. |
| 6770 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6771 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6772 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6773 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6774 | * @see #setDelegatedScopes |
| 6775 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6776 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6777 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6778 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6779 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6780 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6781 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6782 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6783 | } |
| 6784 | } |
| 6785 | |
| 6786 | /** |
| 6787 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6788 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6789 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6790 | * @param admin Which profile or device owner this request is associated with. |
| 6791 | * @return the current policy for future permission requests. |
| 6792 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6793 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6794 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6795 | try { |
| 6796 | return mService.getPermissionPolicy(admin); |
| 6797 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6798 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6799 | } |
| 6800 | } |
| 6801 | |
| 6802 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6803 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6804 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6805 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6806 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6807 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6808 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6809 | * by a profile owner, device owner, or a delegate given the |
| 6810 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6811 | * <p/> |
| 6812 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6813 | * the permission. It retains the previous grant, if any. |
| 6814 | * <p/> |
| 6815 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6816 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6817 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6818 | * @param admin Which profile or device owner this request is associated with. |
| 6819 | * @param packageName The application to grant or revoke a permission to. |
| 6820 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6821 | * @param grantState The permission grant state which is one of |
| 6822 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6823 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6824 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6825 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6826 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6827 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6828 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6829 | * @see #setDelegatedScopes |
| 6830 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6831 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6832 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6833 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6834 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6835 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6836 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6837 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6838 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6839 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6840 | } |
| 6841 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6842 | |
| 6843 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6844 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6845 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6846 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6847 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6848 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6849 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6850 | * @param packageName The application to check the grant state for. |
| 6851 | * @param permission The permission to check for. |
| 6852 | * @return the current grant state specified by device policy. If the profile or device owner |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6853 | * has not set a grant state, the return value is |
| 6854 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6855 | * permission is currently granted for the package. |
| 6856 | * <p/> |
| 6857 | * If a grant state was set by the profile or device owner, then the return value will |
| 6858 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6859 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6860 | * currently denied or granted. |
| 6861 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6862 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6863 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6864 | * @see #setDelegatedScopes |
| 6865 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6866 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 6867 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6868 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6869 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6870 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6871 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6872 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6873 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6874 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6875 | } |
| 6876 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6877 | |
| 6878 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6879 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 6880 | * or device, setting itself as the device or profile owner. |
| 6881 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6882 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6883 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6884 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6885 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6886 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6887 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6888 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6889 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6890 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6891 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6892 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6893 | } |
| 6894 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6895 | |
| 6896 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6897 | * Checks whether it is possible to initiate provisioning a managed device, |
| 6898 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6899 | * |
| 6900 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6901 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 6902 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 6903 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6904 | * @param packageName The package of the component that would be set as device, user, or profile |
| 6905 | * owner. |
| 6906 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6907 | * @hide |
| 6908 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6909 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 6910 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6911 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6912 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6913 | } catch (RemoteException re) { |
| 6914 | throw re.rethrowFromSystemServer(); |
| 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6919 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 6920 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
Kenny Guy | ffa3840 | 2016-03-31 16:40:57 +0100 | [diff] [blame] | 6921 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6922 | * @param admin Which profile owner this request is associated with. |
| 6923 | * @return if this user is a managed profile of another user. |
| 6924 | */ |
| 6925 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6926 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6927 | try { |
| 6928 | return mService.isManagedProfile(admin); |
| 6929 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6930 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6931 | } |
| 6932 | } |
| 6933 | |
| 6934 | /** |
| 6935 | * @hide |
| 6936 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 6937 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 6938 | * @param admin Which device owner this request is associated with. |
| 6939 | * @return if this user is a system-only user. |
| 6940 | */ |
| 6941 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 6942 | try { |
| 6943 | return mService.isSystemOnlyUser(admin); |
| 6944 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6945 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6946 | } |
| 6947 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6948 | |
| 6949 | /** |
| 6950 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 6951 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6952 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6953 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 6954 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 6955 | * <p> |
| 6956 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 6957 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6958 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6959 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6960 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6961 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6962 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6963 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6964 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6965 | } |
| 6966 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6967 | |
| 6968 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6969 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 6970 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6971 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6972 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6973 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6974 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6975 | */ |
| 6976 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6977 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6978 | try { |
| 6979 | mService.reboot(admin); |
| 6980 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6981 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6982 | } |
| 6983 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6984 | |
| 6985 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6986 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 6987 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 6988 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 6989 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 6990 | * truncated. |
| 6991 | * <p> |
| 6992 | * If the short support message needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6993 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6994 | * and set a new version of this string accordingly. |
| 6995 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6996 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6997 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6998 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 6999 | * existing message. |
| 7000 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7001 | */ |
| 7002 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7003 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7004 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7005 | if (mService != null) { |
| 7006 | try { |
| 7007 | mService.setShortSupportMessage(admin, message); |
| 7008 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7009 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7010 | } |
| 7011 | } |
| 7012 | } |
| 7013 | |
| 7014 | /** |
| 7015 | * Called by a device admin to get the short support message. |
| 7016 | * |
| 7017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7018 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 7019 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7020 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7021 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7022 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7023 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7024 | if (mService != null) { |
| 7025 | try { |
| 7026 | return mService.getShortSupportMessage(admin); |
| 7027 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7028 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7029 | } |
| 7030 | } |
| 7031 | return null; |
| 7032 | } |
| 7033 | |
| 7034 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7035 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 7036 | * in the device administators settings screen. |
| 7037 | * <p> |
| 7038 | * If the long support message needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7039 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7040 | * and set a new version of this string accordingly. |
| 7041 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7042 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7043 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7044 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 7045 | * existing message. |
| 7046 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7047 | */ |
| 7048 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7049 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7050 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7051 | if (mService != null) { |
| 7052 | try { |
| 7053 | mService.setLongSupportMessage(admin, message); |
| 7054 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7055 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7056 | } |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | /** |
| 7061 | * Called by a device admin to get the long support message. |
| 7062 | * |
| 7063 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7064 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 7065 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7066 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7067 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7068 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7069 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7070 | if (mService != null) { |
| 7071 | try { |
| 7072 | return mService.getLongSupportMessage(admin); |
| 7073 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7074 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7075 | } |
| 7076 | } |
| 7077 | return null; |
| 7078 | } |
| 7079 | |
| 7080 | /** |
| 7081 | * Called by the system to get the short support message. |
| 7082 | * |
| 7083 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7084 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7085 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7086 | * |
| 7087 | * @hide |
| 7088 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7089 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7090 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7091 | if (mService != null) { |
| 7092 | try { |
| 7093 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 7094 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7095 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7096 | } |
| 7097 | } |
| 7098 | return null; |
| 7099 | } |
| 7100 | |
| 7101 | |
| 7102 | /** |
| 7103 | * Called by the system to get the long support message. |
| 7104 | * |
| 7105 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7106 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7107 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7108 | * |
| 7109 | * @hide |
| 7110 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7111 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 7112 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7113 | if (mService != null) { |
| 7114 | try { |
| 7115 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 7116 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7117 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7118 | } |
| 7119 | } |
| 7120 | return null; |
| 7121 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7122 | |
| 7123 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7124 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 7125 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7126 | * |
| 7127 | * <p>The following methods are supported for the parent instance, all other methods will |
| 7128 | * throw a SecurityException when called on the parent instance: |
| 7129 | * <ul> |
| 7130 | * <li>{@link #getPasswordQuality}</li> |
| 7131 | * <li>{@link #setPasswordQuality}</li> |
| 7132 | * <li>{@link #getPasswordMinimumLength}</li> |
| 7133 | * <li>{@link #setPasswordMinimumLength}</li> |
| 7134 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 7135 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 7136 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 7137 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 7138 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 7139 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 7140 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 7141 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 7142 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 7143 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 7144 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 7145 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 7146 | * <li>{@link #getPasswordHistoryLength}</li> |
| 7147 | * <li>{@link #setPasswordHistoryLength}</li> |
| 7148 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 7149 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 7150 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 7151 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7152 | * <li>{@link #isActivePasswordSufficient}</li> |
| 7153 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 7154 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 7155 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 7156 | * <li>{@link #getMaximumTimeToLock}</li> |
| 7157 | * <li>{@link #setMaximumTimeToLock}</li> |
| 7158 | * <li>{@link #lockNow}</li> |
| 7159 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 7160 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 7161 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 7162 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 7163 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7164 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7165 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7166 | * |
| 7167 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7168 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7169 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7170 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7171 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7172 | try { |
| 7173 | if (!mService.isManagedProfile(admin)) { |
| 7174 | throw new SecurityException("The current user does not have a parent profile."); |
| 7175 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7176 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7177 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7178 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7183 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7184 | * |
| 7185 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7186 | * See {@link SecurityEvent} for details. |
| 7187 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7188 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7189 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7190 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7191 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7192 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7193 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7194 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7195 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7196 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7197 | * @see #retrieveSecurityLogs |
| 7198 | */ |
| 7199 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7200 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7201 | try { |
| 7202 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7203 | } catch (RemoteException re) { |
| 7204 | throw re.rethrowFromSystemServer(); |
| 7205 | } |
| 7206 | } |
| 7207 | |
| 7208 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7209 | * Return whether security logging is enabled or not by the device owner. |
| 7210 | * |
| 7211 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7212 | * thrown. |
| 7213 | * |
| 7214 | * @param admin Which device owner this request is associated with. |
| 7215 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7216 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7217 | */ |
| 7218 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7219 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7220 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7221 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7222 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7223 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7224 | } |
| 7225 | } |
| 7226 | |
| 7227 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7228 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7229 | * this API after device boots. |
| 7230 | * |
| 7231 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7232 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7233 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7234 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7235 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7236 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7237 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7238 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7239 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7240 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7241 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7242 | * profile or secondary user that is not affiliated with the device owner user. |
| 7243 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7244 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7245 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7246 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7247 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7248 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7249 | if (list != null) { |
| 7250 | return list.getList(); |
| 7251 | } else { |
| 7252 | // Rate limit exceeded. |
| 7253 | return null; |
| 7254 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7255 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7256 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7257 | } |
| 7258 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7259 | |
| 7260 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7261 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7262 | * profile. |
| 7263 | * |
| 7264 | * @hide |
| 7265 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7266 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7267 | mContext.checkSelfPermission( |
| 7268 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7269 | if (!uInfo.isManagedProfile()) { |
| 7270 | throw new SecurityException("The user " + uInfo.id |
| 7271 | + " does not have a parent profile."); |
| 7272 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7273 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7274 | } |
| 7275 | |
| 7276 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7277 | * Called by device owners to retrieve device logs from before the device's last reboot. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7278 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7279 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7280 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7281 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7282 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7283 | * |
| 7284 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7285 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7286 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7287 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7288 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7289 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7290 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7291 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7292 | * profile or secondary user that is not affiliated with the device owner user. |
| 7293 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7294 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7295 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7296 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7297 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7298 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7299 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7300 | if (list != null) { |
| 7301 | return list.getList(); |
| 7302 | } else { |
| 7303 | return null; |
| 7304 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7305 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7306 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7307 | } |
| 7308 | } |
| 7309 | |
| 7310 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7311 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7312 | * color is used as background color of the confirm credentials screen for that user. The |
Clara Bayarri | 8d0bd7fa | 2016-03-30 14:59:58 +0100 | [diff] [blame] | 7313 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7314 | * <p> |
| 7315 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7316 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7317 | * |
| 7318 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7319 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7320 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7321 | */ |
| 7322 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7323 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7324 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7325 | // always enforce alpha channel to have 100% opacity |
| 7326 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7327 | mService.setOrganizationColor(admin, color); |
| 7328 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7329 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7330 | } |
| 7331 | } |
| 7332 | |
| 7333 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7334 | * @hide |
| 7335 | * |
| 7336 | * Sets the color used for customization. |
| 7337 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7338 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7339 | * @param userId which user to set the color to. |
| 7340 | * @RequiresPermission(allOf = { |
| 7341 | * Manifest.permission.MANAGE_USERS, |
| 7342 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7343 | */ |
| 7344 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7345 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7346 | // always enforce alpha channel to have 100% opacity |
| 7347 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7348 | mService.setOrganizationColorForUser(color, userId); |
| 7349 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7350 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7351 | } |
| 7352 | } |
| 7353 | |
| 7354 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7355 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7356 | * This color is used as background color of the confirm credentials screen for that user. |
| 7357 | * |
| 7358 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7359 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7360 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7361 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7362 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7363 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7364 | try { |
| 7365 | return mService.getOrganizationColor(admin); |
| 7366 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7367 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7368 | } |
| 7369 | } |
| 7370 | |
| 7371 | /** |
| 7372 | * @hide |
| 7373 | * Retrieve the customization color for a given user. |
| 7374 | * |
| 7375 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7376 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7377 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7378 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7379 | try { |
| 7380 | return mService.getOrganizationColorForUser(userHandle); |
| 7381 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7382 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7383 | } |
| 7384 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7385 | |
| 7386 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7387 | * Called by the device owner or profile owner to set the name of the organization under |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7388 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7389 | * <p> |
| 7390 | * If the organization name needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7391 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7392 | * and set a new version of this string accordingly. |
| 7393 | * |
| 7394 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7395 | * @param title The organization name or {@code null} to clear a previously set name. |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7396 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7397 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7398 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7399 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7400 | try { |
| 7401 | mService.setOrganizationName(admin, title); |
| 7402 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7403 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7404 | } |
| 7405 | } |
| 7406 | |
| 7407 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7408 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7409 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7410 | * |
| 7411 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7412 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7413 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7414 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7415 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7416 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7417 | try { |
| 7418 | return mService.getOrganizationName(admin); |
| 7419 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7420 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7421 | } |
| 7422 | } |
| 7423 | |
| 7424 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7425 | * Called by the system to retrieve the name of the organization managing the device. |
| 7426 | * |
| 7427 | * @return The organization name or {@code null} if none is set. |
| 7428 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7429 | * MANAGE_USERS permission and is not the system. |
| 7430 | * |
| 7431 | * @hide |
| 7432 | */ |
| 7433 | @SystemApi |
| 7434 | @TestApi |
| 7435 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7436 | try { |
| 7437 | return mService.getDeviceOwnerOrganizationName(); |
| 7438 | } catch (RemoteException re) { |
| 7439 | throw re.rethrowFromSystemServer(); |
| 7440 | } |
| 7441 | } |
| 7442 | |
| 7443 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7444 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7445 | * |
| 7446 | * @param userHandle The user id of the user we're interested in. |
| 7447 | * @return The organization name or {@code null} if none is set. |
| 7448 | * |
| 7449 | * @hide |
| 7450 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7451 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7452 | try { |
| 7453 | return mService.getOrganizationNameForUser(userHandle); |
| 7454 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7455 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7456 | } |
| 7457 | } |
| 7458 | |
| 7459 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7460 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7461 | * return {@link #STATE_USER_UNMANAGED} |
| 7462 | * @hide |
| 7463 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7464 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7465 | @UserProvisioningState |
| 7466 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7467 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7468 | if (mService != null) { |
| 7469 | try { |
| 7470 | return mService.getUserProvisioningState(); |
| 7471 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7472 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7473 | } |
| 7474 | } |
| 7475 | return STATE_USER_UNMANAGED; |
| 7476 | } |
| 7477 | |
| 7478 | /** |
| 7479 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7480 | * |
| 7481 | * @param state to store |
| 7482 | * @param userHandle for user |
| 7483 | * @hide |
| 7484 | */ |
| 7485 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7486 | if (mService != null) { |
| 7487 | try { |
| 7488 | mService.setUserProvisioningState(state, userHandle); |
| 7489 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7490 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7491 | } |
| 7492 | } |
| 7493 | } |
| 7494 | |
| 7495 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7496 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7497 | * affiliated if the set of ids set by their device or profile owners intersect. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7498 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7499 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7500 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7501 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7502 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7503 | * created. |
| 7504 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7505 | * @param admin Which profile or device owner this request is associated with. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7506 | * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored. |
| 7507 | * |
| 7508 | * @throws NullPointerException if {@code ids} is null or contains null elements. |
| 7509 | * @throws IllegalArgumentException if {@code ids} contains an empty string. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7510 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7511 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7512 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7513 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7514 | mService.setAffiliationIds(admin, ids); |
| 7515 | } catch (RemoteException e) { |
| 7516 | throw e.rethrowFromSystemServer(); |
| 7517 | } |
| 7518 | } |
| 7519 | |
| 7520 | /** |
| 7521 | * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7522 | * empty list if none have been set. |
| 7523 | */ |
| 7524 | public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) { |
| 7525 | throwIfParentInstance("getAffiliationIds"); |
| 7526 | try { |
| 7527 | return mService.getAffiliationIds(admin); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7528 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7529 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7530 | } |
| 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7535 | * Returns whether this user/profile is affiliated with the device. |
| 7536 | * <p> |
| 7537 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7538 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7539 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7540 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7541 | */ |
| 7542 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7543 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7544 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7545 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7547 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7548 | } |
| 7549 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7550 | |
| 7551 | /** |
| 7552 | * @hide |
| 7553 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7554 | * to be started |
| 7555 | * @param packageName the package to check for |
| 7556 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7557 | */ |
| 7558 | public boolean isUninstallInQueue(String packageName) { |
| 7559 | try { |
| 7560 | return mService.isUninstallInQueue(packageName); |
| 7561 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7562 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7563 | } |
| 7564 | } |
| 7565 | |
| 7566 | /** |
| 7567 | * @hide |
| 7568 | * @param packageName the package containing active DAs to be uninstalled |
| 7569 | */ |
| 7570 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7571 | try { |
| 7572 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7573 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7574 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7575 | } |
| 7576 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7577 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7578 | /** |
| 7579 | * @hide |
| 7580 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7581 | * If the admin is a profile owner or device owner it will still be removed. |
| 7582 | * |
| 7583 | * @param userHandle user id to remove the admin for. |
| 7584 | * @param admin The administration compononent to remove. |
| 7585 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7586 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7587 | */ |
| 7588 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7589 | try { |
| 7590 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7591 | } catch (RemoteException re) { |
| 7592 | throw re.rethrowFromSystemServer(); |
| 7593 | } |
| 7594 | } |
| 7595 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7596 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7597 | * Returns whether the device has been provisioned. |
| 7598 | * |
| 7599 | * <p>Not for use by third-party applications. |
| 7600 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7601 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7602 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7603 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7604 | public boolean isDeviceProvisioned() { |
| 7605 | try { |
| 7606 | return mService.isDeviceProvisioned(); |
| 7607 | } catch (RemoteException re) { |
| 7608 | throw re.rethrowFromSystemServer(); |
| 7609 | } |
| 7610 | } |
| 7611 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7612 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7613 | * Writes that the provisioning configuration has been applied. |
| 7614 | * |
| 7615 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7616 | * permission. |
| 7617 | * |
| 7618 | * <p>Not for use by third-party applications. |
| 7619 | * |
| 7620 | * @hide |
| 7621 | */ |
| 7622 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7623 | public void setDeviceProvisioningConfigApplied() { |
| 7624 | try { |
| 7625 | mService.setDeviceProvisioningConfigApplied(); |
| 7626 | } catch (RemoteException re) { |
| 7627 | throw re.rethrowFromSystemServer(); |
| 7628 | } |
| 7629 | } |
| 7630 | |
| 7631 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7632 | * Returns whether the provisioning configuration has been applied. |
| 7633 | * |
| 7634 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7635 | * |
| 7636 | * <p>Not for use by third-party applications. |
| 7637 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7638 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7639 | * |
| 7640 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7641 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7642 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7643 | public boolean isDeviceProvisioningConfigApplied() { |
| 7644 | try { |
| 7645 | return mService.isDeviceProvisioningConfigApplied(); |
| 7646 | } catch (RemoteException re) { |
| 7647 | throw re.rethrowFromSystemServer(); |
| 7648 | } |
| 7649 | } |
| 7650 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7651 | /** |
| 7652 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7653 | * Force update user setup completed status. This API has no effect on user build. |
| 7654 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7655 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7656 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7657 | */ |
| 7658 | public void forceUpdateUserSetupComplete() { |
| 7659 | try { |
| 7660 | mService.forceUpdateUserSetupComplete(); |
| 7661 | } catch (RemoteException re) { |
| 7662 | throw re.rethrowFromSystemServer(); |
| 7663 | } |
| 7664 | } |
| 7665 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7666 | private void throwIfParentInstance(String functionName) { |
| 7667 | if (mParentInstance) { |
| 7668 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7669 | } |
| 7670 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7671 | |
| 7672 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7673 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7674 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7675 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7676 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7677 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7678 | * <p> Backup service is off by default when device owner is present. |
| 7679 | * |
| 7680 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7681 | */ |
| 7682 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7683 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7684 | try { |
| 7685 | mService.setBackupServiceEnabled(admin, enabled); |
| 7686 | } catch (RemoteException re) { |
| 7687 | throw re.rethrowFromSystemServer(); |
| 7688 | } |
| 7689 | } |
| 7690 | |
| 7691 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7692 | * Return whether the backup service is enabled by the device owner. |
| 7693 | * |
| 7694 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7695 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7696 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7697 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7698 | */ |
| 7699 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7700 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7701 | try { |
| 7702 | return mService.isBackupServiceEnabled(admin); |
| 7703 | } catch (RemoteException re) { |
| 7704 | throw re.rethrowFromSystemServer(); |
| 7705 | } |
| 7706 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7707 | |
| 7708 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7709 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7710 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 7711 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 7712 | * functions are recorded while network logging is active: |
| 7713 | * <ul> |
| 7714 | * <li>{@code getaddrinfo()}</li> |
| 7715 | * <li>{@code gethostbyname()}</li> |
| 7716 | * <li>{@code connect()}</li> |
| 7717 | * </ul> |
| 7718 | * |
| 7719 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 7720 | * full system call logging; event reporting is enabled by default for all processes but not |
| 7721 | * strongly enforced. |
| 7722 | * Events from applications using alternative implementations of libc, making direct kernel |
| 7723 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 7724 | * |
| 7725 | * <p> Some common network events may not be reported. For example: |
| 7726 | * <ul> |
| 7727 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 7728 | * an alternative system for name resolution, and so avoid calling |
| 7729 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 7730 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 7731 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 7732 | * socket, so it will not trigger a network event.</li> |
| 7733 | * </ul> |
| 7734 | * |
| 7735 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 7736 | * always-on VPN service. |
| 7737 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 7738 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7739 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7740 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7741 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7742 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7743 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7744 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7745 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7746 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7747 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7748 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7749 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7750 | */ |
| 7751 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7752 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7753 | try { |
| 7754 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7755 | } catch (RemoteException re) { |
| 7756 | throw re.rethrowFromSystemServer(); |
| 7757 | } |
| 7758 | } |
| 7759 | |
| 7760 | /** |
| 7761 | * Return whether network logging is enabled by a device owner. |
| 7762 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7763 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7764 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7765 | * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7766 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7767 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7768 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7769 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7770 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7771 | try { |
| 7772 | return mService.isNetworkLoggingEnabled(admin); |
| 7773 | } catch (RemoteException re) { |
| 7774 | throw re.rethrowFromSystemServer(); |
| 7775 | } |
| 7776 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7777 | |
| 7778 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7779 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7780 | * A device owner has to provide a batchToken provided as part of |
| 7781 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7782 | * token of the most recent available batch of logs, {@code null} will be returned. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7783 | * |
| 7784 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7785 | * |
| 7786 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7787 | * |
| 7788 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7789 | * after the device device owner has been notified via |
| 7790 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7791 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7792 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7793 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7794 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7795 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7796 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7797 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7798 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7799 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7800 | * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7801 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7802 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7803 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7804 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7805 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7806 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7807 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7808 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7809 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7810 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7811 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7812 | } catch (RemoteException re) { |
| 7813 | throw re.rethrowFromSystemServer(); |
| 7814 | } |
| 7815 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7816 | |
| 7817 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7818 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 7819 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7820 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7821 | * <p> |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7822 | * The service must be unexported. Note that the {@link Context} used to obtain this |
| 7823 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7824 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7825 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7826 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7827 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7828 | * explicit component name or a package name to match an |
| 7829 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7830 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7831 | * must be a valid {@link ServiceConnection} object; it must not be {@code null}. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7832 | * @param flags Operation options for the binding operation. See |
| 7833 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7834 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7835 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7836 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7837 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7838 | * {@code false} is returned if the connection is not made and you will not |
| 7839 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7840 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7841 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7842 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7843 | */ |
| 7844 | public boolean bindDeviceAdminServiceAsUser( |
| 7845 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7846 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7847 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7848 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7849 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7850 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7851 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7852 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7853 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7854 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7855 | sd, flags, targetUser.getIdentifier()); |
| 7856 | } catch (RemoteException re) { |
| 7857 | throw re.rethrowFromSystemServer(); |
| 7858 | } |
| 7859 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7860 | |
| 7861 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7862 | * Returns the list of target users that the calling device or profile owner can use when |
| 7863 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7864 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7865 | * A device owner can bind to a service from a profile owner and vice versa, provided that: |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7866 | * <ul> |
| 7867 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7868 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7869 | * </ul> |
| 7870 | */ |
| 7871 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7872 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7873 | try { |
| 7874 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7875 | } catch (RemoteException re) { |
| 7876 | throw re.rethrowFromSystemServer(); |
| 7877 | } |
| 7878 | } |
| 7879 | |
| 7880 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7881 | * Called by the system to get the time at which the device owner last retrieved security |
| 7882 | * logging entries. |
| 7883 | * |
| 7884 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 7885 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7886 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7887 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7888 | * |
| 7889 | * @hide |
| 7890 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7891 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7892 | public long getLastSecurityLogRetrievalTime() { |
| 7893 | try { |
| 7894 | return mService.getLastSecurityLogRetrievalTime(); |
| 7895 | } catch (RemoteException re) { |
| 7896 | throw re.rethrowFromSystemServer(); |
| 7897 | } |
| 7898 | } |
| 7899 | |
| 7900 | /** |
| 7901 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 7902 | * |
| 7903 | * @return the time at which the device owner most recently requested a bug report, in |
| 7904 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7905 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7906 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7907 | * |
| 7908 | * @hide |
| 7909 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7910 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7911 | public long getLastBugReportRequestTime() { |
| 7912 | try { |
| 7913 | return mService.getLastBugReportRequestTime(); |
| 7914 | } catch (RemoteException re) { |
| 7915 | throw re.rethrowFromSystemServer(); |
| 7916 | } |
| 7917 | } |
| 7918 | |
| 7919 | /** |
| 7920 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 7921 | * events. |
| 7922 | * |
| 7923 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 7924 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7925 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7926 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7927 | * |
| 7928 | * @hide |
| 7929 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7930 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7931 | public long getLastNetworkLogRetrievalTime() { |
| 7932 | try { |
| 7933 | return mService.getLastNetworkLogRetrievalTime(); |
| 7934 | } catch (RemoteException re) { |
| 7935 | throw re.rethrowFromSystemServer(); |
| 7936 | } |
| 7937 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 7938 | |
| 7939 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame^] | 7940 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 7941 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 7942 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 7943 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 7944 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame^] | 7945 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 7946 | * |
| 7947 | * @hide |
| 7948 | */ |
| 7949 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame^] | 7950 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 7951 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame^] | 7952 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 7953 | } catch (RemoteException re) { |
| 7954 | throw re.rethrowFromSystemServer(); |
| 7955 | } |
| 7956 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 7957 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 7958 | /** |
| 7959 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 7960 | * profile owner. |
| 7961 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame^] | 7962 | * <p> The caller must be the target user's device owner/profile Owner or hold the |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 7963 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 7964 | * |
| 7965 | * @param user The user for whom to retrieve information. |
| 7966 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 7967 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 7968 | * about the given user's CA certificates. |
| 7969 | * |
| 7970 | * @hide |
| 7971 | */ |
| 7972 | @TestApi |
| 7973 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 7974 | try { |
| 7975 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 7976 | } catch (RemoteException re) { |
| 7977 | throw re.rethrowFromSystemServer(); |
| 7978 | } |
| 7979 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 7980 | } |