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; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
| 25 | import android.annotation.SdkConstant.SdkConstantType; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 26 | import android.annotation.SuppressLint; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 27 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 28 | import android.annotation.SystemService; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 29 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 30 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 31 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 32 | import android.app.Activity; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 33 | import android.app.IServiceConnection; |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 34 | import android.app.KeyguardManager; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 35 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 36 | import android.content.ComponentName; |
| 37 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 38 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 39 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 40 | import android.content.ServiceConnection; |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 41 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 42 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 43 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 44 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 45 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 46 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 47 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 48 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 49 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 50 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 51 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 52 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 53 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 54 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 56 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 57 | import android.provider.ContactsContract.Directory; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 58 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 59 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 60 | import android.telephony.TelephonyManager; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 61 | import android.util.ArraySet; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | import android.util.Log; |
| 63 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 64 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 65 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 66 | |
| 67 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 68 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 69 | import java.lang.annotation.Retention; |
| 70 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 71 | import java.net.InetSocketAddress; |
| 72 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 73 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 74 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 75 | import java.security.PrivateKey; |
| 76 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 77 | import java.security.cert.CertificateException; |
| 78 | import java.security.cert.CertificateFactory; |
| 79 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 80 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 81 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 82 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 83 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 84 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 85 | import java.util.List; |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 86 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 89 | * 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] | 90 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 91 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 92 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 93 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 94 | * application calling an api may only pass as an argument a device administrator component it |
| 95 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 96 | * <div class="special reference"> |
| 97 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 98 | * <p> |
| 99 | * For more information about managing policies for device administration, read the <a href= |
| 100 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 101 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 102 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 103 | @SystemService(Context.DEVICE_POLICY_SERVICE) |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 104 | public class DevicePolicyManager { |
| 105 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 106 | |
| 107 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 108 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 109 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 110 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 111 | /** @hide */ |
| 112 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 113 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 116 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 118 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 119 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | mContext = context; |
| 121 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 122 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 125 | /** @hide test will override it. */ |
| 126 | @VisibleForTesting |
| 127 | protected int myUserId() { |
| 128 | return UserHandle.myUserId(); |
| 129 | } |
| 130 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 131 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 132 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 134 | * <p>A managed profile allows data separation for example for the usage of a |
| 135 | * device as a personal and corporate device. The user which provisioning is started from and |
| 136 | * the managed profile share a launcher. |
| 137 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 138 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 139 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 140 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 141 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 142 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 143 | * {@link #isProvisioningAllowed(String)}. |
| 144 | * |
| 145 | * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 146 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 147 | * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 148 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 149 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 150 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 151 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 152 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 153 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 154 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 155 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 156 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 157 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 158 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 159 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 160 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 161 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 162 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 163 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 164 | * <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] | 165 | * in the provisioning intent. The |
| 166 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 167 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 168 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 169 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 170 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 171 | * completed, along with the above broadcast, activity intent |
Esteban Talavera | 4047bae | 2017-06-28 11:03:09 +0100 | [diff] [blame] | 172 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner. |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 173 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 174 | * <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] | 175 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 176 | * |
| 177 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 178 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 179 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 180 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 181 | * 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] | 182 | */ |
| 183 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 184 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 185 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 186 | |
| 187 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 188 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 189 | * |
| 190 | * <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] | 191 | * 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] | 192 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 193 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 194 | * allowed. |
| 195 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 196 | * <p>The intent contains the following extras: |
| 197 | * <ul> |
| 198 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 199 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 200 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 201 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 202 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 203 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 204 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 205 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 206 | * |
| 207 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 208 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 209 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 210 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 211 | * 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] | 212 | * |
| 213 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 214 | */ |
| 215 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 216 | public static final String ACTION_PROVISION_MANAGED_USER |
| 217 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 218 | |
| 219 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 220 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 221 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 222 | * |
| 223 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 224 | * A device owner has full control over the device. The device owner can not be modified by the |
| 225 | * user. |
| 226 | * |
| 227 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 228 | * employee or client. |
| 229 | * |
| 230 | * <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] | 231 | * It is possible to check if provisioning is allowed or not by querying the method |
| 232 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 233 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 234 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 235 | * <ul> |
| 236 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 237 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 238 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 239 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 240 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 241 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 242 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 243 | * </ul> |
| 244 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 245 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 246 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 247 | * device owner. |
| 248 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 249 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 250 | * completed, along with the above broadcast, activity intent |
| 251 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 252 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 253 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 254 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 255 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 256 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 257 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 258 | * 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] | 259 | */ |
| 260 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 261 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 262 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 263 | |
| 264 | /** |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 265 | * Activity action: launch when user provisioning completed, i.e. |
| 266 | * {@link #getUserProvisioningState()} returns one of the complete state. |
| 267 | * |
| 268 | * <p> Please note that the API behavior is not necessarily consistent across various releases, |
| 269 | * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default |
| 270 | * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only. |
| 271 | * |
| 272 | * <p> The activity must be protected by permission |
| 273 | * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold |
| 274 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched. |
| 275 | * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the |
| 276 | * components are not started by this intent. |
| 277 | * @hide |
| 278 | */ |
| 279 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
Jeff Sharkey | 9039636 | 2017-06-12 16:26:53 -0600 | [diff] [blame] | 280 | @SystemApi |
Victor Chang | 1880009 | 2017-04-11 19:41:43 +0100 | [diff] [blame] | 281 | public static final String ACTION_STATE_USER_SETUP_COMPLETE = |
| 282 | "android.app.action.STATE_USER_SETUP_COMPLETE"; |
| 283 | |
| 284 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 285 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 286 | * |
| 287 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 288 | * the device. A device owner has full control over the device. The device owner can not be |
| 289 | * modified by the user and the only way of resetting the device is via factory reset. |
| 290 | * |
| 291 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 292 | * employee or client. |
| 293 | * |
| 294 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 295 | * |
| 296 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 297 | * by a privileged app with the permission |
| 298 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 299 | * |
| 300 | * <p>The provisioning intent contains the following properties: |
| 301 | * <ul> |
| 302 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 303 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 304 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 305 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 306 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 307 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 308 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 309 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 314 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 315 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 317 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 318 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 319 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 320 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 321 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 322 | * |
| 323 | * @hide |
| 324 | */ |
| 325 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 326 | @SystemApi |
| 327 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 328 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 329 | |
| 330 | /** |
| 331 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 332 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 333 | * |
| 334 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 335 | * management state that is distinct from that reached by |
| 336 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 337 | * user, and only has control over device-wide policies, not individual users and their data. |
| 338 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 339 | * this form of device management. |
| 340 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 341 | * <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] | 342 | * A device owner has full control over the device. The device owner can not be modified by the |
| 343 | * user. |
| 344 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 345 | * <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] | 346 | * employee or client. |
| 347 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 348 | * <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] | 349 | * It is possible to check if provisioning is allowed or not by querying the method |
| 350 | * {@link #isProvisioningAllowed(String)}. |
| 351 | * |
| 352 | * <p>The intent contains the following extras: |
| 353 | * <ul> |
| 354 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 355 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 356 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 357 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 358 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 359 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 360 | * </ul> |
| 361 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 362 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 363 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 364 | * device owner. |
| 365 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 366 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 367 | * completed, along with the above broadcast, activity intent |
| 368 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 369 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 370 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 371 | * |
| 372 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 373 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 374 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 375 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 376 | * |
| 377 | * @hide |
| 378 | */ |
| 379 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 380 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 381 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 382 | |
| 383 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 384 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 385 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 386 | * <ul> |
| 387 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 388 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 389 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 390 | * </ul> |
| 391 | * |
| 392 | * @hide |
| 393 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 394 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 395 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 396 | public static final String ACTION_PROVISION_FINALIZATION |
| 397 | = "android.app.action.PROVISION_FINALIZATION"; |
| 398 | |
| 399 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 400 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 401 | * |
| 402 | * @hide |
| 403 | */ |
| 404 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 405 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 406 | |
| 407 | /** |
| 408 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 409 | * |
| 410 | * @hide |
| 411 | */ |
| 412 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
Rubin Xu | 7226c7d | 2017-02-06 17:18:50 +0000 | [diff] [blame] | 413 | "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED"; |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 414 | |
| 415 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 416 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 417 | * |
| 418 | * @hide |
| 419 | */ |
| 420 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 421 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 422 | |
| 423 | /** |
| 424 | * Extra for shared bugreport's SHA-256 hash. |
| 425 | * |
| 426 | * @hide |
| 427 | */ |
| 428 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 429 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 430 | |
| 431 | /** |
| 432 | * Extra for remote bugreport notification shown type. |
| 433 | * |
| 434 | * @hide |
| 435 | */ |
| 436 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 437 | "android.app.extra.bugreport_notification_type"; |
| 438 | |
| 439 | /** |
| 440 | * Notification type for a started remote bugreport flow. |
| 441 | * |
| 442 | * @hide |
| 443 | */ |
| 444 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 445 | |
| 446 | /** |
| 447 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 448 | * being taken. |
| 449 | * |
| 450 | * @hide |
| 451 | */ |
| 452 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 453 | |
| 454 | /** |
| 455 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 456 | * |
| 457 | * @hide |
| 458 | */ |
| 459 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 460 | |
| 461 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 462 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 463 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 464 | * |
| 465 | * @hide |
| 466 | */ |
| 467 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 468 | |
| 469 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 470 | * 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] | 471 | * allows a mobile device management application or NFC programmer application which starts |
| 472 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 473 | * <p> |
| 474 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 475 | * sends the intent to pass data to itself on the newly created profile. |
| 476 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 477 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 478 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 479 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 480 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 481 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 482 | * management application after provisioning. |
| 483 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 484 | * <p> |
| 485 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 486 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 487 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 488 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 489 | */ |
| 490 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 491 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 492 | |
| 493 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 494 | * A String extra holding the package name of the mobile device management application that |
| 495 | * will be set as the profile owner or device owner. |
| 496 | * |
| 497 | * <p>If an application starts provisioning directly via an intent with action |
| 498 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 499 | * application that started provisioning. The package will be set as profile owner in that case. |
| 500 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 501 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 502 | * 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] | 503 | * |
| 504 | * <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] | 505 | * 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] | 506 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 507 | * @see DeviceAdminReceiver |
| 508 | * @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] | 509 | * supported, but only if there is only one device admin receiver in the package that requires |
| 510 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 511 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 512 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 513 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 514 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 515 | |
| 516 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 517 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 518 | * application that will be set as the profile owner or device owner and active admin. |
| 519 | * |
| 520 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 521 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 522 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 523 | * 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] | 524 | * |
| 525 | * <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] | 526 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 527 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 528 | * {@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] | 529 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 530 | * |
| 531 | * @see DeviceAdminReceiver |
| 532 | */ |
| 533 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 534 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 535 | |
| 536 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 537 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 538 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 539 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 540 | * |
| 541 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 542 | */ |
| 543 | |
| 544 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 545 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 546 | |
| 547 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 548 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 549 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 550 | * the account will not be removed from the primary user after it is migrated to the newly |
| 551 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 552 | * |
| 553 | * <p> Defaults to {@code false} |
| 554 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 555 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 556 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 557 | */ |
| 558 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 559 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 560 | |
| 561 | /** |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 562 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the |
| 563 | * device. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 564 | */ |
Mahaver | 761ce77 | 2017-03-13 16:40:45 +0000 | [diff] [blame] | 565 | @Deprecated |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 566 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 567 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 568 | |
| 569 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 570 | * A integer extra indicating the predominant color to show during the provisioning. |
| 571 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 572 | * |
| 573 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 574 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 575 | */ |
| 576 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 577 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 578 | |
| 579 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 580 | * 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] | 581 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 582 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 583 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 584 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 585 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 586 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 587 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 588 | |
| 589 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 590 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 591 | * will be set to. |
| 592 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 593 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 594 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 595 | */ |
| 596 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 597 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 598 | |
| 599 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 600 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 601 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 603 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 604 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 605 | */ |
| 606 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 607 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 608 | |
| 609 | /** |
| 610 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 611 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 612 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 613 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 614 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 615 | */ |
| 616 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 617 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 618 | |
| 619 | /** |
| 620 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 621 | * owner provisioning for downloading the mobile device management application. |
| 622 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 623 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 624 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 625 | */ |
| 626 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 627 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 628 | |
| 629 | /** |
| 630 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 631 | * is hidden or not. |
| 632 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 633 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 634 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 635 | */ |
| 636 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 637 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 638 | |
| 639 | /** |
| 640 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 641 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 642 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 644 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 645 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 646 | */ |
| 647 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 648 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 649 | |
| 650 | /** |
| 651 | * A String extra holding the password of the wifi network in |
| 652 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 653 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 654 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 655 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 656 | */ |
| 657 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 658 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 659 | |
| 660 | /** |
| 661 | * A String extra holding the proxy host for the wifi network in |
| 662 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 663 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 664 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 665 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 666 | */ |
| 667 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 668 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * An int extra holding the proxy port for the wifi network in |
| 672 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 673 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 674 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 675 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 676 | */ |
| 677 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 678 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 679 | |
| 680 | /** |
| 681 | * A String extra holding the proxy bypass for the wifi network in |
| 682 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 683 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 684 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 685 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 686 | */ |
| 687 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 688 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 689 | |
| 690 | /** |
| 691 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 692 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 693 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 694 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 695 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 696 | */ |
| 697 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 698 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 699 | |
| 700 | /** |
| 701 | * A String extra holding a url that specifies the download location of the device admin |
| 702 | * package. When not provided it is assumed that the device admin package is already installed. |
| 703 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 704 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 705 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 706 | */ |
| 707 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 708 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 709 | |
| 710 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 711 | * A String extra holding the localized name of the organization under management. |
| 712 | * |
| 713 | * The name is displayed only during provisioning. |
| 714 | * |
| 715 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 716 | * |
| 717 | * @hide |
| 718 | */ |
| 719 | @SystemApi |
| 720 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 721 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 722 | |
| 723 | /** |
Alejandro Fernández | bfd6193 | 2017-04-04 19:33:01 +0100 | [diff] [blame] | 724 | * A String extra holding a url to the website of the device provider so the user can open it |
| 725 | * 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] | 726 | * |
| 727 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 728 | * |
| 729 | * @hide |
| 730 | */ |
| 731 | @SystemApi |
| 732 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 733 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 734 | |
| 735 | /** |
| 736 | * A String extra holding the localized name of the device admin package. It should be the same |
| 737 | * as the app label of the package. |
| 738 | * |
| 739 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 740 | * |
| 741 | * @hide |
| 742 | */ |
| 743 | @SystemApi |
| 744 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 745 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 746 | |
| 747 | /** |
| 748 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 749 | * shown during the provisioning. |
| 750 | * <h5>The following URI schemes are accepted:</h5> |
| 751 | * <ul> |
| 752 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 753 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 754 | * </ul> |
| 755 | * |
| 756 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 757 | * pixel density for the device. |
| 758 | * |
| 759 | * <p> If a content: URI is passed, the intent should have the flag |
| 760 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 761 | * {@link android.content.ClipData} of the intent too. |
| 762 | * |
| 763 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 764 | * |
| 765 | * @hide |
| 766 | */ |
| 767 | @SystemApi |
| 768 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 769 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 770 | |
| 771 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 772 | * An int extra holding a minimum required version code for the device admin package. If the |
| 773 | * device admin is already installed on the device, it will only be re-downloaded from |
| 774 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 775 | * installed package is less than this version code. |
| 776 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 777 | * <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] | 778 | * provisioning via an NFC bump. |
| 779 | */ |
| 780 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 781 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 782 | |
| 783 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 784 | * A String extra holding a http cookie header which should be used in the http request to the |
| 785 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 786 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 787 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 788 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 789 | */ |
| 790 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 791 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 792 | |
| 793 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 794 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 795 | * the file at download location specified in |
| 796 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 797 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 798 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 799 | * 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] | 800 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 801 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 802 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 803 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 804 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 805 | * |
| 806 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 807 | * 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] | 808 | * 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] | 809 | * 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] | 810 | */ |
| 811 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 812 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 813 | |
| 814 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 815 | * 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] | 816 | * android package archive at the download location specified in {@link |
| 817 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 818 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 819 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 820 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 821 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 822 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 823 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 824 | * 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] | 825 | * the download location. If the checksum does not match an error will be shown to the user and |
| 826 | * the user will be asked to factory reset the device. |
| 827 | * |
| 828 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 829 | * provisioning via an NFC bump. |
| 830 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 831 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 832 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 833 | |
| 834 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 835 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 836 | * has completed successfully. |
| 837 | * |
| 838 | * <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] | 839 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 840 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 841 | * <p>This intent will contain the following extras |
| 842 | * <ul> |
| 843 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 844 | * profile.</li> |
| 845 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 846 | * be migrated at provisioning time, if any.</li> |
| 847 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 848 | */ |
| 849 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 850 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 851 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 852 | |
| 853 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 854 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 855 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 856 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 857 | * delivered faster as it's an activity intent. |
| 858 | * |
Esteban Talavera | 4047bae | 2017-06-28 11:03:09 +0100 | [diff] [blame] | 859 | * <p>The intent is only sent to the new device or profile owner. |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 860 | * |
| 861 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 862 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 863 | */ |
| 864 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 865 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 866 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 867 | |
| 868 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 869 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 870 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 871 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 872 | * <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] | 873 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 874 | * |
| 875 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 876 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 877 | */ |
| 878 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 879 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 880 | |
| 881 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 882 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 883 | * provisioning. If this extra is not passed, a default image will be shown. |
| 884 | * <h5>The following URI schemes are accepted:</h5> |
| 885 | * <ul> |
| 886 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 887 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 888 | * </ul> |
| 889 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 890 | * <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] | 891 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 892 | * |
| 893 | * <p> If a content: URI is passed, the intent should have the flag |
| 894 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 895 | * {@link android.content.ClipData} of the intent too. |
| 896 | * |
| 897 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 898 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 899 | */ |
| 900 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 901 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 902 | |
| 903 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 904 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 905 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 906 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 907 | * content. |
| 908 | * |
| 909 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 910 | * management application (MDM), and one disclaimer from the organization. |
| 911 | * |
| 912 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 913 | * |
| 914 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 915 | * |
| 916 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 917 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 918 | */ |
| 919 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 920 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 921 | |
| 922 | /** |
| 923 | * A String extra of localized disclaimer header. |
| 924 | * |
| 925 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 926 | * or the organization name. |
| 927 | * |
| 928 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 929 | * |
| 930 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 931 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 932 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example: |
| 933 | * |
| 934 | * <pre> |
| 935 | * <meta-data |
| 936 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER" |
| 937 | * android:resource="@string/disclaimer_header" |
| 938 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 939 | */ |
| 940 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 941 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 942 | |
| 943 | /** |
| 944 | * A {@link Uri} extra pointing to disclaimer content. |
| 945 | * |
| 946 | * <h5>The following URI schemes are accepted:</h5> |
| 947 | * <ul> |
| 948 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 949 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 950 | * </ul> |
| 951 | * |
| 952 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 953 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 954 | * {@link android.widget.TextView}. |
| 955 | * |
| 956 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 957 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 958 | * {@link android.content.ClipData} of the intent too. |
| 959 | * |
| 960 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
Victor Chang | 9860713 | 2017-01-27 11:51:56 +0000 | [diff] [blame] | 961 | * |
| 962 | * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a |
| 963 | * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}. |
| 964 | * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example: |
| 965 | * |
| 966 | * <pre> |
| 967 | * <meta-data |
| 968 | * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT" |
| 969 | * android:resource="@string/disclaimer_content" |
| 970 | * /></pre> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 971 | */ |
| 972 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 973 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 974 | |
| 975 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 976 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 977 | * during setup-wizard. |
| 978 | * |
| 979 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 980 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 981 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 982 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 983 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 984 | * |
| 985 | * @hide |
| 986 | */ |
| 987 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 988 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 989 | |
| 990 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 991 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 992 | * skipped. If unspecified, defaults to {@code false}. |
| 993 | * |
| 994 | * It can only be used by an existing device owner trying to create a managed profile via |
| 995 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 996 | */ |
| 997 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 998 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 999 | |
| 1000 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1001 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1002 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 1003 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 1004 | * A device owner has full control over the device. The device owner can not be modified by the |
| 1005 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 1006 | * reset. |
| 1007 | * |
| 1008 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 1009 | * employee or client. |
| 1010 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 1011 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1012 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 1013 | * <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] | 1014 | * contains the following properties: |
| 1015 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1016 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 1017 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 1018 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1019 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1020 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 1021 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 1022 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 1023 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 1024 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 1025 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 1026 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 1027 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 1028 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 1029 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 1030 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 1031 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 1032 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1033 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 1034 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 1035 | * 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] | 1036 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1037 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1038 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1039 | */ |
| 1040 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1041 | = "application/com.android.managedprovisioning"; |
| 1042 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1043 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1044 | * Activity action: ask the user to add a new device administrator to the system. |
| 1045 | * The desired policy is the ComponentName of the policy in the |
| 1046 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1047 | * bring the user through adding the device administrator to the system (or |
| 1048 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1049 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1050 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1051 | * field to provide the user with additional explanation (in addition |
| 1052 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1053 | * |
| 1054 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1055 | * user intervention). However, if your administrator has been updated and is requesting |
| 1056 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1057 | * 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] | 1058 | */ |
| 1059 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1060 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1061 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1062 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1063 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1064 | * @hide |
| 1065 | * 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] | 1066 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1067 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1068 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1069 | * 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] | 1070 | * to remotely control restrictions on the user. |
| 1071 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1072 | * <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] | 1073 | * result of whether or not the user approved the action. If approved, the result will |
| 1074 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1075 | * as a profile owner. |
| 1076 | * |
| 1077 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1078 | * field to provide the user with additional explanation (in addition |
| 1079 | * to your component's description) about what is being added. |
| 1080 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1081 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1082 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1083 | */ |
| 1084 | @SystemApi |
| 1085 | public static final String ACTION_SET_PROFILE_OWNER |
| 1086 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1087 | |
| 1088 | /** |
| 1089 | * @hide |
| 1090 | * Name of the profile owner admin that controls the user. |
| 1091 | */ |
| 1092 | @SystemApi |
| 1093 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1094 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1095 | |
| 1096 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1097 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1098 | * 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] | 1099 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1100 | * @hide |
| 1101 | */ |
| 1102 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1103 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1104 | |
| 1105 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1106 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1107 | * |
| 1108 | * This broadcast is sent only to the primary user. |
| 1109 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1110 | */ |
| 1111 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1112 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1113 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1114 | |
| 1115 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1116 | * The ComponentName of the administrator component. |
| 1117 | * |
| 1118 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1119 | */ |
| 1120 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1121 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1122 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1123 | * An optional CharSequence providing additional explanation for why the |
| 1124 | * admin is being added. |
| 1125 | * |
| 1126 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1127 | */ |
| 1128 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1129 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1130 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 1131 | * Constant to indicate the feature of disabling the camera. Used as argument to |
| 1132 | * {@link #createAdminSupportIntent(String)}. |
| 1133 | * @see #setCameraDisabled(ComponentName, boolean) |
| 1134 | */ |
| 1135 | public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera"; |
| 1136 | |
| 1137 | /** |
| 1138 | * Constant to indicate the feature of disabling screen captures. Used as argument to |
| 1139 | * {@link #createAdminSupportIntent(String)}. |
| 1140 | * @see #setScreenCaptureDisabled(ComponentName, boolean) |
| 1141 | */ |
| 1142 | public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; |
| 1143 | |
| 1144 | /** |
| 1145 | * A String indicating a specific restricted feature. Can be a user restriction from the |
| 1146 | * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values |
| 1147 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 1148 | * @see #createAdminSupportIntent(String) |
| 1149 | * @hide |
| 1150 | */ |
| 1151 | @TestApi |
| 1152 | public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION"; |
| 1153 | |
| 1154 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1155 | * Activity action: have the user enter a new password. This activity should |
| 1156 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1157 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1158 | * enter a new password that meets the current requirements. You can use |
| 1159 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1160 | * have the user select a new password in order to meet the current |
| 1161 | * constraints. Upon being resumed from this activity, you can check the new |
| 1162 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1163 | * |
| 1164 | * If the intent is launched from within a managed profile with a profile |
| 1165 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1166 | * this will trigger entering a new password for the parent of the profile. |
| 1167 | * For all other cases it will trigger entering a new password for the user |
| 1168 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1169 | * |
| 1170 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1171 | */ |
| 1172 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1173 | public static final String ACTION_SET_NEW_PASSWORD |
| 1174 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1175 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1176 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1177 | * Activity action: have the user enter a new password for the parent profile. |
| 1178 | * If the intent is launched from within a managed profile, this will trigger |
| 1179 | * entering a new password for the parent of the profile. In all other cases |
| 1180 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1181 | */ |
| 1182 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1183 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1184 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1185 | |
| 1186 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1187 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1188 | * Network logging was enabled and the user tapped the notification. |
| 1189 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1190 | * @hide |
| 1191 | */ |
| 1192 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1193 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1194 | |
| 1195 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1196 | * Broadcast Action: Sent after application delegation scopes are changed. The new delegation |
| 1197 | * scopes will be sent in an {@code ArrayList<String>} extra identified by the |
| 1198 | * {@link #EXTRA_DELEGATION_SCOPES} key. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1199 | * |
| 1200 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1201 | */ |
| 1202 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1203 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1204 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1205 | |
| 1206 | /** |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 1207 | * 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] | 1208 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1209 | */ |
| 1210 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1211 | |
| 1212 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1213 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1214 | * the parent profile to access intents sent from the managed profile. |
| 1215 | * That is, when an app in the managed profile calls |
| 1216 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1217 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1218 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1219 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1220 | |
| 1221 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1222 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1223 | * the managed profile to access intents sent from the parent profile. |
| 1224 | * That is, when an app in the parent profile calls |
| 1225 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1226 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1227 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1228 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1229 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1230 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1231 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1232 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1233 | */ |
| 1234 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1235 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1236 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1237 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1238 | /** |
| 1239 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1240 | * Already granted or denied permissions are not affected by this. |
| 1241 | */ |
| 1242 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1243 | |
| 1244 | /** |
| 1245 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1246 | * Already granted or denied permissions are not affected by this. |
| 1247 | */ |
| 1248 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1249 | |
| 1250 | /** |
| 1251 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1252 | * Already granted or denied permissions are not affected by this. |
| 1253 | */ |
| 1254 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1255 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1256 | /** |
| 1257 | * Runtime permission state: The user can manage the permission |
| 1258 | * through the UI. |
| 1259 | */ |
| 1260 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1261 | |
| 1262 | /** |
| 1263 | * Runtime permission state: The permission is granted to the app |
| 1264 | * and the user cannot manage the permission through the UI. |
| 1265 | */ |
| 1266 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1267 | |
| 1268 | /** |
| 1269 | * Runtime permission state: The permission is denied to the app |
| 1270 | * and the user cannot manage the permission through the UI. |
| 1271 | */ |
| 1272 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1273 | |
| 1274 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1275 | * Delegation of certificate installation and management. This scope grants access to the |
| 1276 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1277 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1278 | */ |
| 1279 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1280 | |
| 1281 | /** |
| 1282 | * Delegation of application restrictions management. This scope grants access to the |
| 1283 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1284 | */ |
| 1285 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1286 | |
| 1287 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1288 | * Delegation of application uninstall block. This scope grants access to the |
| 1289 | * {@link #setUninstallBlocked} API. |
| 1290 | */ |
| 1291 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1292 | |
| 1293 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 1294 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1295 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1296 | * and {@link #setPermissionGrantState} APIs. |
| 1297 | */ |
| 1298 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1299 | |
| 1300 | /** |
| 1301 | * Delegation of package access state. This scope grants access to the |
| 1302 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1303 | * {@link #setPackagesSuspended} APIs. |
| 1304 | */ |
| 1305 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1306 | |
| 1307 | /** |
| 1308 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1309 | * API. |
| 1310 | */ |
| 1311 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1312 | |
| 1313 | /** |
| 1314 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1315 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1316 | * @hide |
| 1317 | */ |
| 1318 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1319 | "delegation-keep-uninstalled-packages"; |
| 1320 | |
| 1321 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1322 | * No management for current user in-effect. This is the default. |
| 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_UNMANAGED = 0; |
| 1327 | |
| 1328 | /** |
| 1329 | * Management partially setup, user setup needs to be completed. |
| 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_SETUP_INCOMPLETE = 1; |
| 1334 | |
| 1335 | /** |
| 1336 | * Management partially setup, user setup completed. |
| 1337 | * @hide |
| 1338 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1339 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1340 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1341 | |
| 1342 | /** |
| 1343 | * Management setup and active on current user. |
| 1344 | * @hide |
| 1345 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1346 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1347 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1348 | |
| 1349 | /** |
| 1350 | * Management partially setup on a managed profile. |
| 1351 | * @hide |
| 1352 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1353 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1354 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1355 | |
| 1356 | /** |
| 1357 | * @hide |
| 1358 | */ |
| 1359 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1360 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1361 | @Retention(RetentionPolicy.SOURCE) |
| 1362 | public @interface UserProvisioningState {} |
| 1363 | |
| 1364 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1365 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1366 | * |
| 1367 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1368 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1369 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1370 | * |
| 1371 | * @hide |
| 1372 | */ |
| 1373 | public static final int CODE_OK = 0; |
| 1374 | |
| 1375 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1376 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1377 | * |
| 1378 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1379 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1380 | * owner. |
| 1381 | * |
| 1382 | * @hide |
| 1383 | */ |
| 1384 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 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} when the user has a profile owner and for |
| 1391 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1392 | * |
| 1393 | * @hide |
| 1394 | */ |
| 1395 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1396 | |
| 1397 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1398 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1399 | * |
| 1400 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1401 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1402 | * |
| 1403 | * @hide |
| 1404 | */ |
| 1405 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1406 | |
| 1407 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1408 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1409 | * |
| 1410 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1411 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1412 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1413 | * |
| 1414 | * @hide |
| 1415 | */ |
| 1416 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1417 | |
| 1418 | /** |
| 1419 | * Code used to indicate that the device also has a user other than the system user. |
| 1420 | * |
| 1421 | * @hide |
| 1422 | */ |
| 1423 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1424 | |
| 1425 | /** |
| 1426 | * Code used to indicate that device has an account that prevents provisioning. |
| 1427 | * |
| 1428 | * @hide |
| 1429 | */ |
| 1430 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 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_DEVICE} and |
| 1436 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1437 | * |
| 1438 | * @hide |
| 1439 | */ |
| 1440 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1441 | |
| 1442 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1443 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1444 | * |
| 1445 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1446 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1447 | * when the device is a watch and is already paired. |
| 1448 | * |
| 1449 | * @hide |
| 1450 | */ |
| 1451 | public static final int CODE_HAS_PAIRED = 8; |
| 1452 | |
| 1453 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1454 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1455 | * |
| 1456 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1457 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1458 | * |
| 1459 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1460 | * @hide |
| 1461 | */ |
| 1462 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1463 | |
| 1464 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1465 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1466 | * |
| 1467 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1468 | * |
| 1469 | * @hide |
| 1470 | */ |
| 1471 | public static final int CODE_SYSTEM_USER = 10; |
| 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_PROFILE} when the user cannot have more |
| 1477 | * managed profiles. |
| 1478 | * |
| 1479 | * @hide |
| 1480 | */ |
| 1481 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1482 | |
| 1483 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1484 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1485 | * |
| 1486 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1487 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1488 | * user. |
| 1489 | * |
| 1490 | * @hide |
| 1491 | */ |
| 1492 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1493 | |
| 1494 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1495 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1496 | * |
| 1497 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1498 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1499 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1500 | * admins. |
| 1501 | * |
| 1502 | * @hide |
| 1503 | */ |
| 1504 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1505 | |
| 1506 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1507 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1508 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1509 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1510 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1511 | * |
| 1512 | * @hide |
| 1513 | */ |
| 1514 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1515 | |
| 1516 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1517 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1518 | * |
| 1519 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1520 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1521 | * |
| 1522 | * @hide |
| 1523 | */ |
| 1524 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1525 | |
| 1526 | /** |
| 1527 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1528 | * conditions. |
| 1529 | * |
| 1530 | * @hide |
| 1531 | */ |
| 1532 | @Retention(RetentionPolicy.SOURCE) |
| 1533 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1534 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1535 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1536 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1537 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1538 | public @interface ProvisioningPreCondition {} |
| 1539 | |
| 1540 | /** |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1541 | * Service action: Action for a service that device owner and profile owner can optionally |
| 1542 | * own. If a device owner or a profile owner has such a service, the system tries to keep |
| 1543 | * 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] | 1544 | * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN} |
| 1545 | * permission. |
Makoto Onuki | fc73d79 | 2017-03-22 14:22:35 -0700 | [diff] [blame] | 1546 | */ |
| 1547 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 1548 | public static final String ACTION_DEVICE_ADMIN_SERVICE |
| 1549 | = "android.app.action.DEVICE_ADMIN_SERVICE"; |
| 1550 | |
| 1551 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1552 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1553 | * |
| 1554 | * @param admin The administrator component to check for. |
| 1555 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1556 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1557 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1558 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1559 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1560 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | /** |
| 1564 | * @see #isAdminActive(ComponentName) |
| 1565 | * @hide |
| 1566 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1567 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1568 | if (mService != null) { |
| 1569 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1570 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1571 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1572 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | return false; |
| 1576 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1577 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1578 | /** |
| 1579 | * Return true if the given administrator component is currently being removed |
| 1580 | * for the user. |
| 1581 | * @hide |
| 1582 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1583 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1584 | if (mService != null) { |
| 1585 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1586 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1587 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1588 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | return false; |
| 1592 | } |
| 1593 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1594 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1595 | * Return a list of all currently active device administrators' component |
| 1596 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1597 | * returned. |
| 1598 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1599 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1600 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1601 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | /** |
| 1605 | * @see #getActiveAdmins() |
| 1606 | * @hide |
| 1607 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1608 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1609 | if (mService != null) { |
| 1610 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1611 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1612 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1613 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | return null; |
| 1617 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1618 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1619 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1620 | * Used by package administration code to determine if a package can be stopped |
| 1621 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1622 | * @hide |
| 1623 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1624 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1625 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1626 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1627 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1628 | } |
| 1629 | |
| 1630 | /** |
| 1631 | * Used by package administration code to determine if a package can be stopped |
| 1632 | * or uninstalled. |
| 1633 | * @hide |
| 1634 | */ |
| 1635 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1636 | if (mService != null) { |
| 1637 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1638 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1639 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1640 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | return false; |
| 1644 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1645 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1646 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1647 | * Remove a current administration component. This can only be called |
| 1648 | * by the application that owns the administration component; if you |
| 1649 | * try to remove someone else's component, a security exception will be |
| 1650 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1651 | * |
| 1652 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1653 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1654 | * |
| 1655 | * @param admin The administration compononent to remove. |
| 1656 | * @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] | 1657 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1658 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1659 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1660 | if (mService != null) { |
| 1661 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1662 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1663 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1664 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1668 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1669 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1670 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1671 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1672 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1673 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1674 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1675 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1676 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1677 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1678 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1679 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1680 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1681 | if (mService != null) { |
| 1682 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1683 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1684 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1685 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | return false; |
| 1689 | } |
| 1690 | |
| 1691 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1692 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1693 | * |
| 1694 | * @hide |
| 1695 | */ |
| 1696 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1697 | if (mService != null) { |
| 1698 | try { |
| 1699 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1700 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1701 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1708 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1709 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1710 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1711 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1712 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
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 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1715 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1716 | * recognition technology. This implies technologies that can recognize the identity of |
| 1717 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1718 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1719 | */ |
| 1720 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1721 | |
| 1722 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1723 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1724 | * 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] | 1725 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1726 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1727 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1728 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1729 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1730 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1731 | * password containing at least numeric characters. Note that quality |
| 1732 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1733 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1734 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1735 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1736 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1737 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1738 | * password containing at least numeric characters with no repeating (4444) |
| 1739 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1740 | * constants are ordered so that higher values are more restrictive. |
| 1741 | */ |
| 1742 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1743 | |
| 1744 | /** |
| 1745 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1746 | * password containing at least alphabetic (or other symbol) characters. |
| 1747 | * Note that quality constants are ordered so that higher values are more |
| 1748 | * restrictive. |
| 1749 | */ |
| 1750 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1751 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1752 | /** |
| 1753 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1754 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1755 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1756 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1757 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1758 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1759 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1760 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1761 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1762 | * password containing at least a letter, a numerical digit and a special |
| 1763 | * symbol, by default. With this password quality, passwords can be |
| 1764 | * restricted to contain various sets of characters, like at least an |
| 1765 | * uppercase letter, etc. These are specified using various methods, |
| 1766 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1767 | * that quality constants are ordered so that higher values are more |
| 1768 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1769 | */ |
| 1770 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1771 | |
| 1772 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1773 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1774 | * modify password. In case this password quality is set, the password is |
| 1775 | * managed by a profile owner. The profile owner can set any password, |
| 1776 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1777 | * that quality constants are ordered so that higher values are more |
| 1778 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1779 | * the highest. |
| 1780 | * @hide |
| 1781 | */ |
| 1782 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1783 | |
| 1784 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1785 | * @hide |
| 1786 | * |
| 1787 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1788 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1789 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1790 | * used by authenticator to exempt their accounts from this: |
| 1791 | * |
| 1792 | * <ul> |
| 1793 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1794 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1795 | * <application> tag in the manifest. |
| 1796 | * |
| 1797 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1798 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1799 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1800 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1801 | * if any of the accounts have it. |
| 1802 | * </ul> |
| 1803 | */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1804 | @SystemApi |
| 1805 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1806 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1807 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1808 | |
| 1809 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
Makoto Onuki | 47c203d | 2017-02-13 16:21:19 -0800 | [diff] [blame] | 1810 | @SystemApi |
| 1811 | @TestApi |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1812 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1813 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1814 | |
| 1815 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1816 | * Called by an application that is administering the device to set the password restrictions it |
| 1817 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1818 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1819 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1820 | * 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] | 1821 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1822 | * <p> |
| 1823 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1824 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1825 | * considerations) is the one that is in effect. |
| 1826 | * <p> |
| 1827 | * The calling device admin must have requested |
| 1828 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1829 | * not, a security exception will be thrown. |
| 1830 | * <p> |
| 1831 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1832 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1833 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1834 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1835 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1836 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1837 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1838 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1839 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1840 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1841 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
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 void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1844 | if (mService != null) { |
| 1845 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1846 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1847 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1848 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1852 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1853 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1854 | * 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] | 1855 | * 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] | 1856 | * a separate challenge are not taken into account. |
| 1857 | * |
| 1858 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1859 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1860 | * restrictions on the parent profile. |
| 1861 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1862 | * @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] | 1863 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1864 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1865 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1866 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1870 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1871 | if (mService != null) { |
| 1872 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1873 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1874 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1875 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1876 | } |
| 1877 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1878 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1879 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1880 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1881 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1882 | * Called by an application that is administering the device to set the minimum allowed password |
| 1883 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1884 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1885 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1886 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1887 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1888 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1889 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1890 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1891 | * {@link #setPasswordQuality}. |
| 1892 | * <p> |
| 1893 | * The calling device admin must have requested |
| 1894 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1895 | * not, a security exception will be thrown. |
| 1896 | * <p> |
| 1897 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1898 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1899 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1900 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1901 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1902 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1903 | * restriction. |
| 1904 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1905 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1906 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1907 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1908 | if (mService != null) { |
| 1909 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1910 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1911 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1912 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1913 | } |
| 1914 | } |
| 1915 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1916 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1917 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1918 | * 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] | 1919 | * 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] | 1920 | * a separate challenge are not taken into account. |
| 1921 | * |
| 1922 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1923 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1924 | * restrictions on the parent profile. |
| 1925 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1926 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1927 | * @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] | 1928 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1929 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1930 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1931 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1935 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1936 | if (mService != null) { |
| 1937 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1938 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1939 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1940 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | return 0; |
| 1944 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1945 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1946 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1947 | * Called by an application that is administering the device to set the minimum number of upper |
| 1948 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1949 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1950 | * current password will remain until the user has set a new one, so the change does not take |
| 1951 | * place immediately. To prompt the user for a new password, use |
| 1952 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1953 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1954 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1955 | * <p> |
| 1956 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1957 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1958 | * not, a security exception will be thrown. |
| 1959 | * <p> |
| 1960 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1961 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1962 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1963 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1964 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1965 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1966 | * A value of 0 means there is no restriction. |
| 1967 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1968 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1969 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1970 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1971 | if (mService != null) { |
| 1972 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1973 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1974 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1975 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1981 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1982 | * 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] | 1983 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1984 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1985 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1986 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1987 | * and only applies when the password quality is |
| 1988 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1989 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1990 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1991 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1992 | * restrictions on the parent profile. |
| 1993 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1994 | * @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] | 1995 | * aggregate all admins. |
| 1996 | * @return The minimum number of upper case letters required in the |
| 1997 | * password. |
| 1998 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1999 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2000 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2004 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2005 | if (mService != null) { |
| 2006 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2007 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2008 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2009 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2016 | * Called by an application that is administering the device to set the minimum number of lower |
| 2017 | * case letters required in the password. After setting this, the user will not be able to enter |
| 2018 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 2019 | * current password will remain until the user has set a new one, so the change does not take |
| 2020 | * place immediately. To prompt the user for a new password, use |
| 2021 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2022 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2023 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2024 | * <p> |
| 2025 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2026 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2027 | * not, a security exception will be thrown. |
| 2028 | * <p> |
| 2029 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2030 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2031 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2032 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2033 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2034 | * @param length The new desired minimum number of lower case letters required in the password. |
| 2035 | * A value of 0 means there is no restriction. |
| 2036 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2037 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2038 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2039 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2040 | if (mService != null) { |
| 2041 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2042 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2043 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2044 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2050 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2051 | * 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] | 2052 | * and its participating profiles. Restrictions on profiles that have |
| 2053 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2054 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2055 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2056 | * and only applies when the password quality is |
| 2057 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2058 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2059 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2060 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2061 | * restrictions on the parent profile. |
| 2062 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2063 | * @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] | 2064 | * aggregate all admins. |
| 2065 | * @return The minimum number of lower case letters required in the |
| 2066 | * password. |
| 2067 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2068 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2069 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2073 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2074 | if (mService != null) { |
| 2075 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2076 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2077 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2078 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | return 0; |
| 2082 | } |
| 2083 | |
| 2084 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2085 | * Called by an application that is administering the device to set the minimum number of |
| 2086 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2087 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2088 | * password will remain until the user has set a new one, so the change does not take place |
| 2089 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2090 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2091 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2092 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2093 | * <p> |
| 2094 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2095 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2096 | * not, a security exception will be thrown. |
| 2097 | * <p> |
| 2098 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2099 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2100 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2101 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2102 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2103 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2104 | * 0 means there is no restriction. |
| 2105 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2106 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2107 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2108 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2109 | if (mService != null) { |
| 2110 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2111 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2112 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2113 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2119 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2120 | * 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] | 2121 | * and its participating profiles. Restrictions on profiles that have |
| 2122 | * a separate challenge are not taken into account. |
| 2123 | * This is the same value as set by |
| 2124 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2125 | * and only applies when the password quality is |
| 2126 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2127 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2128 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2129 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2130 | * restrictions on the parent profile. |
| 2131 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2132 | * @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] | 2133 | * aggregate all admins. |
| 2134 | * @return The minimum number of letters required in the password. |
| 2135 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2136 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2137 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2141 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2142 | if (mService != null) { |
| 2143 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2144 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2145 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2146 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2147 | } |
| 2148 | } |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
| 2152 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2153 | * Called by an application that is administering the device to set the minimum number of |
| 2154 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2155 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2156 | * current password will remain until the user has set a new one, so the change does not take |
| 2157 | * place immediately. To prompt the user for a new password, use |
| 2158 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2159 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2160 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2161 | * <p> |
| 2162 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2163 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2164 | * not, a security exception will be thrown. |
| 2165 | * <p> |
| 2166 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2167 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2168 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2169 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2170 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2171 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2172 | * value of 0 means there is no restriction. |
| 2173 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2174 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2175 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2176 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2177 | if (mService != null) { |
| 2178 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2179 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2180 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2181 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | /** |
| 2187 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2188 | * 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] | 2189 | * and its participating profiles. Restrictions on profiles that have |
| 2190 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2191 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2192 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2193 | * and only applies when the password quality is |
| 2194 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2195 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2196 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2197 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2198 | * restrictions on the parent profile. |
| 2199 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2200 | * @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] | 2201 | * aggregate all admins. |
| 2202 | * @return The minimum number of numerical digits required in the password. |
| 2203 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2204 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2205 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2209 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2210 | if (mService != null) { |
| 2211 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2212 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2213 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2214 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | return 0; |
| 2218 | } |
| 2219 | |
| 2220 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2221 | * Called by an application that is administering the device to set the minimum number of |
| 2222 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2223 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2224 | * password will remain until the user has set a new one, so the change does not take place |
| 2225 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2226 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2227 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2228 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2229 | * <p> |
| 2230 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2231 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2232 | * not, a security exception will be thrown. |
| 2233 | * <p> |
| 2234 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2235 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2236 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2237 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2238 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2239 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2240 | * 0 means there is no restriction. |
| 2241 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2242 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2243 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2244 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2245 | if (mService != null) { |
| 2246 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2247 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2248 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2249 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2255 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2256 | * 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] | 2257 | * and its participating profiles. Restrictions on profiles that have |
| 2258 | * a separate challenge are not taken into account. This is the same value as |
| 2259 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2260 | * and only applies when the password quality is |
| 2261 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2262 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2263 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2264 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2265 | * restrictions on the parent profile. |
| 2266 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2267 | * @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] | 2268 | * aggregate all admins. |
| 2269 | * @return The minimum number of symbols required in the password. |
| 2270 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2271 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2272 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2276 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2277 | if (mService != null) { |
| 2278 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2279 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2280 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2281 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2282 | } |
| 2283 | } |
| 2284 | return 0; |
| 2285 | } |
| 2286 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2287 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2288 | * Called by an application that is administering the device to set the minimum number of |
| 2289 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2290 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2291 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2292 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2293 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2294 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2295 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2296 | * <p> |
| 2297 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2298 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2299 | * not, a security exception will be thrown. |
| 2300 | * <p> |
| 2301 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2302 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2303 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2304 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2305 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2306 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2307 | * 0 means there is no restriction. |
| 2308 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2309 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2310 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2311 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2312 | if (mService != null) { |
| 2313 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2314 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2315 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2316 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2322 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2323 | * 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] | 2324 | * and its participating profiles. Restrictions on profiles that have |
| 2325 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2326 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2327 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2328 | * and only applies when the password quality is |
| 2329 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2330 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2331 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2332 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2333 | * restrictions on the parent profile. |
| 2334 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2335 | * @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] | 2336 | * aggregate all admins. |
| 2337 | * @return The minimum number of letters required in the password. |
| 2338 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2339 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2340 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2344 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2345 | if (mService != null) { |
| 2346 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2347 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2348 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2349 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2355 | /** |
| 2356 | * Called by an application that is administering the device to set the length of the password |
| 2357 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2358 | * same as any password in the history. Note that the current password will remain until the |
| 2359 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2360 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2361 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2362 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2363 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2364 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2365 | * <p> |
| 2366 | * The calling device admin must have requested |
| 2367 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2368 | * not, a security exception will be thrown. |
| 2369 | * <p> |
| 2370 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2371 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2372 | * profile. |
| 2373 | * |
| 2374 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2375 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2376 | * restriction. |
| 2377 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2378 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2379 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2380 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2381 | if (mService != null) { |
| 2382 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2383 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2384 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2385 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2391 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2392 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2393 | * device password (for all admins). |
| 2394 | * <p> |
| 2395 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2396 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2397 | * 432000000 ms for timeout. |
| 2398 | * <p> |
| 2399 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2400 | * <p> |
| 2401 | * The calling device admin must have requested |
| 2402 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2403 | * not, a security exception will be thrown. |
| 2404 | * <p> |
| 2405 | * Note that setting the password will automatically reset the expiration time for all active |
| 2406 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2407 | * <p> |
| 2408 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2409 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2410 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2411 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2412 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2413 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2414 | * there is no restriction (unlimited). |
| 2415 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2416 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2417 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2418 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2419 | if (mService != null) { |
| 2420 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2421 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2422 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2423 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2429 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2430 | * recurring expiration timeout provided in the call to |
| 2431 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2432 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2433 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2434 | * |
| 2435 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2436 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2437 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2438 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2439 | * @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] | 2440 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2441 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2442 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2443 | if (mService != null) { |
| 2444 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2445 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2446 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2447 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | return 0; |
| 2451 | } |
| 2452 | |
| 2453 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2454 | * 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] | 2455 | * 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] | 2456 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2457 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2458 | * |
| 2459 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2460 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2461 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2462 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2463 | * @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] | 2464 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2465 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2466 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2467 | if (mService != null) { |
| 2468 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2469 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2470 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2471 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2472 | } |
| 2473 | } |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
| 2477 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2478 | * 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] | 2479 | * 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] | 2480 | * have a separate challenge are not taken into account. |
| 2481 | * |
| 2482 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2483 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2484 | * restrictions on the parent profile. |
| 2485 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2486 | * @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] | 2487 | * all admins. |
| 2488 | * @return The length of the password history |
| 2489 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2490 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2491 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2495 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2496 | if (mService != null) { |
| 2497 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2498 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2499 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2500 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2501 | } |
| 2502 | } |
| 2503 | return 0; |
| 2504 | } |
| 2505 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2506 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2507 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2508 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2509 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2510 | * @return Returns the maximum length that the user can enter. |
| 2511 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2512 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2513 | // Kind-of arbitrary. |
| 2514 | return 16; |
| 2515 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2516 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2517 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2518 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2519 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2520 | * 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] | 2521 | * 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] | 2522 | * <p> |
| 2523 | * The calling device admin must have requested |
| 2524 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2525 | * not, a security exception will be thrown. |
| 2526 | * <p> |
| 2527 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2528 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2529 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2530 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2531 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2532 | * @throws SecurityException if the calling application does not own an active administrator |
| 2533 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2534 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2535 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2536 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2537 | if (mService != null) { |
| 2538 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2539 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2540 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2541 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2542 | } |
| 2543 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2544 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2545 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2546 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2547 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2548 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2549 | * 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] | 2550 | * requested by the admins of the parent user and its profiles. |
| 2551 | * |
| 2552 | * @param userHandle the userId of the profile to check the password for. |
| 2553 | * @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] | 2554 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2555 | * @hide |
| 2556 | */ |
| 2557 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2558 | if (mService != null) { |
| 2559 | try { |
| 2560 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2561 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2562 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2563 | } |
| 2564 | } |
| 2565 | return false; |
| 2566 | } |
| 2567 | |
| 2568 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2569 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2570 | * successful password entry. |
| 2571 | * <p> |
| 2572 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2573 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2574 | * password attemts for the parent user. |
| 2575 | * <p> |
| 2576 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2577 | * 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] | 2578 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2579 | * @return The number of times user has entered an incorrect password since the last correct |
| 2580 | * password entry. |
| 2581 | * @throws SecurityException if the calling application does not own an active administrator |
| 2582 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2583 | */ |
| 2584 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2585 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2586 | } |
| 2587 | |
| 2588 | /** |
| 2589 | * Retrieve the number of times the given user has failed at entering a |
| 2590 | * password since that last successful password entry. |
| 2591 | * |
| 2592 | * <p>The calling device admin must have requested |
| 2593 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2594 | * not and it is not the system uid, a security exception will be thrown. |
| 2595 | * |
| 2596 | * @hide |
| 2597 | */ |
| 2598 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2599 | if (mService != null) { |
| 2600 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2601 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2602 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2603 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2604 | } |
| 2605 | } |
| 2606 | return -1; |
| 2607 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2608 | |
| 2609 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2610 | * 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] | 2611 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2612 | * @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] | 2613 | * @hide |
| 2614 | */ |
| 2615 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2616 | if (mService != null) { |
| 2617 | try { |
| 2618 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2619 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2620 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | return false; |
| 2624 | } |
| 2625 | |
| 2626 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2627 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2628 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2629 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2630 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2631 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2632 | * <p> |
| 2633 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2634 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2635 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2636 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2637 | * immediately, and your callback will not be invoked. |
| 2638 | * <p> |
| 2639 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2640 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2641 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2642 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2643 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2644 | * @param num The number of failed password attempts at which point the device or profile will |
| 2645 | * be wiped. |
| 2646 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2647 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2648 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2649 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2650 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2651 | if (mService != null) { |
| 2652 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2653 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2654 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2655 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2656 | } |
| 2657 | } |
| 2658 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2659 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2660 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2661 | * 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] | 2662 | * 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] | 2663 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2664 | * not taken into account. |
| 2665 | * |
| 2666 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2667 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2668 | * the value for the parent profile. |
| 2669 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2670 | * @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] | 2671 | * all admins. |
| 2672 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2673 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2674 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2678 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2679 | if (mService != null) { |
| 2680 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2681 | return mService.getMaximumFailedPasswordsForWipe( |
| 2682 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2683 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2684 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | return 0; |
| 2688 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2689 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2690 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2691 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2692 | * for the given user. So for primary user, it might return the primary or |
| 2693 | * a managed profile. For a secondary user, it would be the same as the |
| 2694 | * user passed in. |
| 2695 | * @hide Used only by Keyguard |
| 2696 | */ |
| 2697 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2698 | if (mService != null) { |
| 2699 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2700 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2701 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2702 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2703 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | return UserHandle.USER_NULL; |
| 2707 | } |
| 2708 | |
| 2709 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2710 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2711 | * the password again until the user has entered it. |
| 2712 | */ |
| 2713 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2714 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2715 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2716 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2717 | * If the flag is set, the device can be booted without asking for user password. |
| 2718 | * The absence of this flag does not change the current boot requirements. This flag |
| 2719 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2720 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2721 | * device to factory defaults. |
| 2722 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2723 | 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] | 2724 | |
| 2725 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2726 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2727 | * individual accounts) on the user. This takes effect immediately. |
| 2728 | * <p> |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2729 | * <em>For device owner and profile owners targeting SDK level |
| 2730 | * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will |
| 2731 | * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken} |
| 2732 | * instead. </em> |
| 2733 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2734 | * <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] | 2735 | * device admins that are not device owner and not profile owner. |
| 2736 | * 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] | 2737 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2738 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2739 | * <p> |
| 2740 | * The given password must be sufficient for the current password quality and length constraints |
| 2741 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2742 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2743 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2744 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2745 | * case the currently active quality will be increased to match. |
| 2746 | * <p> |
| 2747 | * 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] | 2748 | * current password constraints allow it. <em>Note: This will not work in |
| 2749 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2750 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2751 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2752 | * <p> |
| 2753 | * The calling device admin must have requested |
| 2754 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2755 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2756 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2757 | * @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] | 2758 | * @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] | 2759 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2760 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2761 | * current constraints or if the user has not been decrypted yet. |
| 2762 | * @throws SecurityException if the calling application does not own an active administrator |
| 2763 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2764 | * @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] | 2765 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2766 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2767 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2768 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2769 | if (mService != null) { |
| 2770 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2771 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2772 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2773 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | return false; |
| 2777 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2778 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2779 | /** |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2780 | * Called by a profile or device owner to provision a token which can later be used to reset the |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2781 | * device lockscreen password (if called by device owner), or managed profile challenge (if |
| 2782 | * called by profile owner), via {@link #resetPasswordWithToken}. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2783 | * <p> |
| 2784 | * If the user currently has a lockscreen password, the provisioned token will not be |
| 2785 | * immediately usable; it only becomes active after the user performs a confirm credential |
| 2786 | * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 2787 | * If the user has no lockscreen password, the token is activated immediately. In all cases, |
| 2788 | * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}. |
| 2789 | * For security reasons, un-activated tokens are only stored in memory and will be lost once |
| 2790 | * the device reboots. In this case a new token needs to be provisioned again. |
| 2791 | * <p> |
| 2792 | * Once provisioned and activated, the token will remain effective even if the user changes |
| 2793 | * or clears the lockscreen password. |
| 2794 | * <p> |
| 2795 | * <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] | 2796 | * credentials. In particular, NEVER store this token on device in plaintext. Do not store |
| 2797 | * the plaintext token in device-encrypted storage if it will be needed to reset password on |
| 2798 | * file-based encryption devices before user unlocks. Consider carefully how any password token |
| 2799 | * will be stored on your server and who will need access to them. Tokens may be the subject of |
| 2800 | * legal access requests. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2801 | * </em> |
| 2802 | * |
| 2803 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2804 | * @param token a secure token a least 32-byte long, which must be generated by a |
| 2805 | * cryptographically strong random number generator. |
| 2806 | * @return true if the operation is successful, false otherwise. |
| 2807 | * @throws IllegalArgumentException if the supplied token is invalid. |
| 2808 | * @throws SecurityException |
| 2809 | */ |
| 2810 | public boolean setResetPasswordToken(ComponentName admin, byte[] token) { |
| 2811 | throwIfParentInstance("setResetPasswordToken"); |
| 2812 | if (mService != null) { |
| 2813 | try { |
| 2814 | return mService.setResetPasswordToken(admin, token); |
| 2815 | } catch (RemoteException e) { |
| 2816 | throw e.rethrowFromSystemServer(); |
| 2817 | } |
| 2818 | } |
| 2819 | return false; |
| 2820 | } |
| 2821 | |
| 2822 | /** |
| 2823 | * Called by a profile or device owner to revoke the current password reset token. |
| 2824 | * |
| 2825 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2826 | * @return true if the operation is successful, false otherwise. |
| 2827 | */ |
| 2828 | public boolean clearResetPasswordToken(ComponentName admin) { |
| 2829 | throwIfParentInstance("clearResetPasswordToken"); |
| 2830 | if (mService != null) { |
| 2831 | try { |
| 2832 | return mService.clearResetPasswordToken(admin); |
| 2833 | } catch (RemoteException e) { |
| 2834 | throw e.rethrowFromSystemServer(); |
| 2835 | } |
| 2836 | } |
| 2837 | return false; |
| 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * Called by a profile or device owner to check if the current reset password token is active. |
| 2842 | * |
| 2843 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2844 | * @return true if the token is active, false otherwise. |
| 2845 | * @throws IllegalStateException if no token has been set. |
| 2846 | */ |
| 2847 | public boolean isResetPasswordTokenActive(ComponentName admin) { |
| 2848 | throwIfParentInstance("isResetPasswordTokenActive"); |
| 2849 | if (mService != null) { |
| 2850 | try { |
| 2851 | return mService.isResetPasswordTokenActive(admin); |
| 2852 | } catch (RemoteException e) { |
| 2853 | throw e.rethrowFromSystemServer(); |
| 2854 | } |
| 2855 | } |
| 2856 | return false; |
| 2857 | } |
| 2858 | |
| 2859 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 2860 | * Called by device or profile owner to force set a new device unlock password or a managed |
| 2861 | * profile challenge on current user. This takes effect immediately. |
Rubin Xu | aab7a41 | 2016-12-30 21:13:29 +0000 | [diff] [blame] | 2862 | * <p> |
| 2863 | * Unlike {@link #resetPassword}, this API can change the password even before the user or |
| 2864 | * device is unlocked or decrypted. The supplied token must have been previously provisioned via |
| 2865 | * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}. |
| 2866 | * <p> |
| 2867 | * The given password must be sufficient for the current password quality and length constraints |
| 2868 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2869 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2870 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2871 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2872 | * case the currently active quality will be increased to match. |
| 2873 | * <p> |
| 2874 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
| 2875 | * current password constraints allow it. |
| 2876 | * |
| 2877 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2878 | * @param password The new password for the user. Null or empty clears the password. |
| 2879 | * @param token the password reset token previously provisioned by #setResetPasswordToken. |
| 2880 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
| 2881 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2882 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2883 | * current constraints. |
| 2884 | * @throws SecurityException if the calling application does not own an active administrator |
| 2885 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
| 2886 | * @throws IllegalStateException if the provided token is not valid. |
| 2887 | * @throws IllegalArgumentException if the password does not meet system requirements. |
| 2888 | */ |
| 2889 | public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password, |
| 2890 | byte[] token, int flags) { |
| 2891 | throwIfParentInstance("resetPassword"); |
| 2892 | if (mService != null) { |
| 2893 | try { |
| 2894 | return mService.resetPasswordWithToken(admin, password, token, flags); |
| 2895 | } catch (RemoteException e) { |
| 2896 | throw e.rethrowFromSystemServer(); |
| 2897 | } |
| 2898 | } |
| 2899 | return false; |
| 2900 | } |
| 2901 | |
| 2902 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2903 | * Called by an application that is administering the device to set the maximum time for user |
| 2904 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2905 | * effect immediately. |
| 2906 | * <p> |
| 2907 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2908 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2909 | * <p> |
| 2910 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2911 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2912 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2913 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2914 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2915 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2916 | * is no restriction. |
| 2917 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2918 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2919 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2920 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2921 | if (mService != null) { |
| 2922 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2923 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2924 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2925 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2929 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2930 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2931 | * 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] | 2932 | * 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] | 2933 | * a separate challenge are not taken into account. |
| 2934 | * |
| 2935 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2936 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2937 | * restrictions on the parent profile. |
| 2938 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2939 | * @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] | 2940 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2941 | * @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] | 2942 | * 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] | 2943 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2944 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2945 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2949 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2950 | if (mService != null) { |
| 2951 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2952 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2953 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2954 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | return 0; |
| 2958 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2959 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2960 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2961 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2962 | * do not have a separate timeout to lock for work challenge only. |
| 2963 | * |
| 2964 | * @hide |
| 2965 | */ |
| 2966 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2967 | if (mService != null) { |
| 2968 | try { |
| 2969 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2970 | } catch (RemoteException e) { |
| 2971 | throw e.rethrowFromSystemServer(); |
| 2972 | } |
| 2973 | } |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
| 2977 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2978 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2979 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2980 | * authentication method like password, pin or pattern. |
| 2981 | * |
| 2982 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2983 | * specified timeout each time it has been successfully used. |
| 2984 | * |
| 2985 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2986 | * |
| 2987 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2988 | * |
| 2989 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2990 | * a {@link SecurityException} will be thrown. |
| 2991 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2992 | * <p>The calling device admin can verify the value it has set by calling |
| 2993 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2994 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2995 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2996 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2997 | * profile. |
| 2998 | * |
| 2999 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3000 | * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock |
| 3001 | * with strong authentication method. A value of 0 means the admin is not participating |
| 3002 | * in controlling the timeout. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 3003 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 3004 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 3005 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 3006 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3007 | * |
| 3008 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 3009 | */ |
| 3010 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 3011 | long timeoutMs) { |
| 3012 | if (mService != null) { |
| 3013 | try { |
| 3014 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 3015 | } catch (RemoteException e) { |
| 3016 | throw e.rethrowFromSystemServer(); |
| 3017 | } |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 3023 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 3024 | * After the returned timeout the user is required to use strong authentication method. |
| 3025 | * |
| 3026 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3027 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3028 | * restrictions on the parent profile. |
| 3029 | * |
| 3030 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 3031 | * accross all participating admins. |
Rubin Xu | 5d39ea7 | 2017-04-24 20:26:30 +0100 | [diff] [blame] | 3032 | * @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] | 3033 | */ |
| 3034 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 3035 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 3036 | } |
| 3037 | |
| 3038 | /** @hide per-user version */ |
| 3039 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 3040 | if (mService != null) { |
| 3041 | try { |
| 3042 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 3043 | } catch (RemoteException e) { |
| 3044 | throw e.rethrowFromSystemServer(); |
| 3045 | } |
| 3046 | } |
| 3047 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 3048 | } |
| 3049 | |
| 3050 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3051 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 3052 | * keyring. The user's credential will need to be entered again in order to derive the |
| 3053 | * credential encryption key that will be stored back in the keyring for future use. |
| 3054 | * <p> |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3055 | * This flag can only be used by a profile owner when locking a managed profile when |
| 3056 | * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3057 | * <p> |
| 3058 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 3059 | * until they are next run to perform further actions. |
| 3060 | */ |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3061 | public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; |
| 3062 | |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3063 | /** @hide */ |
| 3064 | @Retention(RetentionPolicy.SOURCE) |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3065 | @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}) |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3066 | public @interface LockNowFlag {} |
| 3067 | |
| 3068 | /** |
| 3069 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3070 | * this call. |
| 3071 | * <p> |
| 3072 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3073 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3074 | * <p> |
| 3075 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3076 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 3077 | * <p> |
| 3078 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 3079 | * |
| 3080 | * @throws SecurityException if the calling application does not own an active administrator |
| 3081 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3082 | */ |
| 3083 | public void lockNow() { |
| 3084 | lockNow(0); |
| 3085 | } |
| 3086 | |
| 3087 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3088 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 3089 | * this call. |
| 3090 | * <p> |
| 3091 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 3092 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 3093 | * <p> |
| 3094 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 3095 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3096 | * |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3097 | * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3098 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3099 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3100 | * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application |
| 3101 | * that is not a profile |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3102 | * owner of a managed profile. |
Andrew Scull | 17e1b5d | 2017-04-25 14:44:24 +0100 | [diff] [blame] | 3103 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is |
| 3104 | * passed when locking the parent profile. |
| 3105 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} |
| 3106 | * flag is passed when {@link #getStorageEncryptionStatus} does not return |
| 3107 | * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3108 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3109 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3110 | if (mService != null) { |
| 3111 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3112 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3113 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3114 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3118 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3119 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3120 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3121 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3122 | */ |
| 3123 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 3124 | |
| 3125 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3126 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 3127 | * data. |
| 3128 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 3129 | * <p>This flag may only be set by device owner admins; if it is set by |
| 3130 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 3131 | */ |
| 3132 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 3133 | |
| 3134 | /** |
yinxu | f4f9cec | 2017-06-19 10:28:19 -0700 | [diff] [blame] | 3135 | * Flag for {@link #wipeData(int)}: also erase the device's eUICC data. |
| 3136 | * |
| 3137 | * TODO(b/35851809): make this public. |
| 3138 | * @hide |
| 3139 | */ |
| 3140 | public static final int WIPE_EUICC = 0x0004; |
| 3141 | |
| 3142 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 3143 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 3144 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 3145 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 3146 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3147 | * <p> |
| 3148 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 3149 | * 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] | 3150 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3151 | * @param flags Bit mask of additional options: currently supported flags are |
| 3152 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 3153 | * @throws SecurityException if the calling application does not own an active administrator |
| 3154 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3155 | */ |
| 3156 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3157 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3158 | if (mService != null) { |
| 3159 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3160 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3161 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3162 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3163 | } |
| 3164 | } |
| 3165 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3167 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3168 | * Called by an application that is administering the device to set the |
| 3169 | * global proxy and exclusion list. |
| 3170 | * <p> |
| 3171 | * The calling device admin must have requested |
| 3172 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 3173 | * this method; if it has not, a security exception will be thrown. |
| 3174 | * Only the first device admin can set the proxy. If a second admin attempts |
| 3175 | * 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] | 3176 | * 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] | 3177 | * be returned. |
| 3178 | * The method can be called repeatedly by the device admin alrady setting the |
| 3179 | * proxy to update the proxy and exclusion list. |
| 3180 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3181 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3182 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 3183 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 3184 | * @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] | 3185 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 3186 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3187 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3188 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3189 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3190 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3191 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3192 | if (proxySpec == null) { |
| 3193 | throw new NullPointerException(); |
| 3194 | } |
| 3195 | if (mService != null) { |
| 3196 | try { |
| 3197 | String hostSpec; |
| 3198 | String exclSpec; |
| 3199 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 3200 | hostSpec = null; |
| 3201 | exclSpec = null; |
| 3202 | } else { |
| 3203 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 3204 | throw new IllegalArgumentException(); |
| 3205 | } |
| 3206 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 3207 | String hostName = sa.getHostName(); |
| 3208 | int port = sa.getPort(); |
| 3209 | StringBuilder hostBuilder = new StringBuilder(); |
| 3210 | hostSpec = hostBuilder.append(hostName) |
| 3211 | .append(":").append(Integer.toString(port)).toString(); |
| 3212 | if (exclusionList == null) { |
| 3213 | exclSpec = ""; |
| 3214 | } else { |
| 3215 | StringBuilder listBuilder = new StringBuilder(); |
| 3216 | boolean firstDomain = true; |
| 3217 | for (String exclDomain : exclusionList) { |
| 3218 | if (!firstDomain) { |
| 3219 | listBuilder = listBuilder.append(","); |
| 3220 | } else { |
| 3221 | firstDomain = false; |
| 3222 | } |
| 3223 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3224 | } |
| 3225 | exclSpec = listBuilder.toString(); |
| 3226 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3227 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3228 | != android.net.Proxy.PROXY_VALID) |
| 3229 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3230 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3231 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3232 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3233 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3234 | } |
| 3235 | } |
| 3236 | return null; |
| 3237 | } |
| 3238 | |
| 3239 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3240 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3241 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3242 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3243 | * proxy is not accessible, you may break HTTP using this. |
| 3244 | * <p> |
| 3245 | * This method requires the caller to be the device owner. |
| 3246 | * <p> |
| 3247 | * 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] | 3248 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3249 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3251 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3252 | * {@code null} value will clear the global HTTP proxy. |
| 3253 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3254 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3255 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3256 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3257 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3258 | if (mService != null) { |
| 3259 | try { |
| 3260 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3261 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3262 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3263 | } |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3268 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3269 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3270 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3271 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3272 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3273 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3274 | if (mService != null) { |
| 3275 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3276 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3277 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3278 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3279 | } |
| 3280 | } |
| 3281 | return null; |
| 3282 | } |
| 3283 | |
| 3284 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3285 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3286 | * indicating that encryption is not supported. |
| 3287 | */ |
| 3288 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3289 | |
| 3290 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3291 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3292 | * indicating that encryption is supported, but is not currently active. |
| 3293 | */ |
| 3294 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3295 | |
| 3296 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3297 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3298 | * indicating that encryption is not currently active, but is currently |
| 3299 | * being activated. This is only reported by devices that support |
| 3300 | * encryption of data and only when the storage is currently |
| 3301 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3302 | * to become encrypted will never return this value. |
| 3303 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3304 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3305 | |
| 3306 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3307 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3308 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3309 | * <p> |
| 3310 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3311 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3312 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3313 | |
| 3314 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3315 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3316 | * indicating that encryption is active, but an encryption key has not |
| 3317 | * been set by the user. |
| 3318 | */ |
| 3319 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3320 | |
| 3321 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3322 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3323 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3324 | * <p> |
| 3325 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3326 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3327 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3328 | */ |
| 3329 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3330 | |
| 3331 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3332 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3333 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3334 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3335 | * to check encryption status. However, on some devices this activity may never return, as |
| 3336 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3337 | */ |
| 3338 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3339 | public static final String ACTION_START_ENCRYPTION |
| 3340 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3341 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3342 | * Widgets are enabled in keyguard |
| 3343 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3344 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3345 | |
| 3346 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3347 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3348 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3349 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3350 | |
| 3351 | /** |
| 3352 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3353 | */ |
| 3354 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3355 | |
| 3356 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3357 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3358 | */ |
| 3359 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3360 | |
| 3361 | /** |
| 3362 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3363 | */ |
| 3364 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3365 | |
| 3366 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3367 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3368 | * (e.g. PIN/Pattern/Password). |
| 3369 | */ |
| 3370 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3371 | |
| 3372 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3373 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3374 | */ |
| 3375 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3376 | |
| 3377 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3378 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3379 | */ |
| 3380 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3381 | |
| 3382 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3383 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3384 | */ |
| 3385 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3386 | |
| 3387 | /** |
Robin Lee | acdeac6 | 2017-02-21 22:13:38 +0000 | [diff] [blame] | 3388 | * Keyguard features that when set on a managed profile that doesn't have its own challenge will |
| 3389 | * affect the profile's parent user. These can also be set on the managed profile's parent |
| 3390 | * {@link DevicePolicyManager} instance. |
| 3391 | * |
| 3392 | * @hide |
| 3393 | */ |
| 3394 | public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER = |
| 3395 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS |
| 3396 | | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT; |
| 3397 | |
| 3398 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3399 | * Called by an application that is administering the device to request that the storage system |
| 3400 | * be encrypted. |
| 3401 | * <p> |
| 3402 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3403 | * supported setting will always be used. If any device administrator requests device |
| 3404 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3405 | * 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] | 3406 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3407 | * <p> |
| 3408 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3409 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3410 | * control the encryption of any other storage areas. There is one exception: If |
| 3411 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3412 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3413 | * written to disk within the encrypted storage area. |
| 3414 | * <p> |
| 3415 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3416 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3417 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3418 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3419 | * |
| 3420 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3421 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3422 | * @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] | 3423 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3424 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3425 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3426 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3427 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3429 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3430 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3431 | if (mService != null) { |
| 3432 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3433 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3434 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3435 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3436 | } |
| 3437 | } |
| 3438 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3443 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3444 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3445 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3446 | * this will return the requested encryption setting as an aggregate of all active |
| 3447 | * administrators. |
| 3448 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3449 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3450 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3451 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3452 | if (mService != null) { |
| 3453 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3454 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3455 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3456 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3457 | } |
| 3458 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3459 | return false; |
| 3460 | } |
| 3461 | |
| 3462 | /** |
| 3463 | * Called by an application that is administering the device to |
| 3464 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3465 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3466 | * Depending on the returned status code, the caller may proceed in different |
| 3467 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3468 | * storage system does not support encryption. If the |
| 3469 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3470 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3471 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3472 | * 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] | 3473 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3474 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3475 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3476 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3477 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3478 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3479 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3480 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3481 | */ |
| 3482 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3483 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3484 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | /** @hide per-user version */ |
| 3488 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3489 | if (mService != null) { |
| 3490 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3491 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3492 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3493 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3494 | } |
| 3495 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3496 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3497 | } |
| 3498 | |
| 3499 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3500 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3501 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3502 | * keep the certificate on the device. |
| 3503 | * |
| 3504 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3505 | * this certificate. |
| 3506 | * |
| 3507 | * @hide |
| 3508 | */ |
| 3509 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3510 | if (mService != null) { |
| 3511 | try { |
| 3512 | return mService.approveCaCert(alias, userHandle, approval); |
| 3513 | } catch (RemoteException e) { |
| 3514 | throw e.rethrowFromSystemServer(); |
| 3515 | } |
| 3516 | } |
| 3517 | return false; |
| 3518 | } |
| 3519 | |
| 3520 | /** |
| 3521 | * Check whether a CA certificate has been approved by the device user. |
| 3522 | * |
| 3523 | * @hide |
| 3524 | */ |
| 3525 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3526 | if (mService != null) { |
| 3527 | try { |
| 3528 | return mService.isCaCertApproved(alias, userHandle); |
| 3529 | } catch (RemoteException e) { |
| 3530 | throw e.rethrowFromSystemServer(); |
| 3531 | } |
| 3532 | } |
| 3533 | return false; |
| 3534 | } |
| 3535 | |
| 3536 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3537 | * Installs the given certificate as a user CA. |
| 3538 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3539 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3540 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3541 | * security exception will be thrown. |
| 3542 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3543 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3544 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3545 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3546 | * |
| 3547 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3548 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3549 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3550 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3551 | * @see #setDelegatedScopes |
| 3552 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3553 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3554 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3555 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3556 | if (mService != null) { |
| 3557 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3558 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3559 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3560 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | return false; |
| 3564 | } |
| 3565 | |
| 3566 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3567 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3568 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3569 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3570 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3571 | * security exception will be thrown. |
| 3572 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3573 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3574 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3575 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3576 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3577 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3578 | * @see #setDelegatedScopes |
| 3579 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3580 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3581 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3582 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3583 | if (mService != null) { |
| 3584 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3585 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3586 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3587 | } catch (CertificateException e) { |
| 3588 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3589 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3590 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3591 | } |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3596 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3597 | * If a user has installed any certificates by other means than device policy these will be |
| 3598 | * included too. |
| 3599 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3600 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3601 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3602 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3603 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3604 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3605 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3606 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3607 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3608 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3609 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3610 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3611 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3612 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3613 | for (String alias : certStore.userAliases()) { |
| 3614 | try { |
| 3615 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3616 | } catch (CertificateException ce) { |
| 3617 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3618 | } |
| 3619 | } |
| 3620 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3621 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3628 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3629 | * means other than device policy will also be removed, except for system CA certificates. |
| 3630 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3631 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3632 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3633 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3634 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3635 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3636 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3637 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3638 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3639 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3640 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3641 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3642 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3643 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3644 | } |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | /** |
| 3649 | * Returns whether this certificate is installed as a trusted CA. |
| 3650 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3651 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3652 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3653 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3654 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3655 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3656 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3657 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3658 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3659 | if (mService != null) { |
| 3660 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3661 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3662 | return getCaCertAlias(certBuffer) != null; |
| 3663 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3664 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3665 | } catch (CertificateException ce) { |
| 3666 | Log.w(TAG, "Could not parse certificate", ce); |
| 3667 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3668 | } |
| 3669 | return false; |
| 3670 | } |
| 3671 | |
| 3672 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3673 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3674 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3675 | * the certificate and use the private key, given direct user approval. |
| 3676 | * |
| 3677 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3678 | * direct user approval. This is for security - should a certificate installer become |
| 3679 | * compromised, certificates it had already installed will be protected. |
| 3680 | * |
| 3681 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3682 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3683 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3684 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3685 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3686 | * @param privKey The private key to install. |
| 3687 | * @param cert The certificate to install. |
| 3688 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3689 | * with that alias already exists, it will be overwritten. |
| 3690 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3691 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3692 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3693 | * @see #setDelegatedScopes |
| 3694 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3695 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3696 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3697 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3698 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | /** |
| 3702 | * 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] | 3703 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3704 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3705 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3706 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3707 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3708 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3709 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3710 | * |
| 3711 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3712 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3713 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3714 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3715 | * certificate and include the chain of trust in order. This will be returned by |
| 3716 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3717 | * @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] | 3718 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3719 | * @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] | 3720 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3721 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3722 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3723 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3724 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3725 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3726 | * @see #setDelegatedScopes |
| 3727 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3728 | */ |
| 3729 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3730 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3731 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3732 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3733 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3734 | byte[] pemChain = null; |
| 3735 | if (certs.length > 1) { |
| 3736 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3737 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3738 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3739 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3740 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3741 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3742 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3743 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3744 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3745 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3746 | } catch (CertificateException | IOException e) { |
| 3747 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3748 | } |
| 3749 | return false; |
| 3750 | } |
| 3751 | |
| 3752 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3753 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3754 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3755 | * |
| 3756 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3757 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3758 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3759 | * @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] | 3760 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3761 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3762 | * @see #setDelegatedScopes |
| 3763 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3764 | */ |
| 3765 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3766 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3767 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3768 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3769 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3770 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3771 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3775 | * @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] | 3776 | * doesn't exist. |
| 3777 | */ |
| 3778 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3779 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3780 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3781 | new ByteArrayInputStream(certBuffer)); |
| 3782 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3783 | } |
| 3784 | |
| 3785 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3786 | * 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] | 3787 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3788 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3789 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3790 | * <p> |
| 3791 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3792 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3793 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3794 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3795 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3796 | * 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] | 3797 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3798 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3799 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3800 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3801 | * @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] | 3802 | * access. If {@code null} is given the current package will be cleared. |
| 3803 | * @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] | 3804 | * |
| 3805 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3806 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3807 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3808 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3809 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3810 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3811 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3812 | if (mService != null) { |
| 3813 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3814 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3815 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3816 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3822 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3823 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3824 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3825 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3826 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3827 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3828 | * none is set. |
| 3829 | * @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] | 3830 | * |
| 3831 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3832 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3833 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3834 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3835 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3836 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3837 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3838 | if (mService != null) { |
| 3839 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3840 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3841 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3842 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | return null; |
| 3846 | } |
| 3847 | |
| 3848 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3849 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3850 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3851 | * constants. |
| 3852 | * <p> |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3853 | * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be |
| 3854 | * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra |
| 3855 | * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the |
| 3856 | * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag. |
| 3857 | * <p> |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3858 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3859 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3860 | * {@code delegatePackage}. |
| 3861 | * |
| 3862 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3863 | * @param delegatePackage The package name of the app which will be given access. |
| 3864 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3865 | * {@code delegatedPackage}. |
| 3866 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3867 | */ |
| 3868 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3869 | @NonNull List<String> scopes) { |
| 3870 | throwIfParentInstance("setDelegatedScopes"); |
| 3871 | if (mService != null) { |
| 3872 | try { |
| 3873 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3874 | } catch (RemoteException e) { |
| 3875 | throw e.rethrowFromSystemServer(); |
| 3876 | } |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | /** |
| 3881 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3882 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3883 | * passing {@code null} for {@code admin} and their own package name as |
| 3884 | * {@code delegatedPackage}. |
| 3885 | * |
| 3886 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3887 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3888 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3889 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3890 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3891 | */ |
| 3892 | @NonNull |
Edman Anjos | 9e62c31 | 2017-01-26 22:22:58 +0100 | [diff] [blame] | 3893 | public List<String> getDelegatedScopes(@Nullable ComponentName admin, |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3894 | @NonNull String delegatedPackage) { |
| 3895 | throwIfParentInstance("getDelegatedScopes"); |
| 3896 | if (mService != null) { |
| 3897 | try { |
| 3898 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3899 | } catch (RemoteException e) { |
| 3900 | throw e.rethrowFromSystemServer(); |
| 3901 | } |
| 3902 | } |
| 3903 | return null; |
| 3904 | } |
| 3905 | |
| 3906 | /** |
| 3907 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3908 | * granted a delegation scope. |
| 3909 | * |
| 3910 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3911 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3912 | * @return A list of package names of the current delegated packages for |
| 3913 | {@code delegationScope}. |
| 3914 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3915 | */ |
| 3916 | @Nullable |
| 3917 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3918 | @NonNull String delegationScope) { |
| 3919 | throwIfParentInstance("getDelegatePackages"); |
| 3920 | if (mService != null) { |
| 3921 | try { |
| 3922 | return mService.getDelegatePackages(admin, delegationScope); |
| 3923 | } catch (RemoteException e) { |
| 3924 | throw e.rethrowFromSystemServer(); |
| 3925 | } |
| 3926 | } |
| 3927 | return null; |
| 3928 | } |
| 3929 | |
| 3930 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3931 | * 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] | 3932 | * specific application for the current user. This connection is automatically granted and |
| 3933 | * persisted after a reboot. |
| 3934 | * <p> |
Charles He | 3673863 | 2017-05-15 17:07:18 +0100 | [diff] [blame] | 3935 | * To support the always-on feature, an app must |
| 3936 | * <ul> |
| 3937 | * <li>declare a {@link android.net.VpnService} in its manifest, guarded by |
| 3938 | * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li> |
| 3939 | * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li> |
| 3940 | * <li><i>not</i> explicitly opt out of the feature through |
| 3941 | * {@link android.net.VpnService#METADATA_SUPPORTS_ALWAYS_ON}.</li> |
| 3942 | * </ul> |
| 3943 | * The call will fail if called with the package name of an unsupported VPN app. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3944 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3945 | * @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] | 3946 | * remove an existing always-on VPN configuration. |
| 3947 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3948 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3949 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3950 | * @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] | 3951 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3952 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3953 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3954 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3955 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3956 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3957 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3958 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3959 | if (mService != null) { |
| 3960 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3961 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3962 | throw new NameNotFoundException(vpnPackage); |
| 3963 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3964 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3965 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3966 | } |
| 3967 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | /** |
| 3971 | * 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] | 3972 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3973 | * 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] | 3974 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3975 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3976 | * is set. |
| 3977 | * @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] | 3978 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3979 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3980 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3981 | if (mService != null) { |
| 3982 | try { |
| 3983 | return mService.getAlwaysOnVpnPackage(admin); |
| 3984 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3985 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | return null; |
| 3989 | } |
| 3990 | |
| 3991 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3992 | * Called by an application that is administering the device to disable all cameras on the |
| 3993 | * device, for this user. After setting this, no applications running as this user will be able |
| 3994 | * to access any cameras on the device. |
| 3995 | * <p> |
| 3996 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3997 | * <p> |
| 3998 | * The calling device admin must have requested |
| 3999 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 4000 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4001 | * |
| 4002 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4003 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4004 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4005 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4006 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4007 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4008 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4009 | if (mService != null) { |
| 4010 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4011 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4012 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4013 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4014 | } |
| 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4019 | * 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] | 4020 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4021 | * @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] | 4022 | * have disabled the camera |
| 4023 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4024 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4025 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4026 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4030 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4031 | if (mService != null) { |
| 4032 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4033 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4034 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4035 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | return false; |
| 4039 | } |
| 4040 | |
| 4041 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4042 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4043 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 4044 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 4045 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 4046 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4047 | * |
| 4048 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4049 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 4050 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 4051 | * 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] | 4052 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 4053 | * 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] | 4054 | */ |
| 4055 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4056 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4057 | if (mService != null) { |
| 4058 | try { |
| 4059 | return mService.requestBugreport(admin); |
| 4060 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4061 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 4062 | } |
| 4063 | } |
| 4064 | return false; |
| 4065 | } |
| 4066 | |
| 4067 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 4068 | * Determine whether or not creating a guest user has been disabled for the device |
| 4069 | * |
| 4070 | * @hide |
| 4071 | */ |
| 4072 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 4073 | // Currently guest users can always be created if multi-user is enabled |
| 4074 | // TODO introduce a policy for guest user creation |
| 4075 | return false; |
| 4076 | } |
| 4077 | |
| 4078 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 4079 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 4080 | * screen capture also prevents the content from being shown on display devices that do not have |
| 4081 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 4082 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4083 | * <p> |
| 4084 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4085 | * exception will be thrown. |
| 4086 | * <p> |
| 4087 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 4088 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 4089 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4090 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4091 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4092 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4093 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4094 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4095 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4096 | if (mService != null) { |
| 4097 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4098 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4099 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4100 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4101 | } |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4106 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4107 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4108 | * @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] | 4109 | * have disabled screen capture. |
| 4110 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4111 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4112 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4113 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4117 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4118 | if (mService != null) { |
| 4119 | try { |
| 4120 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 4121 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4122 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 4123 | } |
| 4124 | } |
| 4125 | return false; |
| 4126 | } |
| 4127 | |
| 4128 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4129 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 4130 | * 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] | 4131 | * <p> |
| 4132 | * Note: if auto time is required the user can still manually set the time zone. |
| 4133 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 4134 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 4135 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4136 | * |
| 4137 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4138 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4139 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4140 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4141 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4142 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4143 | if (mService != null) { |
| 4144 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4145 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4146 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4147 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4148 | } |
| 4149 | } |
| 4150 | } |
| 4151 | |
| 4152 | /** |
| 4153 | * @return true if auto time is required. |
| 4154 | */ |
| 4155 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4156 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4157 | if (mService != null) { |
| 4158 | try { |
| 4159 | return mService.getAutoTimeRequired(); |
| 4160 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4161 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | return false; |
| 4165 | } |
| 4166 | |
| 4167 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4168 | * 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] | 4169 | * <p> |
| 4170 | * The system user is exempt from this policy - it is never ephemeral. |
| 4171 | * <p> |
| 4172 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 4173 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4174 | * |
| 4175 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4176 | * @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] | 4177 | * subsequently created users will be ephemeral. |
| 4178 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4179 | * @hide |
| 4180 | */ |
| 4181 | public void setForceEphemeralUsers( |
| 4182 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4183 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4184 | if (mService != null) { |
| 4185 | try { |
| 4186 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 4187 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4188 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | /** |
| 4194 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4195 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4196 | * @hide |
| 4197 | */ |
| 4198 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4199 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4200 | if (mService != null) { |
| 4201 | try { |
| 4202 | return mService.getForceEphemeralUsers(admin); |
| 4203 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4204 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 4205 | } |
| 4206 | } |
| 4207 | return false; |
| 4208 | } |
| 4209 | |
| 4210 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4211 | * Called by an application that is administering the device to disable keyguard customizations, |
| 4212 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 4213 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4214 | * <p> |
| 4215 | * The calling device admin must have requested |
| 4216 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4217 | * if it has not, a security exception will be thrown. |
| 4218 | * <p> |
| 4219 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 4220 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 4221 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4222 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4223 | * <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] | 4224 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4225 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4226 | * there is one, or the parent user otherwise. |
| 4227 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4228 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4229 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4230 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4231 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4232 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4233 | * profile. |
| 4234 | * <p> |
| 4235 | * Requests to disable other features on a managed profile will be ignored. |
| 4236 | * <p> |
| 4237 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4238 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4239 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4240 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4241 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4242 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4243 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4244 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4245 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4246 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4247 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4248 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4249 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4250 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4251 | if (mService != null) { |
| 4252 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4253 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4254 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4255 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4256 | } |
| 4257 | } |
| 4258 | } |
| 4259 | |
| 4260 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4261 | * 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] | 4262 | * 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] | 4263 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4264 | * |
| 4265 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4266 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4267 | * restrictions on the parent profile. |
| 4268 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4269 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4270 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4271 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4272 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4273 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4274 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4275 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4279 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4280 | if (mService != null) { |
| 4281 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4282 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4283 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4284 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4285 | } |
| 4286 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4287 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4291 | * @hide |
| 4292 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4293 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4294 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4295 | if (mService != null) { |
| 4296 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4297 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4298 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4299 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4300 | } |
| 4301 | } |
| 4302 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4303 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4304 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4305 | * @hide |
| 4306 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4307 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4308 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4312 | * @hide |
| 4313 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4314 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4315 | if (mService != null) { |
| 4316 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4317 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4318 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4319 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4320 | } |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * @hide |
| 4326 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4327 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4328 | if (mService != null) { |
| 4329 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4330 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4331 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4332 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4333 | } |
| 4334 | } |
| 4335 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4336 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4337 | /** |
| 4338 | * @hide |
| 4339 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4340 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4341 | if (mService != null) { |
| 4342 | try { |
| 4343 | mService.reportPasswordChanged(userId); |
| 4344 | } catch (RemoteException e) { |
| 4345 | throw e.rethrowFromSystemServer(); |
| 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | /** |
| 4351 | * @hide |
| 4352 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4353 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4354 | if (mService != null) { |
| 4355 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4356 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4357 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4358 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4359 | } |
| 4360 | } |
| 4361 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4362 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4363 | /** |
| 4364 | * @hide |
| 4365 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4366 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4367 | if (mService != null) { |
| 4368 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4369 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4370 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4371 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4372 | } |
| 4373 | } |
| 4374 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4375 | |
| 4376 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4377 | * @hide |
| 4378 | */ |
| 4379 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4380 | if (mService != null) { |
| 4381 | try { |
| 4382 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4383 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4384 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4385 | } |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * @hide |
| 4391 | */ |
| 4392 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4393 | if (mService != null) { |
| 4394 | try { |
| 4395 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4396 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4397 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4398 | } |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4403 | * Should be called when keyguard has been dismissed. |
| 4404 | * @hide |
| 4405 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4406 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4407 | if (mService != null) { |
| 4408 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4409 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4410 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4411 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | /** |
| 4417 | * Should be called when keyguard view has been shown to the user. |
| 4418 | * @hide |
| 4419 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4420 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4421 | if (mService != null) { |
| 4422 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4423 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4424 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4425 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4431 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4432 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4433 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4434 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4435 | * @return whether the package was successfully registered as the device owner. |
| 4436 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4437 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4438 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4439 | public boolean setDeviceOwner(ComponentName who) { |
| 4440 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | /** |
| 4444 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4445 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4446 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4447 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | /** |
| 4451 | * @hide |
| 4452 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4453 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4454 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | /** |
| 4458 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4459 | * Sets the given package as the device owner. The package must already be installed. There |
| 4460 | * must not already be a device owner. |
| 4461 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4462 | * this method. |
| 4463 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4464 | * 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] | 4465 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4466 | * @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] | 4467 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4468 | * @return whether the package was successfully registered as the device owner. |
| 4469 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4470 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4471 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4472 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4473 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4474 | if (mService != null) { |
| 4475 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4476 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4477 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4478 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4479 | } |
| 4480 | } |
| 4481 | return false; |
| 4482 | } |
| 4483 | |
| 4484 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4485 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4486 | * 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] | 4487 | * 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] | 4488 | * package is currently registered as the device owner app, pass in the package name from |
| 4489 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4490 | * 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] | 4491 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4492 | * the setup process. |
| 4493 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4494 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4495 | * @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] | 4496 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4497 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4498 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4499 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4500 | } |
| 4501 | |
| 4502 | /** |
| 4503 | * @return true if a package is registered as device owner, only when it's running on the |
| 4504 | * calling user. |
| 4505 | * |
| 4506 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4507 | * @hide |
| 4508 | */ |
| 4509 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4510 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4511 | } |
| 4512 | |
| 4513 | /** |
| 4514 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4515 | * user. |
| 4516 | * |
| 4517 | * <p>Requires the MANAGE_USERS permission. |
| 4518 | * |
| 4519 | * @hide |
| 4520 | */ |
| 4521 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4522 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4523 | } |
| 4524 | |
| 4525 | /** |
| 4526 | * @return device owner component name, only when it's running on the calling user. |
| 4527 | * |
| 4528 | * @hide |
| 4529 | */ |
| 4530 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4531 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4532 | } |
| 4533 | |
| 4534 | /** |
| 4535 | * @return device owner component name, even if it's running on a different user. |
| 4536 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4537 | * @hide |
| 4538 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4539 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4540 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4541 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4542 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4543 | } |
| 4544 | |
| 4545 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4546 | if (packageName == null) { |
| 4547 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4548 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4549 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4550 | if (deviceOwner == null) { |
| 4551 | return false; |
| 4552 | } |
| 4553 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4554 | } |
| 4555 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4556 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4557 | if (mService != null) { |
| 4558 | try { |
| 4559 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4560 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4561 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4565 | } |
| 4566 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4567 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4568 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4569 | * no device owner. |
| 4570 | * |
| 4571 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4572 | * |
| 4573 | * @hide |
| 4574 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4575 | public int getDeviceOwnerUserId() { |
| 4576 | if (mService != null) { |
| 4577 | try { |
| 4578 | return mService.getDeviceOwnerUserId(); |
| 4579 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4580 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4581 | } |
| 4582 | } |
| 4583 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4587 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4588 | * 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] | 4589 | * a part of device setup, before it completes. |
| 4590 | * <p> |
| 4591 | * While some policies previously set by the device owner will be cleared by this method, it is |
| 4592 | * a best-effort process and some other policies will still remain in place after the device |
| 4593 | * owner is cleared. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4594 | * |
| 4595 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4596 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4597 | * does not own the current device owner component. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4598 | * |
| 4599 | * @deprecated This method is expected to be used for testing purposes only. The device owner |
| 4600 | * will lose control of the device and its data after calling it. In order to protect any |
| 4601 | * sensitive data that remains on the device, it is advised that the device owner factory resets |
| 4602 | * the device instead of calling this method. See {@link #wipeData(int)}. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4603 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4604 | @Deprecated |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4605 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4606 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4607 | if (mService != null) { |
| 4608 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4609 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4610 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4611 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4612 | } |
| 4613 | } |
| 4614 | } |
| 4615 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4616 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4617 | * Returns the device owner package name, only if it's running on the calling user. |
| 4618 | * |
| 4619 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4620 | * |
| 4621 | * @hide |
| 4622 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4623 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4624 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4625 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4626 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4627 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4628 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4632 | * 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] | 4633 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4634 | * @return whether the device is managed by a Device Owner. |
| 4635 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4636 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4637 | * |
| 4638 | * @hide |
| 4639 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4640 | @SystemApi |
| 4641 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4642 | @SuppressLint("Doclava125") |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4643 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4644 | try { |
| 4645 | return mService.hasDeviceOwner(); |
| 4646 | } catch (RemoteException re) { |
| 4647 | throw re.rethrowFromSystemServer(); |
| 4648 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | /** |
| 4652 | * Returns the device owner name. Note this method *will* return the device owner |
| 4653 | * name when it's running on a different user. |
| 4654 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4655 | * @hide |
| 4656 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4657 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 4658 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4659 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4660 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4661 | if (mService != null) { |
| 4662 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4663 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4664 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4665 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | return null; |
| 4669 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4670 | |
| 4671 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4672 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4673 | * @deprecated Do not use |
| 4674 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4675 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4676 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4677 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4678 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4679 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4680 | return null; |
| 4681 | } |
| 4682 | |
| 4683 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4684 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4685 | * @deprecated Do not use |
| 4686 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4687 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4688 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4689 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4690 | @SuppressLint("Doclava125") |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4691 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4692 | return null; |
| 4693 | } |
| 4694 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4695 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4696 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4697 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4698 | * Sets the given component as an active admin and registers the package as the profile |
| 4699 | * owner for this user. The package must already be installed and there shouldn't be |
| 4700 | * an existing profile owner registered for this user. Also, this method must be called |
| 4701 | * before the user setup has been completed. |
| 4702 | * <p> |
| 4703 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4704 | * MANAGE_DEVICE_ADMINS permission. |
| 4705 | * @param admin The component to register as an active admin and profile owner. |
| 4706 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4707 | * @return whether the admin was successfully registered as the profile owner. |
| 4708 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4709 | * the user has already been set up. |
| 4710 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4711 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4712 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4713 | @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4714 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4715 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4716 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4717 | if (mService != null) { |
| 4718 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4719 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4720 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4721 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4722 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4723 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4724 | } |
| 4725 | } |
| 4726 | return false; |
| 4727 | } |
| 4728 | |
| 4729 | /** |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4730 | * Clears the active profile owner. The caller must be the profile owner of this user, otherwise |
| 4731 | * 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] | 4732 | * <p> |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4733 | * While some policies previously set by the profile owner will be cleared by this method, it is |
| 4734 | * a best-effort process and some other policies will still remain in place after the profile |
| 4735 | * owner is cleared. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4736 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4737 | * @param admin The component to remove as the profile owner. |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4738 | * @throws SecurityException if {@code admin} is not an active profile owner, or the method is |
| 4739 | * being called from a managed profile. |
| 4740 | * |
| 4741 | * @deprecated This method is expected to be used for testing purposes only. The profile owner |
| 4742 | * will lose control of the user and its data after calling it. In order to protect any |
| 4743 | * sensitive data that remains on this user, it is advised that the profile owner deletes it |
| 4744 | * instead of calling this method. See {@link #wipeData(int)}. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4745 | */ |
Esteban Talavera | a5b0963 | 2017-02-10 16:15:24 +0000 | [diff] [blame] | 4746 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4747 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4748 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4749 | if (mService != null) { |
| 4750 | try { |
| 4751 | mService.clearProfileOwner(admin); |
| 4752 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4753 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4754 | } |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4759 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4760 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4761 | */ |
| 4762 | public boolean hasUserSetupCompleted() { |
| 4763 | if (mService != null) { |
| 4764 | try { |
| 4765 | return mService.hasUserSetupCompleted(); |
| 4766 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4767 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4768 | } |
| 4769 | } |
| 4770 | return true; |
| 4771 | } |
| 4772 | |
| 4773 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4774 | * @hide |
| 4775 | * 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] | 4776 | * already be installed. There must not already be a profile owner for this user. |
| 4777 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4778 | * this method. |
| 4779 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4780 | * - the caller is SYSTEM_UID. |
| 4781 | * - 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] | 4782 | * @param admin the component name to be registered as profile owner. |
| 4783 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4784 | * @param userHandle the userId to set the profile owner for. |
| 4785 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4786 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4787 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4788 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4789 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4790 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4791 | if (mService != null) { |
| 4792 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4793 | if (ownerName == null) { |
| 4794 | ownerName = ""; |
| 4795 | } |
| 4796 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4797 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4798 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | return false; |
| 4802 | } |
| 4803 | |
| 4804 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4805 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4806 | * <p> |
| 4807 | * 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] | 4808 | * 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] | 4809 | * <p> |
| 4810 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4811 | * will be blank and the user will not be allowed to change it. |
| 4812 | * <p> |
| 4813 | * 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] | 4814 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4815 | * and set a new version of this string accordingly. |
| 4816 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4817 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4818 | * @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] | 4819 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4820 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4821 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4822 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4823 | if (mService != null) { |
| 4824 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4825 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4826 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4827 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4828 | } |
| 4829 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | /** |
| 4833 | * @return The device owner information. If it is not set returns {@code null}. |
| 4834 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4835 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4836 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4837 | if (mService != null) { |
| 4838 | try { |
| 4839 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4840 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4841 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4842 | } |
| 4843 | } |
| 4844 | return null; |
| 4845 | } |
| 4846 | |
| 4847 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4848 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4849 | * called by a device owner, profile owner, or by a delegate given the |
| 4850 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4851 | * <p> |
| 4852 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4853 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4854 | * device. |
| 4855 | * <p> |
| 4856 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4857 | * 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] | 4858 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4859 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4860 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4861 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4862 | * @param packageNames The package names to suspend or unsuspend. |
| 4863 | * @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] | 4864 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4865 | * @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] | 4866 | * this method. |
| 4867 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4868 | * @see #setDelegatedScopes |
| 4869 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4870 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4871 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4872 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4873 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4874 | if (mService != null) { |
| 4875 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4876 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4877 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4878 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4879 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4880 | } |
| 4881 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4882 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4886 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4887 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4888 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4889 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4890 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4891 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4892 | * @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] | 4893 | * @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] | 4894 | * suspended, could not be found or an error occurred. |
| 4895 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4896 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4897 | * @see #setDelegatedScopes |
| 4898 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4899 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4900 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4901 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4902 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4903 | if (mService != null) { |
| 4904 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 4905 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4906 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4907 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4908 | } catch (IllegalArgumentException ex) { |
| 4909 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4910 | } |
| 4911 | } |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
| 4915 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4916 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4917 | * be used. Only the profile owner can call this. |
| 4918 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4919 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4920 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4921 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4922 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4923 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4924 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4925 | if (mService != null) { |
| 4926 | try { |
| 4927 | mService.setProfileEnabled(admin); |
| 4928 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4929 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4930 | } |
| 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4935 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4936 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4937 | * 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] | 4938 | * |
| 4939 | * @see #isProfileOwnerApp |
| 4940 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4941 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4942 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4943 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4944 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4945 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4946 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4947 | if (mService != null) { |
| 4948 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4949 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4950 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4951 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4952 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4953 | } |
| 4954 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4955 | |
| 4956 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4957 | * 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] | 4958 | * 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] | 4959 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4960 | * |
| 4961 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4962 | * @return Whether or not the package is registered as the profile owner. |
| 4963 | */ |
| 4964 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4965 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4966 | if (mService != null) { |
| 4967 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4968 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4969 | return profileOwner != null |
| 4970 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4971 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4972 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4973 | } |
| 4974 | } |
| 4975 | return false; |
| 4976 | } |
| 4977 | |
| 4978 | /** |
| 4979 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4980 | * @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] | 4981 | * owner has been set for that user. |
| 4982 | * @throws IllegalArgumentException if the userId is invalid. |
| 4983 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4984 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4985 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4986 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4987 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4988 | } |
| 4989 | |
| 4990 | /** |
| 4991 | * @see #getProfileOwner() |
| 4992 | * @hide |
| 4993 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4994 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4995 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4996 | if (mService != null) { |
| 4997 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4998 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4999 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5000 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5001 | } |
| 5002 | } |
| 5003 | return null; |
| 5004 | } |
| 5005 | |
| 5006 | /** |
| 5007 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5008 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 5009 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5010 | * @throws IllegalArgumentException if the userId is invalid. |
| 5011 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5012 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5013 | if (mService != null) { |
| 5014 | try { |
| 5015 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 5016 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5017 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 5018 | } |
| 5019 | } |
| 5020 | return null; |
| 5021 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5022 | |
| 5023 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5024 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 5025 | * @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] | 5026 | * @return the human readable name of the organisation associated with this profile owner or |
| 5027 | * null if one is not set. |
| 5028 | * @throws IllegalArgumentException if the userId is invalid. |
| 5029 | */ |
| 5030 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 5031 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5032 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5033 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5034 | if (mService != null) { |
| 5035 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 5036 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5037 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5038 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 5039 | } |
| 5040 | } |
| 5041 | return null; |
| 5042 | } |
| 5043 | |
| 5044 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5045 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 5046 | * 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] | 5047 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 5048 | * intent preferences are reset. |
| 5049 | * <p> |
| 5050 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 5051 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 5052 | * the filter. |
| 5053 | * <p> |
| 5054 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 5055 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5056 | * |
| 5057 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5058 | * @param filter The IntentFilter for which a default handler is added. |
| 5059 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5060 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5061 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5062 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 5063 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5064 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5065 | if (mService != null) { |
| 5066 | try { |
| 5067 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 5068 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5069 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | /** |
| 5075 | * 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] | 5076 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5077 | * <p> |
| 5078 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5079 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5080 | * |
| 5081 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5082 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5083 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5084 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5085 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5086 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5087 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5088 | if (mService != null) { |
| 5089 | try { |
| 5090 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 5091 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5092 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5096 | |
| 5097 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5098 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 5099 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 5100 | * {@link #getApplicationRestrictions}. |
| 5101 | * <p> |
| 5102 | * This permission is persistent until it is later cleared by calling this method with a |
| 5103 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 5104 | * <p> |
| 5105 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5106 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5107 | * |
| 5108 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5109 | * @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] | 5110 | * APIs. If {@code null} is given the current package will be cleared. |
| 5111 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5112 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5113 | * |
| 5114 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 5115 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5116 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5117 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5118 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5119 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5120 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5121 | if (mService != null) { |
| 5122 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 5123 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 5124 | throw new NameNotFoundException(packageName); |
| 5125 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5126 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5127 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5128 | } |
| 5129 | } |
| 5130 | } |
| 5131 | |
| 5132 | /** |
| 5133 | * 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] | 5134 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 5135 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5136 | * |
| 5137 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5138 | * @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] | 5139 | * {@code null} if none is set. |
| 5140 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5141 | * |
| 5142 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 5143 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5144 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5145 | @Deprecated |
| 5146 | @Nullable |
| 5147 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5148 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5149 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5150 | if (mService != null) { |
| 5151 | try { |
| 5152 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 5153 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5154 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5155 | } |
| 5156 | } |
| 5157 | return null; |
| 5158 | } |
| 5159 | |
| 5160 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 5161 | * Called by any application to find out whether it has been granted permission via |
| 5162 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 5163 | * for the calling user. |
| 5164 | * |
| 5165 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 5166 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5167 | * |
| 5168 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 5169 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5170 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5171 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5172 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5173 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5174 | if (mService != null) { |
| 5175 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5176 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 5177 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5178 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5179 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5180 | } |
| 5181 | } |
| 5182 | return false; |
| 5183 | } |
| 5184 | |
| 5185 | /** |
| 5186 | * 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] | 5187 | * <p> |
| 5188 | * 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] | 5189 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5190 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5191 | * <p> |
| 5192 | * 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] | 5193 | * <ul> |
| 5194 | * <li>{@code boolean} |
| 5195 | * <li>{@code int} |
| 5196 | * <li>{@code String} or {@code String[]} |
| 5197 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 5198 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5199 | * <p> |
| 5200 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 5201 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5202 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5203 | * <p> |
| 5204 | * The application restrictions are only made visible to the target application via |
| 5205 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 5206 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5207 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5208 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5209 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5210 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5211 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5212 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5213 | * @param packageName The name of the package to update restricted settings for. |
| 5214 | * @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] | 5215 | * set of active restrictions. |
| 5216 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5217 | * @see #setDelegatedScopes |
| 5218 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 5219 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5220 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5221 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5222 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5223 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5224 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5225 | if (mService != null) { |
| 5226 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5227 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 5228 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5229 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5230 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | } |
| 5234 | |
| 5235 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5236 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 5237 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 5238 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5239 | * {@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] | 5240 | * <p> |
| 5241 | * The calling device admin must have requested |
| 5242 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 5243 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5244 | * <p> |
| 5245 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5246 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5247 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5248 | * |
| 5249 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5250 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5251 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5252 | * strictly disabled according to the state of the |
| 5253 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5254 | * <p> |
| 5255 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5256 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5257 | * device admins. |
| 5258 | * <p> |
| 5259 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5260 | * parameters. |
| 5261 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5262 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5263 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5264 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5265 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5266 | if (mService != null) { |
| 5267 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5268 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5269 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5270 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5271 | } |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5276 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5277 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5278 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5279 | * <p> |
| 5280 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5281 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5282 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5283 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5284 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5285 | * this function returns a list of configurations for all admins that declare |
| 5286 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5287 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5288 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5289 | * 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] | 5290 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5291 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5292 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5293 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5294 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5295 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5299 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5300 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5301 | if (mService != null) { |
| 5302 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5303 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5304 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5305 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5306 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5307 | } |
| 5308 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5309 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5313 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5314 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5315 | * <p> |
| 5316 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5317 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5318 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5319 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5320 | * @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] | 5321 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5322 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5323 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5324 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5325 | if (mService != null) { |
| 5326 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5327 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5328 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5329 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5330 | } |
| 5331 | } |
| 5332 | } |
| 5333 | |
| 5334 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5335 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5336 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5337 | * <p> |
| 5338 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5339 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5340 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5341 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5342 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5343 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5344 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5345 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5346 | if (mService != null) { |
| 5347 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5348 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5349 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5350 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5357 | * Determine whether or not caller-Id information has been disabled. |
| 5358 | * |
| 5359 | * @param userHandle The user for whom to check the caller-id permission |
| 5360 | * @hide |
| 5361 | */ |
| 5362 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5363 | if (mService != null) { |
| 5364 | try { |
| 5365 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5366 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5367 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5368 | } |
| 5369 | } |
| 5370 | return false; |
| 5371 | } |
| 5372 | |
| 5373 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5374 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5375 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5376 | * <p> |
| 5377 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5378 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5379 | * |
| 5380 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5381 | * @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] | 5382 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5383 | */ |
| 5384 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5385 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5386 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5387 | if (mService != null) { |
| 5388 | try { |
| 5389 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5390 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5391 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5392 | } |
| 5393 | } |
| 5394 | } |
| 5395 | |
| 5396 | /** |
| 5397 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5398 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5399 | * <p> |
| 5400 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5401 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5402 | * |
| 5403 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5404 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5405 | */ |
| 5406 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5407 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5408 | if (mService != null) { |
| 5409 | try { |
| 5410 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 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 | |
| 5419 | /** |
| 5420 | * Determine whether or not contacts search has been disabled. |
| 5421 | * |
| 5422 | * @param userHandle The user for whom to check the contacts search permission |
| 5423 | * @hide |
| 5424 | */ |
| 5425 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5426 | if (mService != null) { |
| 5427 | try { |
| 5428 | return mService |
| 5429 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5430 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5431 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5432 | } |
| 5433 | } |
| 5434 | return false; |
| 5435 | } |
| 5436 | |
| 5437 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5438 | * 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] | 5439 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5440 | * @hide |
| 5441 | */ |
| 5442 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5443 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5444 | if (mService != null) { |
| 5445 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5446 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5447 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5448 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5449 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5450 | } |
| 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5455 | * 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] | 5456 | * @hide |
| 5457 | */ |
| 5458 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5459 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5460 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5461 | originalIntent); |
| 5462 | } |
| 5463 | |
| 5464 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5465 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5466 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5467 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5468 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5469 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5470 | * <p> |
| 5471 | * This API works on managed profile only. |
| 5472 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5473 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5474 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5475 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5476 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5477 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5478 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5479 | if (mService != null) { |
| 5480 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5481 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5482 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5483 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5484 | } |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5489 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5490 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5491 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5492 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5493 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5494 | * <p> |
| 5495 | * This API works on managed profile only. |
| 5496 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5497 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5498 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5499 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5500 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5501 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5502 | if (mService != null) { |
| 5503 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5504 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5505 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5506 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5507 | } |
| 5508 | } |
| 5509 | return true; |
| 5510 | } |
| 5511 | |
| 5512 | /** |
| 5513 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5514 | * <p> |
| 5515 | * This API works on managed profile UserHandle only. |
| 5516 | * |
| 5517 | * @param userHandle The user for whom to check the caller-id permission |
| 5518 | * @hide |
| 5519 | */ |
| 5520 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5521 | if (mService != null) { |
| 5522 | try { |
| 5523 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5524 | .getIdentifier()); |
| 5525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5526 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5527 | } |
| 5528 | } |
| 5529 | return true; |
| 5530 | } |
| 5531 | |
| 5532 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5533 | * 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] | 5534 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5535 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5536 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5537 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5538 | * @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] | 5539 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5540 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5541 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 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 addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5545 | throwIfParentInstance("addCrossProfileIntentFilter"); |
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.addCrossProfileIntentFilter(admin, filter, flags); |
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 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5556 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5557 | * 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] | 5558 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5559 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5560 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5561 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5562 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5563 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5564 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5565 | if (mService != null) { |
| 5566 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5567 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5568 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5569 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5570 | } |
| 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5575 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5576 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5577 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5578 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5579 | * the list and not part of the system can not be enabled by the user. |
| 5580 | * <p> |
| 5581 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5582 | * used, calling with an empty list only allows the builtin system's services. |
| 5583 | * <p> |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5584 | * 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] | 5585 | * |
| 5586 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5587 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5588 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5589 | * accessibility services enabled, that are not in the list. |
| 5590 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5591 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5592 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5593 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5594 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5595 | if (mService != null) { |
| 5596 | try { |
| 5597 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5598 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5599 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5600 | } |
| 5601 | } |
| 5602 | return false; |
| 5603 | } |
| 5604 | |
| 5605 | /** |
| 5606 | * 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] | 5607 | * <p> |
| 5608 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5609 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5610 | * |
| 5611 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5612 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5613 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5614 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5615 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5616 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5617 | if (mService != null) { |
| 5618 | try { |
| 5619 | return mService.getPermittedAccessibilityServices(admin); |
| 5620 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5621 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5622 | } |
| 5623 | } |
| 5624 | return null; |
| 5625 | } |
| 5626 | |
| 5627 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5628 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5629 | * |
| 5630 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5631 | * @param packageName Accessibility service package name that needs to be checked. |
| 5632 | * @param userHandle user id the admin is running as. |
| 5633 | * @return true if the accessibility service is permitted, otherwise false. |
| 5634 | * |
| 5635 | * @hide |
| 5636 | */ |
| 5637 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5638 | @NonNull String packageName, int userHandle) { |
| 5639 | if (mService != null) { |
| 5640 | try { |
| 5641 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5642 | userHandle); |
| 5643 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5644 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5645 | } |
| 5646 | } |
| 5647 | return false; |
| 5648 | } |
| 5649 | |
| 5650 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5651 | * Returns the list of accessibility services permitted by the device or profiles |
| 5652 | * owners of this user. |
| 5653 | * |
| 5654 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5655 | * it will contain the intersection of the permitted lists for any device or profile |
| 5656 | * owners that apply to this user. It will also include any system accessibility services. |
| 5657 | * |
| 5658 | * @param userId which user to check for. |
| 5659 | * @return List of accessiblity service package names. |
| 5660 | * @hide |
| 5661 | */ |
| 5662 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5663 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5664 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5665 | if (mService != null) { |
| 5666 | try { |
| 5667 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5668 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5669 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | return null; |
| 5673 | } |
| 5674 | |
| 5675 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5676 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5677 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5678 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5679 | * When zero or more packages have been added, input method that are not in the list and not |
| 5680 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5681 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5682 | * <p> |
| 5683 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5684 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5685 | * <p> |
| 5686 | * 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] | 5687 | * |
| 5688 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5689 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5690 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5691 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5692 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5693 | */ |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5694 | public boolean setPermittedInputMethods( |
| 5695 | @NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5696 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5697 | if (mService != null) { |
| 5698 | try { |
| 5699 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5700 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5701 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5702 | } |
| 5703 | } |
| 5704 | return false; |
| 5705 | } |
| 5706 | |
| 5707 | |
| 5708 | /** |
| 5709 | * 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] | 5710 | * <p> |
| 5711 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5712 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5713 | * |
| 5714 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5715 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5716 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5717 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5718 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5719 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5720 | if (mService != null) { |
| 5721 | try { |
| 5722 | return mService.getPermittedInputMethods(admin); |
| 5723 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5724 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5725 | } |
| 5726 | } |
| 5727 | return null; |
| 5728 | } |
| 5729 | |
| 5730 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5731 | * Called by the system to check if a specific input method is disabled by admin. |
| 5732 | * |
| 5733 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5734 | * @param packageName Input method package name that needs to be checked. |
| 5735 | * @param userHandle user id the admin is running as. |
| 5736 | * @return true if the input method is permitted, otherwise false. |
| 5737 | * |
| 5738 | * @hide |
| 5739 | */ |
| 5740 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5741 | @NonNull String packageName, int userHandle) { |
| 5742 | if (mService != null) { |
| 5743 | try { |
| 5744 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5745 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5746 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5747 | } |
| 5748 | } |
| 5749 | return false; |
| 5750 | } |
| 5751 | |
| 5752 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5753 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5754 | * 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] | 5755 | * |
| 5756 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5757 | * it will contain the intersection of the permitted lists for any device or profile |
| 5758 | * owners that apply to this user. It will also include any system input methods. |
| 5759 | * |
| 5760 | * @return List of input method package names. |
| 5761 | * @hide |
| 5762 | */ |
| 5763 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5764 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5765 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5766 | if (mService != null) { |
| 5767 | try { |
| 5768 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5769 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5770 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5771 | } |
| 5772 | } |
| 5773 | return null; |
| 5774 | } |
| 5775 | |
| 5776 | /** |
Esteban Talavera | 7e4cbad | 2017-03-30 17:59:50 +0100 | [diff] [blame] | 5777 | * Called by a profile owner of a managed profile to set the packages that are allowed to use |
| 5778 | * a {@link android.service.notification.NotificationListenerService} in the primary user to |
| 5779 | * see notifications from the managed profile. By default all packages are permitted by this |
| 5780 | * policy. When zero or more packages have been added, notification listeners installed on the |
| 5781 | * primary user that are not in the list and are not part of the system won't receive events |
| 5782 | * for managed profile notifications. |
| 5783 | * <p> |
| 5784 | * Calling with a {@code null} value for the list disables the restriction so that all |
| 5785 | * notification listener services be used. Calling with an empty list disables all but the |
| 5786 | * system's own notification listeners. System notification listener services are always |
| 5787 | * available to the user. |
| 5788 | * <p> |
| 5789 | * If a device or profile owner want to stop notification listeners in their user from seeing |
| 5790 | * that user's notifications they should prevent that service from running instead (e.g. via |
| 5791 | * {@link #setApplicationHidden(ComponentName, String, boolean)}) |
| 5792 | * |
| 5793 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5794 | * @param packageList List of package names to whitelist |
| 5795 | * @return true if setting the restriction succeeded. It will fail if called outside a managed |
| 5796 | * profile |
| 5797 | * @throws SecurityException if {@code admin} is not a profile owner. |
| 5798 | * |
| 5799 | * @see android.service.notification.NotificationListenerService |
| 5800 | */ |
| 5801 | public boolean setPermittedCrossProfileNotificationListeners( |
| 5802 | @NonNull ComponentName admin, @Nullable List<String> packageList) { |
| 5803 | throwIfParentInstance("setPermittedCrossProfileNotificationListeners"); |
| 5804 | if (mService != null) { |
| 5805 | try { |
| 5806 | return mService.setPermittedCrossProfileNotificationListeners(admin, packageList); |
| 5807 | } catch (RemoteException e) { |
| 5808 | throw e.rethrowFromSystemServer(); |
| 5809 | } |
| 5810 | } |
| 5811 | return false; |
| 5812 | } |
| 5813 | |
| 5814 | /** |
| 5815 | * Returns the list of packages installed on the primary user that allowed to use a |
| 5816 | * {@link android.service.notification.NotificationListenerService} to receive |
| 5817 | * notifications from this managed profile, as set by the profile owner. |
| 5818 | * <p> |
| 5819 | * An empty list means no notification listener services except system ones are allowed. |
| 5820 | * A {@code null} return value indicates that all notification listeners are allowed. |
| 5821 | */ |
| 5822 | public @Nullable List<String> getPermittedCrossProfileNotificationListeners( |
| 5823 | @NonNull ComponentName admin) { |
| 5824 | throwIfParentInstance("getPermittedCrossProfileNotificationListeners"); |
| 5825 | if (mService != null) { |
| 5826 | try { |
| 5827 | return mService.getPermittedCrossProfileNotificationListeners(admin); |
| 5828 | } catch (RemoteException e) { |
| 5829 | throw e.rethrowFromSystemServer(); |
| 5830 | } |
| 5831 | } |
| 5832 | return null; |
| 5833 | } |
| 5834 | |
| 5835 | /** |
| 5836 | * Returns true if {@code NotificationListenerServices} from the given package are allowed to |
| 5837 | * receive events for notifications from the given user id. Can only be called by the system uid |
| 5838 | * |
| 5839 | * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List) |
| 5840 | * |
| 5841 | * @hide |
| 5842 | */ |
| 5843 | public boolean isNotificationListenerServicePermitted( |
| 5844 | @NonNull String packageName, @UserIdInt int userId) { |
| 5845 | if (mService != null) { |
| 5846 | try { |
| 5847 | return mService.isNotificationListenerServicePermitted(packageName, userId); |
| 5848 | } catch (RemoteException e) { |
| 5849 | throw e.rethrowFromSystemServer(); |
| 5850 | } |
| 5851 | } |
| 5852 | return true; |
| 5853 | } |
| 5854 | |
| 5855 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5856 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5857 | * function can be called by a device owner or by a delegate given the |
| 5858 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5859 | * <p> |
| 5860 | * 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] | 5861 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5862 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5863 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5864 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5865 | * @see #setDelegatedScopes |
| 5866 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5867 | * @hide |
| 5868 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5869 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5870 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5871 | if (mService != null) { |
| 5872 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5873 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5874 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5875 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5876 | } |
| 5877 | } |
| 5878 | return null; |
| 5879 | } |
| 5880 | |
| 5881 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5882 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5883 | * function can be called by a device owner or by a delegate given the |
| 5884 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5885 | * |
| 5886 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5887 | * automatically pre-cached.</p> |
| 5888 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5889 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5890 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5891 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5892 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5893 | * @see #setDelegatedScopes |
| 5894 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5895 | * @hide |
| 5896 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5897 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5898 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5899 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5900 | if (mService != null) { |
| 5901 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 5902 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5903 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5904 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5905 | } |
| 5906 | } |
| 5907 | } |
| 5908 | |
| 5909 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5910 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5911 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5912 | * created. If you need to persist an identifier for this user, use |
| 5913 | * {@link UserManager#getSerialNumberForUser}. |
| 5914 | * |
| 5915 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5916 | * @param name the user's name |
| 5917 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5918 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5919 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5920 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5921 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5922 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5923 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5924 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5925 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5926 | return null; |
| 5927 | } |
| 5928 | |
| 5929 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5930 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5931 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5932 | * created. If you need to persist an identifier for this user, use |
| 5933 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5934 | * immediately. |
| 5935 | * |
| 5936 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5937 | * as registered as an active admin on the new user. The profile owner package will be |
| 5938 | * installed on the new user if it already is installed on the device. |
| 5939 | * |
| 5940 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5941 | * profileOwnerComponent when onEnable is called. |
| 5942 | * |
| 5943 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5944 | * @param name the user's name |
| 5945 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5946 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5947 | * the user. |
| 5948 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5949 | * on the new user. |
| 5950 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5951 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5952 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5953 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5954 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5955 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5956 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5957 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5958 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5959 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5960 | return null; |
| 5961 | } |
| 5962 | |
| 5963 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5964 | * 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] | 5965 | */ |
| 5966 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5967 | |
| 5968 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5969 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5970 | * ephemeral. |
| 5971 | * @hide |
| 5972 | */ |
| 5973 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5974 | |
| 5975 | /** |
Christine Franks | 361b825 | 2017-06-23 18:12:46 -0700 | [diff] [blame] | 5976 | * Flag used by {@link #createAndManageUser} to specify that the user should be created as a |
| 5977 | * demo user. |
| 5978 | * @hide |
| 5979 | */ |
| 5980 | public static final int MAKE_USER_DEMO = 0x0004; |
| 5981 | |
| 5982 | /** |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame^] | 5983 | * Flag used by {@link #createAndManageUser} to specificy that the newly created user should be |
| 5984 | * started in the background as part of the user creation. |
| 5985 | */ |
| 5986 | // TODO: Investigate solutions for the case where reboot happens before setup is completed. |
| 5987 | public static final int START_USER_IN_BACKGROUND = 0x0008; |
| 5988 | |
| 5989 | /** |
| 5990 | * @hide |
| 5991 | */ |
| 5992 | @IntDef( |
| 5993 | flag = true, |
| 5994 | prefix = {"SKIP_", "MAKE_USER_", "START_"}, |
| 5995 | value = {SKIP_SETUP_WIZARD, MAKE_USER_EPHEMERAL, MAKE_USER_DEMO, |
| 5996 | START_USER_IN_BACKGROUND} |
| 5997 | ) |
| 5998 | @Retention(RetentionPolicy.SOURCE) |
| 5999 | public @interface CreateAndManageUserFlags {} |
| 6000 | |
| 6001 | |
| 6002 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6003 | * Called by a device owner to create a user with the specified name and a given component of |
| 6004 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 6005 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 6006 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 6007 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6008 | * <p> |
| 6009 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 6010 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 6011 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 6012 | * on the new user. |
| 6013 | * <p> |
| 6014 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 6015 | * 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] | 6016 | * |
| 6017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6018 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6019 | * @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] | 6020 | * same package as admin, otherwise no user is created and an |
| 6021 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6022 | * @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] | 6023 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6024 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6025 | * @see UserHandle |
| 6026 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 6027 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6028 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6029 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6030 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 6031 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6032 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
Benjamin Franz | 77c94a9 | 2017-08-09 14:16:03 +0100 | [diff] [blame^] | 6033 | @CreateAndManageUserFlags int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6034 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6035 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 6036 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6037 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6038 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6039 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6043 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 6044 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6045 | * |
| 6046 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6047 | * @param userHandle the user to remove. |
| 6048 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6049 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6050 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6051 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6052 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6053 | try { |
| 6054 | return mService.removeUser(admin, userHandle); |
| 6055 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6056 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6061 | * Called by a device owner to switch the specified user to the foreground. |
| 6062 | * |
| 6063 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6064 | * @param userHandle the user to switch to; null will switch to primary. |
| 6065 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6066 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6067 | * @see Intent#ACTION_USER_FOREGROUND |
| 6068 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6069 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6070 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6071 | try { |
| 6072 | return mService.switchUser(admin, userHandle); |
| 6073 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6074 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 6075 | } |
| 6076 | } |
| 6077 | |
| 6078 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6079 | * Retrieves the application restrictions for a given target application running in the calling |
| 6080 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6081 | * <p> |
| 6082 | * 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] | 6083 | * application restrictions via {@link #setDelegatedScopes} with the |
| 6084 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6085 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6086 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 6087 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 6088 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6089 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6090 | * @param packageName The name of the package to fetch restricted settings of. |
| 6091 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6092 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 6093 | * {@link Bundle} if no restrictions have been set. |
| 6094 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6095 | * @see #setDelegatedScopes |
| 6096 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6097 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 6098 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6099 | public @NonNull Bundle getApplicationRestrictions( |
| 6100 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6101 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6102 | if (mService != null) { |
| 6103 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 6104 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 6105 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6106 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6107 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 6108 | } |
| 6109 | } |
| 6110 | return null; |
| 6111 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6112 | |
| 6113 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6114 | * 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] | 6115 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6116 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6117 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6118 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6119 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6120 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6121 | * for the list of keys. |
| 6122 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6123 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6124 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6125 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6126 | if (mService != null) { |
| 6127 | try { |
| 6128 | mService.setUserRestriction(admin, key, true); |
| 6129 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6130 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 6136 | * 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] | 6137 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6138 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 6139 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 6140 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6141 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6142 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 6143 | * for the list of keys. |
| 6144 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6145 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6146 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6147 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6148 | if (mService != null) { |
| 6149 | try { |
| 6150 | mService.setUserRestriction(admin, key, false); |
| 6151 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6152 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 6153 | } |
| 6154 | } |
| 6155 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 6156 | |
| 6157 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6158 | * Called by a profile or device owner to get user restrictions set with |
| 6159 | * {@link #addUserRestriction(ComponentName, String)}. |
| 6160 | * <p> |
| 6161 | * 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] | 6162 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6163 | * {@link UserManager#getUserRestrictions()}. |
| 6164 | * |
| 6165 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6166 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6167 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6168 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6169 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 6170 | Bundle ret = null; |
| 6171 | if (mService != null) { |
| 6172 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 6173 | ret = mService.getUserRestrictions(admin); |
| 6174 | } catch (RemoteException e) { |
| 6175 | throw e.rethrowFromSystemServer(); |
| 6176 | } |
| 6177 | } |
| 6178 | return ret == null ? new Bundle() : ret; |
| 6179 | } |
| 6180 | |
| 6181 | /** |
phweiss | 73145f4 | 2017-01-17 19:06:38 +0100 | [diff] [blame] | 6182 | * Called by any app to display a support dialog when a feature was disabled by an admin. |
| 6183 | * This returns an intent that can be used with {@link Context#startActivity(Intent)} to |
| 6184 | * display the dialog. It will tell the user that the feature indicated by {@code restriction} |
| 6185 | * was disabled by an admin, and include a link for more information. The default content of |
| 6186 | * the dialog can be changed by the restricting admin via |
| 6187 | * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not |
| 6188 | * set (i.e. the feature is available), then the return value will be {@code null}. |
| 6189 | * @param restriction Indicates for which feature the dialog should be displayed. Can be a |
| 6190 | * user restriction from {@link UserManager}, e.g. |
| 6191 | * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants |
| 6192 | * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. |
| 6193 | * @return Intent An intent to be used to start the dialog-activity if the restriction is |
| 6194 | * set by an admin, or null if the restriction does not exist or no admin set it. |
| 6195 | */ |
| 6196 | public Intent createAdminSupportIntent(@NonNull String restriction) { |
| 6197 | throwIfParentInstance("createAdminSupportIntent"); |
| 6198 | if (mService != null) { |
| 6199 | try { |
| 6200 | return mService.createAdminSupportIntent(restriction); |
| 6201 | } catch (RemoteException e) { |
| 6202 | throw e.rethrowFromSystemServer(); |
| 6203 | } |
| 6204 | } |
| 6205 | return null; |
| 6206 | } |
| 6207 | |
| 6208 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6209 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 6210 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 6211 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6212 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6213 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6214 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6215 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6216 | * @param packageName The name of the package to hide or unhide. |
| 6217 | * @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] | 6218 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6219 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6220 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6221 | * @see #setDelegatedScopes |
| 6222 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6223 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6224 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6225 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6226 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6227 | if (mService != null) { |
| 6228 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6229 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 6230 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6231 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6232 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6233 | } |
| 6234 | } |
| 6235 | return false; |
| 6236 | } |
| 6237 | |
| 6238 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6239 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 6240 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 6241 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6242 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6243 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6244 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 6245 | * @param packageName The name of the package to retrieve the hidden status of. |
| 6246 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6247 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6248 | * @see #setDelegatedScopes |
| 6249 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6250 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6251 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6252 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6253 | if (mService != null) { |
| 6254 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6255 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6256 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6257 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 6258 | } |
| 6259 | } |
| 6260 | return false; |
| 6261 | } |
| 6262 | |
| 6263 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6264 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 6265 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6266 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6267 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6268 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6269 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6270 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6271 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6272 | * @see #setDelegatedScopes |
| 6273 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6274 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6275 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6276 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6277 | if (mService != null) { |
| 6278 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6279 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6280 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6281 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6282 | } |
| 6283 | } |
| 6284 | } |
| 6285 | |
| 6286 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6287 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 6288 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 6289 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6290 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6291 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6292 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6293 | * @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] | 6294 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6295 | * @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] | 6296 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6297 | * @see #setDelegatedScopes |
| 6298 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6299 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6300 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6301 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6302 | if (mService != null) { |
| 6303 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6304 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6305 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6306 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 6307 | } |
| 6308 | } |
| 6309 | return 0; |
| 6310 | } |
| 6311 | |
| 6312 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 6313 | * Called by a device owner or profile owner to disable account management for a specific type |
| 6314 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6315 | * <p> |
| 6316 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 6317 | * exception will be thrown. |
| 6318 | * <p> |
| 6319 | * When account management is disabled for an account type, adding or removing an account of |
| 6320 | * that type will not be possible. |
| 6321 | * <p> |
| 6322 | * 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] | 6323 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 6324 | * management for a specific type is disabled. |
| 6325 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6326 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6327 | * @param accountType For which account management is disabled or enabled. |
| 6328 | * @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] | 6329 | * enabled (false). |
| 6330 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6331 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6332 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6333 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6334 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6335 | if (mService != null) { |
| 6336 | try { |
| 6337 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 6338 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6339 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 6340 | } |
| 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6345 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 6346 | * |
| 6347 | * <p> Account management can be disabled/enabled by calling |
| 6348 | * {@link #setAccountManagementDisabled}. |
| 6349 | * |
| 6350 | * @return a list of account types for which account management has been disabled. |
| 6351 | * |
| 6352 | * @see #setAccountManagementDisabled |
| 6353 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6354 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6355 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 6356 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | /** |
| 6360 | * @see #getAccountTypesWithManagementDisabled() |
| 6361 | * @hide |
| 6362 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6363 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6364 | if (mService != null) { |
| 6365 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 6366 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6367 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6368 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | return null; |
| 6373 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6374 | |
| 6375 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6376 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6377 | * <p> |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6378 | * 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] | 6379 | * 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] | 6380 | * package list results in locked tasks belonging to those packages to be finished. |
| 6381 | * <p> |
| 6382 | * This function can only be called by the device owner or by a profile owner of a user/profile |
| 6383 | * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages |
| 6384 | * set via this method will be cleared if the user becomes unaffiliated. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6385 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6386 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6387 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6388 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6389 | * an affiliated user or profile. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6390 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6391 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6392 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6393 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6394 | */ |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6395 | public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6396 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6397 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6398 | if (mService != null) { |
| 6399 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6400 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6401 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6402 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | } |
| 6406 | |
| 6407 | /** |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6408 | * Returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6409 | * |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6410 | * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of |
| 6411 | * an affiliated user or profile. |
| 6412 | * @see #setLockTaskPackages |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6413 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6414 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6415 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6416 | if (mService != null) { |
| 6417 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6418 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6419 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6420 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6421 | } |
| 6422 | } |
Esteban Talavera | bdcada9 | 2017-02-01 14:20:06 +0000 | [diff] [blame] | 6423 | return new String[0]; |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | /** |
| 6427 | * This function lets the caller know whether the given component is allowed to start the |
| 6428 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6429 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6430 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6431 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6432 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6433 | if (mService != null) { |
| 6434 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6435 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6436 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6437 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6438 | } |
| 6439 | } |
| 6440 | return false; |
| 6441 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6442 | |
| 6443 | /** |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6444 | * Called by device owners to update {@link android.provider.Settings.Global} settings. |
| 6445 | * Validation that the value of the setting is in the correct form for the setting type should |
| 6446 | * be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6447 | * <p> |
| 6448 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6449 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6450 | * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li> |
| 6451 | * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li> |
| 6452 | * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li> |
| 6453 | * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li> |
| 6454 | * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
| 6455 | * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li> |
| 6456 | * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only |
| 6457 | * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6458 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6459 | * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This |
| 6460 | * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6461 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6462 | * <p> |
| 6463 | * 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] | 6464 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6465 | * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6466 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6467 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6468 | * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 6469 | * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6470 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6471 | * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li> |
| 6472 | * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6473 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6474 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6475 | * |
| 6476 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6477 | * @param setting The name of the setting to update. |
| 6478 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6479 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6480 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6481 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6482 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6483 | if (mService != null) { |
| 6484 | try { |
| 6485 | mService.setGlobalSetting(admin, setting, value); |
| 6486 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6487 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6488 | } |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | /** |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6493 | * Called by profile or device owners to update {@link android.provider.Settings.Secure} |
| 6494 | * settings. Validation that the value of the setting is in the correct form for the setting |
| 6495 | * type should be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6496 | * <p> |
| 6497 | * 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] | 6498 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6499 | * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
| 6500 | * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6501 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6502 | * <p> |
| 6503 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6504 | * <ul> |
Benjamin Franz | 482bb23 | 2017-06-23 13:48:20 +0100 | [diff] [blame] | 6505 | * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6506 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6507 | * |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 6508 | * <strong>Note: Starting from Android O, apps should no longer call this method with the |
| 6509 | * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is |
| 6510 | * deprecated. Instead, device owners or profile owners should use the restriction |
| 6511 | * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
| 6512 | * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method |
| 6513 | * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, |
| 6514 | * an {@link UnsupportedOperationException} is thrown. |
| 6515 | * </strong> |
| 6516 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6517 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6518 | * @param setting The name of the setting to update. |
| 6519 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6520 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6521 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6522 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6523 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6524 | if (mService != null) { |
| 6525 | try { |
| 6526 | mService.setSecureSetting(admin, setting, value); |
| 6527 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6528 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6529 | } |
| 6530 | } |
| 6531 | } |
| 6532 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6533 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6534 | * Designates a specific service component as the provider for making permission requests of a |
| 6535 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6536 | * <p/> |
| 6537 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6538 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6539 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6540 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6541 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6542 | * provider previously assigned. |
| 6543 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6544 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6545 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6546 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6547 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6548 | if (mService != null) { |
| 6549 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6550 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6551 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6552 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6553 | } |
| 6554 | } |
| 6555 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6556 | |
| 6557 | /** |
| 6558 | * 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] | 6559 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6560 | * |
| 6561 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6562 | * @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] | 6563 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6564 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6565 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6566 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6567 | if (mService != null) { |
| 6568 | try { |
| 6569 | mService.setMasterVolumeMuted(admin, on); |
| 6570 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6571 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | /** |
| 6577 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6578 | * |
| 6579 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6580 | * @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] | 6581 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6582 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6583 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6584 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6585 | if (mService != null) { |
| 6586 | try { |
| 6587 | return mService.isMasterVolumeMuted(admin); |
| 6588 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6589 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6590 | } |
| 6591 | } |
| 6592 | return false; |
| 6593 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6594 | |
| 6595 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6596 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6597 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6598 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6599 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6600 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6601 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6602 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6603 | * @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] | 6604 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6605 | * @see #setDelegatedScopes |
| 6606 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6607 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6608 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6609 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6610 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6611 | if (mService != null) { |
| 6612 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6613 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6614 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6615 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6616 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6617 | } |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6622 | * 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] | 6623 | * 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] | 6624 | * <p> |
| 6625 | * <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] | 6626 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6627 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6628 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6629 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6630 | * @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] | 6631 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6632 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6633 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6634 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6635 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6636 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6637 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6638 | if (mService != null) { |
| 6639 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6640 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6641 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6642 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6643 | } |
| 6644 | } |
| 6645 | return false; |
| 6646 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6647 | |
| 6648 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6649 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6650 | * package to be available in the parent profile. As a result the user will be able to add |
| 6651 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6652 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6653 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6654 | * <p> |
| 6655 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6656 | * |
| 6657 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6658 | * @param packageName The package from which widget providers are white-listed. |
| 6659 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6660 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6661 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6662 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6663 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6664 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6665 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6666 | if (mService != null) { |
| 6667 | try { |
| 6668 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6669 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6670 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6671 | } |
| 6672 | } |
| 6673 | return false; |
| 6674 | } |
| 6675 | |
| 6676 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6677 | * 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] | 6678 | * package to be available in the parent profile. For this method to take effect the package |
| 6679 | * should have been added via |
| 6680 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6681 | * <p> |
| 6682 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6683 | * |
| 6684 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6685 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6686 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6687 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6688 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6689 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6690 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6691 | public boolean removeCrossProfileWidgetProvider( |
| 6692 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6693 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6694 | if (mService != null) { |
| 6695 | try { |
| 6696 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6697 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6698 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6699 | } |
| 6700 | } |
| 6701 | return false; |
| 6702 | } |
| 6703 | |
| 6704 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6705 | * 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] | 6706 | * available in the parent profile. |
| 6707 | * |
| 6708 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6709 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6710 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6711 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6712 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6713 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6714 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6715 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6716 | if (mService != null) { |
| 6717 | try { |
| 6718 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6719 | if (providers != null) { |
| 6720 | return providers; |
| 6721 | } |
| 6722 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6723 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6724 | } |
| 6725 | } |
| 6726 | return Collections.emptyList(); |
| 6727 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6728 | |
| 6729 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6730 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6731 | * |
| 6732 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6733 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6734 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6735 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6736 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6737 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6738 | try { |
| 6739 | mService.setUserIcon(admin, icon); |
| 6740 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6741 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6742 | } |
| 6743 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6744 | |
| 6745 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6746 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6747 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6748 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6749 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6750 | * components in the device owner package can set system update policies and the most |
| 6751 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6752 | * @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] | 6753 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6754 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6755 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6756 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6757 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6758 | if (mService != null) { |
| 6759 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6760 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6761 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6762 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6763 | } |
| 6764 | } |
| 6765 | } |
| 6766 | |
| 6767 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6768 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6769 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6770 | * @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] | 6771 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6772 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6773 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6774 | if (mService != null) { |
| 6775 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6776 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6777 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6778 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6779 | } |
| 6780 | } |
| 6781 | return null; |
| 6782 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6783 | |
| 6784 | /** |
| 6785 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6786 | * <p> |
| 6787 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6788 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6789 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6790 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6791 | * |
| 6792 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6793 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6794 | * @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] | 6795 | * place. {@code true} otherwise. |
| 6796 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6797 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6798 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6799 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6800 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6801 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6802 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6803 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6804 | } |
| 6805 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6806 | |
| 6807 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6808 | * 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] | 6809 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6810 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6811 | * |
| 6812 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6813 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6814 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6815 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6816 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6817 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6818 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6819 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6820 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6821 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6822 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6823 | } |
| 6824 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6825 | |
| 6826 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6827 | * Called by the system update service to notify device and profile owners of pending system |
| 6828 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6829 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6830 | * This method should only be used when it is unknown whether the pending system |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6831 | * update is a security patch. Otherwise, use |
| 6832 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6833 | * |
| 6834 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6835 | * indicating when the current pending update was first available. {@code -1} if no |
| 6836 | * update is available. |
| 6837 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6838 | * @hide |
| 6839 | */ |
| 6840 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6841 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6842 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6843 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6844 | if (mService != null) { |
| 6845 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6846 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6847 | } catch (RemoteException re) { |
| 6848 | throw re.rethrowFromSystemServer(); |
| 6849 | } |
| 6850 | } |
| 6851 | } |
| 6852 | |
| 6853 | /** |
| 6854 | * Called by the system update service to notify device and profile owners of pending system |
| 6855 | * updates. |
| 6856 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6857 | * This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6858 | * when it is known whether the pending system update is a security patch. |
| 6859 | * |
| 6860 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6861 | * indicating when the current pending update was first available. {@code -1} if no |
| 6862 | * update is available. |
| 6863 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6864 | * {@code false} if not. |
| 6865 | * @see #notifyPendingSystemUpdate(long) |
| 6866 | * @hide |
| 6867 | */ |
| 6868 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 6869 | @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6870 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6871 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6872 | if (mService != null) { |
| 6873 | try { |
| 6874 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6875 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6876 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6877 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6878 | } |
| 6879 | } |
| 6880 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6881 | |
| 6882 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6883 | * Called by device or profile owners to get information about a pending system update. |
| 6884 | * |
| 6885 | * @param admin Which profile or device owner this request is associated with. |
| 6886 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6887 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6888 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6889 | */ |
| 6890 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6891 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6892 | try { |
| 6893 | return mService.getPendingSystemUpdate(admin); |
| 6894 | } catch (RemoteException re) { |
| 6895 | throw re.rethrowFromSystemServer(); |
| 6896 | } |
| 6897 | } |
| 6898 | |
| 6899 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6900 | * Set the default response for future runtime permission requests by applications. This |
| 6901 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6902 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6903 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6904 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6905 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6906 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6907 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6908 | * <p/> |
| 6909 | * 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] | 6910 | * 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] | 6911 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6912 | * @param admin Which profile or device owner this request is associated with. |
| 6913 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6914 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6915 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6916 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6917 | * @see #setDelegatedScopes |
| 6918 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6919 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6920 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6921 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6922 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6923 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6924 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6925 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6926 | } |
| 6927 | } |
| 6928 | |
| 6929 | /** |
| 6930 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6931 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6932 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6933 | * @param admin Which profile or device owner this request is associated with. |
| 6934 | * @return the current policy for future permission requests. |
| 6935 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6936 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6937 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6938 | try { |
| 6939 | return mService.getPermissionPolicy(admin); |
| 6940 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6941 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6942 | } |
| 6943 | } |
| 6944 | |
| 6945 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6946 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6947 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6948 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6949 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6950 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6951 | * 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] | 6952 | * by a profile owner, device owner, or a delegate given the |
| 6953 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6954 | * <p/> |
| 6955 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6956 | * the permission. It retains the previous grant, if any. |
| 6957 | * <p/> |
| 6958 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6959 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6960 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6961 | * @param admin Which profile or device owner this request is associated with. |
| 6962 | * @param packageName The application to grant or revoke a permission to. |
| 6963 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6964 | * @param grantState The permission grant state which is one of |
| 6965 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6966 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6967 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6968 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6969 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6970 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6971 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6972 | * @see #setDelegatedScopes |
| 6973 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6974 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6975 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6976 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6977 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6978 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6979 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6980 | permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6981 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6982 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6983 | } |
| 6984 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6985 | |
| 6986 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6987 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6988 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6989 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6990 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 6991 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6992 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6993 | * @param packageName The application to check the grant state for. |
| 6994 | * @param permission The permission to check for. |
| 6995 | * @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] | 6996 | * has not set a grant state, the return value is |
| 6997 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6998 | * permission is currently granted for the package. |
| 6999 | * <p/> |
| 7000 | * If a grant state was set by the profile or device owner, then the return value will |
| 7001 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 7002 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 7003 | * currently denied or granted. |
| 7004 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7005 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 7006 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7007 | * @see #setDelegatedScopes |
| 7008 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7009 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 7010 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7011 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7012 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7013 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame] | 7014 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 7015 | permission); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7016 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7017 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 7018 | } |
| 7019 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7020 | |
| 7021 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7022 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 7023 | * or device, setting itself as the device or profile owner. |
| 7024 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7025 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 7026 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7027 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7028 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 7029 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7030 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7031 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7032 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7033 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7034 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7035 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 7036 | } |
| 7037 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7038 | |
| 7039 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7040 | * Checks whether it is possible to initiate provisioning a managed device, |
| 7041 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7042 | * |
| 7043 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 7044 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 7045 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 7046 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7047 | * @param packageName The package of the component that would be set as device, user, or profile |
| 7048 | * owner. |
| 7049 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7050 | * @hide |
| 7051 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7052 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 7053 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7054 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7055 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 7056 | } catch (RemoteException re) { |
| 7057 | throw re.rethrowFromSystemServer(); |
| 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7062 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 7063 | * 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] | 7064 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7065 | * @param admin Which profile owner this request is associated with. |
| 7066 | * @return if this user is a managed profile of another user. |
| 7067 | */ |
| 7068 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7069 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7070 | try { |
| 7071 | return mService.isManagedProfile(admin); |
| 7072 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7073 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7074 | } |
| 7075 | } |
| 7076 | |
| 7077 | /** |
| 7078 | * @hide |
| 7079 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 7080 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 7081 | * @param admin Which device owner this request is associated with. |
| 7082 | * @return if this user is a system-only user. |
| 7083 | */ |
| 7084 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 7085 | try { |
| 7086 | return mService.isSystemOnlyUser(admin); |
| 7087 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7088 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 7089 | } |
| 7090 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7091 | |
| 7092 | /** |
| 7093 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 7094 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7095 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7096 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 7097 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 7098 | * <p> |
| 7099 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 7100 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7101 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7102 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7103 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7104 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 7105 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7106 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7107 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 7108 | } |
| 7109 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7110 | |
| 7111 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7112 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 7113 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7114 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7115 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7116 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 7117 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7118 | */ |
| 7119 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7120 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7121 | try { |
| 7122 | mService.reboot(admin); |
| 7123 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7124 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 7125 | } |
| 7126 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7127 | |
| 7128 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7129 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 7130 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 7131 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 7132 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 7133 | * truncated. |
| 7134 | * <p> |
| 7135 | * 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] | 7136 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7137 | * and set a new version of this string accordingly. |
| 7138 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7139 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7140 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7141 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 7142 | * existing message. |
| 7143 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7144 | */ |
| 7145 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7146 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7147 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7148 | if (mService != null) { |
| 7149 | try { |
| 7150 | mService.setShortSupportMessage(admin, message); |
| 7151 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7152 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7153 | } |
| 7154 | } |
| 7155 | } |
| 7156 | |
| 7157 | /** |
| 7158 | * Called by a device admin to get the short support message. |
| 7159 | * |
| 7160 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7161 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 7162 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7163 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7164 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7165 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7166 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7167 | if (mService != null) { |
| 7168 | try { |
| 7169 | return mService.getShortSupportMessage(admin); |
| 7170 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7171 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7172 | } |
| 7173 | } |
| 7174 | return null; |
| 7175 | } |
| 7176 | |
| 7177 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7178 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 7179 | * in the device administators settings screen. |
| 7180 | * <p> |
| 7181 | * 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] | 7182 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7183 | * and set a new version of this string accordingly. |
| 7184 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7185 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7186 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7187 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 7188 | * existing message. |
| 7189 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7190 | */ |
| 7191 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7192 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7193 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7194 | if (mService != null) { |
| 7195 | try { |
| 7196 | mService.setLongSupportMessage(admin, message); |
| 7197 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7198 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7199 | } |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | /** |
| 7204 | * Called by a device admin to get the long support message. |
| 7205 | * |
| 7206 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7207 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 7208 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7209 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7210 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7211 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7212 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7213 | if (mService != null) { |
| 7214 | try { |
| 7215 | return mService.getLongSupportMessage(admin); |
| 7216 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7217 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7218 | } |
| 7219 | } |
| 7220 | return null; |
| 7221 | } |
| 7222 | |
| 7223 | /** |
| 7224 | * Called by the system to get the short support message. |
| 7225 | * |
| 7226 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7227 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7228 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7229 | * |
| 7230 | * @hide |
| 7231 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7232 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7233 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7234 | if (mService != null) { |
| 7235 | try { |
| 7236 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 7237 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7238 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7239 | } |
| 7240 | } |
| 7241 | return null; |
| 7242 | } |
| 7243 | |
| 7244 | |
| 7245 | /** |
| 7246 | * Called by the system to get the long support message. |
| 7247 | * |
| 7248 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7249 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 7250 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7251 | * |
| 7252 | * @hide |
| 7253 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7254 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 7255 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7256 | if (mService != null) { |
| 7257 | try { |
| 7258 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 7259 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7260 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 7261 | } |
| 7262 | } |
| 7263 | return null; |
| 7264 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7265 | |
| 7266 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 7267 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 7268 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7269 | * |
| 7270 | * <p>The following methods are supported for the parent instance, all other methods will |
| 7271 | * throw a SecurityException when called on the parent instance: |
| 7272 | * <ul> |
| 7273 | * <li>{@link #getPasswordQuality}</li> |
| 7274 | * <li>{@link #setPasswordQuality}</li> |
| 7275 | * <li>{@link #getPasswordMinimumLength}</li> |
| 7276 | * <li>{@link #setPasswordMinimumLength}</li> |
| 7277 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 7278 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 7279 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 7280 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 7281 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 7282 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 7283 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 7284 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 7285 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 7286 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 7287 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 7288 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 7289 | * <li>{@link #getPasswordHistoryLength}</li> |
| 7290 | * <li>{@link #setPasswordHistoryLength}</li> |
| 7291 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 7292 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 7293 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 7294 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7295 | * <li>{@link #isActivePasswordSufficient}</li> |
| 7296 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 7297 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 7298 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 7299 | * <li>{@link #getMaximumTimeToLock}</li> |
| 7300 | * <li>{@link #setMaximumTimeToLock}</li> |
| 7301 | * <li>{@link #lockNow}</li> |
| 7302 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 7303 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 7304 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 7305 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 7306 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 7307 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 7308 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7309 | * |
| 7310 | * @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] | 7311 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7312 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7313 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7314 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7315 | try { |
| 7316 | if (!mService.isManagedProfile(admin)) { |
| 7317 | throw new SecurityException("The current user does not have a parent profile."); |
| 7318 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7319 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7320 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7321 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7326 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7327 | * |
| 7328 | * <p> Security logs contain various information intended for security auditing purposes. |
| 7329 | * See {@link SecurityEvent} for details. |
| 7330 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7331 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 7332 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7333 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7334 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7335 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7336 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7337 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7338 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7339 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7340 | * @see #retrieveSecurityLogs |
| 7341 | */ |
| 7342 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7343 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7344 | try { |
| 7345 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 7346 | } catch (RemoteException re) { |
| 7347 | throw re.rethrowFromSystemServer(); |
| 7348 | } |
| 7349 | } |
| 7350 | |
| 7351 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7352 | * Return whether security logging is enabled or not by the device owner. |
| 7353 | * |
| 7354 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 7355 | * thrown. |
| 7356 | * |
| 7357 | * @param admin Which device owner this request is associated with. |
| 7358 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 7359 | * @throws SecurityException if {@code admin} is not a device owner. |
| 7360 | */ |
Bartosz Fabianowski | 0ec0000 | 2017-03-24 14:22:24 +0100 | [diff] [blame] | 7361 | public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7362 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7363 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7364 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7365 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7366 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7367 | } |
| 7368 | } |
| 7369 | |
| 7370 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7371 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 7372 | * this API after device boots. |
| 7373 | * |
| 7374 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 7375 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 7376 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7377 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7378 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7379 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7380 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7381 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7382 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 7383 | * 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] | 7384 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7385 | * profile or secondary user that is not affiliated with the device owner user. |
| 7386 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7387 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7388 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7389 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7390 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7391 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7392 | if (list != null) { |
| 7393 | return list.getList(); |
| 7394 | } else { |
| 7395 | // Rate limit exceeded. |
| 7396 | return null; |
| 7397 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7398 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7399 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7400 | } |
| 7401 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7402 | |
| 7403 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7404 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7405 | * profile. |
| 7406 | * |
| 7407 | * @hide |
| 7408 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7409 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7410 | mContext.checkSelfPermission( |
| 7411 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7412 | if (!uInfo.isManagedProfile()) { |
| 7413 | throw new SecurityException("The user " + uInfo.id |
| 7414 | + " does not have a parent profile."); |
| 7415 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7416 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7420 | * 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] | 7421 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7422 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7423 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7424 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7425 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7426 | * |
| 7427 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7428 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7429 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7430 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7431 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7432 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7433 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7434 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7435 | * profile or secondary user that is not affiliated with the device owner user. |
| 7436 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7437 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7438 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7439 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7440 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7441 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7442 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7443 | if (list != null) { |
| 7444 | return list.getList(); |
| 7445 | } else { |
| 7446 | return null; |
| 7447 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7448 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7449 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7450 | } |
| 7451 | } |
| 7452 | |
| 7453 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7454 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7455 | * 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] | 7456 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7457 | * <p> |
| 7458 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7459 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7460 | * |
| 7461 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7462 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7463 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7464 | */ |
| 7465 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7466 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7467 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7468 | // always enforce alpha channel to have 100% opacity |
| 7469 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7470 | mService.setOrganizationColor(admin, color); |
| 7471 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7472 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7473 | } |
| 7474 | } |
| 7475 | |
| 7476 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7477 | * @hide |
| 7478 | * |
| 7479 | * Sets the color used for customization. |
| 7480 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7481 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7482 | * @param userId which user to set the color to. |
| 7483 | * @RequiresPermission(allOf = { |
| 7484 | * Manifest.permission.MANAGE_USERS, |
| 7485 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7486 | */ |
| 7487 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7488 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7489 | // always enforce alpha channel to have 100% opacity |
| 7490 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7491 | mService.setOrganizationColorForUser(color, userId); |
| 7492 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7493 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7494 | } |
| 7495 | } |
| 7496 | |
| 7497 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7498 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7499 | * This color is used as background color of the confirm credentials screen for that user. |
| 7500 | * |
| 7501 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7502 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7503 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7504 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7505 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7506 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7507 | try { |
| 7508 | return mService.getOrganizationColor(admin); |
| 7509 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7510 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | /** |
| 7515 | * @hide |
| 7516 | * Retrieve the customization color for a given user. |
| 7517 | * |
| 7518 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7519 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7520 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7521 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7522 | try { |
| 7523 | return mService.getOrganizationColorForUser(userHandle); |
| 7524 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7525 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7526 | } |
| 7527 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7528 | |
| 7529 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7530 | * 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] | 7531 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7532 | * <p> |
| 7533 | * 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] | 7534 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7535 | * and set a new version of this string accordingly. |
| 7536 | * |
| 7537 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7538 | * @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] | 7539 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7540 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7541 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7542 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7543 | try { |
| 7544 | mService.setOrganizationName(admin, title); |
| 7545 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7546 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7547 | } |
| 7548 | } |
| 7549 | |
| 7550 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7551 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7552 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7553 | * |
| 7554 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7555 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7556 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7557 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7558 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7559 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7560 | try { |
| 7561 | return mService.getOrganizationName(admin); |
| 7562 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7563 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7564 | } |
| 7565 | } |
| 7566 | |
| 7567 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7568 | * Called by the system to retrieve the name of the organization managing the device. |
| 7569 | * |
| 7570 | * @return The organization name or {@code null} if none is set. |
| 7571 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7572 | * MANAGE_USERS permission and is not the system. |
| 7573 | * |
| 7574 | * @hide |
| 7575 | */ |
| 7576 | @SystemApi |
| 7577 | @TestApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 7578 | @SuppressLint("Doclava125") |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7579 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7580 | try { |
| 7581 | return mService.getDeviceOwnerOrganizationName(); |
| 7582 | } catch (RemoteException re) { |
| 7583 | throw re.rethrowFromSystemServer(); |
| 7584 | } |
| 7585 | } |
| 7586 | |
| 7587 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7588 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7589 | * |
| 7590 | * @param userHandle The user id of the user we're interested in. |
| 7591 | * @return The organization name or {@code null} if none is set. |
| 7592 | * |
| 7593 | * @hide |
| 7594 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7595 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7596 | try { |
| 7597 | return mService.getOrganizationNameForUser(userHandle); |
| 7598 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7599 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7600 | } |
| 7601 | } |
| 7602 | |
| 7603 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7604 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7605 | * return {@link #STATE_USER_UNMANAGED} |
| 7606 | * @hide |
| 7607 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7608 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7609 | @UserProvisioningState |
| 7610 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7611 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7612 | if (mService != null) { |
| 7613 | try { |
| 7614 | return mService.getUserProvisioningState(); |
| 7615 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7616 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7617 | } |
| 7618 | } |
| 7619 | return STATE_USER_UNMANAGED; |
| 7620 | } |
| 7621 | |
| 7622 | /** |
| 7623 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7624 | * |
| 7625 | * @param state to store |
| 7626 | * @param userHandle for user |
| 7627 | * @hide |
| 7628 | */ |
| 7629 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7630 | if (mService != null) { |
| 7631 | try { |
| 7632 | mService.setUserProvisioningState(state, userHandle); |
| 7633 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7634 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7635 | } |
| 7636 | } |
| 7637 | } |
| 7638 | |
| 7639 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7640 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7641 | * 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] | 7642 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7643 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7644 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7645 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7646 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7647 | * created. |
| 7648 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7649 | * @param admin Which profile or device owner this request is associated with. |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7650 | * @param ids A set of opaque non-empty affiliation ids. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7651 | * |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7652 | * @throws IllegalArgumentException if {@code ids} is null or contains an empty string. |
| 7653 | */ |
| 7654 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) { |
| 7655 | throwIfParentInstance("setAffiliationIds"); |
| 7656 | if (ids == null) { |
| 7657 | throw new IllegalArgumentException("ids must not be null"); |
| 7658 | } |
| 7659 | try { |
| 7660 | mService.setAffiliationIds(admin, new ArrayList<>(ids)); |
| 7661 | } catch (RemoteException e) { |
| 7662 | throw e.rethrowFromSystemServer(); |
| 7663 | } |
| 7664 | } |
| 7665 | |
| 7666 | /** |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7667 | * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7668 | * empty set if none have been set. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7669 | */ |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7670 | public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) { |
Tony Mak | 62cf586 | 2017-05-02 13:50:18 +0100 | [diff] [blame] | 7671 | throwIfParentInstance("getAffiliationIds"); |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7672 | try { |
Tony Mak | 3165743 | 2017-04-25 09:29:55 +0100 | [diff] [blame] | 7673 | return new ArraySet<>(mService.getAffiliationIds(admin)); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7674 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7675 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7676 | } |
| 7677 | } |
| 7678 | |
| 7679 | /** |
| 7680 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7681 | * Returns whether this user/profile is affiliated with the device. |
| 7682 | * <p> |
| 7683 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7684 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7685 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7686 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7687 | */ |
| 7688 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7689 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7690 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7691 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7692 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7693 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7694 | } |
| 7695 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7696 | |
| 7697 | /** |
| 7698 | * @hide |
| 7699 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7700 | * to be started |
| 7701 | * @param packageName the package to check for |
| 7702 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7703 | */ |
| 7704 | public boolean isUninstallInQueue(String packageName) { |
| 7705 | try { |
| 7706 | return mService.isUninstallInQueue(packageName); |
| 7707 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7708 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | /** |
| 7713 | * @hide |
| 7714 | * @param packageName the package containing active DAs to be uninstalled |
| 7715 | */ |
| 7716 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7717 | try { |
| 7718 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7719 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7720 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7721 | } |
| 7722 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7723 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7724 | /** |
| 7725 | * @hide |
| 7726 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7727 | * If the admin is a profile owner or device owner it will still be removed. |
| 7728 | * |
| 7729 | * @param userHandle user id to remove the admin for. |
| 7730 | * @param admin The administration compononent to remove. |
| 7731 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7732 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7733 | */ |
| 7734 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7735 | try { |
| 7736 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7737 | } catch (RemoteException re) { |
| 7738 | throw re.rethrowFromSystemServer(); |
| 7739 | } |
| 7740 | } |
| 7741 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7742 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7743 | * Returns whether the device has been provisioned. |
| 7744 | * |
| 7745 | * <p>Not for use by third-party applications. |
| 7746 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7747 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7748 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7749 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7750 | public boolean isDeviceProvisioned() { |
| 7751 | try { |
| 7752 | return mService.isDeviceProvisioned(); |
| 7753 | } catch (RemoteException re) { |
| 7754 | throw re.rethrowFromSystemServer(); |
| 7755 | } |
| 7756 | } |
| 7757 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7758 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7759 | * Writes that the provisioning configuration has been applied. |
| 7760 | * |
| 7761 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7762 | * permission. |
| 7763 | * |
| 7764 | * <p>Not for use by third-party applications. |
| 7765 | * |
| 7766 | * @hide |
| 7767 | */ |
| 7768 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 7769 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7770 | public void setDeviceProvisioningConfigApplied() { |
| 7771 | try { |
| 7772 | mService.setDeviceProvisioningConfigApplied(); |
| 7773 | } catch (RemoteException re) { |
| 7774 | throw re.rethrowFromSystemServer(); |
| 7775 | } |
| 7776 | } |
| 7777 | |
| 7778 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7779 | * Returns whether the provisioning configuration has been applied. |
| 7780 | * |
| 7781 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7782 | * |
| 7783 | * <p>Not for use by third-party applications. |
| 7784 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7785 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7786 | * |
| 7787 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7788 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7789 | @SystemApi |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 7790 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7791 | public boolean isDeviceProvisioningConfigApplied() { |
| 7792 | try { |
| 7793 | return mService.isDeviceProvisioningConfigApplied(); |
| 7794 | } catch (RemoteException re) { |
| 7795 | throw re.rethrowFromSystemServer(); |
| 7796 | } |
| 7797 | } |
| 7798 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7799 | /** |
| 7800 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7801 | * Force update user setup completed status. This API has no effect on user build. |
| 7802 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7803 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7804 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7805 | */ |
| 7806 | public void forceUpdateUserSetupComplete() { |
| 7807 | try { |
| 7808 | mService.forceUpdateUserSetupComplete(); |
| 7809 | } catch (RemoteException re) { |
| 7810 | throw re.rethrowFromSystemServer(); |
| 7811 | } |
| 7812 | } |
| 7813 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7814 | private void throwIfParentInstance(String functionName) { |
| 7815 | if (mParentInstance) { |
| 7816 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7817 | } |
| 7818 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7819 | |
| 7820 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7821 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7822 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7823 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7824 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7825 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7826 | * <p> Backup service is off by default when device owner is present. |
| 7827 | * |
Rubin Xu | 0367f07 | 2017-04-24 20:17:16 +0100 | [diff] [blame] | 7828 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7829 | * @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] | 7830 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7831 | */ |
| 7832 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7833 | throwIfParentInstance("setBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7834 | try { |
| 7835 | mService.setBackupServiceEnabled(admin, enabled); |
| 7836 | } catch (RemoteException re) { |
| 7837 | throw re.rethrowFromSystemServer(); |
| 7838 | } |
| 7839 | } |
| 7840 | |
| 7841 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7842 | * Return whether the backup service is enabled by the device owner. |
| 7843 | * |
| 7844 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7845 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7846 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7847 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7848 | */ |
| 7849 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
Esteban Talavera | 5b7f2d0 | 2017-02-17 09:45:24 +0000 | [diff] [blame] | 7850 | throwIfParentInstance("isBackupServiceEnabled"); |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7851 | try { |
| 7852 | return mService.isBackupServiceEnabled(admin); |
| 7853 | } catch (RemoteException re) { |
| 7854 | throw re.rethrowFromSystemServer(); |
| 7855 | } |
| 7856 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7857 | |
| 7858 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7859 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7860 | * |
Robin Lee | a40a2fb | 2017-02-08 17:07:06 +0000 | [diff] [blame] | 7861 | * <p> Network logs contain DNS lookup and connect() library call events. The following library |
| 7862 | * functions are recorded while network logging is active: |
| 7863 | * <ul> |
| 7864 | * <li>{@code getaddrinfo()}</li> |
| 7865 | * <li>{@code gethostbyname()}</li> |
| 7866 | * <li>{@code connect()}</li> |
| 7867 | * </ul> |
| 7868 | * |
| 7869 | * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use |
| 7870 | * full system call logging; event reporting is enabled by default for all processes but not |
| 7871 | * strongly enforced. |
| 7872 | * Events from applications using alternative implementations of libc, making direct kernel |
| 7873 | * calls, or deliberately obfuscating traffic may not be recorded. |
| 7874 | * |
| 7875 | * <p> Some common network events may not be reported. For example: |
| 7876 | * <ul> |
| 7877 | * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use |
| 7878 | * an alternative system for name resolution, and so avoid calling |
| 7879 | * {@code getaddrinfo()} or {@code gethostbyname}.</li> |
| 7880 | * <li>Applications may use datagram sockets for performance reasons, for example |
| 7881 | * for a game client. Calling {@code connect()} is unnecessary for this kind of |
| 7882 | * socket, so it will not trigger a network event.</li> |
| 7883 | * </ul> |
| 7884 | * |
| 7885 | * <p> It is possible to directly intercept layer 3 traffic leaving the device using an |
| 7886 | * always-on VPN service. |
| 7887 | * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} |
| 7888 | * and {@link android.net.VpnService} for details. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7889 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7890 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7891 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7892 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7893 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7894 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7895 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7897 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7898 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7899 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7900 | */ |
| 7901 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7902 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7903 | try { |
| 7904 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7905 | } catch (RemoteException re) { |
| 7906 | throw re.rethrowFromSystemServer(); |
| 7907 | } |
| 7908 | } |
| 7909 | |
| 7910 | /** |
| 7911 | * Return whether network logging is enabled by a device owner. |
| 7912 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7913 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7914 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7915 | * @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] | 7916 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7917 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7918 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7919 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7920 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7921 | try { |
| 7922 | return mService.isNetworkLoggingEnabled(admin); |
| 7923 | } catch (RemoteException re) { |
| 7924 | throw re.rethrowFromSystemServer(); |
| 7925 | } |
| 7926 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7927 | |
| 7928 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7929 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7930 | * A device owner has to provide a batchToken provided as part of |
| 7931 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7932 | * 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] | 7933 | * |
| 7934 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7935 | * |
| 7936 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7937 | * |
| 7938 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7939 | * after the device device owner has been notified via |
| 7940 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7941 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7942 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7943 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7944 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7945 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7946 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7947 | * |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7948 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7949 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7950 | * @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] | 7951 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7952 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7953 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7954 | * 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] | 7955 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7956 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7957 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7958 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7959 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7960 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7961 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7962 | } catch (RemoteException re) { |
| 7963 | throw re.rethrowFromSystemServer(); |
| 7964 | } |
| 7965 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7966 | |
| 7967 | /** |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 7968 | * Called by a device owner to bind to a service from a profile owner or vice versa. |
| 7969 | * See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7970 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7971 | * <p> |
Tony Mak | eda0a9a | 2017-04-25 12:07:14 +0100 | [diff] [blame] | 7972 | * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
| 7973 | * Note that the {@link Context} used to obtain this |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7974 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7975 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7976 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7977 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7978 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7979 | * explicit component name or a package name to match an |
| 7980 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7981 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7982 | * 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] | 7983 | * @param flags Operation options for the binding operation. See |
| 7984 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7985 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7986 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7987 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7988 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7989 | * {@code false} is returned if the connection is not made and you will not |
| 7990 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7991 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7992 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7993 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7994 | */ |
| 7995 | public boolean bindDeviceAdminServiceAsUser( |
| 7996 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7997 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7998 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7999 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 8000 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 8001 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 8002 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 8003 | serviceIntent.prepareToLeaveProcess(mContext); |
| 8004 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 8005 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 8006 | sd, flags, targetUser.getIdentifier()); |
| 8007 | } catch (RemoteException re) { |
| 8008 | throw re.rethrowFromSystemServer(); |
| 8009 | } |
| 8010 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8011 | |
| 8012 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8013 | * Returns the list of target users that the calling device or profile owner can use when |
| 8014 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 8015 | * <p> |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8016 | * 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] | 8017 | * <ul> |
| 8018 | * <li>Both belong to the same package name. |
Esteban Talavera | 2f89791 | 2017-01-26 10:30:48 +0000 | [diff] [blame] | 8019 | * <li>Both users are affiliated. See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 8020 | * </ul> |
| 8021 | */ |
| 8022 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 8023 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 8024 | try { |
| 8025 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 8026 | } catch (RemoteException re) { |
| 8027 | throw re.rethrowFromSystemServer(); |
| 8028 | } |
| 8029 | } |
| 8030 | |
| 8031 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8032 | * Called by the system to get the time at which the device owner last retrieved security |
| 8033 | * logging entries. |
| 8034 | * |
| 8035 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 8036 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8037 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8038 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8039 | * |
| 8040 | * @hide |
| 8041 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8042 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8043 | public long getLastSecurityLogRetrievalTime() { |
| 8044 | try { |
| 8045 | return mService.getLastSecurityLogRetrievalTime(); |
| 8046 | } catch (RemoteException re) { |
| 8047 | throw re.rethrowFromSystemServer(); |
| 8048 | } |
| 8049 | } |
| 8050 | |
| 8051 | /** |
| 8052 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 8053 | * |
| 8054 | * @return the time at which the device owner most recently requested a bug report, in |
| 8055 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8056 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8057 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8058 | * |
| 8059 | * @hide |
| 8060 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8061 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8062 | public long getLastBugReportRequestTime() { |
| 8063 | try { |
| 8064 | return mService.getLastBugReportRequestTime(); |
| 8065 | } catch (RemoteException re) { |
| 8066 | throw re.rethrowFromSystemServer(); |
| 8067 | } |
| 8068 | } |
| 8069 | |
| 8070 | /** |
| 8071 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 8072 | * events. |
| 8073 | * |
| 8074 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 8075 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8076 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 8077 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8078 | * |
| 8079 | * @hide |
| 8080 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 8081 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 8082 | public long getLastNetworkLogRetrievalTime() { |
| 8083 | try { |
| 8084 | return mService.getLastNetworkLogRetrievalTime(); |
| 8085 | } catch (RemoteException re) { |
| 8086 | throw re.rethrowFromSystemServer(); |
| 8087 | } |
| 8088 | } |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8089 | |
| 8090 | /** |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8091 | * Called by the system to find out whether the current user's IME was set by the device/profile |
| 8092 | * owner or the user. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8093 | * |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8094 | * @return {@code true} if the user's IME was set by the device or profile owner, {@code false} |
| 8095 | * otherwise. |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8096 | * @throws SecurityException if the caller is not the device owner/profile owner. |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8097 | * |
| 8098 | * @hide |
| 8099 | */ |
| 8100 | @TestApi |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8101 | public boolean isCurrentInputMethodSetByOwner() { |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8102 | try { |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8103 | return mService.isCurrentInputMethodSetByOwner(); |
Bartosz Fabianowski | aff5e9c | 2017-01-25 06:09:13 +0100 | [diff] [blame] | 8104 | } catch (RemoteException re) { |
| 8105 | throw re.rethrowFromSystemServer(); |
| 8106 | } |
| 8107 | } |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8108 | |
Bartosz Fabianowski | 05dc9f7 | 2017-02-22 23:41:14 +0100 | [diff] [blame] | 8109 | /** |
| 8110 | * Called by the system to get a list of CA certificates that were installed by the device or |
| 8111 | * profile owner. |
| 8112 | * |
Bartosz Fabianowski | 172f780 | 2017-03-06 12:07:57 +0100 | [diff] [blame] | 8113 | * <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] | 8114 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 8115 | * |
| 8116 | * @param user The user for whom to retrieve information. |
| 8117 | * @return list of aliases identifying CA certificates installed by the device or profile owner |
| 8118 | * @throws SecurityException if the caller does not have permission to retrieve information |
| 8119 | * about the given user's CA certificates. |
| 8120 | * |
| 8121 | * @hide |
| 8122 | */ |
| 8123 | @TestApi |
| 8124 | public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) { |
| 8125 | try { |
| 8126 | return mService.getOwnerInstalledCaCerts(user).getList(); |
| 8127 | } catch (RemoteException re) { |
| 8128 | throw re.rethrowFromSystemServer(); |
| 8129 | } |
| 8130 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 8131 | } |