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; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 59 | import android.util.ArraySet; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 60 | import android.util.Log; |
| 61 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 62 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 63 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 64 | |
| 65 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 66 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 67 | import java.lang.annotation.Retention; |
| 68 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 69 | import java.net.InetSocketAddress; |
| 70 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 71 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 72 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 73 | import java.security.PrivateKey; |
| 74 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 75 | import java.security.cert.CertificateException; |
| 76 | import java.security.cert.CertificateFactory; |
| 77 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 78 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 79 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 80 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 81 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 82 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 83 | import java.util.List; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 84 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 87 | * 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] | 88 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 89 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 90 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 91 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 92 | * application calling an api may only pass as an argument a device administrator component it |
| 93 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 94 | * <div class="special reference"> |
| 95 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 96 | * <p> |
| 97 | * For more information about managing policies for device administration, read the <a href= |
| 98 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 99 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 100 | */ |
| 101 | public class DevicePolicyManager { |
| 102 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 103 | |
| 104 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 105 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 106 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 107 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 108 | /** @hide */ |
| 109 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 110 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 113 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 115 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 116 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | mContext = context; |
| 118 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 119 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 122 | /** @hide test will override it. */ |
| 123 | @VisibleForTesting |
| 124 | protected int myUserId() { |
| 125 | return UserHandle.myUserId(); |
| 126 | } |
| 127 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 128 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 129 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 130 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 131 | * <p>A managed profile allows data separation for example for the usage of a |
| 132 | * device as a personal and corporate device. The user which provisioning is started from and |
| 133 | * the managed profile share a launcher. |
| 134 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 135 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 136 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 137 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 138 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 139 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 140 | * {@link #isProvisioningAllowed(String)}. |
| 141 | * |
| 142 | * <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] | 143 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 144 | * 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] | 145 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 146 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 147 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 148 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 149 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 150 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 152 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 153 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 154 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 155 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 156 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 157 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 158 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 159 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 160 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 161 | * <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] | 162 | * in the provisioning intent. The |
| 163 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 164 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 165 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 166 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 167 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 168 | * completed, along with the above broadcast, activity intent |
| 169 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 170 | * the provisioning intent. |
| 171 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 172 | * <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] | 173 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 174 | * |
| 175 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 176 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 177 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 178 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 179 | * 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] | 180 | */ |
| 181 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 182 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 183 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 184 | |
| 185 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 186 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 187 | * |
| 188 | * <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] | 189 | * 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] | 190 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 191 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 192 | * allowed. |
| 193 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 194 | * <p>The intent contains the following extras: |
| 195 | * <ul> |
| 196 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 197 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 198 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 199 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 200 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 201 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 202 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 203 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 204 | * |
| 205 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 206 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 207 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 208 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 209 | * 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] | 210 | * |
| 211 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 212 | */ |
| 213 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 214 | public static final String ACTION_PROVISION_MANAGED_USER |
| 215 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 216 | |
| 217 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 218 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 219 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 220 | * |
| 221 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 222 | * A device owner has full control over the device. The device owner can not be modified by the |
| 223 | * user. |
| 224 | * |
| 225 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 226 | * employee or client. |
| 227 | * |
| 228 | * <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] | 229 | * It is possible to check if provisioning is allowed or not by querying the method |
| 230 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 231 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 232 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 233 | * <ul> |
| 234 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 235 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 236 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 237 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 238 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 239 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 240 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 241 | * </ul> |
| 242 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 243 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 244 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 245 | * device owner. |
| 246 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 247 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 248 | * completed, along with the above broadcast, activity intent |
| 249 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 250 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 251 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 252 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 253 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 254 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 255 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 256 | * 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] | 257 | */ |
| 258 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 259 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 260 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 261 | |
| 262 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 263 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 264 | * |
| 265 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 266 | * the device. A device owner has full control over the device. The device owner can not be |
| 267 | * modified by the user and the only way of resetting the device is via factory reset. |
| 268 | * |
| 269 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 270 | * employee or client. |
| 271 | * |
| 272 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 273 | * |
| 274 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 275 | * by a privileged app with the permission |
| 276 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 277 | * |
| 278 | * <p>The provisioning intent contains the following properties: |
| 279 | * <ul> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 282 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 283 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 284 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 286 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 288 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 290 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 291 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 292 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 293 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 294 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 295 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 296 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 297 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 298 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 299 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 300 | * |
| 301 | * @hide |
| 302 | */ |
| 303 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 304 | @SystemApi |
| 305 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 306 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 307 | |
| 308 | /** |
| 309 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 310 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 311 | * |
| 312 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 313 | * management state that is distinct from that reached by |
| 314 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 315 | * user, and only has control over device-wide policies, not individual users and their data. |
| 316 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 317 | * this form of device management. |
| 318 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 319 | * <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] | 320 | * A device owner has full control over the device. The device owner can not be modified by the |
| 321 | * user. |
| 322 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 323 | * <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] | 324 | * employee or client. |
| 325 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 326 | * <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] | 327 | * It is possible to check if provisioning is allowed or not by querying the method |
| 328 | * {@link #isProvisioningAllowed(String)}. |
| 329 | * |
| 330 | * <p>The intent contains the following extras: |
| 331 | * <ul> |
| 332 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 333 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 334 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 335 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 336 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 337 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 338 | * </ul> |
| 339 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 340 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 341 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 342 | * device owner. |
| 343 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 344 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 345 | * completed, along with the above broadcast, activity intent |
| 346 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 347 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 348 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 349 | * |
| 350 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 351 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 352 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 353 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 354 | * |
| 355 | * @hide |
| 356 | */ |
| 357 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 358 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 359 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 360 | |
| 361 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 362 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 363 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 364 | * <ul> |
| 365 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 366 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 367 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 368 | * </ul> |
| 369 | * |
| 370 | * @hide |
| 371 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 372 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 373 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 374 | public static final String ACTION_PROVISION_FINALIZATION |
| 375 | = "android.app.action.PROVISION_FINALIZATION"; |
| 376 | |
| 377 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 378 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 379 | * |
| 380 | * @hide |
| 381 | */ |
| 382 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 383 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 384 | |
| 385 | /** |
| 386 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 387 | * |
| 388 | * @hide |
| 389 | */ |
| 390 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 391 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 392 | |
| 393 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 394 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 395 | * |
| 396 | * @hide |
| 397 | */ |
| 398 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 399 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 400 | |
| 401 | /** |
| 402 | * Extra for shared bugreport's SHA-256 hash. |
| 403 | * |
| 404 | * @hide |
| 405 | */ |
| 406 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 407 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 408 | |
| 409 | /** |
| 410 | * Extra for remote bugreport notification shown type. |
| 411 | * |
| 412 | * @hide |
| 413 | */ |
| 414 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 415 | "android.app.extra.bugreport_notification_type"; |
| 416 | |
| 417 | /** |
| 418 | * Notification type for a started remote bugreport flow. |
| 419 | * |
| 420 | * @hide |
| 421 | */ |
| 422 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 423 | |
| 424 | /** |
| 425 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 426 | * being taken. |
| 427 | * |
| 428 | * @hide |
| 429 | */ |
| 430 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 431 | |
| 432 | /** |
| 433 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 434 | * |
| 435 | * @hide |
| 436 | */ |
| 437 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 438 | |
| 439 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 440 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 441 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 442 | * |
| 443 | * @hide |
| 444 | */ |
| 445 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 446 | |
| 447 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 448 | * 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] | 449 | * allows a mobile device management application or NFC programmer application which starts |
| 450 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 451 | * <p> |
| 452 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 453 | * sends the intent to pass data to itself on the newly created profile. |
| 454 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 455 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 456 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 457 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 458 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 459 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 460 | * management application after provisioning. |
| 461 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 462 | * <p> |
| 463 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 464 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 465 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 466 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 467 | */ |
| 468 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 469 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 470 | |
| 471 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 472 | * A String extra holding the package name of the mobile device management application that |
| 473 | * will be set as the profile owner or device owner. |
| 474 | * |
| 475 | * <p>If an application starts provisioning directly via an intent with action |
| 476 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 477 | * application that started provisioning. The package will be set as profile owner in that case. |
| 478 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 479 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 480 | * 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] | 481 | * |
| 482 | * <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] | 483 | * 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] | 484 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 485 | * @see DeviceAdminReceiver |
| 486 | * @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] | 487 | * supported, but only if there is only one device admin receiver in the package that requires |
| 488 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 489 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 490 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 491 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 492 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 493 | |
| 494 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 495 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 496 | * application that will be set as the profile owner or device owner and active admin. |
| 497 | * |
| 498 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 499 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 500 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 501 | * 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] | 502 | * |
| 503 | * <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] | 504 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 505 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 506 | * {@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] | 507 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 508 | * |
| 509 | * @see DeviceAdminReceiver |
| 510 | */ |
| 511 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 512 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 513 | |
| 514 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 515 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 516 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 517 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 518 | * |
| 519 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 520 | */ |
| 521 | |
| 522 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 523 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 524 | |
| 525 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 526 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 527 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 528 | * the account will not be removed from the primary user after it is migrated to the newly |
| 529 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 530 | * |
| 531 | * <p> Defaults to {@code false} |
| 532 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 533 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 534 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 535 | */ |
| 536 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 537 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 538 | |
| 539 | /** |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 540 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the |
| 541 | * device. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 542 | */ |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 543 | @Deprecated |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 544 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 545 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 546 | |
| 547 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 548 | * A integer extra indicating the predominant color to show during the provisioning. |
| 549 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 550 | * |
| 551 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 552 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 553 | */ |
| 554 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 555 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 556 | |
| 557 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 558 | * 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] | 559 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 560 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 561 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 562 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 563 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 564 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 565 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 566 | |
| 567 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 568 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 569 | * will be set to. |
| 570 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 571 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 572 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 573 | */ |
| 574 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 575 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 576 | |
| 577 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 578 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 579 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 580 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 581 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 582 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 583 | */ |
| 584 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 585 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 586 | |
| 587 | /** |
| 588 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 589 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 590 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 591 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 592 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 593 | */ |
| 594 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 595 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 596 | |
| 597 | /** |
| 598 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 599 | * owner provisioning for downloading the mobile device management application. |
| 600 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 601 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 602 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 603 | */ |
| 604 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 605 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 606 | |
| 607 | /** |
| 608 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 609 | * is hidden or not. |
| 610 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 611 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 612 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 613 | */ |
| 614 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 615 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 616 | |
| 617 | /** |
| 618 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 619 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 620 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 621 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 622 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 623 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 624 | */ |
| 625 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 626 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 627 | |
| 628 | /** |
| 629 | * A String extra holding the password of the wifi network in |
| 630 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 631 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 632 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 633 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 634 | */ |
| 635 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 636 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 637 | |
| 638 | /** |
| 639 | * A String extra holding the proxy host for the wifi network in |
| 640 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 641 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 642 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 643 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 644 | */ |
| 645 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 646 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 647 | |
| 648 | /** |
| 649 | * An int extra holding the proxy port for the wifi network in |
| 650 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 651 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 652 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 653 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 654 | */ |
| 655 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 656 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 657 | |
| 658 | /** |
| 659 | * A String extra holding the proxy bypass for the wifi network in |
| 660 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 661 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 662 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 663 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 664 | */ |
| 665 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 666 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 667 | |
| 668 | /** |
| 669 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 670 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 671 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 672 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 673 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 674 | */ |
| 675 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 676 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 677 | |
| 678 | /** |
| 679 | * A String extra holding a url that specifies the download location of the device admin |
| 680 | * package. When not provided it is assumed that the device admin package is already installed. |
| 681 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 682 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 683 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 684 | */ |
| 685 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 686 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 687 | |
| 688 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 689 | * A String extra holding the localized name of the organization under management. |
| 690 | * |
| 691 | * The name is displayed only during provisioning. |
| 692 | * |
| 693 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 694 | * |
| 695 | * @hide |
| 696 | */ |
| 697 | @SystemApi |
| 698 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 699 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 700 | |
| 701 | /** |
Alejandro Fernández | bfd6193 | 2017-04-04 19:33:01 +0100 | [diff] [blame] | 702 | * A String extra holding a url to the website of the device provider so the user can open it |
| 703 | * during provisioning. If the url is not HTTPS, an error will be shown. |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 704 | * |
| 705 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 706 | * |
| 707 | * @hide |
| 708 | */ |
| 709 | @SystemApi |
| 710 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 711 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 712 | |
| 713 | /** |
| 714 | * A String extra holding the localized name of the device admin package. It should be the same |
| 715 | * as the app label of the package. |
| 716 | * |
| 717 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 718 | * |
| 719 | * @hide |
| 720 | */ |
| 721 | @SystemApi |
| 722 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 723 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 724 | |
| 725 | /** |
| 726 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 727 | * shown during the provisioning. |
| 728 | * <h5>The following URI schemes are accepted:</h5> |
| 729 | * <ul> |
| 730 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 731 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 732 | * </ul> |
| 733 | * |
| 734 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 735 | * pixel density for the device. |
| 736 | * |
| 737 | * <p> If a content: URI is passed, the intent should have the flag |
| 738 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 739 | * {@link android.content.ClipData} of the intent too. |
| 740 | * |
| 741 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 742 | * |
| 743 | * @hide |
| 744 | */ |
| 745 | @SystemApi |
| 746 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 747 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 748 | |
| 749 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 750 | * An int extra holding a minimum required version code for the device admin package. If the |
| 751 | * device admin is already installed on the device, it will only be re-downloaded from |
| 752 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 753 | * installed package is less than this version code. |
| 754 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 755 | * <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] | 756 | * provisioning via an NFC bump. |
| 757 | */ |
| 758 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 759 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 760 | |
| 761 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 762 | * A String extra holding a http cookie header which should be used in the http request to the |
| 763 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 764 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 765 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 766 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 767 | */ |
| 768 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 769 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 770 | |
| 771 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 772 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 773 | * the file at download location specified in |
| 774 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 775 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 776 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 777 | * 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] | 778 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 779 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 780 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 781 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 782 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 783 | * |
| 784 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 785 | * 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] | 786 | * 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] | 787 | * 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] | 788 | */ |
| 789 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 790 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 791 | |
| 792 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 793 | * 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] | 794 | * android package archive at the download location specified in {@link |
| 795 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 796 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 797 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 798 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 799 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 800 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 801 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 802 | * 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] | 803 | * the download location. If the checksum does not match an error will be shown to the user and |
| 804 | * the user will be asked to factory reset the device. |
| 805 | * |
| 806 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 807 | * provisioning via an NFC bump. |
| 808 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 809 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 810 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 811 | |
| 812 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 813 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 814 | * has completed successfully. |
| 815 | * |
| 816 | * <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] | 817 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 818 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 819 | * <p>This intent will contain the following extras |
| 820 | * <ul> |
| 821 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 822 | * profile.</li> |
| 823 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 824 | * be migrated at provisioning time, if any.</li> |
| 825 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 826 | */ |
| 827 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 828 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 829 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 830 | |
| 831 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 832 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 833 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 834 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 835 | * delivered faster as it's an activity intent. |
| 836 | * |
| 837 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 838 | * the device owner case the profile is the primary user. |
| 839 | * |
| 840 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 841 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 842 | */ |
| 843 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 844 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 845 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 846 | |
| 847 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 848 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 849 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 850 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 851 | * <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] | 852 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 853 | * |
| 854 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 855 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 856 | */ |
| 857 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 858 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 859 | |
| 860 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 861 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 862 | * provisioning. If this extra is not passed, a default image will be shown. |
| 863 | * <h5>The following URI schemes are accepted:</h5> |
| 864 | * <ul> |
| 865 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 866 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 867 | * </ul> |
| 868 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 869 | * <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] | 870 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 871 | * |
| 872 | * <p> If a content: URI is passed, the intent should have the flag |
| 873 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 874 | * {@link android.content.ClipData} of the intent too. |
| 875 | * |
| 876 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 877 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 878 | */ |
| 879 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 880 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 881 | |
| 882 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 883 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 884 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 885 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 886 | * content. |
| 887 | * |
| 888 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 889 | * management application (MDM), and one disclaimer from the organization. |
| 890 | * |
| 891 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 892 | * |
| 893 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 894 | * |
| 895 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 896 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 897 | */ |
| 898 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 899 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 900 | |
| 901 | /** |
| 902 | * A String extra of localized disclaimer header. |
| 903 | * |
| 904 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 905 | * or the organization name. |
| 906 | * |
| 907 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 908 | * |
| 909 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 910 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 911 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 912 | * |
| 913 | * <pre> |
| 914 | * <meta-data |
| 915 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 916 | * android:resource="@string/disclaimer_header" |
| 917 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 918 | */ |
| 919 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 920 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 921 | |
| 922 | /** |
| 923 | * A {@link Uri} extra pointing to disclaimer content. |
| 924 | * |
| 925 | * <h5>The following URI schemes are accepted:</h5> |
| 926 | * <ul> |
| 927 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 928 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 929 | * </ul> |
| 930 | * |
| 931 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 932 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 933 | * {@link android.widget.TextView}. |
| 934 | * |
| 935 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 936 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 937 | * {@link android.content.ClipData} of the intent too. |
| 938 | * |
| 939 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 940 | * |
| 941 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 942 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 943 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 944 | * |
| 945 | * <pre> |
| 946 | * <meta-data |
| 947 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 948 | * android:resource="@string/disclaimer_content" |
| 949 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 950 | */ |
| 951 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 952 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 953 | |
| 954 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 955 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 956 | * during setup-wizard. |
| 957 | * |
| 958 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 959 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 960 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 961 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 962 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 963 | * |
| 964 | * @hide |
| 965 | */ |
| 966 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 967 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 968 | |
| 969 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 970 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 971 | * skipped. If unspecified, defaults to {@code false}. |
| 972 | * |
| 973 | * It can only be used by an existing device owner trying to create a managed profile via |
| 974 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 975 | */ |
| 976 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 977 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 978 | |
| 979 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 980 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 981 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 982 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 983 | * A device owner has full control over the device. The device owner can not be modified by the |
| 984 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 985 | * reset. |
| 986 | * |
| 987 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 988 | * employee or client. |
| 989 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 990 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 991 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 992 | * <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] | 993 | * contains the following properties: |
| 994 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 995 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 996 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 997 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 998 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 999 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1000 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1001 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1002 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1003 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1004 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1005 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1006 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1007 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1008 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1009 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1010 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1011 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1012 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1013 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1014 | * 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] | 1015 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1016 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1017 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1018 | */ |
| 1019 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1020 | = "application/com.android.managedprovisioning"; |
| 1021 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1022 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1023 | * Activity action: ask the user to add a new device administrator to the system. |
| 1024 | * The desired policy is the ComponentName of the policy in the |
| 1025 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1026 | * bring the user through adding the device administrator to the system (or |
| 1027 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1028 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1029 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1030 | * field to provide the user with additional explanation (in addition |
| 1031 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1032 | * |
| 1033 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1034 | * user intervention). However, if your administrator has been updated and is requesting |
| 1035 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1036 | * 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] | 1037 | */ |
| 1038 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1039 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1040 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1041 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1042 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1043 | * @hide |
| 1044 | * 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] | 1045 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1046 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1047 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1048 | * 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] | 1049 | * to remotely control restrictions on the user. |
| 1050 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1051 | * <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] | 1052 | * result of whether or not the user approved the action. If approved, the result will |
| 1053 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1054 | * as a profile owner. |
| 1055 | * |
| 1056 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1057 | * field to provide the user with additional explanation (in addition |
| 1058 | * to your component's description) about what is being added. |
| 1059 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1060 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1061 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1062 | */ |
| 1063 | @SystemApi |
| 1064 | public static final String ACTION_SET_PROFILE_OWNER |
| 1065 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1066 | |
| 1067 | /** |
| 1068 | * @hide |
| 1069 | * Name of the profile owner admin that controls the user. |
| 1070 | */ |
| 1071 | @SystemApi |
| 1072 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1073 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1074 | |
| 1075 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1076 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1077 | * 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] | 1078 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1079 | * @hide |
| 1080 | */ |
| 1081 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1082 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1083 | |
| 1084 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1085 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1086 | * |
| 1087 | * This broadcast is sent only to the primary user. |
| 1088 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1089 | */ |
| 1090 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1091 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1092 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1093 | |
| 1094 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1095 | * The ComponentName of the administrator component. |
| 1096 | * |
| 1097 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1098 | */ |
| 1099 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1100 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1101 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1102 | * An optional CharSequence providing additional explanation for why the |
| 1103 | * admin is being added. |
| 1104 | * |
| 1105 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1106 | */ |
| 1107 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1108 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1109 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1110 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1111 | * {@link #createAdminSupportIntent(String)}. |
| 1112 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1113 | */ |
| 1114 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1115 | |
| 1116 | /** |
| 1117 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1118 | * {@link #createAdminSupportIntent(String)}. |
| 1119 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1120 | */ |
| 1121 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1122 | |
| 1123 | /** |
| 1124 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1125 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1126 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1127 | * @see #createAdminSupportIntent(String) |
| 1128 | * @hide |
| 1129 | */ |
| 1130 | @TestApi |
| 1131 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1132 | |
| 1133 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1134 | * Activity action: have the user enter a new password. This activity should |
| 1135 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1136 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1137 | * enter a new password that meets the current requirements. You can use |
| 1138 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1139 | * have the user select a new password in order to meet the current |
| 1140 | * constraints. Upon being resumed from this activity, you can check the new |
| 1141 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1142 | * |
| 1143 | * If the intent is launched from within a managed profile with a profile |
| 1144 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1145 | * this will trigger entering a new password for the parent of the profile. |
| 1146 | * For all other cases it will trigger entering a new password for the user |
| 1147 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1148 | * |
| 1149 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1150 | */ |
| 1151 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1152 | public static final String ACTION_SET_NEW_PASSWORD |
| 1153 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1154 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1155 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1156 | * Activity action: have the user enter a new password for the parent profile. |
| 1157 | * If the intent is launched from within a managed profile, this will trigger |
| 1158 | * entering a new password for the parent of the profile. In all other cases |
| 1159 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1160 | */ |
| 1161 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1162 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1163 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1164 | |
| 1165 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1166 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1167 | * Network logging was enabled and the user tapped the notification. |
| 1168 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1169 | * @hide |
| 1170 | */ |
| 1171 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1172 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1173 | |
| 1174 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1175 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1176 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1177 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1178 | * |
| 1179 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1180 | */ |
| 1181 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1182 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1183 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1184 | |
| 1185 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1186 | * 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] | 1187 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1188 | */ |
| 1189 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1190 | |
| 1191 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1192 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1193 | * the parent profile to access intents sent from the managed profile. |
| 1194 | * That is, when an app in the managed profile calls |
| 1195 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1196 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1197 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1198 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1199 | |
| 1200 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1201 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1202 | * the managed profile to access intents sent from the parent profile. |
| 1203 | * That is, when an app in the parent profile calls |
| 1204 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1205 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1206 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1207 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1208 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1209 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1210 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1211 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1212 | */ |
| 1213 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1214 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1215 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1216 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1217 | /** |
| 1218 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1219 | * Already granted or denied permissions are not affected by this. |
| 1220 | */ |
| 1221 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1222 | |
| 1223 | /** |
| 1224 | * Permission policy to always grant 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_AUTO_GRANT = 1; |
| 1228 | |
| 1229 | /** |
| 1230 | * Permission policy to always deny 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_DENY = 2; |
| 1234 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1235 | /** |
| 1236 | * Runtime permission state: The user can manage the permission |
| 1237 | * through the UI. |
| 1238 | */ |
| 1239 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1240 | |
| 1241 | /** |
| 1242 | * Runtime permission state: The permission is granted to the app |
| 1243 | * and the user cannot manage the permission through the UI. |
| 1244 | */ |
| 1245 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1246 | |
| 1247 | /** |
| 1248 | * Runtime permission state: The permission is denied to the app |
| 1249 | * and the user cannot manage the permission through the UI. |
| 1250 | */ |
| 1251 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1252 | |
| 1253 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1254 | * Delegation of certificate installation and management. This scope grants access to the |
| 1255 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1256 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1257 | */ |
| 1258 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1259 | |
| 1260 | /** |
| 1261 | * Delegation of application restrictions management. This scope grants access to the |
| 1262 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1263 | */ |
| 1264 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1265 | |
| 1266 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1267 | * Delegation of application uninstall block. This scope grants access to the |
| 1268 | * {@link #setUninstallBlocked} API. |
| 1269 | */ |
| 1270 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1271 | |
| 1272 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1273 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1274 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1275 | * and {@link #setPermissionGrantState} APIs. |
| 1276 | */ |
| 1277 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1278 | |
| 1279 | /** |
| 1280 | * Delegation of package access state. This scope grants access to the |
| 1281 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1282 | * {@link #setPackagesSuspended} APIs. |
| 1283 | */ |
| 1284 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1285 | |
| 1286 | /** |
| 1287 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1288 | * API. |
| 1289 | */ |
| 1290 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1291 | |
| 1292 | /** |
| 1293 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1294 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1295 | * @hide |
| 1296 | */ |
| 1297 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1298 | "delegation-keep-uninstalled-packages"; |
| 1299 | |
| 1300 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1301 | * No management for current user in-effect. This is the default. |
| 1302 | * @hide |
| 1303 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1304 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1305 | public static final int STATE_USER_UNMANAGED = 0; |
| 1306 | |
| 1307 | /** |
| 1308 | * Management partially setup, user setup needs to be completed. |
| 1309 | * @hide |
| 1310 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1311 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1312 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1313 | |
| 1314 | /** |
| 1315 | * Management partially setup, user setup completed. |
| 1316 | * @hide |
| 1317 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1318 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1319 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1320 | |
| 1321 | /** |
| 1322 | * Management setup and active on current user. |
| 1323 | * @hide |
| 1324 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1325 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1326 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1327 | |
| 1328 | /** |
| 1329 | * Management partially setup on a managed profile. |
| 1330 | * @hide |
| 1331 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1332 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1333 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1334 | |
| 1335 | /** |
| 1336 | * @hide |
| 1337 | */ |
| 1338 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1339 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1340 | @Retention(RetentionPolicy.SOURCE) |
| 1341 | public @interface UserProvisioningState {} |
| 1342 | |
| 1343 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1344 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1345 | * |
| 1346 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1347 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1348 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1349 | * |
| 1350 | * @hide |
| 1351 | */ |
| 1352 | public static final int CODE_OK = 0; |
| 1353 | |
| 1354 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1355 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1356 | * |
| 1357 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1358 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1359 | * owner. |
| 1360 | * |
| 1361 | * @hide |
| 1362 | */ |
| 1363 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1364 | |
| 1365 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1366 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1367 | * |
| 1368 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1369 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1370 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1371 | * |
| 1372 | * @hide |
| 1373 | */ |
| 1374 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1375 | |
| 1376 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1377 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1378 | * |
| 1379 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1380 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1381 | * |
| 1382 | * @hide |
| 1383 | */ |
| 1384 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1385 | |
| 1386 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1387 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1388 | * |
| 1389 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1390 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1391 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1392 | * |
| 1393 | * @hide |
| 1394 | */ |
| 1395 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1396 | |
| 1397 | /** |
| 1398 | * Code used to indicate that the device also has a user other than the system user. |
| 1399 | * |
| 1400 | * @hide |
| 1401 | */ |
| 1402 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1403 | |
| 1404 | /** |
| 1405 | * Code used to indicate that device has an account that prevents provisioning. |
| 1406 | * |
| 1407 | * @hide |
| 1408 | */ |
| 1409 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1410 | |
| 1411 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1412 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1413 | * |
| 1414 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1415 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1416 | * |
| 1417 | * @hide |
| 1418 | */ |
| 1419 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1420 | |
| 1421 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1422 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1423 | * |
| 1424 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1425 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1426 | * when the device is a watch and is already paired. |
| 1427 | * |
| 1428 | * @hide |
| 1429 | */ |
| 1430 | public static final int CODE_HAS_PAIRED = 8; |
| 1431 | |
| 1432 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1433 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1434 | * |
| 1435 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1436 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1437 | * |
| 1438 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1439 | * @hide |
| 1440 | */ |
| 1441 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1442 | |
| 1443 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1444 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1445 | * |
| 1446 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1447 | * |
| 1448 | * @hide |
| 1449 | */ |
| 1450 | public static final int CODE_SYSTEM_USER = 10; |
| 1451 | |
| 1452 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1453 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1454 | * |
| 1455 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1456 | * managed profiles. |
| 1457 | * |
| 1458 | * @hide |
| 1459 | */ |
| 1460 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1461 | |
| 1462 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1463 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1464 | * |
| 1465 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1466 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1467 | * user. |
| 1468 | * |
| 1469 | * @hide |
| 1470 | */ |
| 1471 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1472 | |
| 1473 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1474 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1475 | * |
| 1476 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1477 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1478 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1479 | * admins. |
| 1480 | * |
| 1481 | * @hide |
| 1482 | */ |
| 1483 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1484 | |
| 1485 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1486 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1487 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1488 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1489 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1490 | * |
| 1491 | * @hide |
| 1492 | */ |
| 1493 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1494 | |
| 1495 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1496 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1497 | * |
| 1498 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1499 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1500 | * |
| 1501 | * @hide |
| 1502 | */ |
| 1503 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1504 | |
| 1505 | /** |
| 1506 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1507 | * conditions. |
| 1508 | * |
| 1509 | * @hide |
| 1510 | */ |
| 1511 | @Retention(RetentionPolicy.SOURCE) |
| 1512 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1513 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1514 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1515 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1516 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1517 | public @interface ProvisioningPreCondition {} |
| 1518 | |
| 1519 | /** |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1520 | * Service action: Action for a service that device owner and profile owner can optionally |
| 1521 | * own. If a device owner or a profile owner has such a service, the system tries to keep |
| 1522 | * a bound connection to it, in order to keep their process always running. |
Makoto Onuki | fe73970 | 2017-04-25 13:26:21 -0700 | [diff] [blame] | 1523 | * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN} |
| 1524 | * permission. |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1525 | */ |
| 1526 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 1527 | public static final String ACTION_DEVICE_ADMIN_SERVICE |
| 1528 | = "android.app.action.DEVICE_ADMIN_SERVICE"; |
| 1529 | |
| 1530 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1531 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1532 | * |
| 1533 | * @param admin The administrator component to check for. |
| 1534 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1535 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1536 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1537 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1538 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1539 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /** |
| 1543 | * @see #isAdminActive(ComponentName) |
| 1544 | * @hide |
| 1545 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1546 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1547 | if (mService != null) { |
| 1548 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1549 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1550 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1551 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | return false; |
| 1555 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1556 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1557 | /** |
| 1558 | * Return true if the given administrator component is currently being removed |
| 1559 | * for the user. |
| 1560 | * @hide |
| 1561 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1562 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1563 | if (mService != null) { |
| 1564 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1565 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1566 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1567 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1568 | } |
| 1569 | } |
| 1570 | return false; |
| 1571 | } |
| 1572 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1573 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1574 | * Return a list of all currently active device administrators' component |
| 1575 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1576 | * returned. |
| 1577 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1578 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1579 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1580 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * @see #getActiveAdmins() |
| 1585 | * @hide |
| 1586 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1587 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1588 | if (mService != null) { |
| 1589 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1590 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1591 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1592 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | return null; |
| 1596 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1597 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1598 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1599 | * Used by package administration code to determine if a package can be stopped |
| 1600 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1601 | * @hide |
| 1602 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1603 | @SystemApi |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1604 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1605 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1606 | } |
| 1607 | |
| 1608 | /** |
| 1609 | * Used by package administration code to determine if a package can be stopped |
| 1610 | * or uninstalled. |
| 1611 | * @hide |
| 1612 | */ |
| 1613 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1614 | if (mService != null) { |
| 1615 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1616 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1617 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1618 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | return false; |
| 1622 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1623 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1624 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1625 | * Remove a current administration component. This can only be called |
| 1626 | * by the application that owns the administration component; if you |
| 1627 | * try to remove someone else's component, a security exception will be |
| 1628 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1629 | * |
| 1630 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1631 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1632 | * |
| 1633 | * @param admin The administration compononent to remove. |
| 1634 | * @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] | 1635 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1636 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1637 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1638 | if (mService != null) { |
| 1639 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1640 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1641 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1642 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1643 | } |
| 1644 | } |
| 1645 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1646 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1647 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1648 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1649 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1650 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1651 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1652 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1653 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1654 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1655 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1656 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1657 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1658 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1659 | if (mService != null) { |
| 1660 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1661 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1662 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1663 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1664 | } |
| 1665 | } |
| 1666 | return false; |
| 1667 | } |
| 1668 | |
| 1669 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1670 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1671 | * |
| 1672 | * @hide |
| 1673 | */ |
| 1674 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1675 | if (mService != null) { |
| 1676 | try { |
| 1677 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1678 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1679 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | return false; |
| 1683 | } |
| 1684 | |
| 1685 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1686 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1687 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1688 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1689 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1690 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1691 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1692 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1693 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1694 | * recognition technology. This implies technologies that can recognize the identity of |
| 1695 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1696 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1697 | */ |
| 1698 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1699 | |
| 1700 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1701 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1702 | * 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] | 1703 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1704 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1705 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1706 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1707 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1708 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1709 | * password containing at least numeric characters. Note that quality |
| 1710 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1711 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1712 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1713 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1714 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1715 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1716 | * password containing at least numeric characters with no repeating (4444) |
| 1717 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1718 | * constants are ordered so that higher values are more restrictive. |
| 1719 | */ |
| 1720 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1721 | |
| 1722 | /** |
| 1723 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1724 | * password containing at least alphabetic (or other symbol) characters. |
| 1725 | * Note that quality constants are ordered so that higher values are more |
| 1726 | * restrictive. |
| 1727 | */ |
| 1728 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1729 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1730 | /** |
| 1731 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1732 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1733 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1734 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1735 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1736 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1737 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1738 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1739 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1740 | * password containing at least a letter, a numerical digit and a special |
| 1741 | * symbol, by default. With this password quality, passwords can be |
| 1742 | * restricted to contain various sets of characters, like at least an |
| 1743 | * uppercase letter, etc. These are specified using various methods, |
| 1744 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1745 | * that quality constants are ordered so that higher values are more |
| 1746 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1747 | */ |
| 1748 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1749 | |
| 1750 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1751 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1752 | * modify password. In case this password quality is set, the password is |
| 1753 | * managed by a profile owner. The profile owner can set any password, |
| 1754 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1755 | * that quality constants are ordered so that higher values are more |
| 1756 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1757 | * the highest. |
| 1758 | * @hide |
| 1759 | */ |
| 1760 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1761 | |
| 1762 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1763 | * @hide |
| 1764 | * |
| 1765 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1766 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1767 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1768 | * used by authenticator to exempt their accounts from this: |
| 1769 | * |
| 1770 | * <ul> |
| 1771 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1772 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1773 | * <application> tag in the manifest. |
| 1774 | * |
| 1775 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1776 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1777 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1778 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1779 | * if any of the accounts have it. |
| 1780 | * </ul> |
| 1781 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1782 | @SystemApi |
| 1783 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1784 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1785 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1786 | |
| 1787 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1788 | @SystemApi |
| 1789 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1790 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1791 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1792 | |
| 1793 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1794 | * Called by an application that is administering the device to set the password restrictions it |
| 1795 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1796 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1797 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1798 | * 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] | 1799 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1800 | * <p> |
| 1801 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1802 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1803 | * considerations) is the one that is in effect. |
| 1804 | * <p> |
| 1805 | * The calling device admin must have requested |
| 1806 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1807 | * not, a security exception will be thrown. |
| 1808 | * <p> |
| 1809 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1810 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1811 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1812 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1813 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1814 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1815 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1816 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1817 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1818 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1819 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1820 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1821 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1822 | if (mService != null) { |
| 1823 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1824 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1825 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1826 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1830 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1831 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1832 | * 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] | 1833 | * 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] | 1834 | * a separate challenge are not taken into account. |
| 1835 | * |
| 1836 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1837 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1838 | * restrictions on the parent profile. |
| 1839 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1840 | * @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] | 1841 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1842 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1843 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1844 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1848 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1849 | if (mService != null) { |
| 1850 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1851 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1852 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1853 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1854 | } |
| 1855 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1856 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1857 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1858 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1859 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1860 | * Called by an application that is administering the device to set the minimum allowed password |
| 1861 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1862 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1863 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1864 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1865 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1866 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1867 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1868 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1869 | * {@link #setPasswordQuality}. |
| 1870 | * <p> |
| 1871 | * The calling device admin must have requested |
| 1872 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1873 | * not, a security exception will be thrown. |
| 1874 | * <p> |
| 1875 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1876 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1877 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1878 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1879 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1880 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1881 | * restriction. |
| 1882 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1883 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1884 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1885 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1886 | if (mService != null) { |
| 1887 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1888 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1889 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1890 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1891 | } |
| 1892 | } |
| 1893 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1894 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1895 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1896 | * 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] | 1897 | * 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] | 1898 | * a separate challenge are not taken into account. |
| 1899 | * |
| 1900 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1901 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1902 | * restrictions on the parent profile. |
| 1903 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1904 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1905 | * @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] | 1906 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1907 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1908 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1909 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1913 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1914 | if (mService != null) { |
| 1915 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1916 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1917 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1918 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | return 0; |
| 1922 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1923 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1924 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1925 | * Called by an application that is administering the device to set the minimum number of upper |
| 1926 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1927 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1928 | * current password will remain until the user has set a new one, so the change does not take |
| 1929 | * place immediately. To prompt the user for a new password, use |
| 1930 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1931 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1932 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1933 | * <p> |
| 1934 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1935 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1936 | * not, a security exception will be thrown. |
| 1937 | * <p> |
| 1938 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1939 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1940 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1941 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1942 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1943 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1944 | * A value of 0 means there is no restriction. |
| 1945 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1946 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1947 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1948 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1949 | if (mService != null) { |
| 1950 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1951 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1952 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1953 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1959 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1960 | * 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] | 1961 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1962 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1963 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1964 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1965 | * and only applies when the password quality is |
| 1966 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1967 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1968 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1969 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1970 | * restrictions on the parent profile. |
| 1971 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1972 | * @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] | 1973 | * aggregate all admins. |
| 1974 | * @return The minimum number of upper case letters required in the |
| 1975 | * password. |
| 1976 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1977 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1978 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1982 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1983 | if (mService != null) { |
| 1984 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1985 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1986 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1987 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | return 0; |
| 1991 | } |
| 1992 | |
| 1993 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1994 | * Called by an application that is administering the device to set the minimum number of lower |
| 1995 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1996 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1997 | * current password will remain until the user has set a new one, so the change does not take |
| 1998 | * place immediately. To prompt the user for a new password, use |
| 1999 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2000 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2001 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2002 | * <p> |
| 2003 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2004 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2005 | * not, a security exception will be thrown. |
| 2006 | * <p> |
| 2007 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2008 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2009 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2010 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2011 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2012 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2013 | * A value of 0 means there is no restriction. |
| 2014 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2015 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2016 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2017 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2018 | if (mService != null) { |
| 2019 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2020 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2021 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2022 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2028 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2029 | * 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] | 2030 | * and its participating profiles. Restrictions on profiles that have |
| 2031 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2032 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2033 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2034 | * and only applies when the password quality is |
| 2035 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2036 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2037 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2038 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2039 | * restrictions on the parent profile. |
| 2040 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2041 | * @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] | 2042 | * aggregate all admins. |
| 2043 | * @return The minimum number of lower case letters required in the |
| 2044 | * password. |
| 2045 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2046 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2047 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2051 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2052 | if (mService != null) { |
| 2053 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2054 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2055 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2056 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2057 | } |
| 2058 | } |
| 2059 | return 0; |
| 2060 | } |
| 2061 | |
| 2062 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2063 | * Called by an application that is administering the device to set the minimum number of |
| 2064 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2065 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2066 | * password will remain until the user has set a new one, so the change does not take place |
| 2067 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2068 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2069 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2070 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2071 | * <p> |
| 2072 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2073 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2074 | * not, a security exception will be thrown. |
| 2075 | * <p> |
| 2076 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2077 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2078 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2079 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2080 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2081 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2082 | * 0 means there is no restriction. |
| 2083 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2084 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2085 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2086 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2087 | if (mService != null) { |
| 2088 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2089 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2090 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2091 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2097 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2098 | * 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] | 2099 | * and its participating profiles. Restrictions on profiles that have |
| 2100 | * a separate challenge are not taken into account. |
| 2101 | * This is the same value as set by |
| 2102 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2103 | * and only applies when the password quality is |
| 2104 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2105 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2106 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2107 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2108 | * restrictions on the parent profile. |
| 2109 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2110 | * @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] | 2111 | * aggregate all admins. |
| 2112 | * @return The minimum number of letters required in the password. |
| 2113 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2114 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2115 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2119 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2120 | if (mService != null) { |
| 2121 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2122 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2123 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2124 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | return 0; |
| 2128 | } |
| 2129 | |
| 2130 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2131 | * Called by an application that is administering the device to set the minimum number of |
| 2132 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2133 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2134 | * current password will remain until the user has set a new one, so the change does not take |
| 2135 | * place immediately. To prompt the user for a new password, use |
| 2136 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2137 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2138 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2139 | * <p> |
| 2140 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2141 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2142 | * not, a security exception will be thrown. |
| 2143 | * <p> |
| 2144 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2145 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2146 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2147 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2148 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2149 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2150 | * value of 0 means there is no restriction. |
| 2151 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2152 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2153 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2154 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2155 | if (mService != null) { |
| 2156 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2157 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2158 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2159 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | /** |
| 2165 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2166 | * 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] | 2167 | * and its participating profiles. Restrictions on profiles that have |
| 2168 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2169 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2170 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2171 | * and only applies when the password quality is |
| 2172 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2173 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2174 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2175 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2176 | * restrictions on the parent profile. |
| 2177 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2178 | * @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] | 2179 | * aggregate all admins. |
| 2180 | * @return The minimum number of numerical digits required in the password. |
| 2181 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2182 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2183 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2187 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2188 | if (mService != null) { |
| 2189 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2190 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2191 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2192 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
| 2198 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2199 | * Called by an application that is administering the device to set the minimum number of |
| 2200 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2201 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2202 | * password will remain until the user has set a new one, so the change does not take place |
| 2203 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2204 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2205 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2206 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2207 | * <p> |
| 2208 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2209 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2210 | * not, a security exception will be thrown. |
| 2211 | * <p> |
| 2212 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2213 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2214 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2215 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2216 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2217 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2218 | * 0 means there is no restriction. |
| 2219 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2220 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2221 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2222 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2223 | if (mService != null) { |
| 2224 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2225 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2226 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2227 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2233 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2234 | * 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] | 2235 | * and its participating profiles. Restrictions on profiles that have |
| 2236 | * a separate challenge are not taken into account. This is the same value as |
| 2237 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2238 | * and only applies when the password quality is |
| 2239 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2240 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2241 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2242 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2243 | * restrictions on the parent profile. |
| 2244 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2245 | * @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] | 2246 | * aggregate all admins. |
| 2247 | * @return The minimum number of symbols required in the password. |
| 2248 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2249 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2250 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2254 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2255 | if (mService != null) { |
| 2256 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2257 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2258 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2259 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | return 0; |
| 2263 | } |
| 2264 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2265 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2266 | * Called by an application that is administering the device to set the minimum number of |
| 2267 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2268 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2269 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2270 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2271 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2272 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2273 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2274 | * <p> |
| 2275 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2276 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2277 | * not, a security exception will be thrown. |
| 2278 | * <p> |
| 2279 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2280 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2281 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2282 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2283 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2284 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2285 | * 0 means there is no restriction. |
| 2286 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2287 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2288 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2289 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2290 | if (mService != null) { |
| 2291 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2292 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2293 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2294 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2300 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2301 | * 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] | 2302 | * and its participating profiles. Restrictions on profiles that have |
| 2303 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2304 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2305 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2306 | * and only applies when the password quality is |
| 2307 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2308 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2309 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2310 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2311 | * restrictions on the parent profile. |
| 2312 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2313 | * @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] | 2314 | * aggregate all admins. |
| 2315 | * @return The minimum number of letters required in the password. |
| 2316 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2317 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2318 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2322 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2323 | if (mService != null) { |
| 2324 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2325 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2326 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2327 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2333 | /** |
| 2334 | * Called by an application that is administering the device to set the length of the password |
| 2335 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2336 | * same as any password in the history. Note that the current password will remain until the |
| 2337 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2338 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2339 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2340 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2341 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2342 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2343 | * <p> |
| 2344 | * The calling device admin must have requested |
| 2345 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2346 | * not, a security exception will be thrown. |
| 2347 | * <p> |
| 2348 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2349 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2350 | * profile. |
| 2351 | * |
| 2352 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2353 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2354 | * restriction. |
| 2355 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2356 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2357 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2358 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2359 | if (mService != null) { |
| 2360 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2361 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2362 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2363 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2364 | } |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2369 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2370 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2371 | * device password (for all admins). |
| 2372 | * <p> |
| 2373 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2374 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2375 | * 432000000 ms for timeout. |
| 2376 | * <p> |
| 2377 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2378 | * <p> |
| 2379 | * The calling device admin must have requested |
| 2380 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2381 | * not, a security exception will be thrown. |
| 2382 | * <p> |
| 2383 | * Note that setting the password will automatically reset the expiration time for all active |
| 2384 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2385 | * <p> |
| 2386 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2387 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2388 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2389 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2390 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2391 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2392 | * there is no restriction (unlimited). |
| 2393 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2394 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2395 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2396 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2397 | if (mService != null) { |
| 2398 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2399 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2400 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2401 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2407 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2408 | * recurring expiration timeout provided in the call to |
| 2409 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2410 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2411 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2412 | * |
| 2413 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2414 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2415 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2416 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2417 | * @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] | 2418 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2419 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2420 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2421 | if (mService != null) { |
| 2422 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2423 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2424 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2425 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | return 0; |
| 2429 | } |
| 2430 | |
| 2431 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2432 | * 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] | 2433 | * 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] | 2434 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2435 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2436 | * |
| 2437 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2438 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2439 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2440 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2441 | * @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] | 2442 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2443 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2444 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2445 | if (mService != null) { |
| 2446 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2447 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2448 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2449 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | return 0; |
| 2453 | } |
| 2454 | |
| 2455 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2456 | * 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] | 2457 | * 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] | 2458 | * have a separate challenge are not taken into account. |
| 2459 | * |
| 2460 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2461 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2462 | * restrictions on the parent profile. |
| 2463 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2464 | * @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] | 2465 | * all admins. |
| 2466 | * @return The length of the password history |
| 2467 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2468 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2469 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2473 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2474 | if (mService != null) { |
| 2475 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2476 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2477 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2478 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | return 0; |
| 2482 | } |
| 2483 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2484 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2485 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2486 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2487 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2488 | * @return Returns the maximum length that the user can enter. |
| 2489 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2490 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2491 | // Kind-of arbitrary. |
| 2492 | return 16; |
| 2493 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2494 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2495 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2496 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2497 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2498 | * 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] | 2499 | * 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] | 2500 | * <p> |
| 2501 | * The calling device admin must have requested |
| 2502 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2503 | * not, a security exception will be thrown. |
| 2504 | * <p> |
| 2505 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2506 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2507 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2508 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2509 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2510 | * @throws SecurityException if the calling application does not own an active administrator |
| 2511 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2512 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2513 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2514 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2515 | if (mService != null) { |
| 2516 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2517 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2518 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2519 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2520 | } |
| 2521 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2522 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2523 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2524 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2525 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2526 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2527 | * 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] | 2528 | * requested by the admins of the parent user and its profiles. |
| 2529 | * |
| 2530 | * @param userHandle the userId of the profile to check the password for. |
| 2531 | * @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] | 2532 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2533 | * @hide |
| 2534 | */ |
| 2535 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2536 | if (mService != null) { |
| 2537 | try { |
| 2538 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2539 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2540 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | return false; |
| 2544 | } |
| 2545 | |
| 2546 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2547 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2548 | * successful password entry. |
| 2549 | * <p> |
| 2550 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2551 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2552 | * password attemts for the parent user. |
| 2553 | * <p> |
| 2554 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2555 | * 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] | 2556 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2557 | * @return The number of times user has entered an incorrect password since the last correct |
| 2558 | * password entry. |
| 2559 | * @throws SecurityException if the calling application does not own an active administrator |
| 2560 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2561 | */ |
| 2562 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2563 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2564 | } |
| 2565 | |
| 2566 | /** |
| 2567 | * Retrieve the number of times the given user has failed at entering a |
| 2568 | * password since that last successful password entry. |
| 2569 | * |
| 2570 | * <p>The calling device admin must have requested |
| 2571 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2572 | * not and it is not the system uid, a security exception will be thrown. |
| 2573 | * |
| 2574 | * @hide |
| 2575 | */ |
| 2576 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2577 | if (mService != null) { |
| 2578 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2579 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2580 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2581 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | return -1; |
| 2585 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2586 | |
| 2587 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2588 | * 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] | 2589 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2590 | * @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] | 2591 | * @hide |
| 2592 | */ |
| 2593 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2594 | if (mService != null) { |
| 2595 | try { |
| 2596 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2597 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2598 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | return false; |
| 2602 | } |
| 2603 | |
| 2604 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2605 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2606 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2607 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2608 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2609 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2610 | * <p> |
| 2611 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2612 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2613 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2614 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2615 | * immediately, and your callback will not be invoked. |
| 2616 | * <p> |
| 2617 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2618 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2619 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2620 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2621 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2622 | * @param num The number of failed password attempts at which point the device or profile will |
| 2623 | * be wiped. |
| 2624 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2625 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2626 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2627 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2628 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2629 | if (mService != null) { |
| 2630 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2631 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2632 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2633 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2637 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2638 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2639 | * 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] | 2640 | * 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] | 2641 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2642 | * not taken into account. |
| 2643 | * |
| 2644 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2645 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2646 | * the value for the parent profile. |
| 2647 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2648 | * @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] | 2649 | * all admins. |
| 2650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2651 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2652 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2656 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2657 | if (mService != null) { |
| 2658 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2659 | return mService.getMaximumFailedPasswordsForWipe( |
| 2660 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2661 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2662 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2663 | } |
| 2664 | } |
| 2665 | return 0; |
| 2666 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2667 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2668 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2669 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2670 | * for the given user. So for primary user, it might return the primary or |
| 2671 | * a managed profile. For a secondary user, it would be the same as the |
| 2672 | * user passed in. |
| 2673 | * @hide Used only by Keyguard |
| 2674 | */ |
| 2675 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2676 | if (mService != null) { |
| 2677 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2678 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2679 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2680 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2681 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2682 | } |
| 2683 | } |
| 2684 | return UserHandle.USER_NULL; |
| 2685 | } |
| 2686 | |
| 2687 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2688 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2689 | * the password again until the user has entered it. |
| 2690 | */ |
| 2691 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2692 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2693 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2694 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2695 | * If the flag is set, the device can be booted without asking for user password. |
| 2696 | * The absence of this flag does not change the current boot requirements. This flag |
| 2697 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2698 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2699 | * device to factory defaults. |
| 2700 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2701 | 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] | 2702 | |
| 2703 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2704 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2705 | * individual accounts) on the user. This takes effect immediately. |
| 2706 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2707 | * <em>For device owner and profile owners targeting SDK level |
| 2708 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 2709 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 2710 | * instead. </em> |
| 2711 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2712 | * <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] | 2713 | * device admins that are not device owner and not profile owner. |
| 2714 | * 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] | 2715 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2716 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2717 | * <p> |
| 2718 | * The given password must be sufficient for the current password quality and length constraints |
| 2719 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2720 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2721 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2722 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2723 | * case the currently active quality will be increased to match. |
| 2724 | * <p> |
| 2725 | * 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] | 2726 | * current password constraints allow it. <em>Note: This will not work in |
| 2727 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2728 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2729 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2730 | * <p> |
| 2731 | * The calling device admin must have requested |
| 2732 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2733 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2734 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2735 | * @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] | 2736 | * @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] | 2737 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2738 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2739 | * current constraints or if the user has not been decrypted yet. |
| 2740 | * @throws SecurityException if the calling application does not own an active administrator |
| 2741 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2742 | * @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] | 2743 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2744 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2745 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2746 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2747 | if (mService != null) { |
| 2748 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2749 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2750 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2751 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | return false; |
| 2755 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2756 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2757 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2758 | * Called by a profile or device owner to provision a token which can later be used to reset the |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2759 | * device lockscreen password (if called by device owner), or managed profile challenge (if |
| 2760 | * called by profile owner), via {@link #resetPasswordWithToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2761 | * <p> |
| 2762 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 2763 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 2764 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 2765 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 2766 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 2767 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 2768 | * the device reboots. In this case a new token needs to be provisioned again. |
| 2769 | * <p> |
| 2770 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 2771 | * or clears the lockscreen password. |
| 2772 | * <p> |
| 2773 | * <em>This token is highly sensitive and should be treated at the same level as user |
Rubin Xu | f7b036d | 2017-04-05 18:37:07 +0100 | [diff] [blame] | 2774 | * credentials. In particular, NEVER store this token on device in plaintext. Do not store |
| 2775 | * the plaintext token in device-encrypted storage if it will be needed to reset password on |
| 2776 | * file-based encryption devices before user unlocks. Consider carefully how any password token |
| 2777 | * will be stored on your server and who will need access to them. Tokens may be the subject of |
| 2778 | * legal access requests. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2779 | * </em> |
| 2780 | * |
| 2781 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2782 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 2783 | * cryptographically strong random number generator. |
| 2784 | * @return true if the operation is successful, false otherwise. |
| 2785 | * @throws IllegalArgumentException if the supplied token is invalid. |
| 2786 | * @throws SecurityException |
| 2787 | */ |
| 2788 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 2789 | throwIfParentInstance("setResetPasswordToken"); |
| 2790 | if (mService != null) { |
| 2791 | try { |
| 2792 | return mService.setResetPasswordToken(admin, token); |
| 2793 | } catch (RemoteException e) { |
| 2794 | throw e.rethrowFromSystemServer(); |
| 2795 | } |
| 2796 | } |
| 2797 | return false; |
| 2798 | } |
| 2799 | |
| 2800 | /** |
| 2801 | * Called by a profile or device owner to revoke the current password reset token. |
| 2802 | * |
| 2803 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2804 | * @return true if the operation is successful, false otherwise. |
| 2805 | */ |
| 2806 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 2807 | throwIfParentInstance("clearResetPasswordToken"); |
| 2808 | if (mService != null) { |
| 2809 | try { |
| 2810 | return mService.clearResetPasswordToken(admin); |
| 2811 | } catch (RemoteException e) { |
| 2812 | throw e.rethrowFromSystemServer(); |
| 2813 | } |
| 2814 | } |
| 2815 | return false; |
| 2816 | } |
| 2817 | |
| 2818 | /** |
| 2819 | * Called by a profile or device owner to check if the current reset password token is active. |
| 2820 | * |
| 2821 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2822 | * @return true if the token is active, false otherwise. |
| 2823 | * @throws IllegalStateException if no token has been set. |
| 2824 | */ |
| 2825 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 2826 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 2827 | if (mService != null) { |
| 2828 | try { |
| 2829 | return mService.isResetPasswordTokenActive(admin); |
| 2830 | } catch (RemoteException e) { |
| 2831 | throw e.rethrowFromSystemServer(); |
| 2832 | } |
| 2833 | } |
| 2834 | return false; |
| 2835 | } |
| 2836 | |
| 2837 | /** |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2838 | * Called by device or profile owner to force set a new device unlock password or a managed |
| 2839 | * profile challenge on current user. This takes effect immediately. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2840 | * <p> |
| 2841 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 2842 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 2843 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 2844 | * <p> |
| 2845 | * The given password must be sufficient for the current password quality and length constraints |
| 2846 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2847 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2848 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2849 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2850 | * case the currently active quality will be increased to match. |
| 2851 | * <p> |
| 2852 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
| 2853 | * current password constraints allow it. |
| 2854 | * |
| 2855 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2856 | * @param password The new password for the user. Null or empty clears the password. |
| 2857 | * @param token the password reset token previously provisioned by #setResetPasswordToken. |
| 2858 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
| 2859 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2860 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2861 | * current constraints. |
| 2862 | * @throws SecurityException if the calling application does not own an active administrator |
| 2863 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
| 2864 | * @throws IllegalStateException if the provided token is not valid. |
| 2865 | * @throws IllegalArgumentException if the password does not meet system requirements. |
| 2866 | */ |
| 2867 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 2868 | byte[] token, int flags) { |
| 2869 | throwIfParentInstance("resetPassword"); |
| 2870 | if (mService != null) { |
| 2871 | try { |
| 2872 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 2873 | } catch (RemoteException e) { |
| 2874 | throw e.rethrowFromSystemServer(); |
| 2875 | } |
| 2876 | } |
| 2877 | return false; |
| 2878 | } |
| 2879 | |
| 2880 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2881 | * Called by an application that is administering the device to set the maximum time for user |
| 2882 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2883 | * effect immediately. |
| 2884 | * <p> |
| 2885 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2886 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2887 | * <p> |
| 2888 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2889 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2890 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2891 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2892 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2893 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2894 | * is no restriction. |
| 2895 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2896 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2897 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2898 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2899 | if (mService != null) { |
| 2900 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2901 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2902 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2903 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2904 | } |
| 2905 | } |
| 2906 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2907 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2908 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2909 | * 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] | 2910 | * 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] | 2911 | * a separate challenge are not taken into account. |
| 2912 | * |
| 2913 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2914 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2915 | * restrictions on the parent profile. |
| 2916 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2917 | * @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] | 2918 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2919 | * @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] | 2920 | * 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] | 2921 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2922 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2923 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2927 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2928 | if (mService != null) { |
| 2929 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2930 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2931 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2932 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2933 | } |
| 2934 | } |
| 2935 | return 0; |
| 2936 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2937 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2938 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2939 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2940 | * do not have a separate timeout to lock for work challenge only. |
| 2941 | * |
| 2942 | * @hide |
| 2943 | */ |
| 2944 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2945 | if (mService != null) { |
| 2946 | try { |
| 2947 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2948 | } catch (RemoteException e) { |
| 2949 | throw e.rethrowFromSystemServer(); |
| 2950 | } |
| 2951 | } |
| 2952 | return 0; |
| 2953 | } |
| 2954 | |
| 2955 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2956 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2957 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2958 | * authentication method like password, pin or pattern. |
| 2959 | * |
| 2960 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2961 | * specified timeout each time it has been successfully used. |
| 2962 | * |
| 2963 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2964 | * |
| 2965 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2966 | * |
| 2967 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2968 | * a {@link SecurityException} will be thrown. |
| 2969 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2970 | * <p>The calling device admin can verify the value it has set by calling |
| 2971 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2972 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2973 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2974 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2975 | * profile. |
| 2976 | * |
| 2977 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 2978 | * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock |
| 2979 | * with strong authentication method. A value of 0 means the admin is not participating |
| 2980 | * in controlling the timeout. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2981 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2982 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2983 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2984 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2985 | * |
| 2986 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2987 | */ |
| 2988 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2989 | long timeoutMs) { |
| 2990 | if (mService != null) { |
| 2991 | try { |
| 2992 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2993 | } catch (RemoteException e) { |
| 2994 | throw e.rethrowFromSystemServer(); |
| 2995 | } |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | /** |
| 3000 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 3001 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 3002 | * After the returned timeout the user is required to use strong authentication method. |
| 3003 | * |
| 3004 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3005 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3006 | * restrictions on the parent profile. |
| 3007 | * |
| 3008 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 3009 | * accross all participating admins. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3010 | * @return The timeout in milliseconds or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3011 | */ |
| 3012 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3013 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3014 | } |
| 3015 | |
| 3016 | /** @hide per-user version */ |
| 3017 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3018 | if (mService != null) { |
| 3019 | try { |
| 3020 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3021 | } catch (RemoteException e) { |
| 3022 | throw e.rethrowFromSystemServer(); |
| 3023 | } |
| 3024 | } |
| 3025 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3026 | } |
| 3027 | |
| 3028 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3029 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3030 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3031 | * credential encryption key that will be stored back in the keyring for future use. |
| 3032 | * <p> |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3033 | * This flag can only be used by a profile owner when locking a managed profile when |
| 3034 | * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3035 | * <p> |
| 3036 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3037 | * until they are next run to perform further actions. |
| 3038 | */ |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3039 | public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; |
| 3040 | |
| 3041 | /** |
| 3042 | * Instead use {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
| 3043 | * @removed |
| 3044 | */ |
| 3045 | @Deprecated |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3046 | public static final int FLAG_EVICT_CE_KEY = 1; |
| 3047 | |
| 3048 | /** @hide */ |
| 3049 | @Retention(RetentionPolicy.SOURCE) |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3050 | @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}) |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3051 | public @interface LockNowFlag {} |
| 3052 | |
| 3053 | /** |
| 3054 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3055 | * this call. |
| 3056 | * <p> |
| 3057 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3058 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3059 | * <p> |
| 3060 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3061 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3062 | * <p> |
| 3063 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3064 | * |
| 3065 | * @throws SecurityException if the calling application does not own an active administrator |
| 3066 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3067 | */ |
| 3068 | public void lockNow() { |
| 3069 | lockNow(0); |
| 3070 | } |
| 3071 | |
| 3072 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3073 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3074 | * this call. |
| 3075 | * <p> |
| 3076 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3077 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3078 | * <p> |
| 3079 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3080 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3081 | * |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3082 | * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3083 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3084 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3085 | * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application |
| 3086 | * that is not a profile |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3087 | * owner of a managed profile. |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3088 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is |
| 3089 | * passed when locking the parent profile. |
| 3090 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} |
| 3091 | * flag is passed when {@link #getStorageEncryptionStatus} does not return |
| 3092 | * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3093 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3094 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3095 | if (mService != null) { |
| 3096 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3097 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3098 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3099 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3103 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3104 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3105 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3106 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3107 | */ |
| 3108 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3109 | |
| 3110 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3111 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3112 | * data. |
| 3113 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3114 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3115 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3116 | */ |
| 3117 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3118 | |
| 3119 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3120 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3121 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3122 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3123 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3124 | * <p> |
| 3125 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3126 | * 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] | 3127 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3128 | * @param flags Bit mask of additional options: currently supported flags are |
| 3129 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3130 | * @throws SecurityException if the calling application does not own an active administrator |
| 3131 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3132 | */ |
| 3133 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3134 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3135 | if (mService != null) { |
| 3136 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3137 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3138 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3139 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3140 | } |
| 3141 | } |
| 3142 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3143 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3144 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3145 | * Called by an application that is administering the device to set the |
| 3146 | * global proxy and exclusion list. |
| 3147 | * <p> |
| 3148 | * The calling device admin must have requested |
| 3149 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3150 | * this method; if it has not, a security exception will be thrown. |
| 3151 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3152 | * 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] | 3153 | * 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] | 3154 | * be returned. |
| 3155 | * The method can be called repeatedly by the device admin alrady setting the |
| 3156 | * proxy to update the proxy and exclusion list. |
| 3157 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3158 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3159 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3160 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3161 | * @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] | 3162 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3163 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3164 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3165 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3166 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3167 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3168 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3169 | if (proxySpec == null) { |
| 3170 | throw new NullPointerException(); |
| 3171 | } |
| 3172 | if (mService != null) { |
| 3173 | try { |
| 3174 | String hostSpec; |
| 3175 | String exclSpec; |
| 3176 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3177 | hostSpec = null; |
| 3178 | exclSpec = null; |
| 3179 | } else { |
| 3180 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3181 | throw new IllegalArgumentException(); |
| 3182 | } |
| 3183 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3184 | String hostName = sa.getHostName(); |
| 3185 | int port = sa.getPort(); |
| 3186 | StringBuilder hostBuilder = new StringBuilder(); |
| 3187 | hostSpec = hostBuilder.append(hostName) |
| 3188 | .append(":").append(Integer.toString(port)).toString(); |
| 3189 | if (exclusionList == null) { |
| 3190 | exclSpec = ""; |
| 3191 | } else { |
| 3192 | StringBuilder listBuilder = new StringBuilder(); |
| 3193 | boolean firstDomain = true; |
| 3194 | for (String exclDomain : exclusionList) { |
| 3195 | if (!firstDomain) { |
| 3196 | listBuilder = listBuilder.append(","); |
| 3197 | } else { |
| 3198 | firstDomain = false; |
| 3199 | } |
| 3200 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3201 | } |
| 3202 | exclSpec = listBuilder.toString(); |
| 3203 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3204 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3205 | != android.net.Proxy.PROXY_VALID) |
| 3206 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3207 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3208 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3209 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3210 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | return null; |
| 3214 | } |
| 3215 | |
| 3216 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3217 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3218 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3219 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3220 | * proxy is not accessible, you may break HTTP using this. |
| 3221 | * <p> |
| 3222 | * This method requires the caller to be the device owner. |
| 3223 | * <p> |
| 3224 | * 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] | 3225 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3226 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3227 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3228 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3229 | * {@code null} value will clear the global HTTP proxy. |
| 3230 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3231 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3232 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3233 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3234 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3235 | if (mService != null) { |
| 3236 | try { |
| 3237 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3238 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3239 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3240 | } |
| 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3245 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3246 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3247 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3248 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3249 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3250 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3251 | if (mService != null) { |
| 3252 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3253 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3254 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3255 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | return null; |
| 3259 | } |
| 3260 | |
| 3261 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3262 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3263 | * indicating that encryption is not supported. |
| 3264 | */ |
| 3265 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 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 supported, but is not currently active. |
| 3270 | */ |
| 3271 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3272 | |
| 3273 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3274 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3275 | * indicating that encryption is not currently active, but is currently |
| 3276 | * being activated. This is only reported by devices that support |
| 3277 | * encryption of data and only when the storage is currently |
| 3278 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3279 | * to become encrypted will never return this value. |
| 3280 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3281 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3282 | |
| 3283 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3284 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3285 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3286 | * <p> |
| 3287 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3288 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3289 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3290 | |
| 3291 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3292 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3293 | * indicating that encryption is active, but an encryption key has not |
| 3294 | * been set by the user. |
| 3295 | */ |
| 3296 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3297 | |
| 3298 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3299 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3300 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3301 | * <p> |
| 3302 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3303 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3304 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3305 | */ |
| 3306 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3307 | |
| 3308 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3309 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3310 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3311 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3312 | * to check encryption status. However, on some devices this activity may never return, as |
| 3313 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3314 | */ |
| 3315 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3316 | public static final String ACTION_START_ENCRYPTION |
| 3317 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3318 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3319 | * Widgets are enabled in keyguard |
| 3320 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3321 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3322 | |
| 3323 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3324 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3325 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3326 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3327 | |
| 3328 | /** |
| 3329 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3330 | */ |
| 3331 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3332 | |
| 3333 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3334 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3335 | */ |
| 3336 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3337 | |
| 3338 | /** |
| 3339 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3340 | */ |
| 3341 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3342 | |
| 3343 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3344 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3345 | * (e.g. PIN/Pattern/Password). |
| 3346 | */ |
| 3347 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3348 | |
| 3349 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3350 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3351 | */ |
| 3352 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3353 | |
| 3354 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3355 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3356 | */ |
| 3357 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3358 | |
| 3359 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3360 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3361 | */ |
| 3362 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3363 | |
| 3364 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3365 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3366 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3367 | * {@link DevicePolicyManager} instance. |
| 3368 | * |
| 3369 | * @hide |
| 3370 | */ |
| 3371 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3372 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
| 3373 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3374 | |
| 3375 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3376 | * Called by an application that is administering the device to request that the storage system |
| 3377 | * be encrypted. |
| 3378 | * <p> |
| 3379 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3380 | * supported setting will always be used. If any device administrator requests device |
| 3381 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3382 | * 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] | 3383 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3384 | * <p> |
| 3385 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3386 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3387 | * control the encryption of any other storage areas. There is one exception: If |
| 3388 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3389 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3390 | * written to disk within the encrypted storage area. |
| 3391 | * <p> |
| 3392 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3393 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3394 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3395 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3396 | * |
| 3397 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3398 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3399 | * @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] | 3400 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3401 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3402 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3403 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3404 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3405 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3406 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3407 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3408 | if (mService != null) { |
| 3409 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3410 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3411 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3412 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3416 | } |
| 3417 | |
| 3418 | /** |
| 3419 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3420 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3421 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3422 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3423 | * this will return the requested encryption setting as an aggregate of all active |
| 3424 | * administrators. |
| 3425 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3426 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3427 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3428 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3429 | if (mService != null) { |
| 3430 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3431 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3432 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3433 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3434 | } |
| 3435 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3436 | return false; |
| 3437 | } |
| 3438 | |
| 3439 | /** |
| 3440 | * Called by an application that is administering the device to |
| 3441 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3442 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3443 | * Depending on the returned status code, the caller may proceed in different |
| 3444 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3445 | * storage system does not support encryption. If the |
| 3446 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3447 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3448 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3449 | * 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] | 3450 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3451 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3452 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3453 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3454 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3455 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3456 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3457 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3458 | */ |
| 3459 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3460 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3461 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | /** @hide per-user version */ |
| 3465 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3466 | if (mService != null) { |
| 3467 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3468 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3469 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3470 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3471 | } |
| 3472 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3473 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3474 | } |
| 3475 | |
| 3476 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3477 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3478 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3479 | * keep the certificate on the device. |
| 3480 | * |
| 3481 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3482 | * this certificate. |
| 3483 | * |
| 3484 | * @hide |
| 3485 | */ |
| 3486 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3487 | if (mService != null) { |
| 3488 | try { |
| 3489 | return mService.approveCaCert(alias, userHandle, approval); |
| 3490 | } catch (RemoteException e) { |
| 3491 | throw e.rethrowFromSystemServer(); |
| 3492 | } |
| 3493 | } |
| 3494 | return false; |
| 3495 | } |
| 3496 | |
| 3497 | /** |
| 3498 | * Check whether a CA certificate has been approved by the device user. |
| 3499 | * |
| 3500 | * @hide |
| 3501 | */ |
| 3502 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3503 | if (mService != null) { |
| 3504 | try { |
| 3505 | return mService.isCaCertApproved(alias, userHandle); |
| 3506 | } catch (RemoteException e) { |
| 3507 | throw e.rethrowFromSystemServer(); |
| 3508 | } |
| 3509 | } |
| 3510 | return false; |
| 3511 | } |
| 3512 | |
| 3513 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3514 | * Installs the given certificate as a user CA. |
| 3515 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3516 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3517 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3518 | * security exception will be thrown. |
| 3519 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3520 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3521 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3522 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3523 | * |
| 3524 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3525 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3526 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3527 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3528 | * @see #setDelegatedScopes |
| 3529 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3530 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3531 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3532 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3533 | if (mService != null) { |
| 3534 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3535 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3536 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3537 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3538 | } |
| 3539 | } |
| 3540 | return false; |
| 3541 | } |
| 3542 | |
| 3543 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3544 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3545 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3546 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3547 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3548 | * security exception will be thrown. |
| 3549 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3550 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3551 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3552 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3553 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3554 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3555 | * @see #setDelegatedScopes |
| 3556 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3557 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3558 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3559 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3560 | if (mService != null) { |
| 3561 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3562 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3563 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3564 | } catch (CertificateException e) { |
| 3565 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3566 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3567 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3573 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3574 | * If a user has installed any certificates by other means than device policy these will be |
| 3575 | * included too. |
| 3576 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3577 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3578 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3579 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3580 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3581 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3582 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3583 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3584 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3585 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3586 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3587 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3588 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3589 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3590 | for (String alias : certStore.userAliases()) { |
| 3591 | try { |
| 3592 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3593 | } catch (CertificateException ce) { |
| 3594 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3595 | } |
| 3596 | } |
| 3597 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3598 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3605 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3606 | * means other than device policy will also be removed, except for system CA certificates. |
| 3607 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3608 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3609 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3610 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3611 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3612 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3613 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3614 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3615 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3616 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3617 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3618 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3619 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3620 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | /** |
| 3626 | * Returns whether this certificate is installed as a trusted CA. |
| 3627 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3628 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3629 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3630 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3631 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3632 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3633 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3634 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3635 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3636 | if (mService != null) { |
| 3637 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3638 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3639 | return getCaCertAlias(certBuffer) != null; |
| 3640 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3641 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3642 | } catch (CertificateException ce) { |
| 3643 | Log.w(TAG, "Could not parse certificate", ce); |
| 3644 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3645 | } |
| 3646 | return false; |
| 3647 | } |
| 3648 | |
| 3649 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3650 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3651 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3652 | * the certificate and use the private key, given direct user approval. |
| 3653 | * |
| 3654 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3655 | * direct user approval. This is for security - should a certificate installer become |
| 3656 | * compromised, certificates it had already installed will be protected. |
| 3657 | * |
| 3658 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3659 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3660 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3661 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3662 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3663 | * @param privKey The private key to install. |
| 3664 | * @param cert The certificate to install. |
| 3665 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3666 | * with that alias already exists, it will be overwritten. |
| 3667 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3668 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3669 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3670 | * @see #setDelegatedScopes |
| 3671 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3672 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3673 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3674 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3675 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | /** |
| 3679 | * 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] | 3680 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3681 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3682 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3683 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3684 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3685 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3686 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3687 | * |
| 3688 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3689 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3690 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3691 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3692 | * certificate and include the chain of trust in order. This will be returned by |
| 3693 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3694 | * @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] | 3695 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3696 | * @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] | 3697 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3698 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3699 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3700 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3701 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3702 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3703 | * @see #setDelegatedScopes |
| 3704 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3705 | */ |
| 3706 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3707 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3708 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3709 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3710 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3711 | byte[] pemChain = null; |
| 3712 | if (certs.length > 1) { |
| 3713 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3714 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3715 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3716 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3717 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3718 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3719 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3720 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3721 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3722 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3723 | } catch (CertificateException | IOException e) { |
| 3724 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3725 | } |
| 3726 | return false; |
| 3727 | } |
| 3728 | |
| 3729 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3730 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3731 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3732 | * |
| 3733 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3734 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3735 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3736 | * @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] | 3737 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3738 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3739 | * @see #setDelegatedScopes |
| 3740 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3741 | */ |
| 3742 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3743 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3744 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3745 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3746 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3747 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3748 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3752 | * @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] | 3753 | * doesn't exist. |
| 3754 | */ |
| 3755 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3756 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3757 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3758 | new ByteArrayInputStream(certBuffer)); |
| 3759 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3760 | } |
| 3761 | |
| 3762 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3763 | * 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] | 3764 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3765 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3766 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3767 | * <p> |
| 3768 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3769 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3770 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3771 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3772 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3773 | * 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] | 3774 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3775 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3776 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3777 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3778 | * @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] | 3779 | * access. If {@code null} is given the current package will be cleared. |
| 3780 | * @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] | 3781 | * |
| 3782 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3783 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3784 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3785 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3786 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3787 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3788 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3789 | if (mService != null) { |
| 3790 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3791 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3792 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3793 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3794 | } |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3799 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3800 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3801 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3802 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3803 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3804 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3805 | * none is set. |
| 3806 | * @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] | 3807 | * |
| 3808 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3809 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3810 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3811 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3812 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3813 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3814 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3815 | if (mService != null) { |
| 3816 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3817 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3818 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3819 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3820 | } |
| 3821 | } |
| 3822 | return null; |
| 3823 | } |
| 3824 | |
| 3825 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3826 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3827 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3828 | * constants. |
| 3829 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3830 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3831 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3832 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3833 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3834 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3835 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3836 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3837 | * {@code delegatePackage}. |
| 3838 | * |
| 3839 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3840 | * @param delegatePackage The package name of the app which will be given access. |
| 3841 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3842 | * {@code delegatedPackage}. |
| 3843 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3844 | */ |
| 3845 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3846 | @NonNull List<String> scopes) { |
| 3847 | throwIfParentInstance("setDelegatedScopes"); |
| 3848 | if (mService != null) { |
| 3849 | try { |
| 3850 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3851 | } catch (RemoteException e) { |
| 3852 | throw e.rethrowFromSystemServer(); |
| 3853 | } |
| 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | /** |
| 3858 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3859 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3860 | * passing {@code null} for {@code admin} and their own package name as |
| 3861 | * {@code delegatedPackage}. |
| 3862 | * |
| 3863 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3864 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3865 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3866 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3867 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3868 | */ |
| 3869 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3870 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3871 | @NonNull String delegatedPackage) { |
| 3872 | throwIfParentInstance("getDelegatedScopes"); |
| 3873 | if (mService != null) { |
| 3874 | try { |
| 3875 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3876 | } catch (RemoteException e) { |
| 3877 | throw e.rethrowFromSystemServer(); |
| 3878 | } |
| 3879 | } |
| 3880 | return null; |
| 3881 | } |
| 3882 | |
| 3883 | /** |
| 3884 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3885 | * granted a delegation scope. |
| 3886 | * |
| 3887 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3888 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3889 | * @return A list of package names of the current delegated packages for |
| 3890 | {@code delegationScope}. |
| 3891 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3892 | */ |
| 3893 | @Nullable |
| 3894 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3895 | @NonNull String delegationScope) { |
| 3896 | throwIfParentInstance("getDelegatePackages"); |
| 3897 | if (mService != null) { |
| 3898 | try { |
| 3899 | return mService.getDelegatePackages(admin, delegationScope); |
| 3900 | } catch (RemoteException e) { |
| 3901 | throw e.rethrowFromSystemServer(); |
| 3902 | } |
| 3903 | } |
| 3904 | return null; |
| 3905 | } |
| 3906 | |
| 3907 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3908 | * 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] | 3909 | * specific application for the current user. |
| 3910 | * |
| 3911 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3912 | * TODO: delete once there are no longer any live references. |
| 3913 | * @hide |
| 3914 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3915 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3916 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3917 | throws NameNotFoundException, UnsupportedOperationException { |
| 3918 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3919 | } |
| 3920 | |
| 3921 | /** |
| 3922 | * 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] | 3923 | * specific application for the current user. This connection is automatically granted and |
| 3924 | * persisted after a reboot. |
| 3925 | * <p> |
| 3926 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3927 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3928 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3929 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3930 | * @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] | 3931 | * remove an existing always-on VPN configuration. |
| 3932 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3933 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3934 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3935 | * @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] | 3936 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3937 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3938 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3939 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3940 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3941 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3942 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3943 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3944 | if (mService != null) { |
| 3945 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3946 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3947 | throw new NameNotFoundException(vpnPackage); |
| 3948 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3949 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3950 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3951 | } |
| 3952 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /** |
| 3956 | * 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] | 3957 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3958 | * 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] | 3959 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3960 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3961 | * is set. |
| 3962 | * @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] | 3963 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3964 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3965 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3966 | if (mService != null) { |
| 3967 | try { |
| 3968 | return mService.getAlwaysOnVpnPackage(admin); |
| 3969 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3970 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3971 | } |
| 3972 | } |
| 3973 | return null; |
| 3974 | } |
| 3975 | |
| 3976 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3977 | * Called by an application that is administering the device to disable all cameras on the |
| 3978 | * device, for this user. After setting this, no applications running as this user will be able |
| 3979 | * to access any cameras on the device. |
| 3980 | * <p> |
| 3981 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3982 | * <p> |
| 3983 | * The calling device admin must have requested |
| 3984 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3985 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3986 | * |
| 3987 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3988 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3989 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3990 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3991 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3992 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3993 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3994 | if (mService != null) { |
| 3995 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3996 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3997 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3998 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3999 | } |
| 4000 | } |
| 4001 | } |
| 4002 | |
| 4003 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4004 | * 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] | 4005 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4006 | * @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] | 4007 | * have disabled the camera |
| 4008 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4009 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4010 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4011 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4015 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4016 | if (mService != null) { |
| 4017 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4018 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4019 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4020 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4021 | } |
| 4022 | } |
| 4023 | return false; |
| 4024 | } |
| 4025 | |
| 4026 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4027 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4028 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4029 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 4030 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 4031 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4032 | * |
| 4033 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4034 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4035 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4036 | * 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] | 4037 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 4038 | * 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] | 4039 | */ |
| 4040 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4041 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4042 | if (mService != null) { |
| 4043 | try { |
| 4044 | return mService.requestBugreport(admin); |
| 4045 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4046 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | return false; |
| 4050 | } |
| 4051 | |
| 4052 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4053 | * Determine whether or not creating a guest user has been disabled for the device |
| 4054 | * |
| 4055 | * @hide |
| 4056 | */ |
| 4057 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4058 | // Currently guest users can always be created if multi-user is enabled |
| 4059 | // TODO introduce a policy for guest user creation |
| 4060 | return false; |
| 4061 | } |
| 4062 | |
| 4063 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4064 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4065 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4066 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4067 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4068 | * <p> |
| 4069 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4070 | * exception will be thrown. |
| 4071 | * <p> |
| 4072 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4073 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4074 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4075 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4076 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4077 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4078 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4079 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4080 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4081 | if (mService != null) { |
| 4082 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4083 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4084 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4085 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4091 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4092 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4093 | * @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] | 4094 | * have disabled screen capture. |
| 4095 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4096 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4097 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4098 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4102 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4103 | if (mService != null) { |
| 4104 | try { |
| 4105 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4106 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4107 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4108 | } |
| 4109 | } |
| 4110 | return false; |
| 4111 | } |
| 4112 | |
| 4113 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4114 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4115 | * 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] | 4116 | * <p> |
| 4117 | * Note: if auto time is required the user can still manually set the time zone. |
| 4118 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4119 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4120 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4121 | * |
| 4122 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4123 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4124 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4125 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4126 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4127 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4128 | if (mService != null) { |
| 4129 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4130 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4131 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4132 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * @return true if auto time is required. |
| 4139 | */ |
| 4140 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4141 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4142 | if (mService != null) { |
| 4143 | try { |
| 4144 | return mService.getAutoTimeRequired(); |
| 4145 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4146 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | return false; |
| 4150 | } |
| 4151 | |
| 4152 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4153 | * 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] | 4154 | * <p> |
| 4155 | * The system user is exempt from this policy - it is never ephemeral. |
| 4156 | * <p> |
| 4157 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4158 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4159 | * |
| 4160 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4161 | * @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] | 4162 | * subsequently created users will be ephemeral. |
| 4163 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4164 | * @hide |
| 4165 | */ |
| 4166 | public void setForceEphemeralUsers( |
| 4167 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4168 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4169 | if (mService != null) { |
| 4170 | try { |
| 4171 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 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 | } |
| 4177 | |
| 4178 | /** |
| 4179 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4180 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4181 | * @hide |
| 4182 | */ |
| 4183 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4184 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4185 | if (mService != null) { |
| 4186 | try { |
| 4187 | return mService.getForceEphemeralUsers(admin); |
| 4188 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4189 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4190 | } |
| 4191 | } |
| 4192 | return false; |
| 4193 | } |
| 4194 | |
| 4195 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4196 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4197 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4198 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4199 | * <p> |
| 4200 | * The calling device admin must have requested |
| 4201 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4202 | * if it has not, a security exception will be thrown. |
| 4203 | * <p> |
| 4204 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4205 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4206 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4207 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4208 | * <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] | 4209 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4210 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4211 | * there is one, or the parent user otherwise. |
| 4212 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4213 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4214 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4215 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4216 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4217 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4218 | * profile. |
| 4219 | * <p> |
| 4220 | * Requests to disable other features on a managed profile will be ignored. |
| 4221 | * <p> |
| 4222 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4223 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4224 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4225 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4226 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4227 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4228 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4229 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4230 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4231 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4232 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4233 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4234 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4235 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4236 | if (mService != null) { |
| 4237 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4238 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4239 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4240 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4246 | * 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] | 4247 | * 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] | 4248 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4249 | * |
| 4250 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4251 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4252 | * restrictions on the parent profile. |
| 4253 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4254 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4255 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4256 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4257 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4258 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4259 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4260 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4264 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4265 | if (mService != null) { |
| 4266 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4267 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4268 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4269 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4270 | } |
| 4271 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4272 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4276 | * @hide |
| 4277 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4278 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4279 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4280 | if (mService != null) { |
| 4281 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4282 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4283 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4284 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4285 | } |
| 4286 | } |
| 4287 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4288 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4289 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4290 | * @hide |
| 4291 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4292 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4293 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4297 | * @hide |
| 4298 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4299 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4300 | if (mService != null) { |
| 4301 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4302 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4303 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4304 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4305 | } |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | /** |
| 4310 | * @hide |
| 4311 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4312 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4313 | if (mService != null) { |
| 4314 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4315 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4316 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4317 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4318 | } |
| 4319 | } |
| 4320 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4321 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4322 | /** |
| 4323 | * @hide |
| 4324 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4325 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4326 | if (mService != null) { |
| 4327 | try { |
| 4328 | mService.reportPasswordChanged(userId); |
| 4329 | } catch (RemoteException e) { |
| 4330 | throw e.rethrowFromSystemServer(); |
| 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | /** |
| 4336 | * @hide |
| 4337 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4338 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4339 | if (mService != null) { |
| 4340 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4341 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4342 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4343 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4344 | } |
| 4345 | } |
| 4346 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4347 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4348 | /** |
| 4349 | * @hide |
| 4350 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4351 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4352 | if (mService != null) { |
| 4353 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4354 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4355 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4356 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4357 | } |
| 4358 | } |
| 4359 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4360 | |
| 4361 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4362 | * @hide |
| 4363 | */ |
| 4364 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4365 | if (mService != null) { |
| 4366 | try { |
| 4367 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4368 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4369 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4370 | } |
| 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | /** |
| 4375 | * @hide |
| 4376 | */ |
| 4377 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4378 | if (mService != null) { |
| 4379 | try { |
| 4380 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4381 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4382 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4388 | * Should be called when keyguard has been dismissed. |
| 4389 | * @hide |
| 4390 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4391 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4392 | if (mService != null) { |
| 4393 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4394 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4395 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4396 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4397 | } |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | /** |
| 4402 | * Should be called when keyguard view has been shown to the user. |
| 4403 | * @hide |
| 4404 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4405 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4406 | if (mService != null) { |
| 4407 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4408 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4409 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4410 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4411 | } |
| 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4416 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4417 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4418 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4419 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4420 | * @return whether the package was successfully registered as the device owner. |
| 4421 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4422 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4423 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4424 | public boolean setDeviceOwner(ComponentName who) { |
| 4425 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | /** |
| 4429 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4430 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4431 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4432 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | /** |
| 4436 | * @hide |
| 4437 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4438 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4439 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | /** |
| 4443 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4444 | * Sets the given package as the device owner. The package must already be installed. There |
| 4445 | * must not already be a device owner. |
| 4446 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4447 | * this method. |
| 4448 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4449 | * 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] | 4450 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4451 | * @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] | 4452 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4453 | * @return whether the package was successfully registered as the device owner. |
| 4454 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4455 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4456 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4457 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4458 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4459 | if (mService != null) { |
| 4460 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4461 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4462 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4463 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4464 | } |
| 4465 | } |
| 4466 | return false; |
| 4467 | } |
| 4468 | |
| 4469 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4470 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4471 | * 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] | 4472 | * 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] | 4473 | * package is currently registered as the device owner app, pass in the package name from |
| 4474 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4475 | * 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] | 4476 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4477 | * the setup process. |
| 4478 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4479 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4480 | * @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] | 4481 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4482 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4483 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4484 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4485 | } |
| 4486 | |
| 4487 | /** |
| 4488 | * @return true if a package is registered as device owner, only when it's running on the |
| 4489 | * calling user. |
| 4490 | * |
| 4491 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4492 | * @hide |
| 4493 | */ |
| 4494 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4495 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4496 | } |
| 4497 | |
| 4498 | /** |
| 4499 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4500 | * user. |
| 4501 | * |
| 4502 | * <p>Requires the MANAGE_USERS permission. |
| 4503 | * |
| 4504 | * @hide |
| 4505 | */ |
| 4506 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4507 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4508 | } |
| 4509 | |
| 4510 | /** |
| 4511 | * @return device owner component name, only when it's running on the calling user. |
| 4512 | * |
| 4513 | * @hide |
| 4514 | */ |
| 4515 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4516 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4517 | } |
| 4518 | |
| 4519 | /** |
| 4520 | * @return device owner component name, even if it's running on a different user. |
| 4521 | * |
| 4522 | * <p>Requires the MANAGE_USERS permission. |
| 4523 | * |
| 4524 | * @hide |
| 4525 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4526 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4527 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4528 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4529 | } |
| 4530 | |
| 4531 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4532 | if (packageName == null) { |
| 4533 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4534 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4535 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4536 | if (deviceOwner == null) { |
| 4537 | return false; |
| 4538 | } |
| 4539 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4542 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4543 | if (mService != null) { |
| 4544 | try { |
| 4545 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4546 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4547 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4548 | } |
| 4549 | } |
| 4550 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4553 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4554 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4555 | * no device owner. |
| 4556 | * |
| 4557 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4558 | * |
| 4559 | * @hide |
| 4560 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4561 | public int getDeviceOwnerUserId() { |
| 4562 | if (mService != null) { |
| 4563 | try { |
| 4564 | return mService.getDeviceOwnerUserId(); |
| 4565 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4566 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4567 | } |
| 4568 | } |
| 4569 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4573 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4574 | * 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] | 4575 | * a part of device setup, before it completes. |
| 4576 | * <p> |
| 4577 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 4578 | * a best-effort process and some other policies will still remain in place after the device |
| 4579 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4580 | * |
| 4581 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4582 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4583 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4584 | * |
| 4585 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 4586 | * will lose control of the device and its data after calling it. In order to protect any |
| 4587 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 4588 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4589 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4590 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4591 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4592 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4593 | if (mService != null) { |
| 4594 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4595 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4596 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4597 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | } |
| 4601 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4602 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4603 | * Returns the device owner package name, only if it's running on the calling user. |
| 4604 | * |
| 4605 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4606 | * |
| 4607 | * @hide |
| 4608 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4609 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4610 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4611 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4612 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4613 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4617 | * 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] | 4618 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4619 | * @return whether the device is managed by a Device Owner. |
| 4620 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4621 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4622 | * |
| 4623 | * @hide |
| 4624 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4625 | @SystemApi |
| 4626 | @TestApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4627 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4628 | try { |
| 4629 | return mService.hasDeviceOwner(); |
| 4630 | } catch (RemoteException re) { |
| 4631 | throw re.rethrowFromSystemServer(); |
| 4632 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | /** |
| 4636 | * Returns the device owner name. Note this method *will* return the device owner |
| 4637 | * name when it's running on a different user. |
| 4638 | * |
| 4639 | * <p>Requires the MANAGE_USERS permission. |
| 4640 | * |
| 4641 | * @hide |
| 4642 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4643 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4644 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4645 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4646 | if (mService != null) { |
| 4647 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4648 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4649 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4650 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4651 | } |
| 4652 | } |
| 4653 | return null; |
| 4654 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4655 | |
| 4656 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4657 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4658 | * @deprecated Do not use |
| 4659 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4660 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4661 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4662 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4663 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4664 | return null; |
| 4665 | } |
| 4666 | |
| 4667 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4668 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4669 | * @deprecated Do not use |
| 4670 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4671 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4672 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4673 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4674 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4675 | return null; |
| 4676 | } |
| 4677 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4678 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4679 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4680 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4681 | * Sets the given component as an active admin and registers the package as the profile |
| 4682 | * owner for this user. The package must already be installed and there shouldn't be |
| 4683 | * an existing profile owner registered for this user. Also, this method must be called |
| 4684 | * before the user setup has been completed. |
| 4685 | * <p> |
| 4686 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4687 | * MANAGE_DEVICE_ADMINS permission. |
| 4688 | * @param admin The component to register as an active admin and profile owner. |
| 4689 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4690 | * @return whether the admin was successfully registered as the profile owner. |
| 4691 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4692 | * the user has already been set up. |
| 4693 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4694 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4695 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4696 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4697 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4698 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4699 | if (mService != null) { |
| 4700 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4701 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4702 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4703 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4704 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4705 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4706 | } |
| 4707 | } |
| 4708 | return false; |
| 4709 | } |
| 4710 | |
| 4711 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4712 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 4713 | * 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] | 4714 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4715 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 4716 | * a best-effort process and some other policies will still remain in place after the profile |
| 4717 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4718 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4719 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4720 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 4721 | * being called from a managed profile. |
| 4722 | * |
| 4723 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 4724 | * will lose control of the user and its data after calling it. In order to protect any |
| 4725 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 4726 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4727 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4728 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4729 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4730 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4731 | if (mService != null) { |
| 4732 | try { |
| 4733 | mService.clearProfileOwner(admin); |
| 4734 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4735 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4736 | } |
| 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4741 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4742 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4743 | */ |
| 4744 | public boolean hasUserSetupCompleted() { |
| 4745 | if (mService != null) { |
| 4746 | try { |
| 4747 | return mService.hasUserSetupCompleted(); |
| 4748 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4749 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4750 | } |
| 4751 | } |
| 4752 | return true; |
| 4753 | } |
| 4754 | |
| 4755 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4756 | * @hide |
| 4757 | * 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] | 4758 | * already be installed. There must not already be a profile owner for this user. |
| 4759 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4760 | * this method. |
| 4761 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4762 | * - the caller is SYSTEM_UID. |
| 4763 | * - 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] | 4764 | * @param admin the component name to be registered as profile owner. |
| 4765 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4766 | * @param userHandle the userId to set the profile owner for. |
| 4767 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4768 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4769 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4770 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4771 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4772 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4773 | if (mService != null) { |
| 4774 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4775 | if (ownerName == null) { |
| 4776 | ownerName = ""; |
| 4777 | } |
| 4778 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4779 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4780 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4781 | } |
| 4782 | } |
| 4783 | return false; |
| 4784 | } |
| 4785 | |
| 4786 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4787 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4788 | * <p> |
| 4789 | * 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] | 4790 | * 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] | 4791 | * <p> |
| 4792 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4793 | * will be blank and the user will not be allowed to change it. |
| 4794 | * <p> |
| 4795 | * 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] | 4796 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4797 | * and set a new version of this string accordingly. |
| 4798 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4799 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4800 | * @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] | 4801 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4802 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4803 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4804 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4805 | if (mService != null) { |
| 4806 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4807 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4808 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4809 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4810 | } |
| 4811 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | /** |
| 4815 | * @return The device owner information. If it is not set returns {@code null}. |
| 4816 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4817 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4818 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4819 | if (mService != null) { |
| 4820 | try { |
| 4821 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4822 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4823 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4824 | } |
| 4825 | } |
| 4826 | return null; |
| 4827 | } |
| 4828 | |
| 4829 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4830 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4831 | * called by a device owner, profile owner, or by a delegate given the |
| 4832 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4833 | * <p> |
| 4834 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4835 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4836 | * device. |
| 4837 | * <p> |
| 4838 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4839 | * 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] | 4840 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4841 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4842 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4843 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4844 | * @param packageNames The package names to suspend or unsuspend. |
| 4845 | * @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] | 4846 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4847 | * @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] | 4848 | * this method. |
| 4849 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4850 | * @see #setDelegatedScopes |
| 4851 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4852 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4853 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4854 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4855 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4856 | if (mService != null) { |
| 4857 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4858 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4859 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4860 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4861 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4862 | } |
| 4863 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4864 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4868 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4869 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4870 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4871 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4872 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4873 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4874 | * @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] | 4875 | * @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] | 4876 | * suspended, could not be found or an error occurred. |
| 4877 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4878 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4879 | * @see #setDelegatedScopes |
| 4880 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4881 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4882 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4883 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4884 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4885 | if (mService != null) { |
| 4886 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4887 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4888 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4889 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4890 | } catch (IllegalArgumentException ex) { |
| 4891 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | return false; |
| 4895 | } |
| 4896 | |
| 4897 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4898 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4899 | * be used. Only the profile owner can call this. |
| 4900 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4901 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4902 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4903 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4904 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4905 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4906 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4907 | if (mService != null) { |
| 4908 | try { |
| 4909 | mService.setProfileEnabled(admin); |
| 4910 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4911 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4912 | } |
| 4913 | } |
| 4914 | } |
| 4915 | |
| 4916 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4917 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4918 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4919 | * 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] | 4920 | * |
| 4921 | * @see #isProfileOwnerApp |
| 4922 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4923 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4924 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4925 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4927 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4928 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4929 | if (mService != null) { |
| 4930 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4931 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4932 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4933 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4934 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4935 | } |
| 4936 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4937 | |
| 4938 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4939 | * 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] | 4940 | * 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] | 4941 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4942 | * |
| 4943 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4944 | * @return Whether or not the package is registered as the profile owner. |
| 4945 | */ |
| 4946 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4947 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4948 | if (mService != null) { |
| 4949 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4950 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4951 | return profileOwner != null |
| 4952 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4953 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4954 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | return false; |
| 4958 | } |
| 4959 | |
| 4960 | /** |
| 4961 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4962 | * @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] | 4963 | * owner has been set for that user. |
| 4964 | * @throws IllegalArgumentException if the userId is invalid. |
| 4965 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4966 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4967 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4968 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4969 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4970 | } |
| 4971 | |
| 4972 | /** |
| 4973 | * @see #getProfileOwner() |
| 4974 | * @hide |
| 4975 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4976 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4977 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4978 | if (mService != null) { |
| 4979 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4980 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4981 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4982 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4983 | } |
| 4984 | } |
| 4985 | return null; |
| 4986 | } |
| 4987 | |
| 4988 | /** |
| 4989 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4990 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4991 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4992 | * @throws IllegalArgumentException if the userId is invalid. |
| 4993 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4994 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4995 | if (mService != null) { |
| 4996 | try { |
| 4997 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4998 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4999 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5000 | } |
| 5001 | } |
| 5002 | return null; |
| 5003 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5004 | |
| 5005 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5006 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5007 | * @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] | 5008 | * @return the human readable name of the organisation associated with this profile owner or |
| 5009 | * null if one is not set. |
| 5010 | * @throws IllegalArgumentException if the userId is invalid. |
| 5011 | */ |
| 5012 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5013 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5014 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5015 | if (mService != null) { |
| 5016 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5017 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5018 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5019 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | return null; |
| 5023 | } |
| 5024 | |
| 5025 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5026 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 5027 | * 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] | 5028 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 5029 | * intent preferences are reset. |
| 5030 | * <p> |
| 5031 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5032 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5033 | * the filter. |
| 5034 | * <p> |
| 5035 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5036 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5037 | * |
| 5038 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5039 | * @param filter The IntentFilter for which a default handler is added. |
| 5040 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5041 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5042 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5043 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5044 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5045 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5046 | if (mService != null) { |
| 5047 | try { |
| 5048 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5049 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5050 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5051 | } |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | /** |
| 5056 | * 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] | 5057 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5058 | * <p> |
| 5059 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5060 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5061 | * |
| 5062 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5063 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5064 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5065 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5066 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5067 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5068 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5069 | if (mService != null) { |
| 5070 | try { |
| 5071 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5072 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5073 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5074 | } |
| 5075 | } |
| 5076 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5077 | |
| 5078 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5079 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5080 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5081 | * {@link #getApplicationRestrictions}. |
| 5082 | * <p> |
| 5083 | * This permission is persistent until it is later cleared by calling this method with a |
| 5084 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5085 | * <p> |
| 5086 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5087 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5088 | * |
| 5089 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5090 | * @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] | 5091 | * APIs. If {@code null} is given the current package will be cleared. |
| 5092 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5093 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5094 | * |
| 5095 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5096 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5097 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5098 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5099 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5100 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5101 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5102 | if (mService != null) { |
| 5103 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5104 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5105 | throw new NameNotFoundException(packageName); |
| 5106 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5107 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5108 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5109 | } |
| 5110 | } |
| 5111 | } |
| 5112 | |
| 5113 | /** |
| 5114 | * 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] | 5115 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5116 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5117 | * |
| 5118 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5119 | * @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] | 5120 | * {@code null} if none is set. |
| 5121 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5122 | * |
| 5123 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 5124 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5125 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5126 | @Deprecated |
| 5127 | @Nullable |
| 5128 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5129 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5130 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5131 | if (mService != null) { |
| 5132 | try { |
| 5133 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5134 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5135 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5136 | } |
| 5137 | } |
| 5138 | return null; |
| 5139 | } |
| 5140 | |
| 5141 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5142 | * Called by any application to find out whether it has been granted permission via |
| 5143 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5144 | * for the calling user. |
| 5145 | * |
| 5146 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5147 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5148 | * |
| 5149 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5150 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5151 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5152 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5153 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5154 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5155 | if (mService != null) { |
| 5156 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5157 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5158 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5159 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5160 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5161 | } |
| 5162 | } |
| 5163 | return false; |
| 5164 | } |
| 5165 | |
| 5166 | /** |
| 5167 | * 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] | 5168 | * <p> |
| 5169 | * 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] | 5170 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5171 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5172 | * <p> |
| 5173 | * 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] | 5174 | * <ul> |
| 5175 | * <li>{@code boolean} |
| 5176 | * <li>{@code int} |
| 5177 | * <li>{@code String} or {@code String[]} |
| 5178 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5179 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5180 | * <p> |
| 5181 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5182 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5183 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5184 | * <p> |
| 5185 | * The application restrictions are only made visible to the target application via |
| 5186 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5187 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5188 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5189 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5190 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5191 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5192 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5193 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5194 | * @param packageName The name of the package to update restricted settings for. |
| 5195 | * @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] | 5196 | * set of active restrictions. |
| 5197 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5198 | * @see #setDelegatedScopes |
| 5199 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5200 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5201 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5202 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5203 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5204 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5205 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5206 | if (mService != null) { |
| 5207 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5208 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5209 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5210 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5211 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5212 | } |
| 5213 | } |
| 5214 | } |
| 5215 | |
| 5216 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5217 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5218 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5219 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5220 | * {@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] | 5221 | * <p> |
| 5222 | * The calling device admin must have requested |
| 5223 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5224 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5225 | * <p> |
| 5226 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5227 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5228 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5229 | * |
| 5230 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5231 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5232 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5233 | * strictly disabled according to the state of the |
| 5234 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5235 | * <p> |
| 5236 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5237 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5238 | * device admins. |
| 5239 | * <p> |
| 5240 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5241 | * parameters. |
| 5242 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5243 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5244 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5245 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5246 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5247 | if (mService != null) { |
| 5248 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5249 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5250 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5251 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5252 | } |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5257 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5258 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5259 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5260 | * <p> |
| 5261 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5262 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5263 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5264 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5265 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5266 | * this function returns a list of configurations for all admins that declare |
| 5267 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5268 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5269 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5270 | * 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] | 5271 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5272 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5273 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5274 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5275 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5276 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5280 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5281 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5282 | if (mService != null) { |
| 5283 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5284 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5285 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5286 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5287 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5288 | } |
| 5289 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5290 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5294 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5295 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5296 | * <p> |
| 5297 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5298 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5299 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5300 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5301 | * @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] | 5302 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5303 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5304 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5305 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5306 | if (mService != null) { |
| 5307 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5308 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5309 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5310 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5311 | } |
| 5312 | } |
| 5313 | } |
| 5314 | |
| 5315 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5316 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5317 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5318 | * <p> |
| 5319 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5320 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5321 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5322 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5323 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5324 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5325 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5326 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5327 | if (mService != null) { |
| 5328 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5329 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5330 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5331 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5332 | } |
| 5333 | } |
| 5334 | return false; |
| 5335 | } |
| 5336 | |
| 5337 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5338 | * Determine whether or not caller-Id information has been disabled. |
| 5339 | * |
| 5340 | * @param userHandle The user for whom to check the caller-id permission |
| 5341 | * @hide |
| 5342 | */ |
| 5343 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5344 | if (mService != null) { |
| 5345 | try { |
| 5346 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5347 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5348 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5349 | } |
| 5350 | } |
| 5351 | return false; |
| 5352 | } |
| 5353 | |
| 5354 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5355 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5356 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5357 | * <p> |
| 5358 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5359 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5360 | * |
| 5361 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5362 | * @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] | 5363 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5364 | */ |
| 5365 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5366 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5367 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5368 | if (mService != null) { |
| 5369 | try { |
| 5370 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5371 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5372 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5373 | } |
| 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | /** |
| 5378 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5379 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5380 | * <p> |
| 5381 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5382 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5383 | * |
| 5384 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5385 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5386 | */ |
| 5387 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5388 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5389 | if (mService != null) { |
| 5390 | try { |
| 5391 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5392 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5393 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | return false; |
| 5397 | } |
| 5398 | |
| 5399 | |
| 5400 | /** |
| 5401 | * Determine whether or not contacts search has been disabled. |
| 5402 | * |
| 5403 | * @param userHandle The user for whom to check the contacts search permission |
| 5404 | * @hide |
| 5405 | */ |
| 5406 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5407 | if (mService != null) { |
| 5408 | try { |
| 5409 | return mService |
| 5410 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5411 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5412 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | return false; |
| 5416 | } |
| 5417 | |
| 5418 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5419 | * 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] | 5420 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5421 | * @hide |
| 5422 | */ |
| 5423 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5424 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5425 | if (mService != null) { |
| 5426 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5427 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5428 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5429 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5430 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5436 | * 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] | 5437 | * @hide |
| 5438 | */ |
| 5439 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5440 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5441 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5442 | originalIntent); |
| 5443 | } |
| 5444 | |
| 5445 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5446 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5447 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5448 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5449 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5450 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5451 | * <p> |
| 5452 | * This API works on managed profile only. |
| 5453 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5454 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5455 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5456 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5457 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5458 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5459 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5460 | if (mService != null) { |
| 5461 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5462 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5463 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5464 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5465 | } |
| 5466 | } |
| 5467 | } |
| 5468 | |
| 5469 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5470 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5471 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5472 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5473 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5474 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5475 | * <p> |
| 5476 | * This API works on managed profile only. |
| 5477 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5478 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5479 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5480 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5481 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5482 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5483 | if (mService != null) { |
| 5484 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5485 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5486 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5487 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5488 | } |
| 5489 | } |
| 5490 | return true; |
| 5491 | } |
| 5492 | |
| 5493 | /** |
| 5494 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5495 | * <p> |
| 5496 | * This API works on managed profile UserHandle only. |
| 5497 | * |
| 5498 | * @param userHandle The user for whom to check the caller-id permission |
| 5499 | * @hide |
| 5500 | */ |
| 5501 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5502 | if (mService != null) { |
| 5503 | try { |
| 5504 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5505 | .getIdentifier()); |
| 5506 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5507 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5508 | } |
| 5509 | } |
| 5510 | return true; |
| 5511 | } |
| 5512 | |
| 5513 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5514 | * 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] | 5515 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5516 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5517 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5518 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5519 | * @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] | 5520 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5521 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5522 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5523 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5524 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5525 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5526 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5527 | if (mService != null) { |
| 5528 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5529 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5530 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5531 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5532 | } |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5537 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5538 | * 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] | 5539 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5540 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5541 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5542 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5543 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5544 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5545 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5546 | if (mService != null) { |
| 5547 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5548 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5549 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5550 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5551 | } |
| 5552 | } |
| 5553 | } |
| 5554 | |
| 5555 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5556 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5557 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5558 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5559 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5560 | * the list and not part of the system can not be enabled by the user. |
| 5561 | * <p> |
| 5562 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5563 | * used, calling with an empty list only allows the builtin system's services. |
| 5564 | * <p> |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5565 | * System accessibility 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] | 5566 | * |
| 5567 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5568 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5569 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5570 | * accessibility services enabled, that are not in the list. |
| 5571 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5572 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5573 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5574 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5575 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5576 | if (mService != null) { |
| 5577 | try { |
| 5578 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5579 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5580 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5581 | } |
| 5582 | } |
| 5583 | return false; |
| 5584 | } |
| 5585 | |
| 5586 | /** |
| 5587 | * 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] | 5588 | * <p> |
| 5589 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5590 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5591 | * |
| 5592 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5593 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5594 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5595 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5596 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5597 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5598 | if (mService != null) { |
| 5599 | try { |
| 5600 | return mService.getPermittedAccessibilityServices(admin); |
| 5601 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5602 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5603 | } |
| 5604 | } |
| 5605 | return null; |
| 5606 | } |
| 5607 | |
| 5608 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5609 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5610 | * |
| 5611 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5612 | * @param packageName Accessibility service package name that needs to be checked. |
| 5613 | * @param userHandle user id the admin is running as. |
| 5614 | * @return true if the accessibility service is permitted, otherwise false. |
| 5615 | * |
| 5616 | * @hide |
| 5617 | */ |
| 5618 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5619 | @NonNull String packageName, int userHandle) { |
| 5620 | if (mService != null) { |
| 5621 | try { |
| 5622 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5623 | userHandle); |
| 5624 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5625 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5626 | } |
| 5627 | } |
| 5628 | return false; |
| 5629 | } |
| 5630 | |
| 5631 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5632 | * Returns the list of accessibility services permitted by the device or profiles |
| 5633 | * owners of this user. |
| 5634 | * |
| 5635 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5636 | * it will contain the intersection of the permitted lists for any device or profile |
| 5637 | * owners that apply to this user. It will also include any system accessibility services. |
| 5638 | * |
| 5639 | * @param userId which user to check for. |
| 5640 | * @return List of accessiblity service package names. |
| 5641 | * @hide |
| 5642 | */ |
| 5643 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5644 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5645 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5646 | if (mService != null) { |
| 5647 | try { |
| 5648 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5649 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5650 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5651 | } |
| 5652 | } |
| 5653 | return null; |
| 5654 | } |
| 5655 | |
| 5656 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5657 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5658 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5659 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5660 | * When zero or more packages have been added, input method that are not in the list and not |
| 5661 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5662 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5663 | * <p> |
| 5664 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5665 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5666 | * <p> |
| 5667 | * 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] | 5668 | * |
| 5669 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5670 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5671 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5672 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5673 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5674 | */ |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5675 | public boolean setPermittedInputMethods( |
| 5676 | @NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5677 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5678 | if (mService != null) { |
| 5679 | try { |
| 5680 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5681 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5682 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5683 | } |
| 5684 | } |
| 5685 | return false; |
| 5686 | } |
| 5687 | |
| 5688 | |
| 5689 | /** |
| 5690 | * 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] | 5691 | * <p> |
| 5692 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5693 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5694 | * |
| 5695 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5696 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5697 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5698 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5699 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5700 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5701 | if (mService != null) { |
| 5702 | try { |
| 5703 | return mService.getPermittedInputMethods(admin); |
| 5704 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5705 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5706 | } |
| 5707 | } |
| 5708 | return null; |
| 5709 | } |
| 5710 | |
| 5711 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5712 | * Called by the system to check if a specific input method is disabled by admin. |
| 5713 | * |
| 5714 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5715 | * @param packageName Input method package name that needs to be checked. |
| 5716 | * @param userHandle user id the admin is running as. |
| 5717 | * @return true if the input method is permitted, otherwise false. |
| 5718 | * |
| 5719 | * @hide |
| 5720 | */ |
| 5721 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5722 | @NonNull String packageName, int userHandle) { |
| 5723 | if (mService != null) { |
| 5724 | try { |
| 5725 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5726 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5727 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5728 | } |
| 5729 | } |
| 5730 | return false; |
| 5731 | } |
| 5732 | |
| 5733 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5734 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5735 | * 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] | 5736 | * |
| 5737 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5738 | * it will contain the intersection of the permitted lists for any device or profile |
| 5739 | * owners that apply to this user. It will also include any system input methods. |
| 5740 | * |
| 5741 | * @return List of input method package names. |
| 5742 | * @hide |
| 5743 | */ |
| 5744 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5745 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5746 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5747 | if (mService != null) { |
| 5748 | try { |
| 5749 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5750 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5751 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5752 | } |
| 5753 | } |
| 5754 | return null; |
| 5755 | } |
| 5756 | |
| 5757 | /** |
Esteban Talavera | 9c6458d | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5758 | * Called by a profile owner of a managed profile to set the packages that are allowed to use |
| 5759 | * a {@link android.service.notification.NotificationListenerService} in the primary user to |
| 5760 | * see notifications from the managed profile. By default all packages are permitted by this |
| 5761 | * policy. When zero or more packages have been added, notification listeners installed on the |
| 5762 | * primary user that are not in the list and are not part of the system won't receive events |
| 5763 | * for managed profile notifications. |
| 5764 | * <p> |
| 5765 | * Calling with a {@code null} value for the list disables the restriction so that all |
| 5766 | * notification listener services be used. Calling with an empty list disables all but the |
| 5767 | * system's own notification listeners. System notification listener services are always |
| 5768 | * available to the user. |
| 5769 | * <p> |
| 5770 | * If a device or profile owner want to stop notification listeners in their user from seeing |
| 5771 | * that user's notifications they should prevent that service from running instead (e.g. via |
| 5772 | * {@link #setApplicationHidden(ComponentName, String, boolean)}) |
| 5773 | * |
| 5774 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5775 | * @param packageList List of package names to whitelist |
| 5776 | * @return true if setting the restriction succeeded. It will fail if called outside a managed |
| 5777 | * profile |
| 5778 | * @throws SecurityException if {@code admin} is not a profile owner. |
| 5779 | * |
| 5780 | * @see android.service.notification.NotificationListenerService |
| 5781 | */ |
| 5782 | public boolean setPermittedCrossProfileNotificationListeners( |
| 5783 | @NonNull ComponentName admin, @Nullable List<String> packageList) { |
| 5784 | throwIfParentInstance("setPermittedCrossProfileNotificationListeners"); |
| 5785 | if (mService != null) { |
| 5786 | try { |
| 5787 | return mService.setPermittedCrossProfileNotificationListeners(admin, packageList); |
| 5788 | } catch (RemoteException e) { |
| 5789 | throw e.rethrowFromSystemServer(); |
| 5790 | } |
| 5791 | } |
| 5792 | return false; |
| 5793 | } |
| 5794 | |
| 5795 | /** |
| 5796 | * Returns the list of packages installed on the primary user that allowed to use a |
| 5797 | * {@link android.service.notification.NotificationListenerService} to receive |
| 5798 | * notifications from this managed profile, as set by the profile owner. |
| 5799 | * <p> |
| 5800 | * An empty list means no notification listener services except system ones are allowed. |
| 5801 | * A {@code null} return value indicates that all notification listeners are allowed. |
| 5802 | */ |
| 5803 | public @Nullable List<String> getPermittedCrossProfileNotificationListeners( |
| 5804 | @NonNull ComponentName admin) { |
| 5805 | throwIfParentInstance("getPermittedCrossProfileNotificationListeners"); |
| 5806 | if (mService != null) { |
| 5807 | try { |
| 5808 | return mService.getPermittedCrossProfileNotificationListeners(admin); |
| 5809 | } catch (RemoteException e) { |
| 5810 | throw e.rethrowFromSystemServer(); |
| 5811 | } |
| 5812 | } |
| 5813 | return null; |
| 5814 | } |
| 5815 | |
| 5816 | /** |
| 5817 | * Returns true if {@code NotificationListenerServices} from the given package are allowed to |
| 5818 | * receive events for notifications from the given user id. Can only be called by the system uid |
| 5819 | * |
| 5820 | * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List) |
| 5821 | * |
| 5822 | * @hide |
| 5823 | */ |
| 5824 | public boolean isNotificationListenerServicePermitted( |
| 5825 | @NonNull String packageName, @UserIdInt int userId) { |
| 5826 | if (mService != null) { |
| 5827 | try { |
| 5828 | return mService.isNotificationListenerServicePermitted(packageName, userId); |
| 5829 | } catch (RemoteException e) { |
| 5830 | throw e.rethrowFromSystemServer(); |
| 5831 | } |
| 5832 | } |
| 5833 | return true; |
| 5834 | } |
| 5835 | |
| 5836 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5837 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5838 | * function can be called by a device owner or by a delegate given the |
| 5839 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5840 | * <p> |
| 5841 | * 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] | 5842 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5844 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5845 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5846 | * @see #setDelegatedScopes |
| 5847 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5848 | * @hide |
| 5849 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5850 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5851 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5852 | if (mService != null) { |
| 5853 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5854 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5855 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5856 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5857 | } |
| 5858 | } |
| 5859 | return null; |
| 5860 | } |
| 5861 | |
| 5862 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5863 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5864 | * function can be called by a device owner or by a delegate given the |
| 5865 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5866 | * |
| 5867 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5868 | * automatically pre-cached.</p> |
| 5869 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5870 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5871 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5872 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5873 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5874 | * @see #setDelegatedScopes |
| 5875 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5876 | * @hide |
| 5877 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5878 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5879 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5880 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5881 | if (mService != null) { |
| 5882 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5883 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5884 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5885 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5886 | } |
| 5887 | } |
| 5888 | } |
| 5889 | |
| 5890 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5891 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5892 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5893 | * created. If you need to persist an identifier for this user, use |
| 5894 | * {@link UserManager#getSerialNumberForUser}. |
| 5895 | * |
| 5896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5897 | * @param name the user's name |
| 5898 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5899 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5900 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5901 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5902 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5903 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5904 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5905 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5906 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5907 | return null; |
| 5908 | } |
| 5909 | |
| 5910 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5911 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5912 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5913 | * created. If you need to persist an identifier for this user, use |
| 5914 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5915 | * immediately. |
| 5916 | * |
| 5917 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5918 | * as registered as an active admin on the new user. The profile owner package will be |
| 5919 | * installed on the new user if it already is installed on the device. |
| 5920 | * |
| 5921 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5922 | * profileOwnerComponent when onEnable is called. |
| 5923 | * |
| 5924 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5925 | * @param name the user's name |
| 5926 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5927 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5928 | * the user. |
| 5929 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5930 | * on the new user. |
| 5931 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5932 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5933 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5934 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5935 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5936 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5937 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5938 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5939 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5940 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5941 | return null; |
| 5942 | } |
| 5943 | |
| 5944 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5945 | * 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] | 5946 | */ |
| 5947 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5948 | |
| 5949 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5950 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5951 | * ephemeral. |
| 5952 | * @hide |
| 5953 | */ |
| 5954 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5955 | |
| 5956 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5957 | * Called by a device owner to create a user with the specified name and a given component of |
| 5958 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5959 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5960 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5961 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5962 | * <p> |
| 5963 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5964 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5965 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5966 | * on the new user. |
| 5967 | * <p> |
| 5968 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5969 | * 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] | 5970 | * |
| 5971 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5972 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5973 | * @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] | 5974 | * same package as admin, otherwise no user is created and an |
| 5975 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5976 | * @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] | 5977 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5978 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5979 | * @see UserHandle |
| 5980 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5981 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5982 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5983 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5984 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5985 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5986 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5987 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5988 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5989 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5990 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5991 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5992 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5993 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5997 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5998 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5999 | * |
| 6000 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6001 | * @param userHandle the user to remove. |
| 6002 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6003 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6004 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6005 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6006 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6007 | try { |
| 6008 | return mService.removeUser(admin, userHandle); |
| 6009 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6010 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6011 | } |
| 6012 | } |
| 6013 | |
| 6014 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6015 | * Called by a device owner to switch the specified user to the foreground. |
| 6016 | * |
| 6017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6018 | * @param userHandle the user to switch to; null will switch to primary. |
| 6019 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6020 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6021 | * @see Intent#ACTION_USER_FOREGROUND |
| 6022 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6023 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6024 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6025 | try { |
| 6026 | return mService.switchUser(admin, userHandle); |
| 6027 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6028 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6033 | * Retrieves the application restrictions for a given target application running in the calling |
| 6034 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6035 | * <p> |
| 6036 | * 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] | 6037 | * application restrictions via {@link #setDelegatedScopes} with the |
| 6038 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6039 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6040 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 6041 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6042 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6043 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6044 | * @param packageName The name of the package to fetch restricted settings of. |
| 6045 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6046 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 6047 | * {@link Bundle} if no restrictions have been set. |
| 6048 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6049 | * @see #setDelegatedScopes |
| 6050 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6051 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6052 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6053 | public @NonNull Bundle getApplicationRestrictions( |
| 6054 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6055 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6056 | if (mService != null) { |
| 6057 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6058 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 6059 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6060 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6061 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6062 | } |
| 6063 | } |
| 6064 | return null; |
| 6065 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6066 | |
| 6067 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6068 | * 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] | 6069 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6070 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6071 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6072 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6073 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6074 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6075 | * for the list of keys. |
| 6076 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6077 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6078 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6079 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6080 | if (mService != null) { |
| 6081 | try { |
| 6082 | mService.setUserRestriction(admin, key, true); |
| 6083 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6084 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6085 | } |
| 6086 | } |
| 6087 | } |
| 6088 | |
| 6089 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6090 | * 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] | 6091 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6092 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6093 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6094 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6095 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6096 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6097 | * for the list of keys. |
| 6098 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6099 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6100 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6101 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6102 | if (mService != null) { |
| 6103 | try { |
| 6104 | mService.setUserRestriction(admin, key, false); |
| 6105 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6106 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6107 | } |
| 6108 | } |
| 6109 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6110 | |
| 6111 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6112 | * Called by a profile or device owner to get user restrictions set with |
| 6113 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6114 | * <p> |
| 6115 | * 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] | 6116 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6117 | * {@link UserManager#getUserRestrictions()}. |
| 6118 | * |
| 6119 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6120 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6121 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6122 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6123 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6124 | Bundle ret = null; |
| 6125 | if (mService != null) { |
| 6126 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6127 | ret = mService.getUserRestrictions(admin); |
| 6128 | } catch (RemoteException e) { |
| 6129 | throw e.rethrowFromSystemServer(); |
| 6130 | } |
| 6131 | } |
| 6132 | return ret == null ? new Bundle() : ret; |
| 6133 | } |
| 6134 | |
| 6135 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6136 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6137 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6138 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6139 | * was disabled by an admin, and include a link for more information. The default content of |
| 6140 | * the dialog can be changed by the restricting admin via |
| 6141 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6142 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6143 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6144 | * user restriction from {@link UserManager}, e.g. |
| 6145 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 6146 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 6147 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6148 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6149 | */ |
| 6150 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6151 | throwIfParentInstance("createAdminSupportIntent"); |
| 6152 | if (mService != null) { |
| 6153 | try { |
| 6154 | return mService.createAdminSupportIntent(restriction); |
| 6155 | } catch (RemoteException e) { |
| 6156 | throw e.rethrowFromSystemServer(); |
| 6157 | } |
| 6158 | } |
| 6159 | return null; |
| 6160 | } |
| 6161 | |
| 6162 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6163 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 6164 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 6165 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6166 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6167 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6168 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6169 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6170 | * @param packageName The name of the package to hide or unhide. |
| 6171 | * @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] | 6172 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6173 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6174 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6175 | * @see #setDelegatedScopes |
| 6176 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6177 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6178 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6179 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6180 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6181 | if (mService != null) { |
| 6182 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6183 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 6184 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6185 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6186 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6187 | } |
| 6188 | } |
| 6189 | return false; |
| 6190 | } |
| 6191 | |
| 6192 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6193 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 6194 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6195 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6196 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6197 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6198 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6199 | * @param packageName The name of the package to retrieve the hidden status of. |
| 6200 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6201 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6202 | * @see #setDelegatedScopes |
| 6203 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6204 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6205 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6206 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6207 | if (mService != null) { |
| 6208 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6209 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6210 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6211 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6212 | } |
| 6213 | } |
| 6214 | return false; |
| 6215 | } |
| 6216 | |
| 6217 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6218 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 6219 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6220 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6221 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6222 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6223 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6224 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6225 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6226 | * @see #setDelegatedScopes |
| 6227 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6228 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6229 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6230 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6231 | if (mService != null) { |
| 6232 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6233 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6234 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6235 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6236 | } |
| 6237 | } |
| 6238 | } |
| 6239 | |
| 6240 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6241 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 6242 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 6243 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6244 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6245 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6246 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6247 | * @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] | 6248 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6249 | * @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] | 6250 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6251 | * @see #setDelegatedScopes |
| 6252 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6253 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6254 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6255 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6256 | if (mService != null) { |
| 6257 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6258 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6259 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6260 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6261 | } |
| 6262 | } |
| 6263 | return 0; |
| 6264 | } |
| 6265 | |
| 6266 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6267 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6268 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6269 | * <p> |
| 6270 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6271 | * exception will be thrown. |
| 6272 | * <p> |
| 6273 | * When account management is disabled for an account type, adding or removing an account of |
| 6274 | * that type will not be possible. |
| 6275 | * <p> |
| 6276 | * 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] | 6277 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6278 | * management for a specific type is disabled. |
| 6279 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6280 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6281 | * @param accountType For which account management is disabled or enabled. |
| 6282 | * @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] | 6283 | * enabled (false). |
| 6284 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6285 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6286 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6287 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6288 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6289 | if (mService != null) { |
| 6290 | try { |
| 6291 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6292 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6293 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6294 | } |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6299 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6300 | * |
| 6301 | * <p> Account management can be disabled/enabled by calling |
| 6302 | * {@link #setAccountManagementDisabled}. |
| 6303 | * |
| 6304 | * @return a list of account types for which account management has been disabled. |
| 6305 | * |
| 6306 | * @see #setAccountManagementDisabled |
| 6307 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6308 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6309 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6310 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | /** |
| 6314 | * @see #getAccountTypesWithManagementDisabled() |
| 6315 | * @hide |
| 6316 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6317 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6318 | if (mService != null) { |
| 6319 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6320 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6321 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6322 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6323 | } |
| 6324 | } |
| 6325 | |
| 6326 | return null; |
| 6327 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6328 | |
| 6329 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6330 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6331 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6332 | * 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] | 6333 | * 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] | 6334 | * package list results in locked tasks belonging to those packages to be finished. |
| 6335 | * <p> |
| 6336 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6337 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6338 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6339 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6340 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6341 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6342 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6343 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6344 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6345 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6346 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6347 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6348 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6349 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6350 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6351 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6352 | if (mService != null) { |
| 6353 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6354 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6355 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6356 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6362 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6363 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6364 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6365 | * an affiliated user or profile. |
| 6366 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6367 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6368 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6369 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6370 | if (mService != null) { |
| 6371 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6372 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6373 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6374 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6375 | } |
| 6376 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6377 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | /** |
| 6381 | * This function lets the caller know whether the given component is allowed to start the |
| 6382 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6383 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6384 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6385 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6386 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6387 | if (mService != null) { |
| 6388 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6389 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6390 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6391 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6392 | } |
| 6393 | } |
| 6394 | return false; |
| 6395 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6396 | |
| 6397 | /** |
| 6398 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 6399 | * 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] | 6400 | * <p> |
| 6401 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6402 | * <ul> |
| 6403 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 6404 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 6405 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6406 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6407 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6408 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6409 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 6410 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 6411 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 6412 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 6413 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6414 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6415 | * <p> |
| 6416 | * 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] | 6417 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6418 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 6419 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6420 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6421 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6422 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 6423 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6424 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6425 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 6426 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6427 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6428 | * |
| 6429 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6430 | * @param setting The name of the setting to update. |
| 6431 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6432 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6433 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6434 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6435 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6436 | if (mService != null) { |
| 6437 | try { |
| 6438 | mService.setGlobalSetting(admin, setting, value); |
| 6439 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6440 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6441 | } |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | /** |
| 6446 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 6447 | * that the value of the setting is in the correct form for the setting type should be performed |
| 6448 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6449 | * <p> |
| 6450 | * 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] | 6451 | * <ul> |
| 6452 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 6453 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 6454 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6455 | * <p> |
| 6456 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6457 | * <ul> |
| 6458 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 6459 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6460 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 6461 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 6462 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 6463 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 6464 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 6465 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 6466 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 6467 | * an {@link UnsupportedOperationException} is thrown. |
| 6468 | * </strong> |
| 6469 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6470 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6471 | * @param setting The name of the setting to update. |
| 6472 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6473 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6474 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6475 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6476 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6477 | if (mService != null) { |
| 6478 | try { |
| 6479 | mService.setSecureSetting(admin, setting, value); |
| 6480 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6481 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6482 | } |
| 6483 | } |
| 6484 | } |
| 6485 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6486 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6487 | * Designates a specific service component as the provider for making permission requests of a |
| 6488 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6489 | * <p/> |
| 6490 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6491 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6492 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6493 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6494 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6495 | * provider previously assigned. |
| 6496 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6497 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6498 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6499 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6500 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6501 | if (mService != null) { |
| 6502 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6503 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6504 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6505 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6506 | } |
| 6507 | } |
| 6508 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6509 | |
| 6510 | /** |
| 6511 | * 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] | 6512 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6513 | * |
| 6514 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6515 | * @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] | 6516 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6517 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6518 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6519 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6520 | if (mService != null) { |
| 6521 | try { |
| 6522 | mService.setMasterVolumeMuted(admin, on); |
| 6523 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6524 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6525 | } |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | /** |
| 6530 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6531 | * |
| 6532 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6533 | * @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] | 6534 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6535 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6536 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6537 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6538 | if (mService != null) { |
| 6539 | try { |
| 6540 | return mService.isMasterVolumeMuted(admin); |
| 6541 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6542 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6543 | } |
| 6544 | } |
| 6545 | return false; |
| 6546 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6547 | |
| 6548 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6549 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6550 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6551 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6552 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6553 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6554 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6555 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6556 | * @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] | 6557 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6558 | * @see #setDelegatedScopes |
| 6559 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6560 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6561 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6562 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6563 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6564 | if (mService != null) { |
| 6565 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6566 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6567 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6568 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6569 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6570 | } |
| 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6575 | * 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] | 6576 | * 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] | 6577 | * <p> |
| 6578 | * <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] | 6579 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6580 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6581 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6582 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6583 | * @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] | 6584 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6585 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6586 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6587 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6588 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6589 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6590 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6591 | if (mService != null) { |
| 6592 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6593 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6594 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6595 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6596 | } |
| 6597 | } |
| 6598 | return false; |
| 6599 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6600 | |
| 6601 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6602 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6603 | * package to be available in the parent profile. As a result the user will be able to add |
| 6604 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6605 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6606 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6607 | * <p> |
| 6608 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6609 | * |
| 6610 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6611 | * @param packageName The package from which widget providers are white-listed. |
| 6612 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6613 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6614 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6615 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6616 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6617 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6618 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6619 | if (mService != null) { |
| 6620 | try { |
| 6621 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6622 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6623 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6624 | } |
| 6625 | } |
| 6626 | return false; |
| 6627 | } |
| 6628 | |
| 6629 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6630 | * 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] | 6631 | * package to be available in the parent profile. For this method to take effect the package |
| 6632 | * should have been added via |
| 6633 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6634 | * <p> |
| 6635 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6636 | * |
| 6637 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6638 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6639 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6640 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6641 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6642 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6643 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6644 | public boolean removeCrossProfileWidgetProvider( |
| 6645 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6646 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6647 | if (mService != null) { |
| 6648 | try { |
| 6649 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6650 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6651 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6652 | } |
| 6653 | } |
| 6654 | return false; |
| 6655 | } |
| 6656 | |
| 6657 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6658 | * 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] | 6659 | * available in the parent profile. |
| 6660 | * |
| 6661 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6662 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6663 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6664 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6665 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6666 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6667 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6668 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6669 | if (mService != null) { |
| 6670 | try { |
| 6671 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6672 | if (providers != null) { |
| 6673 | return providers; |
| 6674 | } |
| 6675 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6676 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6677 | } |
| 6678 | } |
| 6679 | return Collections.emptyList(); |
| 6680 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6681 | |
| 6682 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6683 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6684 | * |
| 6685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6686 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6687 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6688 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6689 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6690 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6691 | try { |
| 6692 | mService.setUserIcon(admin, icon); |
| 6693 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6694 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6695 | } |
| 6696 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6697 | |
| 6698 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6699 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6700 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6701 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6702 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6703 | * components in the device owner package can set system update policies and the most |
| 6704 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6705 | * @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] | 6706 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6707 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6708 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6709 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6710 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6711 | if (mService != null) { |
| 6712 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6713 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6714 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6715 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6716 | } |
| 6717 | } |
| 6718 | } |
| 6719 | |
| 6720 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6721 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6722 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6723 | * @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] | 6724 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6725 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6726 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6727 | if (mService != null) { |
| 6728 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6729 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6730 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6731 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6732 | } |
| 6733 | } |
| 6734 | return null; |
| 6735 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6736 | |
| 6737 | /** |
| 6738 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6739 | * <p> |
| 6740 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6741 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6742 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6743 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6744 | * |
| 6745 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6746 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6747 | * @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] | 6748 | * place. {@code true} otherwise. |
| 6749 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6750 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6751 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6752 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6753 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6754 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6755 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6756 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6757 | } |
| 6758 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6759 | |
| 6760 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6761 | * 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] | 6762 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6763 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6764 | * |
| 6765 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6766 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6767 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6768 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6769 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6770 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6771 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6772 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6773 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6774 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6775 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6776 | } |
| 6777 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6778 | |
| 6779 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6780 | * Called by the system update service to notify device and profile owners of pending system |
| 6781 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6782 | * |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6783 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6784 | * permission. This method should only be used when it is unknown whether the pending system |
| 6785 | * update is a security patch. Otherwise, use |
| 6786 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6787 | * |
| 6788 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6789 | * indicating when the current pending update was first available. {@code -1} if no |
| 6790 | * update is available. |
| 6791 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6792 | * @hide |
| 6793 | */ |
| 6794 | @SystemApi |
| 6795 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6796 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6797 | if (mService != null) { |
| 6798 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6799 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6800 | } catch (RemoteException re) { |
| 6801 | throw re.rethrowFromSystemServer(); |
| 6802 | } |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | /** |
| 6807 | * Called by the system update service to notify device and profile owners of pending system |
| 6808 | * updates. |
| 6809 | * |
| 6810 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6811 | * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
| 6812 | * when it is known whether the pending system update is a security patch. |
| 6813 | * |
| 6814 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6815 | * indicating when the current pending update was first available. {@code -1} if no |
| 6816 | * update is available. |
| 6817 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6818 | * {@code false} if not. |
| 6819 | * @see #notifyPendingSystemUpdate(long) |
| 6820 | * @hide |
| 6821 | */ |
| 6822 | @SystemApi |
| 6823 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6824 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6825 | if (mService != null) { |
| 6826 | try { |
| 6827 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6828 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6829 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6830 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6831 | } |
| 6832 | } |
| 6833 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6834 | |
| 6835 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6836 | * Called by device or profile owners to get information about a pending system update. |
| 6837 | * |
| 6838 | * @param admin Which profile or device owner this request is associated with. |
| 6839 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6840 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6841 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6842 | */ |
| 6843 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6844 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6845 | try { |
| 6846 | return mService.getPendingSystemUpdate(admin); |
| 6847 | } catch (RemoteException re) { |
| 6848 | throw re.rethrowFromSystemServer(); |
| 6849 | } |
| 6850 | } |
| 6851 | |
| 6852 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6853 | * Set the default response for future runtime permission requests by applications. This |
| 6854 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6855 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6856 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6857 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6858 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6859 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6860 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6861 | * <p/> |
| 6862 | * 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] | 6863 | * 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] | 6864 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6865 | * @param admin Which profile or device owner this request is associated with. |
| 6866 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6867 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6868 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6869 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6870 | * @see #setDelegatedScopes |
| 6871 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6872 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6873 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6874 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6875 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6876 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6877 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6878 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6879 | } |
| 6880 | } |
| 6881 | |
| 6882 | /** |
| 6883 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6884 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6885 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6886 | * @param admin Which profile or device owner this request is associated with. |
| 6887 | * @return the current policy for future permission requests. |
| 6888 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6889 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6890 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6891 | try { |
| 6892 | return mService.getPermissionPolicy(admin); |
| 6893 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6894 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6895 | } |
| 6896 | } |
| 6897 | |
| 6898 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6899 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6900 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6901 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6902 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6903 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6904 | * 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] | 6905 | * by a profile owner, device owner, or a delegate given the |
| 6906 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6907 | * <p/> |
| 6908 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6909 | * the permission. It retains the previous grant, if any. |
| 6910 | * <p/> |
| 6911 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6912 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6913 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6914 | * @param admin Which profile or device owner this request is associated with. |
| 6915 | * @param packageName The application to grant or revoke a permission to. |
| 6916 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6917 | * @param grantState The permission grant state which is one of |
| 6918 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6919 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6920 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6921 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6922 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6923 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6924 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6925 | * @see #setDelegatedScopes |
| 6926 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6927 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6928 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6929 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6930 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6931 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6932 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6933 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6934 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6935 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6936 | } |
| 6937 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6938 | |
| 6939 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6940 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6941 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6942 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6943 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6944 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6945 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6946 | * @param packageName The application to check the grant state for. |
| 6947 | * @param permission The permission to check for. |
| 6948 | * @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] | 6949 | * has not set a grant state, the return value is |
| 6950 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6951 | * permission is currently granted for the package. |
| 6952 | * <p/> |
| 6953 | * If a grant state was set by the profile or device owner, then the return value will |
| 6954 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6955 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6956 | * currently denied or granted. |
| 6957 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6958 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6959 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6960 | * @see #setDelegatedScopes |
| 6961 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6962 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 6963 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6964 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6965 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6966 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6967 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6968 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6969 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6970 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6971 | } |
| 6972 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6973 | |
| 6974 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6975 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 6976 | * or device, setting itself as the device or profile owner. |
| 6977 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6978 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6979 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6980 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6981 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6982 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6983 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6984 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6985 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6986 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6987 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6988 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6989 | } |
| 6990 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6991 | |
| 6992 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6993 | * Checks whether it is possible to initiate provisioning a managed device, |
| 6994 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6995 | * |
| 6996 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6997 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 6998 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 6999 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7000 | * @param packageName The package of the component that would be set as device, user, or profile |
| 7001 | * owner. |
| 7002 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7003 | * @hide |
| 7004 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7005 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 7006 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7007 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7008 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7009 | } catch (RemoteException re) { |
| 7010 | throw re.rethrowFromSystemServer(); |
| 7011 | } |
| 7012 | } |
| 7013 | |
| 7014 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7015 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 7016 | * 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] | 7017 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7018 | * @param admin Which profile owner this request is associated with. |
| 7019 | * @return if this user is a managed profile of another user. |
| 7020 | */ |
| 7021 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7022 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7023 | try { |
| 7024 | return mService.isManagedProfile(admin); |
| 7025 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7026 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7027 | } |
| 7028 | } |
| 7029 | |
| 7030 | /** |
| 7031 | * @hide |
| 7032 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 7033 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 7034 | * @param admin Which device owner this request is associated with. |
| 7035 | * @return if this user is a system-only user. |
| 7036 | */ |
| 7037 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 7038 | try { |
| 7039 | return mService.isSystemOnlyUser(admin); |
| 7040 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7041 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7042 | } |
| 7043 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7044 | |
| 7045 | /** |
| 7046 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 7047 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7048 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7049 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 7050 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 7051 | * <p> |
| 7052 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 7053 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7054 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7055 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7056 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7057 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7058 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7059 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7060 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7061 | } |
| 7062 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7063 | |
| 7064 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7065 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 7066 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7067 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7068 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7069 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7070 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7071 | */ |
| 7072 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7073 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7074 | try { |
| 7075 | mService.reboot(admin); |
| 7076 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7077 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7078 | } |
| 7079 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7080 | |
| 7081 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7082 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 7083 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 7084 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 7085 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 7086 | * truncated. |
| 7087 | * <p> |
| 7088 | * 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] | 7089 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7090 | * and set a new version of this string accordingly. |
| 7091 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7092 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7093 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7094 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 7095 | * existing message. |
| 7096 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7097 | */ |
| 7098 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7099 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7100 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7101 | if (mService != null) { |
| 7102 | try { |
| 7103 | mService.setShortSupportMessage(admin, message); |
| 7104 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7105 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7106 | } |
| 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * Called by a device admin to get the short support message. |
| 7112 | * |
| 7113 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7114 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 7115 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7116 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7117 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7118 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7119 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7120 | if (mService != null) { |
| 7121 | try { |
| 7122 | return mService.getShortSupportMessage(admin); |
| 7123 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7124 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7125 | } |
| 7126 | } |
| 7127 | return null; |
| 7128 | } |
| 7129 | |
| 7130 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7131 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 7132 | * in the device administators settings screen. |
| 7133 | * <p> |
| 7134 | * 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] | 7135 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7136 | * and set a new version of this string accordingly. |
| 7137 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7138 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7139 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7140 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 7141 | * existing message. |
| 7142 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7143 | */ |
| 7144 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7145 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7146 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7147 | if (mService != null) { |
| 7148 | try { |
| 7149 | mService.setLongSupportMessage(admin, message); |
| 7150 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7151 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7152 | } |
| 7153 | } |
| 7154 | } |
| 7155 | |
| 7156 | /** |
| 7157 | * Called by a device admin to get the long support message. |
| 7158 | * |
| 7159 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7160 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 7161 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7162 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7163 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7164 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7165 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7166 | if (mService != null) { |
| 7167 | try { |
| 7168 | return mService.getLongSupportMessage(admin); |
| 7169 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7170 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7171 | } |
| 7172 | } |
| 7173 | return null; |
| 7174 | } |
| 7175 | |
| 7176 | /** |
| 7177 | * Called by the system to get the short support message. |
| 7178 | * |
| 7179 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7180 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7181 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7182 | * |
| 7183 | * @hide |
| 7184 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7185 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7186 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7187 | if (mService != null) { |
| 7188 | try { |
| 7189 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 7190 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7191 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7192 | } |
| 7193 | } |
| 7194 | return null; |
| 7195 | } |
| 7196 | |
| 7197 | |
| 7198 | /** |
| 7199 | * Called by the system to get the long support message. |
| 7200 | * |
| 7201 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7202 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7203 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7204 | * |
| 7205 | * @hide |
| 7206 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7207 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 7208 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7209 | if (mService != null) { |
| 7210 | try { |
| 7211 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 7212 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7213 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7214 | } |
| 7215 | } |
| 7216 | return null; |
| 7217 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7218 | |
| 7219 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7220 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 7221 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7222 | * |
| 7223 | * <p>The following methods are supported for the parent instance, all other methods will |
| 7224 | * throw a SecurityException when called on the parent instance: |
| 7225 | * <ul> |
| 7226 | * <li>{@link #getPasswordQuality}</li> |
| 7227 | * <li>{@link #setPasswordQuality}</li> |
| 7228 | * <li>{@link #getPasswordMinimumLength}</li> |
| 7229 | * <li>{@link #setPasswordMinimumLength}</li> |
| 7230 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 7231 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 7232 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 7233 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 7234 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 7235 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 7236 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 7237 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 7238 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 7239 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 7240 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 7241 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 7242 | * <li>{@link #getPasswordHistoryLength}</li> |
| 7243 | * <li>{@link #setPasswordHistoryLength}</li> |
| 7244 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 7245 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 7246 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 7247 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7248 | * <li>{@link #isActivePasswordSufficient}</li> |
| 7249 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 7250 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 7251 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 7252 | * <li>{@link #getMaximumTimeToLock}</li> |
| 7253 | * <li>{@link #setMaximumTimeToLock}</li> |
| 7254 | * <li>{@link #lockNow}</li> |
| 7255 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 7256 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 7257 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 7258 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 7259 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7260 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7261 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7262 | * |
| 7263 | * @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] | 7264 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7265 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7266 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7267 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7268 | try { |
| 7269 | if (!mService.isManagedProfile(admin)) { |
| 7270 | throw new SecurityException("The current user does not have a parent profile."); |
| 7271 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7272 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7273 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7274 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7275 | } |
| 7276 | } |
| 7277 | |
| 7278 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7279 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7280 | * |
| 7281 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7282 | * See {@link SecurityEvent} for details. |
| 7283 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7284 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7285 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7286 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7287 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7288 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7289 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7290 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7291 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7292 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7293 | * @see #retrieveSecurityLogs |
| 7294 | */ |
| 7295 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7296 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7297 | try { |
| 7298 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7299 | } catch (RemoteException re) { |
| 7300 | throw re.rethrowFromSystemServer(); |
| 7301 | } |
| 7302 | } |
| 7303 | |
| 7304 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7305 | * Return whether security logging is enabled or not by the device owner. |
| 7306 | * |
| 7307 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7308 | * thrown. |
| 7309 | * |
| 7310 | * @param admin Which device owner this request is associated with. |
| 7311 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7312 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7313 | */ |
Bartosz Fabianowski | 0ec0000 | 2017-03-24 14:22:24 +0100 | [diff] [blame] | 7314 | public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7315 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7316 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7317 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7318 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7319 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7324 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7325 | * this API after device boots. |
| 7326 | * |
| 7327 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7328 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7329 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7330 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7331 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7332 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7333 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7334 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7335 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7336 | * 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] | 7337 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7338 | * profile or secondary user that is not affiliated with the device owner user. |
| 7339 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7340 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7341 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7342 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7343 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7344 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7345 | if (list != null) { |
| 7346 | return list.getList(); |
| 7347 | } else { |
| 7348 | // Rate limit exceeded. |
| 7349 | return null; |
| 7350 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7351 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7352 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7353 | } |
| 7354 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7355 | |
| 7356 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7357 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7358 | * profile. |
| 7359 | * |
| 7360 | * @hide |
| 7361 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7362 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7363 | mContext.checkSelfPermission( |
| 7364 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7365 | if (!uInfo.isManagedProfile()) { |
| 7366 | throw new SecurityException("The user " + uInfo.id |
| 7367 | + " does not have a parent profile."); |
| 7368 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7369 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7370 | } |
| 7371 | |
| 7372 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7373 | * 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] | 7374 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7375 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7376 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7377 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7378 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7379 | * |
| 7380 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7381 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7382 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7383 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7384 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7385 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7386 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7387 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7388 | * profile or secondary user that is not affiliated with the device owner user. |
| 7389 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7390 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7391 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7392 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7393 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7394 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7395 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7396 | if (list != null) { |
| 7397 | return list.getList(); |
| 7398 | } else { |
| 7399 | return null; |
| 7400 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7401 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7402 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7403 | } |
| 7404 | } |
| 7405 | |
| 7406 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7407 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7408 | * 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] | 7409 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7410 | * <p> |
| 7411 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7412 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7413 | * |
| 7414 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7415 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7416 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7417 | */ |
| 7418 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7419 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7420 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7421 | // always enforce alpha channel to have 100% opacity |
| 7422 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7423 | mService.setOrganizationColor(admin, color); |
| 7424 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7425 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7430 | * @hide |
| 7431 | * |
| 7432 | * Sets the color used for customization. |
| 7433 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7434 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7435 | * @param userId which user to set the color to. |
| 7436 | * @RequiresPermission(allOf = { |
| 7437 | * Manifest.permission.MANAGE_USERS, |
| 7438 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7439 | */ |
| 7440 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7441 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7442 | // always enforce alpha channel to have 100% opacity |
| 7443 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7444 | mService.setOrganizationColorForUser(color, userId); |
| 7445 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7446 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7447 | } |
| 7448 | } |
| 7449 | |
| 7450 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7451 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7452 | * This color is used as background color of the confirm credentials screen for that user. |
| 7453 | * |
| 7454 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7455 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7456 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7457 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7458 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7459 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7460 | try { |
| 7461 | return mService.getOrganizationColor(admin); |
| 7462 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7463 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7464 | } |
| 7465 | } |
| 7466 | |
| 7467 | /** |
| 7468 | * @hide |
| 7469 | * Retrieve the customization color for a given user. |
| 7470 | * |
| 7471 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7472 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7473 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7474 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7475 | try { |
| 7476 | return mService.getOrganizationColorForUser(userHandle); |
| 7477 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7478 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7479 | } |
| 7480 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7481 | |
| 7482 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7483 | * 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] | 7484 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7485 | * <p> |
| 7486 | * 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] | 7487 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7488 | * and set a new version of this string accordingly. |
| 7489 | * |
| 7490 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7491 | * @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] | 7492 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7493 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7494 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7495 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7496 | try { |
| 7497 | mService.setOrganizationName(admin, title); |
| 7498 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7499 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7500 | } |
| 7501 | } |
| 7502 | |
| 7503 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7504 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7505 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7506 | * |
| 7507 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7508 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7509 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7510 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7511 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7512 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7513 | try { |
| 7514 | return mService.getOrganizationName(admin); |
| 7515 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7516 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7517 | } |
| 7518 | } |
| 7519 | |
| 7520 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7521 | * Called by the system to retrieve the name of the organization managing the device. |
| 7522 | * |
| 7523 | * @return The organization name or {@code null} if none is set. |
| 7524 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7525 | * MANAGE_USERS permission and is not the system. |
| 7526 | * |
| 7527 | * @hide |
| 7528 | */ |
| 7529 | @SystemApi |
| 7530 | @TestApi |
| 7531 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7532 | try { |
| 7533 | return mService.getDeviceOwnerOrganizationName(); |
| 7534 | } catch (RemoteException re) { |
| 7535 | throw re.rethrowFromSystemServer(); |
| 7536 | } |
| 7537 | } |
| 7538 | |
| 7539 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7540 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7541 | * |
| 7542 | * @param userHandle The user id of the user we're interested in. |
| 7543 | * @return The organization name or {@code null} if none is set. |
| 7544 | * |
| 7545 | * @hide |
| 7546 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7547 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7548 | try { |
| 7549 | return mService.getOrganizationNameForUser(userHandle); |
| 7550 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7551 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7552 | } |
| 7553 | } |
| 7554 | |
| 7555 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7556 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7557 | * return {@link #STATE_USER_UNMANAGED} |
| 7558 | * @hide |
| 7559 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7560 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7561 | @UserProvisioningState |
| 7562 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7563 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7564 | if (mService != null) { |
| 7565 | try { |
| 7566 | return mService.getUserProvisioningState(); |
| 7567 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7568 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7569 | } |
| 7570 | } |
| 7571 | return STATE_USER_UNMANAGED; |
| 7572 | } |
| 7573 | |
| 7574 | /** |
| 7575 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7576 | * |
| 7577 | * @param state to store |
| 7578 | * @param userHandle for user |
| 7579 | * @hide |
| 7580 | */ |
| 7581 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7582 | if (mService != null) { |
| 7583 | try { |
| 7584 | mService.setUserProvisioningState(state, userHandle); |
| 7585 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7586 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7587 | } |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7592 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7593 | * 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] | 7594 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7595 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7596 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7597 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7598 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7599 | * created. |
| 7600 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7601 | * @param admin Which profile or device owner this request is associated with. |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7602 | * @param ids A set of opaque non-empty affiliation ids. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7603 | * |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7604 | * @throws IllegalArgumentException if {@code ids} is null or contains an empty string. |
| 7605 | */ |
| 7606 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) { |
| 7607 | throwIfParentInstance("setAffiliationIds"); |
| 7608 | if (ids == null) { |
| 7609 | throw new IllegalArgumentException("ids must not be null"); |
| 7610 | } |
| 7611 | try { |
| 7612 | mService.setAffiliationIds(admin, new ArrayList<>(ids)); |
| 7613 | } catch (RemoteException e) { |
| 7614 | throw e.rethrowFromSystemServer(); |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | /** |
| 7619 | * STOPSHIP (b/37622682) Remove it before release. |
| 7620 | * @removed |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7621 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7622 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7623 | throwIfParentInstance("setAffiliationIds"); |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7624 | if (ids == null) { |
| 7625 | throw new IllegalArgumentException("ids must not be null"); |
| 7626 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7627 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7628 | mService.setAffiliationIds(admin, ids); |
| 7629 | } catch (RemoteException e) { |
| 7630 | throw e.rethrowFromSystemServer(); |
| 7631 | } |
| 7632 | } |
| 7633 | |
| 7634 | /** |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7635 | * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7636 | * empty set if none have been set. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7637 | */ |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7638 | public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) { |
Tony Mak | 62cf586 | 2017-05-02 13:50:18 +0100 | [diff] [blame^] | 7639 | throwIfParentInstance("getAffiliationIds"); |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7640 | try { |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7641 | return new ArraySet<>(mService.getAffiliationIds(admin)); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7642 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7643 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7644 | } |
| 7645 | } |
| 7646 | |
| 7647 | /** |
| 7648 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7649 | * Returns whether this user/profile is affiliated with the device. |
| 7650 | * <p> |
| 7651 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7652 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7653 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7654 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7655 | */ |
| 7656 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7657 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7658 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7659 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7660 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7661 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7662 | } |
| 7663 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7664 | |
| 7665 | /** |
| 7666 | * @hide |
| 7667 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7668 | * to be started |
| 7669 | * @param packageName the package to check for |
| 7670 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7671 | */ |
| 7672 | public boolean isUninstallInQueue(String packageName) { |
| 7673 | try { |
| 7674 | return mService.isUninstallInQueue(packageName); |
| 7675 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7676 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7677 | } |
| 7678 | } |
| 7679 | |
| 7680 | /** |
| 7681 | * @hide |
| 7682 | * @param packageName the package containing active DAs to be uninstalled |
| 7683 | */ |
| 7684 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7685 | try { |
| 7686 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7687 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7688 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7689 | } |
| 7690 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7691 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7692 | /** |
| 7693 | * @hide |
| 7694 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7695 | * If the admin is a profile owner or device owner it will still be removed. |
| 7696 | * |
| 7697 | * @param userHandle user id to remove the admin for. |
| 7698 | * @param admin The administration compononent to remove. |
| 7699 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7700 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7701 | */ |
| 7702 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7703 | try { |
| 7704 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7705 | } catch (RemoteException re) { |
| 7706 | throw re.rethrowFromSystemServer(); |
| 7707 | } |
| 7708 | } |
| 7709 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7710 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7711 | * Returns whether the device has been provisioned. |
| 7712 | * |
| 7713 | * <p>Not for use by third-party applications. |
| 7714 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7715 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7716 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7717 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7718 | public boolean isDeviceProvisioned() { |
| 7719 | try { |
| 7720 | return mService.isDeviceProvisioned(); |
| 7721 | } catch (RemoteException re) { |
| 7722 | throw re.rethrowFromSystemServer(); |
| 7723 | } |
| 7724 | } |
| 7725 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7726 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7727 | * Writes that the provisioning configuration has been applied. |
| 7728 | * |
| 7729 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7730 | * permission. |
| 7731 | * |
| 7732 | * <p>Not for use by third-party applications. |
| 7733 | * |
| 7734 | * @hide |
| 7735 | */ |
| 7736 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7737 | public void setDeviceProvisioningConfigApplied() { |
| 7738 | try { |
| 7739 | mService.setDeviceProvisioningConfigApplied(); |
| 7740 | } catch (RemoteException re) { |
| 7741 | throw re.rethrowFromSystemServer(); |
| 7742 | } |
| 7743 | } |
| 7744 | |
| 7745 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7746 | * Returns whether the provisioning configuration has been applied. |
| 7747 | * |
| 7748 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7749 | * |
| 7750 | * <p>Not for use by third-party applications. |
| 7751 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7752 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7753 | * |
| 7754 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7755 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7756 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7757 | public boolean isDeviceProvisioningConfigApplied() { |
| 7758 | try { |
| 7759 | return mService.isDeviceProvisioningConfigApplied(); |
| 7760 | } catch (RemoteException re) { |
| 7761 | throw re.rethrowFromSystemServer(); |
| 7762 | } |
| 7763 | } |
| 7764 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7765 | /** |
| 7766 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7767 | * Force update user setup completed status. This API has no effect on user build. |
| 7768 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7769 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7770 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7771 | */ |
| 7772 | public void forceUpdateUserSetupComplete() { |
| 7773 | try { |
| 7774 | mService.forceUpdateUserSetupComplete(); |
| 7775 | } catch (RemoteException re) { |
| 7776 | throw re.rethrowFromSystemServer(); |
| 7777 | } |
| 7778 | } |
| 7779 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7780 | private void throwIfParentInstance(String functionName) { |
| 7781 | if (mParentInstance) { |
| 7782 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7783 | } |
| 7784 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7785 | |
| 7786 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7787 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7788 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7789 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7790 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7791 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7792 | * <p> Backup service is off by default when device owner is present. |
| 7793 | * |
Rubin Xu | 0367f07 | 2017-04-24 20:17:16 +0100 | [diff] [blame] | 7794 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7795 | * @param enabled {@code true} to enable the backup service, {@code false} to disable it. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7796 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7797 | */ |
| 7798 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7799 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7800 | try { |
| 7801 | mService.setBackupServiceEnabled(admin, enabled); |
| 7802 | } catch (RemoteException re) { |
| 7803 | throw re.rethrowFromSystemServer(); |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7808 | * Return whether the backup service is enabled by the device owner. |
| 7809 | * |
| 7810 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7811 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7812 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7813 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7814 | */ |
| 7815 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7816 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7817 | try { |
| 7818 | return mService.isBackupServiceEnabled(admin); |
| 7819 | } catch (RemoteException re) { |
| 7820 | throw re.rethrowFromSystemServer(); |
| 7821 | } |
| 7822 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7823 | |
| 7824 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7825 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7826 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 7827 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 7828 | * functions are recorded while network logging is active: |
| 7829 | * <ul> |
| 7830 | * <li>{@code getaddrinfo()}</li> |
| 7831 | * <li>{@code gethostbyname()}</li> |
| 7832 | * <li>{@code connect()}</li> |
| 7833 | * </ul> |
| 7834 | * |
| 7835 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 7836 | * full system call logging; event reporting is enabled by default for all processes but not |
| 7837 | * strongly enforced. |
| 7838 | * Events from applications using alternative implementations of libc, making direct kernel |
| 7839 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 7840 | * |
| 7841 | * <p> Some common network events may not be reported. For example: |
| 7842 | * <ul> |
| 7843 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 7844 | * an alternative system for name resolution, and so avoid calling |
| 7845 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 7846 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 7847 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 7848 | * socket, so it will not trigger a network event.</li> |
| 7849 | * </ul> |
| 7850 | * |
| 7851 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 7852 | * always-on VPN service. |
| 7853 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 7854 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7855 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7856 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7857 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7858 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7859 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7860 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7861 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7862 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7863 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7864 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7865 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7866 | */ |
| 7867 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7868 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7869 | try { |
| 7870 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7871 | } catch (RemoteException re) { |
| 7872 | throw re.rethrowFromSystemServer(); |
| 7873 | } |
| 7874 | } |
| 7875 | |
| 7876 | /** |
| 7877 | * Return whether network logging is enabled by a device owner. |
| 7878 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7879 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7880 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7881 | * @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] | 7882 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7883 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7884 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7885 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7886 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7887 | try { |
| 7888 | return mService.isNetworkLoggingEnabled(admin); |
| 7889 | } catch (RemoteException re) { |
| 7890 | throw re.rethrowFromSystemServer(); |
| 7891 | } |
| 7892 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7893 | |
| 7894 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7895 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7896 | * A device owner has to provide a batchToken provided as part of |
| 7897 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7898 | * 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] | 7899 | * |
| 7900 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7901 | * |
| 7902 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7903 | * |
| 7904 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7905 | * after the device device owner has been notified via |
| 7906 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7907 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7908 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7909 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7910 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7911 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7912 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7913 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7914 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7915 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7916 | * @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] | 7917 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7918 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7919 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7920 | * 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] | 7921 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7922 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7923 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7924 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7925 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7926 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7927 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7928 | } catch (RemoteException re) { |
| 7929 | throw re.rethrowFromSystemServer(); |
| 7930 | } |
| 7931 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7932 | |
| 7933 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7934 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 7935 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7936 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7937 | * <p> |
Tony Mak | eda0a9a | 2017-04-25 12:07:14 +0100 | [diff] [blame] | 7938 | * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
| 7939 | * Note that the {@link Context} used to obtain this |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7940 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7941 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7942 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7943 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7944 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7945 | * explicit component name or a package name to match an |
| 7946 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7947 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7948 | * 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] | 7949 | * @param flags Operation options for the binding operation. See |
| 7950 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7951 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7952 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7953 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7954 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7955 | * {@code false} is returned if the connection is not made and you will not |
| 7956 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7957 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7958 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7959 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7960 | */ |
| 7961 | public boolean bindDeviceAdminServiceAsUser( |
| 7962 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7963 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7964 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7965 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7966 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7967 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7968 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7969 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7970 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7971 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7972 | sd, flags, targetUser.getIdentifier()); |
| 7973 | } catch (RemoteException re) { |
| 7974 | throw re.rethrowFromSystemServer(); |
| 7975 | } |
| 7976 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7977 | |
| 7978 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7979 | * Returns the list of target users that the calling device or profile owner can use when |
| 7980 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7981 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7982 | * 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] | 7983 | * <ul> |
| 7984 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7985 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7986 | * </ul> |
| 7987 | */ |
| 7988 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7989 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7990 | try { |
| 7991 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7992 | } catch (RemoteException re) { |
| 7993 | throw re.rethrowFromSystemServer(); |
| 7994 | } |
| 7995 | } |
| 7996 | |
| 7997 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7998 | * Called by the system to get the time at which the device owner last retrieved security |
| 7999 | * logging entries. |
| 8000 | * |
| 8001 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 8002 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8003 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8004 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8005 | * |
| 8006 | * @hide |
| 8007 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8008 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8009 | public long getLastSecurityLogRetrievalTime() { |
| 8010 | try { |
| 8011 | return mService.getLastSecurityLogRetrievalTime(); |
| 8012 | } catch (RemoteException re) { |
| 8013 | throw re.rethrowFromSystemServer(); |
| 8014 | } |
| 8015 | } |
| 8016 | |
| 8017 | /** |
| 8018 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 8019 | * |
| 8020 | * @return the time at which the device owner most recently requested a bug report, in |
| 8021 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8022 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8023 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8024 | * |
| 8025 | * @hide |
| 8026 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8027 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8028 | public long getLastBugReportRequestTime() { |
| 8029 | try { |
| 8030 | return mService.getLastBugReportRequestTime(); |
| 8031 | } catch (RemoteException re) { |
| 8032 | throw re.rethrowFromSystemServer(); |
| 8033 | } |
| 8034 | } |
| 8035 | |
| 8036 | /** |
| 8037 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 8038 | * events. |
| 8039 | * |
| 8040 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 8041 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8042 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8043 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8044 | * |
| 8045 | * @hide |
| 8046 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8047 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8048 | public long getLastNetworkLogRetrievalTime() { |
| 8049 | try { |
| 8050 | return mService.getLastNetworkLogRetrievalTime(); |
| 8051 | } catch (RemoteException re) { |
| 8052 | throw re.rethrowFromSystemServer(); |
| 8053 | } |
| 8054 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8055 | |
| 8056 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8057 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 8058 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8059 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8060 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 8061 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8062 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8063 | * |
| 8064 | * @hide |
| 8065 | */ |
| 8066 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8067 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8068 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8069 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8070 | } catch (RemoteException re) { |
| 8071 | throw re.rethrowFromSystemServer(); |
| 8072 | } |
| 8073 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8074 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8075 | /** |
| 8076 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 8077 | * profile owner. |
| 8078 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8079 | * <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] | 8080 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 8081 | * |
| 8082 | * @param user The user for whom to retrieve information. |
| 8083 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 8084 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 8085 | * about the given user's CA certificates. |
| 8086 | * |
| 8087 | * @hide |
| 8088 | */ |
| 8089 | @TestApi |
| 8090 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 8091 | try { |
| 8092 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 8093 | } catch (RemoteException re) { |
| 8094 | throw re.rethrowFromSystemServer(); |
| 8095 | } |
| 8096 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 8097 | } |