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 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
| 20 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 22 | import android.app.Activity; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 23 | import android.app.admin.IDevicePolicyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 26 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
| 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.pm.ResolveInfo; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 31 | import android.net.ProxyInfo; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 32 | import android.os.Bundle; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 33 | import android.os.Handler; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 34 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 35 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 36 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 37 | import android.os.RemoteException; |
| 38 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 39 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 40 | import android.os.UserManager; |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 41 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 42 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 43 | import android.service.restrictions.RestrictionsReceiver; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 44 | import android.service.trust.TrustAgentService; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 45 | import android.util.Log; |
| 46 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 47 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 48 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 49 | import org.xmlpull.v1.XmlPullParserException; |
| 50 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 51 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 52 | import java.io.IOException; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 53 | import java.net.InetSocketAddress; |
| 54 | import java.net.Proxy; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 55 | import java.security.PrivateKey; |
| 56 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 57 | import java.security.cert.CertificateException; |
| 58 | import java.security.cert.CertificateFactory; |
| 59 | import java.security.cert.X509Certificate; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 60 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 61 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 62 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 65 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 66 | * registered with the system as a |
| 67 | * <a href={@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally, |
| 68 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 69 | * accessible to all device administrators unless the documentation for that method specifies that |
| 70 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 71 | * |
| 72 | * <div class="special reference"> |
| 73 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 74 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 75 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
| 76 | * developer guide.</p> |
| 77 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 78 | */ |
| 79 | public class DevicePolicyManager { |
| 80 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 81 | |
| 82 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 83 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 84 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 85 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 86 | mContext = context; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 87 | mService = IDevicePolicyManager.Stub.asInterface( |
| 88 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 89 | } |
| 90 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 91 | /** @hide */ |
| 92 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 93 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 94 | return me.mService != null ? me : null; |
| 95 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 96 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 97 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 98 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 99 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 100 | * <p>A managed profile allows data separation for example for the usage of a |
| 101 | * device as a personal and corporate device. The user which provisioning is started from and |
| 102 | * the managed profile share a launcher. |
| 103 | * |
| 104 | * <p>This intent will typically be sent by a mobile device management application (mdm). |
| 105 | * Provisioning adds a managed profile and sets the mdm as the profile owner who has full |
| 106 | * control over the profile |
| 107 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 108 | * <p>This intent must contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 109 | * |
| 110 | * <p> When managed provisioning has completed, an intent of the type |
| 111 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 112 | * managed profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 113 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 114 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 115 | * previous state. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 116 | * |
| 117 | * <p>Input: Nothing.</p> |
| 118 | * <p>Output: Nothing</p> |
| 119 | */ |
| 120 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 121 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 122 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 125 | * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows |
| 126 | * a mobile device management application that starts managed profile provisioning to pass data |
| 127 | * to itself on the managed profile when provisioning completes. The mobile device management |
| 128 | * application sends this extra in an intent with the action |
| 129 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in |
| 130 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 131 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
| 132 | * during the managed profile provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 133 | */ |
| 134 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 135 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 136 | |
| 137 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 138 | * A String extra holding the package name of the mobile device management application that |
| 139 | * will be set as the profile owner or device owner. |
| 140 | * |
| 141 | * <p>If an application starts provisioning directly via an intent with action |
| 142 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 143 | * application that started provisioning. The package will be set as profile owner in that case. |
| 144 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 145 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 146 | * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 147 | */ |
| 148 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 149 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 150 | |
| 151 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 152 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 153 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 154 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 155 | * |
| 156 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 157 | */ |
| 158 | |
| 159 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 160 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 161 | |
| 162 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 163 | * A String extra that, holds the email address of the account which a managed profile is |
| 164 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 165 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 166 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 167 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 168 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 169 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 170 | * contains this extra, it is forwarded in the |
| 171 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 172 | * device management application that was set as the profile owner during provisioning. |
| 173 | * It is usually used to avoid that the user has to enter their email address twice. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 174 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 175 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 176 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 177 | |
| 178 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 179 | * A Boolean extra that can be used by the mobile device management application to skip the |
| 180 | * disabling of system apps during provisioning when set to <code>true</code>. |
| 181 | * |
| 182 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 183 | * provisioning via an NFC bump. |
| 184 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 185 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 186 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 187 | |
| 188 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 189 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 190 | * will be set to. |
| 191 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 192 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 193 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 194 | */ |
| 195 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 196 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 197 | |
| 198 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 199 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 200 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 201 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 202 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 203 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 204 | */ |
| 205 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 206 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 210 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 211 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 212 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 213 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 214 | */ |
| 215 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 216 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 220 | * owner provisioning for downloading the mobile device management application. |
| 221 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 222 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 223 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 224 | */ |
| 225 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 226 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 230 | * is hidden or not. |
| 231 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 232 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 233 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 234 | */ |
| 235 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 236 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * A String extra indicating the security type of the wifi network in |
| 240 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 241 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 242 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 243 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 244 | */ |
| 245 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 246 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 247 | |
| 248 | /** |
| 249 | * A String extra holding the password of the wifi network in |
| 250 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 251 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 252 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 253 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 254 | */ |
| 255 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 256 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * A String extra holding the proxy host for the wifi network in |
| 260 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 261 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 262 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 263 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 264 | */ |
| 265 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 266 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 267 | |
| 268 | /** |
| 269 | * An int extra holding the proxy port for the wifi network in |
| 270 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 271 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 272 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 273 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 274 | */ |
| 275 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 276 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * A String extra holding the proxy bypass for the wifi network in |
| 280 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 281 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 282 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 283 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 284 | */ |
| 285 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 286 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 287 | |
| 288 | /** |
| 289 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 290 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 291 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 292 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 293 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 294 | */ |
| 295 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 296 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * A String extra holding a url that specifies the download location of the device admin |
| 300 | * package. When not provided it is assumed that the device admin package is already installed. |
| 301 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 302 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 303 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 304 | */ |
| 305 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 306 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 307 | |
| 308 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 309 | * A String extra holding a http cookie header which should be used in the http request to the |
| 310 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 311 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 312 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 313 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 314 | */ |
| 315 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 316 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 317 | |
| 318 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 319 | * A String extra holding the SHA-1 checksum of the file at download location specified in |
| 320 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match |
| 321 | * the file at the download location an error will be shown to the user and the user will be |
| 322 | * asked to factory reset the device. |
| 323 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 324 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 325 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 326 | */ |
| 327 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 328 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 329 | |
| 330 | /** |
| 331 | * This MIME type is used for starting the Device Owner provisioning. |
| 332 | * |
| 333 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 334 | * A device owner has full control over the device. The device owner can not be modified by the |
| 335 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 336 | * reset. |
| 337 | * |
| 338 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 339 | * employee or client. |
| 340 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 341 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 342 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 343 | * <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] | 344 | * contains the following properties: |
| 345 | * <ul> |
| 346 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 347 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 348 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 349 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li> |
| 350 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 351 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 352 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 353 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 354 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 355 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 356 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 357 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 358 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 359 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 360 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul> |
| 361 | * |
| 362 | * <p> When device owner provisioning has completed, an intent of the type |
| 363 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the |
| 364 | * device owner. |
| 365 | * |
| 366 | * <p> |
| 367 | * If provisioning fails, the device is factory reset. |
| 368 | * |
| 369 | * <p>Input: Nothing.</p> |
| 370 | * <p>Output: Nothing</p> |
| 371 | */ |
Esteban Talavera | f057f06 | 2014-08-20 14:27:45 +0100 | [diff] [blame] | 372 | public static final String MIME_TYPE_PROVISIONING_NFC |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 373 | = "application/com.android.managedprovisioning"; |
| 374 | |
| 375 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 376 | * Activity action: ask the user to add a new device administrator to the system. |
| 377 | * The desired policy is the ComponentName of the policy in the |
| 378 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 379 | * bring the user through adding the device administrator to the system (or |
| 380 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 381 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 382 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 383 | * field to provide the user with additional explanation (in addition |
| 384 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 385 | * |
| 386 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 387 | * user intervention). However, if your administrator has been updated and is requesting |
| 388 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 389 | * 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] | 390 | */ |
| 391 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 392 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 393 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 394 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 395 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 396 | * @hide |
| 397 | * Activity action: ask the user to add a new device administrator as the profile owner |
| 398 | * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS |
| 399 | * permission can call this API. |
| 400 | * |
| 401 | * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra |
| 402 | * field. This will invoke a UI to bring the user through adding the profile owner admin |
| 403 | * to remotely control restrictions on the user. |
| 404 | * |
| 405 | * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the |
| 406 | * result of whether or not the user approved the action. If approved, the result will |
| 407 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 408 | * as a profile owner. |
| 409 | * |
| 410 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 411 | * field to provide the user with additional explanation (in addition |
| 412 | * to your component's description) about what is being added. |
| 413 | * |
| 414 | * <p>If there is already a profile owner active or the caller doesn't have the required |
| 415 | * permissions, the operation will return a failure result. |
| 416 | */ |
| 417 | @SystemApi |
| 418 | public static final String ACTION_SET_PROFILE_OWNER |
| 419 | = "android.app.action.SET_PROFILE_OWNER"; |
| 420 | |
| 421 | /** |
| 422 | * @hide |
| 423 | * Name of the profile owner admin that controls the user. |
| 424 | */ |
| 425 | @SystemApi |
| 426 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 427 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 428 | |
| 429 | /** |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 430 | * Activity action: send when any policy admin changes a policy. |
| 431 | * 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] | 432 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 433 | * @hide |
| 434 | */ |
| 435 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 436 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 437 | |
| 438 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 439 | * The ComponentName of the administrator component. |
| 440 | * |
| 441 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 442 | */ |
| 443 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 444 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 445 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 446 | * An optional CharSequence providing additional explanation for why the |
| 447 | * admin is being added. |
| 448 | * |
| 449 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 450 | */ |
| 451 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 452 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 453 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 454 | * Activity action: have the user enter a new password. This activity should |
| 455 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 456 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 457 | * enter a new password that meets the current requirements. You can use |
| 458 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 459 | * have the user select a new password in order to meet the current |
| 460 | * constraints. Upon being resumed from this activity, you can check the new |
| 461 | * password characteristics to see if they are sufficient. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 462 | */ |
| 463 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 464 | public static final String ACTION_SET_NEW_PASSWORD |
| 465 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 466 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 467 | /** |
Jeff Sharkey | 9797880 | 2014-10-14 10:48:18 -0700 | [diff] [blame] | 468 | * Flag used by {@link #addCrossProfileIntentFilter} to allow access |
| 469 | * <em>from</em> a managed profile <em>to</em> its parent. That is, any |
| 470 | * matching activities in the parent profile are included in the |
| 471 | * disambiguation list shown when an app in the managed profile calls |
| 472 | * {@link Activity#startActivity(Intent)}. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 473 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 474 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 475 | |
| 476 | /** |
Jeff Sharkey | 9797880 | 2014-10-14 10:48:18 -0700 | [diff] [blame] | 477 | * Flag used by {@link #addCrossProfileIntentFilter} to allow access |
| 478 | * <em>from</em> a parent <em>to</em> its managed profile. That is, any |
| 479 | * matching activities in the managed profile are included in the |
| 480 | * disambiguation list shown when an app in the parent profile calls |
| 481 | * {@link Activity#startActivity(Intent)}. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 482 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 483 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 484 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 485 | /** |
| 486 | * Return true if the given administrator component is currently |
| 487 | * active (enabled) in the system. |
| 488 | */ |
| 489 | public boolean isAdminActive(ComponentName who) { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 490 | return isAdminActiveAsUser(who, UserHandle.myUserId()); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * @see #isAdminActive(ComponentName) |
| 495 | * @hide |
| 496 | */ |
| 497 | public boolean isAdminActiveAsUser(ComponentName who, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 498 | if (mService != null) { |
| 499 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 500 | return mService.isAdminActive(who, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 501 | } catch (RemoteException e) { |
| 502 | Log.w(TAG, "Failed talking with device policy service", e); |
| 503 | } |
| 504 | } |
| 505 | return false; |
| 506 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 507 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 508 | /** |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 509 | * Return a list of all currently active device administrator's component |
| 510 | * names. Note that if there are no administrators than null may be |
| 511 | * returned. |
| 512 | */ |
| 513 | public List<ComponentName> getActiveAdmins() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 514 | return getActiveAdminsAsUser(UserHandle.myUserId()); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * @see #getActiveAdmins() |
| 519 | * @hide |
| 520 | */ |
| 521 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 522 | if (mService != null) { |
| 523 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 524 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 525 | } catch (RemoteException e) { |
| 526 | Log.w(TAG, "Failed talking with device policy service", e); |
| 527 | } |
| 528 | } |
| 529 | return null; |
| 530 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 531 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 532 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 533 | * Used by package administration code to determine if a package can be stopped |
| 534 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 535 | * @hide |
| 536 | */ |
| 537 | public boolean packageHasActiveAdmins(String packageName) { |
| 538 | if (mService != null) { |
| 539 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 540 | return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 541 | } catch (RemoteException e) { |
| 542 | Log.w(TAG, "Failed talking with device policy service", e); |
| 543 | } |
| 544 | } |
| 545 | return false; |
| 546 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 547 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 548 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 549 | * Remove a current administration component. This can only be called |
| 550 | * by the application that owns the administration component; if you |
| 551 | * try to remove someone else's component, a security exception will be |
| 552 | * thrown. |
| 553 | */ |
| 554 | public void removeActiveAdmin(ComponentName who) { |
| 555 | if (mService != null) { |
| 556 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 557 | mService.removeActiveAdmin(who, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 558 | } catch (RemoteException e) { |
| 559 | Log.w(TAG, "Failed talking with device policy service", e); |
| 560 | } |
| 561 | } |
| 562 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 563 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 564 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 565 | * Returns true if an administrator has been granted a particular device policy. This can |
| 566 | * be used to check if the administrator was activated under an earlier set of policies, |
| 567 | * but requires additional policies after an upgrade. |
| 568 | * |
| 569 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 570 | * an active administrator, or an exception will be thrown. |
| 571 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 572 | */ |
| 573 | public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) { |
| 574 | if (mService != null) { |
| 575 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 576 | return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 577 | } catch (RemoteException e) { |
| 578 | Log.w(TAG, "Failed talking with device policy service", e); |
| 579 | } |
| 580 | } |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 585 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 586 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 587 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 588 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 589 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 590 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 591 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 592 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 593 | * recognition technology. This implies technologies that can recognize the identity of |
| 594 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 595 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 596 | */ |
| 597 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 598 | |
| 599 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 600 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 601 | * of password, but doesn't care what it is. Note that quality constants |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 602 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 603 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 604 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 605 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 606 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 607 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 608 | * password containing at least numeric characters. Note that quality |
| 609 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 610 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 611 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 612 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 613 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 614 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 615 | * password containing at least numeric characters with no repeating (4444) |
| 616 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 617 | * constants are ordered so that higher values are more restrictive. |
| 618 | */ |
| 619 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 620 | |
| 621 | /** |
| 622 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 623 | * password containing at least alphabetic (or other symbol) characters. |
| 624 | * Note that quality constants are ordered so that higher values are more |
| 625 | * restrictive. |
| 626 | */ |
| 627 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 628 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 629 | /** |
| 630 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 631 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 632 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 633 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 634 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 635 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 636 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 637 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 638 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 639 | * password containing at least a letter, a numerical digit and a special |
| 640 | * symbol, by default. With this password quality, passwords can be |
| 641 | * restricted to contain various sets of characters, like at least an |
| 642 | * uppercase letter, etc. These are specified using various methods, |
| 643 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 644 | * that quality constants are ordered so that higher values are more |
| 645 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 646 | */ |
| 647 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 648 | |
| 649 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 650 | * Called by an application that is administering the device to set the |
| 651 | * password restrictions it is imposing. After setting this, the user |
| 652 | * will not be able to enter a new password that is not at least as |
| 653 | * restrictive as what has been set. Note that the current password |
| 654 | * will remain until the user has set a new one, so the change does not |
| 655 | * take place immediately. To prompt the user for a new password, use |
| 656 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 657 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 658 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 659 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 660 | * the user's preference, and any other considerations) is the one that |
| 661 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 662 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 663 | * <p>The calling device admin must have requested |
| 664 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 665 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 666 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 667 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 668 | * @param quality The new desired quality. One of |
| 669 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 670 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 671 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 672 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 673 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 674 | public void setPasswordQuality(ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 675 | if (mService != null) { |
| 676 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 677 | mService.setPasswordQuality(admin, quality, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 678 | } catch (RemoteException e) { |
| 679 | Log.w(TAG, "Failed talking with device policy service", e); |
| 680 | } |
| 681 | } |
| 682 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 683 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 684 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 685 | * Retrieve the current minimum password quality for all admins of this user |
| 686 | * and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 687 | * @param admin The name of the admin component to check, or null to aggregate |
| 688 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 689 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 690 | public int getPasswordQuality(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 691 | return getPasswordQuality(admin, UserHandle.myUserId()); |
| 692 | } |
| 693 | |
| 694 | /** @hide per-user version */ |
| 695 | public int getPasswordQuality(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 696 | if (mService != null) { |
| 697 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 698 | return mService.getPasswordQuality(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 699 | } catch (RemoteException e) { |
| 700 | Log.w(TAG, "Failed talking with device policy service", e); |
| 701 | } |
| 702 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 703 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 704 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 705 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 706 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 707 | * Called by an application that is administering the device to set the |
| 708 | * minimum allowed password length. After setting this, the user |
| 709 | * will not be able to enter a new password that is not at least as |
| 710 | * restrictive as what has been set. Note that the current password |
| 711 | * will remain until the user has set a new one, so the change does not |
| 712 | * take place immediately. To prompt the user for a new password, use |
| 713 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 714 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 715 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 716 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 717 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 718 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 719 | * <p>The calling device admin must have requested |
| 720 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 721 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 722 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 723 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 724 | * @param length The new desired minimum password length. A value of 0 |
| 725 | * means there is no restriction. |
| 726 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 727 | public void setPasswordMinimumLength(ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 728 | if (mService != null) { |
| 729 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 730 | mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 731 | } catch (RemoteException e) { |
| 732 | Log.w(TAG, "Failed talking with device policy service", e); |
| 733 | } |
| 734 | } |
| 735 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 736 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 737 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 738 | * Retrieve the current minimum password length for all admins of this |
| 739 | * user and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 740 | * @param admin The name of the admin component to check, or null to aggregate |
| 741 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 742 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 743 | public int getPasswordMinimumLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 744 | return getPasswordMinimumLength(admin, UserHandle.myUserId()); |
| 745 | } |
| 746 | |
| 747 | /** @hide per-user version */ |
| 748 | public int getPasswordMinimumLength(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 749 | if (mService != null) { |
| 750 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 751 | return mService.getPasswordMinimumLength(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 752 | } catch (RemoteException e) { |
| 753 | Log.w(TAG, "Failed talking with device policy service", e); |
| 754 | } |
| 755 | } |
| 756 | return 0; |
| 757 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 758 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 759 | /** |
| 760 | * Called by an application that is administering the device to set the |
| 761 | * minimum number of upper case letters required in the password. After |
| 762 | * setting this, the user will not be able to enter a new password that is |
| 763 | * not at least as restrictive as what has been set. Note that the current |
| 764 | * password will remain until the user has set a new one, so the change does |
| 765 | * not take place immediately. To prompt the user for a new password, use |
| 766 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 767 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 768 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 769 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 770 | * <p> |
| 771 | * The calling device admin must have requested |
| 772 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 773 | * this method; if it has not, a security exception will be thrown. |
| 774 | * |
| 775 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 776 | * with. |
| 777 | * @param length The new desired minimum number of upper case letters |
| 778 | * required in the password. A value of 0 means there is no |
| 779 | * restriction. |
| 780 | */ |
| 781 | public void setPasswordMinimumUpperCase(ComponentName admin, int length) { |
| 782 | if (mService != null) { |
| 783 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 784 | mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 785 | } catch (RemoteException e) { |
| 786 | Log.w(TAG, "Failed talking with device policy service", e); |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 793 | * password for all admins of this user and its profiles or a particular one. |
| 794 | * This is the same value as set by |
| 795 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 796 | * and only applies when the password quality is |
| 797 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 798 | * |
| 799 | * @param admin The name of the admin component to check, or null to |
| 800 | * aggregate all admins. |
| 801 | * @return The minimum number of upper case letters required in the |
| 802 | * password. |
| 803 | */ |
| 804 | public int getPasswordMinimumUpperCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 805 | return getPasswordMinimumUpperCase(admin, UserHandle.myUserId()); |
| 806 | } |
| 807 | |
| 808 | /** @hide per-user version */ |
| 809 | public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 810 | if (mService != null) { |
| 811 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 812 | return mService.getPasswordMinimumUpperCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 813 | } catch (RemoteException e) { |
| 814 | Log.w(TAG, "Failed talking with device policy service", e); |
| 815 | } |
| 816 | } |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Called by an application that is administering the device to set the |
| 822 | * minimum number of lower case letters required in the password. After |
| 823 | * setting this, the user will not be able to enter a new password that is |
| 824 | * not at least as restrictive as what has been set. Note that the current |
| 825 | * password will remain until the user has set a new one, so the change does |
| 826 | * not take place immediately. To prompt the user for a new password, use |
| 827 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 828 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 829 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 830 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 831 | * <p> |
| 832 | * The calling device admin must have requested |
| 833 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 834 | * this method; if it has not, a security exception will be thrown. |
| 835 | * |
| 836 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 837 | * with. |
| 838 | * @param length The new desired minimum number of lower case letters |
| 839 | * required in the password. A value of 0 means there is no |
| 840 | * restriction. |
| 841 | */ |
| 842 | public void setPasswordMinimumLowerCase(ComponentName admin, int length) { |
| 843 | if (mService != null) { |
| 844 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 845 | mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 846 | } catch (RemoteException e) { |
| 847 | Log.w(TAG, "Failed talking with device policy service", e); |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 854 | * password for all admins of this user and its profiles or a particular one. |
| 855 | * This is the same value as set by |
| 856 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 857 | * and only applies when the password quality is |
| 858 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 859 | * |
| 860 | * @param admin The name of the admin component to check, or null to |
| 861 | * aggregate all admins. |
| 862 | * @return The minimum number of lower case letters required in the |
| 863 | * password. |
| 864 | */ |
| 865 | public int getPasswordMinimumLowerCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 866 | return getPasswordMinimumLowerCase(admin, UserHandle.myUserId()); |
| 867 | } |
| 868 | |
| 869 | /** @hide per-user version */ |
| 870 | public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 871 | if (mService != null) { |
| 872 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 873 | return mService.getPasswordMinimumLowerCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 874 | } catch (RemoteException e) { |
| 875 | Log.w(TAG, "Failed talking with device policy service", e); |
| 876 | } |
| 877 | } |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * Called by an application that is administering the device to set the |
| 883 | * minimum number of letters required in the password. After setting this, |
| 884 | * the user will not be able to enter a new password that is not at least as |
| 885 | * restrictive as what has been set. Note that the current password will |
| 886 | * remain until the user has set a new one, so the change does not take |
| 887 | * place immediately. To prompt the user for a new password, use |
| 888 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 889 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 890 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 891 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 892 | * <p> |
| 893 | * The calling device admin must have requested |
| 894 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 895 | * this method; if it has not, a security exception will be thrown. |
| 896 | * |
| 897 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 898 | * with. |
| 899 | * @param length The new desired minimum number of letters required in the |
| 900 | * password. A value of 0 means there is no restriction. |
| 901 | */ |
| 902 | public void setPasswordMinimumLetters(ComponentName admin, int length) { |
| 903 | if (mService != null) { |
| 904 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 905 | mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 906 | } catch (RemoteException e) { |
| 907 | Log.w(TAG, "Failed talking with device policy service", e); |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 914 | * admins or a particular one. This is the same value as |
| 915 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 916 | * and only applies when the password quality is |
| 917 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 918 | * |
| 919 | * @param admin The name of the admin component to check, or null to |
| 920 | * aggregate all admins. |
| 921 | * @return The minimum number of letters required in the password. |
| 922 | */ |
| 923 | public int getPasswordMinimumLetters(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 924 | return getPasswordMinimumLetters(admin, UserHandle.myUserId()); |
| 925 | } |
| 926 | |
| 927 | /** @hide per-user version */ |
| 928 | public int getPasswordMinimumLetters(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 929 | if (mService != null) { |
| 930 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 931 | return mService.getPasswordMinimumLetters(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 932 | } catch (RemoteException e) { |
| 933 | Log.w(TAG, "Failed talking with device policy service", e); |
| 934 | } |
| 935 | } |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * Called by an application that is administering the device to set the |
| 941 | * minimum number of numerical digits required in the password. After |
| 942 | * setting this, the user will not be able to enter a new password that is |
| 943 | * not at least as restrictive as what has been set. Note that the current |
| 944 | * password will remain until the user has set a new one, so the change does |
| 945 | * not take place immediately. To prompt the user for a new password, use |
| 946 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 947 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 948 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 949 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 950 | * <p> |
| 951 | * The calling device admin must have requested |
| 952 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 953 | * this method; if it has not, a security exception will be thrown. |
| 954 | * |
| 955 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 956 | * with. |
| 957 | * @param length The new desired minimum number of numerical digits required |
| 958 | * in the password. A value of 0 means there is no restriction. |
| 959 | */ |
| 960 | public void setPasswordMinimumNumeric(ComponentName admin, int length) { |
| 961 | if (mService != null) { |
| 962 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 963 | mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 964 | } catch (RemoteException e) { |
| 965 | Log.w(TAG, "Failed talking with device policy service", e); |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 972 | * for all admins of this user and its profiles or a particular one. |
| 973 | * This is the same value as set by |
| 974 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 975 | * and only applies when the password quality is |
| 976 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 977 | * |
| 978 | * @param admin The name of the admin component to check, or null to |
| 979 | * aggregate all admins. |
| 980 | * @return The minimum number of numerical digits required in the password. |
| 981 | */ |
| 982 | public int getPasswordMinimumNumeric(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 983 | return getPasswordMinimumNumeric(admin, UserHandle.myUserId()); |
| 984 | } |
| 985 | |
| 986 | /** @hide per-user version */ |
| 987 | public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 988 | if (mService != null) { |
| 989 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 990 | return mService.getPasswordMinimumNumeric(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 991 | } catch (RemoteException e) { |
| 992 | Log.w(TAG, "Failed talking with device policy service", e); |
| 993 | } |
| 994 | } |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * Called by an application that is administering the device to set the |
| 1000 | * minimum number of symbols required in the password. After setting this, |
| 1001 | * the user will not be able to enter a new password that is not at least as |
| 1002 | * restrictive as what has been set. Note that the current password will |
| 1003 | * remain until the user has set a new one, so the change does not take |
| 1004 | * place immediately. To prompt the user for a new password, use |
| 1005 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1006 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1007 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1008 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1009 | * <p> |
| 1010 | * The calling device admin must have requested |
| 1011 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1012 | * this method; if it has not, a security exception will be thrown. |
| 1013 | * |
| 1014 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1015 | * with. |
| 1016 | * @param length The new desired minimum number of symbols required in the |
| 1017 | * password. A value of 0 means there is no restriction. |
| 1018 | */ |
| 1019 | public void setPasswordMinimumSymbols(ComponentName admin, int length) { |
| 1020 | if (mService != null) { |
| 1021 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1022 | mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1023 | } catch (RemoteException e) { |
| 1024 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1031 | * admins or a particular one. This is the same value as |
| 1032 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1033 | * and only applies when the password quality is |
| 1034 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1035 | * |
| 1036 | * @param admin The name of the admin component to check, or null to |
| 1037 | * aggregate all admins. |
| 1038 | * @return The minimum number of symbols required in the password. |
| 1039 | */ |
| 1040 | public int getPasswordMinimumSymbols(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1041 | return getPasswordMinimumSymbols(admin, UserHandle.myUserId()); |
| 1042 | } |
| 1043 | |
| 1044 | /** @hide per-user version */ |
| 1045 | public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1046 | if (mService != null) { |
| 1047 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1048 | return mService.getPasswordMinimumSymbols(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1049 | } catch (RemoteException e) { |
| 1050 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1051 | } |
| 1052 | } |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1056 | /** |
| 1057 | * Called by an application that is administering the device to set the |
| 1058 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1059 | * required in the password. After setting this, the user will not be able |
| 1060 | * to enter a new password that is not at least as restrictive as what has |
| 1061 | * been set. Note that the current password will remain until the user has |
| 1062 | * set a new one, so the change does not take place immediately. To prompt |
| 1063 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1064 | * setting this value. This constraint is only imposed if the administrator |
| 1065 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1066 | * {@link #setPasswordQuality}. The default value is 0. |
| 1067 | * <p> |
| 1068 | * The calling device admin must have requested |
| 1069 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1070 | * this method; if it has not, a security exception will be thrown. |
| 1071 | * |
| 1072 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1073 | * with. |
| 1074 | * @param length The new desired minimum number of letters required in the |
| 1075 | * password. A value of 0 means there is no restriction. |
| 1076 | */ |
| 1077 | public void setPasswordMinimumNonLetter(ComponentName admin, int length) { |
| 1078 | if (mService != null) { |
| 1079 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1080 | mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1081 | } catch (RemoteException e) { |
| 1082 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1089 | * password for all admins of this user and its profiles or a particular one. |
| 1090 | * This is the same value as set by |
| 1091 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1092 | * and only applies when the password quality is |
| 1093 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1094 | * |
| 1095 | * @param admin The name of the admin component to check, or null to |
| 1096 | * aggregate all admins. |
| 1097 | * @return The minimum number of letters required in the password. |
| 1098 | */ |
| 1099 | public int getPasswordMinimumNonLetter(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1100 | return getPasswordMinimumNonLetter(admin, UserHandle.myUserId()); |
| 1101 | } |
| 1102 | |
| 1103 | /** @hide per-user version */ |
| 1104 | public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1105 | if (mService != null) { |
| 1106 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1107 | return mService.getPasswordMinimumNonLetter(admin, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1108 | } catch (RemoteException e) { |
| 1109 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1110 | } |
| 1111 | } |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * Called by an application that is administering the device to set the length |
| 1117 | * of the password history. After setting this, the user will not be able to |
| 1118 | * enter a new password that is the same as any password in the history. Note |
| 1119 | * that the current password will remain until the user has set a new one, so |
| 1120 | * the change does not take place immediately. To prompt the user for a new |
| 1121 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1122 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1123 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1124 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1125 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1126 | * |
| 1127 | * <p> |
| 1128 | * The calling device admin must have requested |
| 1129 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1130 | * method; if it has not, a security exception will be thrown. |
| 1131 | * |
| 1132 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1133 | * with. |
| 1134 | * @param length The new desired length of password history. A value of 0 |
| 1135 | * means there is no restriction. |
| 1136 | */ |
| 1137 | public void setPasswordHistoryLength(ComponentName admin, int length) { |
| 1138 | if (mService != null) { |
| 1139 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1140 | mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1141 | } catch (RemoteException e) { |
| 1142 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1148 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1149 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1150 | * the device password (for all admins). |
| 1151 | * |
| 1152 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1153 | * For example, to have the password expire 5 days from now, timeout would be |
| 1154 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1155 | * |
| 1156 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1157 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1158 | * <p>The calling device admin must have requested |
| 1159 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1160 | * method; if it has not, a security exception will be thrown. |
| 1161 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1162 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1163 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1164 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1165 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1166 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1167 | * means there is no restriction (unlimited). |
| 1168 | */ |
| 1169 | public void setPasswordExpirationTimeout(ComponentName admin, long timeout) { |
| 1170 | if (mService != null) { |
| 1171 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1172 | mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1173 | } catch (RemoteException e) { |
| 1174 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1180 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1181 | * recurring expiration timeout provided in the call to |
| 1182 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
| 1183 | * aggregate of all policy administrators if admin is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1184 | * |
| 1185 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 1186 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1187 | */ |
| 1188 | public long getPasswordExpirationTimeout(ComponentName admin) { |
| 1189 | if (mService != null) { |
| 1190 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1191 | return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1192 | } catch (RemoteException e) { |
| 1193 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1194 | } |
| 1195 | } |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * Get the current password expiration time for the given admin or an aggregate of |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1201 | * all admins of this user and its profiles if admin is null. If the password is |
| 1202 | * expired, this will return the time since the password expired as a negative number. |
| 1203 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1204 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1205 | * |
| 1206 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 1207 | * @return The password expiration time, in ms. |
| 1208 | */ |
| 1209 | public long getPasswordExpiration(ComponentName admin) { |
| 1210 | if (mService != null) { |
| 1211 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1212 | return mService.getPasswordExpiration(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1213 | } catch (RemoteException e) { |
| 1214 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1215 | } |
| 1216 | } |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1221 | * Retrieve the current password history length for all admins of this |
| 1222 | * user and its profiles or a particular one. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1223 | * @param admin The name of the admin component to check, or null to aggregate |
| 1224 | * all admins. |
| 1225 | * @return The length of the password history |
| 1226 | */ |
| 1227 | public int getPasswordHistoryLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1228 | return getPasswordHistoryLength(admin, UserHandle.myUserId()); |
| 1229 | } |
| 1230 | |
| 1231 | /** @hide per-user version */ |
| 1232 | public int getPasswordHistoryLength(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1233 | if (mService != null) { |
| 1234 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1235 | return mService.getPasswordHistoryLength(admin, userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1236 | } catch (RemoteException e) { |
| 1237 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1238 | } |
| 1239 | } |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1243 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1244 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1245 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1246 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1247 | * @return Returns the maximum length that the user can enter. |
| 1248 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1249 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1250 | // Kind-of arbitrary. |
| 1251 | return 16; |
| 1252 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1253 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1254 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1255 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1256 | * to meet the policy requirements (quality, minimum length) that have been |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1257 | * requested by the admins of this user and its profiles. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1258 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1259 | * <p>The calling device admin must have requested |
| 1260 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1261 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1262 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1263 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1264 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1265 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1266 | if (mService != null) { |
| 1267 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1268 | return mService.isActivePasswordSufficient(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1269 | } catch (RemoteException e) { |
| 1270 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1271 | } |
| 1272 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1273 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1274 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1275 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1276 | /** |
| 1277 | * Retrieve the number of times the user has failed at entering a |
| 1278 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1279 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1280 | * <p>The calling device admin must have requested |
| 1281 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1282 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1283 | */ |
| 1284 | public int getCurrentFailedPasswordAttempts() { |
| 1285 | if (mService != null) { |
| 1286 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1287 | return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1288 | } catch (RemoteException e) { |
| 1289 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1290 | } |
| 1291 | } |
| 1292 | return -1; |
| 1293 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1294 | |
| 1295 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1296 | * Setting this to a value greater than zero enables a built-in policy |
| 1297 | * that will perform a device wipe after too many incorrect |
| 1298 | * device-unlock passwords have been entered. This built-in policy combines |
| 1299 | * watching for failed passwords and wiping the device, and requires |
| 1300 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1301 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1302 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1303 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1304 | * application only, erasing or revoking credentials, or reporting the |
| 1305 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1306 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1307 | * instead. Do not use this API, because if the maximum count is reached, |
| 1308 | * the device will be wiped immediately, and your callback will not be invoked. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1309 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1310 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1311 | * @param num The number of failed password attempts at which point the |
| 1312 | * device will wipe its data. |
| 1313 | */ |
| 1314 | public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) { |
| 1315 | if (mService != null) { |
| 1316 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1317 | mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1318 | } catch (RemoteException e) { |
| 1319 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1320 | } |
| 1321 | } |
| 1322 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1323 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1324 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1325 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1326 | * before the device wipes itself, for all admins of this user and its profiles |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1327 | * or a particular one. |
| 1328 | * @param admin The name of the admin component to check, or null to aggregate |
| 1329 | * all admins. |
| 1330 | */ |
| 1331 | public int getMaximumFailedPasswordsForWipe(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1332 | return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId()); |
| 1333 | } |
| 1334 | |
| 1335 | /** @hide per-user version */ |
| 1336 | public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1337 | if (mService != null) { |
| 1338 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1339 | return mService.getMaximumFailedPasswordsForWipe(admin, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1340 | } catch (RemoteException e) { |
| 1341 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1342 | } |
| 1343 | } |
| 1344 | return 0; |
| 1345 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1346 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1347 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1348 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1349 | * for the given user. So for primary user, it might return the primary or |
| 1350 | * a managed profile. For a secondary user, it would be the same as the |
| 1351 | * user passed in. |
| 1352 | * @hide Used only by Keyguard |
| 1353 | */ |
| 1354 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1355 | if (mService != null) { |
| 1356 | try { |
| 1357 | return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle); |
| 1358 | } catch (RemoteException e) { |
| 1359 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1360 | } |
| 1361 | } |
| 1362 | return UserHandle.USER_NULL; |
| 1363 | } |
| 1364 | |
| 1365 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1366 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1367 | * the password again until the user has entered it. |
| 1368 | */ |
| 1369 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1370 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1371 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1372 | * Force a new device unlock password (the password needed to access the |
| 1373 | * entire device, not for individual accounts) on the user. This takes |
| 1374 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1375 | * The given password must be sufficient for the |
| 1376 | * current password quality and length constraints as returned by |
| 1377 | * {@link #getPasswordQuality(ComponentName)} and |
| 1378 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1379 | * these constraints, then it will be rejected and false returned. Note |
| 1380 | * that the password may be a stronger quality (containing alphanumeric |
| 1381 | * characters when the requested quality is only numeric), in which case |
| 1382 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1383 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1384 | * <p>Calling with a null or empty password will clear any existing PIN, |
| 1385 | * pattern or password if the current password constraints allow it. |
| 1386 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1387 | * <p>The calling device admin must have requested |
| 1388 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1389 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1390 | * |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 1391 | * <p>Calling this from a managed profile will throw a security exception. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1392 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1393 | * @param password The new password for the user. Null or empty clears the password. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1394 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1395 | * @return Returns true if the password was applied, or false if it is |
| 1396 | * not acceptable for the current constraints. |
| 1397 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1398 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1399 | if (mService != null) { |
| 1400 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1401 | return mService.resetPassword(password, flags, UserHandle.myUserId()); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1402 | } catch (RemoteException e) { |
| 1403 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1404 | } |
| 1405 | } |
| 1406 | return false; |
| 1407 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1408 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1409 | /** |
| 1410 | * Called by an application that is administering the device to set the |
| 1411 | * maximum time for user activity until the device will lock. This limits |
| 1412 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1413 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1414 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1415 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1416 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1417 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1418 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1419 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1420 | * A value of 0 means there is no restriction. |
| 1421 | */ |
| 1422 | public void setMaximumTimeToLock(ComponentName admin, long timeMs) { |
| 1423 | if (mService != null) { |
| 1424 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1425 | mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1426 | } catch (RemoteException e) { |
| 1427 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1428 | } |
| 1429 | } |
| 1430 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1431 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1432 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1433 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1434 | * and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1435 | * @param admin The name of the admin component to check, or null to aggregate |
| 1436 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 1437 | * @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] | 1438 | * 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] | 1439 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1440 | public long getMaximumTimeToLock(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1441 | return getMaximumTimeToLock(admin, UserHandle.myUserId()); |
| 1442 | } |
| 1443 | |
| 1444 | /** @hide per-user version */ |
| 1445 | public long getMaximumTimeToLock(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1446 | if (mService != null) { |
| 1447 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1448 | return mService.getMaximumTimeToLock(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1449 | } catch (RemoteException e) { |
| 1450 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1451 | } |
| 1452 | } |
| 1453 | return 0; |
| 1454 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1455 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1456 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1457 | * Make the device lock immediately, as if the lock screen timeout has |
| 1458 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1459 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1460 | * <p>The calling device admin must have requested |
| 1461 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 1462 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1463 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1464 | public void lockNow() { |
| 1465 | if (mService != null) { |
| 1466 | try { |
| 1467 | mService.lockNow(); |
| 1468 | } catch (RemoteException e) { |
| 1469 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1470 | } |
| 1471 | } |
| 1472 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1473 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1474 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1475 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1476 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1477 | */ |
| 1478 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 1479 | |
| 1480 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1481 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 1482 | * data. |
| 1483 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 1484 | * <p>This flag may only be set by device owner admins; if it is set by |
| 1485 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1486 | */ |
| 1487 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 1488 | |
| 1489 | /** |
Paul Quei | 2450a0e | 2013-09-20 09:26:21 +0800 | [diff] [blame] | 1490 | * Ask the user data be wiped. This will cause the device to reboot, |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1491 | * erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1492 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1493 | * <p>The calling device admin must have requested |
| 1494 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 1495 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1496 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1497 | * @param flags Bit mask of additional options: currently supported flags |
| 1498 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 1499 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1500 | */ |
| 1501 | public void wipeData(int flags) { |
| 1502 | if (mService != null) { |
| 1503 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1504 | mService.wipeData(flags, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1505 | } catch (RemoteException e) { |
| 1506 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1507 | } |
| 1508 | } |
| 1509 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1510 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1511 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1512 | * Called by an application that is administering the device to set the |
| 1513 | * global proxy and exclusion list. |
| 1514 | * <p> |
| 1515 | * The calling device admin must have requested |
| 1516 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 1517 | * this method; if it has not, a security exception will be thrown. |
| 1518 | * Only the first device admin can set the proxy. If a second admin attempts |
| 1519 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
| 1520 | * proxy will be returned. If successful in setting the proxy, null will |
| 1521 | * be returned. |
| 1522 | * The method can be called repeatedly by the device admin alrady setting the |
| 1523 | * proxy to update the proxy and exclusion list. |
| 1524 | * |
| 1525 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1526 | * with. |
| 1527 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 1528 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 1529 | * @param exclusionList a list of domains to be excluded from the global proxy. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1530 | * @return returns null if the proxy was successfully set, or a {@link ComponentName} |
| 1531 | * of the device admin that sets thew proxy otherwise. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1532 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1533 | */ |
| 1534 | public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec, |
| 1535 | List<String> exclusionList ) { |
| 1536 | if (proxySpec == null) { |
| 1537 | throw new NullPointerException(); |
| 1538 | } |
| 1539 | if (mService != null) { |
| 1540 | try { |
| 1541 | String hostSpec; |
| 1542 | String exclSpec; |
| 1543 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 1544 | hostSpec = null; |
| 1545 | exclSpec = null; |
| 1546 | } else { |
| 1547 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 1548 | throw new IllegalArgumentException(); |
| 1549 | } |
| 1550 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 1551 | String hostName = sa.getHostName(); |
| 1552 | int port = sa.getPort(); |
| 1553 | StringBuilder hostBuilder = new StringBuilder(); |
| 1554 | hostSpec = hostBuilder.append(hostName) |
| 1555 | .append(":").append(Integer.toString(port)).toString(); |
| 1556 | if (exclusionList == null) { |
| 1557 | exclSpec = ""; |
| 1558 | } else { |
| 1559 | StringBuilder listBuilder = new StringBuilder(); |
| 1560 | boolean firstDomain = true; |
| 1561 | for (String exclDomain : exclusionList) { |
| 1562 | if (!firstDomain) { |
| 1563 | listBuilder = listBuilder.append(","); |
| 1564 | } else { |
| 1565 | firstDomain = false; |
| 1566 | } |
| 1567 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 1568 | } |
| 1569 | exclSpec = listBuilder.toString(); |
| 1570 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 1571 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 1572 | != android.net.Proxy.PROXY_VALID) |
| 1573 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1574 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1575 | return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1576 | } catch (RemoteException e) { |
| 1577 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1578 | } |
| 1579 | } |
| 1580 | return null; |
| 1581 | } |
| 1582 | |
| 1583 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 1584 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 1585 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 1586 | * doing something unusual like general internal filtering this may be useful. On |
| 1587 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 1588 | * |
| 1589 | * <p>This method requires the caller to be the device owner. |
| 1590 | * |
| 1591 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 1592 | * @see ProxyInfo |
| 1593 | * |
| 1594 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1595 | * with. |
| 1596 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 1597 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 1598 | */ |
| 1599 | public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) { |
| 1600 | if (mService != null) { |
| 1601 | try { |
| 1602 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 1603 | } catch (RemoteException e) { |
| 1604 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1610 | * Returns the component name setting the global proxy. |
| 1611 | * @return ComponentName object of the device admin that set the global proxy, or |
| 1612 | * null if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1613 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1614 | */ |
| 1615 | public ComponentName getGlobalProxyAdmin() { |
| 1616 | if (mService != null) { |
| 1617 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1618 | return mService.getGlobalProxyAdmin(UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1619 | } catch (RemoteException e) { |
| 1620 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1621 | } |
| 1622 | } |
| 1623 | return null; |
| 1624 | } |
| 1625 | |
| 1626 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1627 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1628 | * indicating that encryption is not supported. |
| 1629 | */ |
| 1630 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 1631 | |
| 1632 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1633 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1634 | * indicating that encryption is supported, but is not currently active. |
| 1635 | */ |
| 1636 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 1637 | |
| 1638 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1639 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1640 | * indicating that encryption is not currently active, but is currently |
| 1641 | * being activated. This is only reported by devices that support |
| 1642 | * encryption of data and only when the storage is currently |
| 1643 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 1644 | * to become encrypted will never return this value. |
| 1645 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1646 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1647 | |
| 1648 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1649 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1650 | * indicating that encryption is active. |
| 1651 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1652 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1653 | |
| 1654 | /** |
| 1655 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 1656 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 1657 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 1658 | * to check encryption status. However, on some devices this activity may never return, as |
| 1659 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 1660 | */ |
| 1661 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1662 | public static final String ACTION_START_ENCRYPTION |
| 1663 | = "android.app.action.START_ENCRYPTION"; |
| 1664 | |
| 1665 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1666 | * Widgets are enabled in keyguard |
| 1667 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1668 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1669 | |
| 1670 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1671 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1672 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1673 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 1674 | |
| 1675 | /** |
| 1676 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1677 | */ |
| 1678 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 1679 | |
| 1680 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1681 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1682 | */ |
| 1683 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 1684 | |
| 1685 | /** |
| 1686 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1687 | */ |
| 1688 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 1689 | |
| 1690 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 1691 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1692 | * (e.g. PIN/Pattern/Password). |
| 1693 | */ |
| 1694 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 1695 | |
| 1696 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 1697 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 1698 | */ |
| 1699 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 1700 | |
| 1701 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1702 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1703 | */ |
| 1704 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1705 | |
| 1706 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1707 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1708 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1709 | * |
| 1710 | * <p>When multiple device administrators attempt to control device |
| 1711 | * encryption, the most secure, supported setting will always be |
| 1712 | * used. If any device administrator requests device encryption, |
| 1713 | * it will be enabled; Conversely, if a device administrator |
| 1714 | * attempts to disable device encryption while another |
| 1715 | * device administrator has enabled it, the call to disable will |
| 1716 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 1717 | * |
| 1718 | * <p>This policy controls encryption of the secure (application data) storage area. Data |
Andy Stadler | 50c294f | 2011-03-07 19:13:42 -0800 | [diff] [blame] | 1719 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 1720 | * or control the encryption of any other storage areas. |
| 1721 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 1722 | * {@code true}, then the directory returned by |
| 1723 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 1724 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1725 | * |
| 1726 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 1727 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 1728 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 1729 | * also require (and check for) a pattern, PIN, or password. |
| 1730 | * |
| 1731 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1732 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1733 | * @return the new request status (for all active admins) - will be one of |
| 1734 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 1735 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 1736 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1737 | */ |
| 1738 | public int setStorageEncryption(ComponentName admin, boolean encrypt) { |
| 1739 | if (mService != null) { |
| 1740 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1741 | return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1742 | } catch (RemoteException e) { |
| 1743 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1744 | } |
| 1745 | } |
| 1746 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1751 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1752 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1753 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 1754 | * this will return the requested encryption setting as an aggregate of all active |
| 1755 | * administrators. |
| 1756 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1757 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1758 | public boolean getStorageEncryption(ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1759 | if (mService != null) { |
| 1760 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1761 | return mService.getStorageEncryption(admin, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1762 | } catch (RemoteException e) { |
| 1763 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1764 | } |
| 1765 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1766 | return false; |
| 1767 | } |
| 1768 | |
| 1769 | /** |
| 1770 | * Called by an application that is administering the device to |
| 1771 | * determine the current encryption status of the device. |
| 1772 | * |
| 1773 | * Depending on the returned status code, the caller may proceed in different |
| 1774 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 1775 | * storage system does not support encryption. If the |
| 1776 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 1777 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
| 1778 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
| 1779 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 1780 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1781 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1782 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
| 1783 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}. |
| 1784 | */ |
| 1785 | public int getStorageEncryptionStatus() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1786 | return getStorageEncryptionStatus(UserHandle.myUserId()); |
| 1787 | } |
| 1788 | |
| 1789 | /** @hide per-user version */ |
| 1790 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1791 | if (mService != null) { |
| 1792 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1793 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1794 | } catch (RemoteException e) { |
| 1795 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1796 | } |
| 1797 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1798 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1799 | } |
| 1800 | |
| 1801 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1802 | * Installs the given certificate as a user CA. |
| 1803 | * |
| 1804 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1805 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1806 | * |
| 1807 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1808 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1809 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1810 | public boolean installCaCert(ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1811 | if (mService != null) { |
| 1812 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1813 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1814 | } catch (RemoteException e) { |
| 1815 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1816 | } |
| 1817 | } |
| 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1822 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 1823 | * |
| 1824 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1825 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1826 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1827 | public void uninstallCaCert(ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1828 | if (mService != null) { |
| 1829 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1830 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1831 | mService.uninstallCaCert(admin, alias); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1832 | } catch (CertificateException e) { |
| 1833 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1834 | } catch (RemoteException e) { |
| 1835 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1841 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 1842 | * If a user has installed any certificates by other means than device policy these will be |
| 1843 | * included too. |
| 1844 | * |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 1845 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1846 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1847 | */ |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 1848 | public List<byte[]> getInstalledCaCerts(ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1849 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 1850 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1851 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 1852 | mService.enforceCanManageCaCerts(admin); |
| 1853 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 1854 | for (String alias : certStore.userAliases()) { |
| 1855 | try { |
| 1856 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 1857 | } catch (CertificateException ce) { |
| 1858 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 1859 | } |
| 1860 | } |
| 1861 | } catch (RemoteException re) { |
| 1862 | Log.w(TAG, "Failed talking with device policy service", re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1869 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 1870 | * means other than device policy will also be removed, except for system CA certificates. |
| 1871 | * |
| 1872 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1873 | */ |
| 1874 | public void uninstallAllUserCaCerts(ComponentName admin) { |
| 1875 | if (mService != null) { |
| 1876 | for (String alias : new TrustedCertificateStore().userAliases()) { |
| 1877 | try { |
| 1878 | mService.uninstallCaCert(admin, alias); |
| 1879 | } catch (RemoteException re) { |
| 1880 | Log.w(TAG, "Failed talking with device policy service", re); |
| 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | /** |
| 1887 | * Returns whether this certificate is installed as a trusted CA. |
| 1888 | * |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 1889 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1890 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1891 | */ |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 1892 | public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) { |
| 1893 | if (mService != null) { |
| 1894 | try { |
| 1895 | mService.enforceCanManageCaCerts(admin); |
| 1896 | return getCaCertAlias(certBuffer) != null; |
| 1897 | } catch (RemoteException re) { |
| 1898 | Log.w(TAG, "Failed talking with device policy service", re); |
| 1899 | } catch (CertificateException ce) { |
| 1900 | Log.w(TAG, "Could not parse certificate", ce); |
| 1901 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1902 | } |
| 1903 | return false; |
| 1904 | } |
| 1905 | |
| 1906 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 1907 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 1908 | * keypair will be visible to all apps within the profile. |
| 1909 | * |
| 1910 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 1911 | * @param privKey The private key to install. |
| 1912 | * @param cert The certificate to install. |
| 1913 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 1914 | * with that alias already exists, it will be overwritten. |
| 1915 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 1916 | */ |
| 1917 | public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert, |
| 1918 | String alias) { |
| 1919 | try { |
| 1920 | final byte[] pemCert = Credentials.convertToPem(cert); |
| 1921 | return mService.installKeyPair(who, privKey.getEncoded(), pemCert, alias); |
| 1922 | } catch (CertificateException e) { |
| 1923 | Log.w(TAG, "Error encoding certificate", e); |
| 1924 | } catch (IOException e) { |
| 1925 | Log.w(TAG, "Error writing certificate", e); |
| 1926 | } catch (RemoteException e) { |
| 1927 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1928 | } |
| 1929 | return false; |
| 1930 | } |
| 1931 | |
| 1932 | /** |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1933 | * Returns the alias of a given CA certificate in the certificate store, or null if it |
| 1934 | * doesn't exist. |
| 1935 | */ |
| 1936 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 1937 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 1938 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 1939 | new ByteArrayInputStream(certBuffer)); |
| 1940 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 1941 | } |
| 1942 | |
| 1943 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1944 | * Called by an application that is administering the device to disable all cameras |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 1945 | * on the device, for this user. After setting this, no applications running as this user |
| 1946 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1947 | * |
| 1948 | * <p>The calling device admin must have requested |
| 1949 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 1950 | * this method; if it has not, a security exception will be thrown. |
| 1951 | * |
| 1952 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1953 | * @param disabled Whether or not the camera should be disabled. |
| 1954 | */ |
| 1955 | public void setCameraDisabled(ComponentName admin, boolean disabled) { |
| 1956 | if (mService != null) { |
| 1957 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1958 | mService.setCameraDisabled(admin, disabled, UserHandle.myUserId()); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1959 | } catch (RemoteException e) { |
| 1960 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 1966 | * Determine whether or not the device's cameras have been disabled for this user, |
| 1967 | * either by the current admin, if specified, or all admins. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1968 | * @param admin The name of the admin component to check, or null to check if any admins |
| 1969 | * have disabled the camera |
| 1970 | */ |
| 1971 | public boolean getCameraDisabled(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1972 | return getCameraDisabled(admin, UserHandle.myUserId()); |
| 1973 | } |
| 1974 | |
| 1975 | /** @hide per-user version */ |
| 1976 | public boolean getCameraDisabled(ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1977 | if (mService != null) { |
| 1978 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1979 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1980 | } catch (RemoteException e) { |
| 1981 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1982 | } |
| 1983 | } |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
| 1987 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 1988 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 1989 | * screen capture also prevents the content from being shown on display devices that do not have |
| 1990 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 1991 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 1992 | * |
| 1993 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 1994 | * security exception will be thrown. |
| 1995 | * |
| 1996 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 1997 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 1998 | */ |
| 1999 | public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) { |
| 2000 | if (mService != null) { |
| 2001 | try { |
| 2002 | mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled); |
| 2003 | } catch (RemoteException e) { |
| 2004 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | /** |
| 2010 | * Determine whether or not screen capture has been disabled by the current |
| 2011 | * admin, if specified, or all admins. |
| 2012 | * @param admin The name of the admin component to check, or null to check if any admins |
| 2013 | * have disabled screen capture. |
| 2014 | */ |
| 2015 | public boolean getScreenCaptureDisabled(ComponentName admin) { |
| 2016 | return getScreenCaptureDisabled(admin, UserHandle.myUserId()); |
| 2017 | } |
| 2018 | |
| 2019 | /** @hide per-user version */ |
| 2020 | public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) { |
| 2021 | if (mService != null) { |
| 2022 | try { |
| 2023 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2024 | } catch (RemoteException e) { |
| 2025 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2026 | } |
| 2027 | } |
| 2028 | return false; |
| 2029 | } |
| 2030 | |
| 2031 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2032 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2033 | * required the user cannot set the date and time, but has to use network date and time. |
| 2034 | * |
| 2035 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2036 | * |
| 2037 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2038 | * be thrown. |
| 2039 | * |
| 2040 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2041 | * @param required Whether auto time is set required or not. |
| 2042 | */ |
| 2043 | public void setAutoTimeRequired(ComponentName admin, boolean required) { |
| 2044 | if (mService != null) { |
| 2045 | try { |
| 2046 | mService.setAutoTimeRequired(admin, UserHandle.myUserId(), required); |
| 2047 | } catch (RemoteException e) { |
| 2048 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2049 | } |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | /** |
| 2054 | * @return true if auto time is required. |
| 2055 | */ |
| 2056 | public boolean getAutoTimeRequired() { |
| 2057 | if (mService != null) { |
| 2058 | try { |
| 2059 | return mService.getAutoTimeRequired(); |
| 2060 | } catch (RemoteException e) { |
| 2061 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2062 | } |
| 2063 | } |
| 2064 | return false; |
| 2065 | } |
| 2066 | |
| 2067 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2068 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2069 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2070 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2071 | * |
| 2072 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2073 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2074 | * this method; if it has not, a security exception will be thrown. |
| 2075 | * |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2076 | * <p>Calling this from a managed profile will throw a security exception. |
| 2077 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2078 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2079 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2080 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2081 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 2082 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2083 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2084 | public void setKeyguardDisabledFeatures(ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2085 | if (mService != null) { |
| 2086 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2087 | mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId()); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2088 | } catch (RemoteException e) { |
| 2089 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2095 | * Determine whether or not features have been disabled in keyguard either by the current |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2096 | * admin, if specified, or all admins. |
| 2097 | * @param admin The name of the admin component to check, or null to check if any admins |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2098 | * have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2099 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2100 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2101 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2102 | public int getKeyguardDisabledFeatures(ComponentName admin) { |
| 2103 | return getKeyguardDisabledFeatures(admin, UserHandle.myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | /** @hide per-user version */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2107 | public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2108 | if (mService != null) { |
| 2109 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2110 | return mService.getKeyguardDisabledFeatures(admin, userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2111 | } catch (RemoteException e) { |
| 2112 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2113 | } |
| 2114 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2115 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2119 | * @hide |
| 2120 | */ |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2121 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2122 | if (mService != null) { |
| 2123 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2124 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2125 | } catch (RemoteException e) { |
| 2126 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2127 | } |
| 2128 | } |
| 2129 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2130 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2131 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2132 | * @hide |
| 2133 | */ |
| 2134 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) { |
| 2135 | setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId()); |
| 2136 | } |
| 2137 | |
| 2138 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 2139 | * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2140 | * @hide |
| 2141 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 2142 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2143 | ActivityInfo ai; |
| 2144 | try { |
| 2145 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2146 | PackageManager.GET_META_DATA); |
| 2147 | } catch (PackageManager.NameNotFoundException e) { |
| 2148 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2149 | return null; |
| 2150 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2151 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2152 | ResolveInfo ri = new ResolveInfo(); |
| 2153 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2154 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2155 | try { |
| 2156 | return new DeviceAdminInfo(mContext, ri); |
| 2157 | } catch (XmlPullParserException e) { |
| 2158 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2159 | return null; |
| 2160 | } catch (IOException e) { |
| 2161 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2162 | return null; |
| 2163 | } |
| 2164 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2165 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2166 | /** |
| 2167 | * @hide |
| 2168 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2169 | public void getRemoveWarning(ComponentName admin, RemoteCallback result) { |
| 2170 | if (mService != null) { |
| 2171 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2172 | mService.getRemoveWarning(admin, result, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2173 | } catch (RemoteException e) { |
| 2174 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2175 | } |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | /** |
| 2180 | * @hide |
| 2181 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2182 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2183 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2184 | if (mService != null) { |
| 2185 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2186 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2187 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2188 | } catch (RemoteException e) { |
| 2189 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2190 | } |
| 2191 | } |
| 2192 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2193 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2194 | /** |
| 2195 | * @hide |
| 2196 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2197 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2198 | if (mService != null) { |
| 2199 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2200 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2201 | } catch (RemoteException e) { |
| 2202 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2203 | } |
| 2204 | } |
| 2205 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2206 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2207 | /** |
| 2208 | * @hide |
| 2209 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2210 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2211 | if (mService != null) { |
| 2212 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2213 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2214 | } catch (RemoteException e) { |
| 2215 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2216 | } |
| 2217 | } |
| 2218 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2219 | |
| 2220 | /** |
| 2221 | * @hide |
| 2222 | * Sets the given package as the device owner. The package must already be installed and there |
| 2223 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 2224 | * method must be called before the device is provisioned. |
| 2225 | * @param packageName the package name of the application to be registered as the device owner. |
| 2226 | * @return whether the package was successfully registered as the device owner. |
| 2227 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2228 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 2229 | * already been provisioned. |
| 2230 | */ |
| 2231 | public boolean setDeviceOwner(String packageName) throws IllegalArgumentException, |
| 2232 | IllegalStateException { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2233 | return setDeviceOwner(packageName, null); |
| 2234 | } |
| 2235 | |
| 2236 | /** |
| 2237 | * @hide |
| 2238 | * Sets the given package as the device owner. The package must already be installed and there |
| 2239 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 2240 | * method must be called before the device is provisioned. |
| 2241 | * @param packageName the package name of the application to be registered as the device owner. |
| 2242 | * @param ownerName the human readable name of the institution that owns this device. |
| 2243 | * @return whether the package was successfully registered as the device owner. |
| 2244 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2245 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 2246 | * already been provisioned. |
| 2247 | */ |
| 2248 | public boolean setDeviceOwner(String packageName, String ownerName) |
| 2249 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2250 | if (mService != null) { |
| 2251 | try { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2252 | return mService.setDeviceOwner(packageName, ownerName); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2253 | } catch (RemoteException re) { |
| 2254 | Log.w(TAG, "Failed to set device owner"); |
| 2255 | } |
| 2256 | } |
| 2257 | return false; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2261 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 2262 | * A device owner app is a special device admin that cannot be deactivated by the user, once |
| 2263 | * activated as a device admin. It also cannot be uninstalled. To check if a particular |
| 2264 | * package is currently registered as the device owner app, pass in the package name from |
| 2265 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
| 2266 | * admin apps that want to check if they are also registered as the device owner app. The |
| 2267 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 2268 | * the setup process. |
| 2269 | * @param packageName the package name of the app, to compare with the registered device owner |
| 2270 | * app, if any. |
| 2271 | * @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] | 2272 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2273 | public boolean isDeviceOwnerApp(String packageName) { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2274 | if (mService != null) { |
| 2275 | try { |
| 2276 | return mService.isDeviceOwner(packageName); |
| 2277 | } catch (RemoteException re) { |
| 2278 | Log.w(TAG, "Failed to check device owner"); |
| 2279 | } |
| 2280 | } |
| 2281 | return false; |
| 2282 | } |
| 2283 | |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2284 | /** |
| 2285 | * @hide |
| 2286 | * Redirect to isDeviceOwnerApp. |
| 2287 | */ |
| 2288 | public boolean isDeviceOwner(String packageName) { |
| 2289 | return isDeviceOwnerApp(packageName); |
| 2290 | } |
| 2291 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2292 | /** |
| 2293 | * Clears the current device owner. The caller must be the device owner. |
| 2294 | * |
| 2295 | * This function should be used cautiously as once it is called it cannot |
| 2296 | * be undone. The device owner can only be set as a part of device setup |
| 2297 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2298 | * |
| 2299 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2300 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2301 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2302 | if (mService != null) { |
| 2303 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2304 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2305 | } catch (RemoteException re) { |
| 2306 | Log.w(TAG, "Failed to clear device owner"); |
| 2307 | } |
| 2308 | } |
| 2309 | } |
| 2310 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2311 | /** @hide */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 2312 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2313 | public String getDeviceOwner() { |
| 2314 | if (mService != null) { |
| 2315 | try { |
| 2316 | return mService.getDeviceOwner(); |
| 2317 | } catch (RemoteException re) { |
| 2318 | Log.w(TAG, "Failed to get device owner"); |
| 2319 | } |
| 2320 | } |
| 2321 | return null; |
| 2322 | } |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2323 | |
| 2324 | /** @hide */ |
| 2325 | public String getDeviceOwnerName() { |
| 2326 | if (mService != null) { |
| 2327 | try { |
| 2328 | return mService.getDeviceOwnerName(); |
| 2329 | } catch (RemoteException re) { |
| 2330 | Log.w(TAG, "Failed to get device owner"); |
| 2331 | } |
| 2332 | } |
| 2333 | return null; |
| 2334 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2335 | |
| 2336 | /** |
| 2337 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2338 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2339 | * Sets the given component as an active admin and registers the package as the profile |
| 2340 | * owner for this user. The package must already be installed and there shouldn't be |
| 2341 | * an existing profile owner registered for this user. Also, this method must be called |
| 2342 | * before the user setup has been completed. |
| 2343 | * <p> |
| 2344 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 2345 | * MANAGE_DEVICE_ADMINS permission. |
| 2346 | * @param admin The component to register as an active admin and profile owner. |
| 2347 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 2348 | * @return whether the admin was successfully registered as the profile owner. |
| 2349 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 2350 | * the user has already been set up. |
| 2351 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 2352 | @SystemApi |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2353 | public boolean setActiveProfileOwner(ComponentName admin, String ownerName) |
| 2354 | throws IllegalArgumentException { |
| 2355 | if (mService != null) { |
| 2356 | try { |
| 2357 | final int myUserId = UserHandle.myUserId(); |
| 2358 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2359 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2360 | } catch (RemoteException re) { |
| 2361 | Log.w(TAG, "Failed to set profile owner " + re); |
| 2362 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2363 | } |
| 2364 | } |
| 2365 | return false; |
| 2366 | } |
| 2367 | |
| 2368 | /** |
| 2369 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2370 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 2371 | * be from the same package as the active profile owner for this user, otherwise a |
| 2372 | * SecurityException will be thrown. |
| 2373 | * |
| 2374 | * @param admin The component to remove as the profile owner. |
| 2375 | * @return |
| 2376 | */ |
| 2377 | @SystemApi |
| 2378 | public void clearProfileOwner(ComponentName admin) { |
| 2379 | if (mService != null) { |
| 2380 | try { |
| 2381 | mService.clearProfileOwner(admin); |
| 2382 | } catch (RemoteException re) { |
| 2383 | Log.w(TAG, "Failed to clear profile owner " + admin + re); |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | /** |
| 2389 | * @hide |
| 2390 | * Checks if the user was already setup. |
| 2391 | */ |
| 2392 | public boolean hasUserSetupCompleted() { |
| 2393 | if (mService != null) { |
| 2394 | try { |
| 2395 | return mService.hasUserSetupCompleted(); |
| 2396 | } catch (RemoteException re) { |
| 2397 | Log.w(TAG, "Failed to check if user setup has completed"); |
| 2398 | } |
| 2399 | } |
| 2400 | return true; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * @deprecated Use setProfileOwner(ComponentName ...) |
| 2405 | * @hide |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2406 | * Sets the given package as the profile owner of the given user profile. The package must |
| 2407 | * already be installed and there shouldn't be an existing profile owner registered for this |
| 2408 | * user. Also, this method must be called before the user has been used for the first time. |
| 2409 | * @param packageName the package name of the application to be registered as profile owner. |
| 2410 | * @param ownerName the human readable name of the organisation associated with this DPM. |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 2411 | * @param userHandle the userId to set the profile owner for. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2412 | * @return whether the package was successfully registered as the profile owner. |
| 2413 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 2414 | * the user has already been set up. |
| 2415 | */ |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 2416 | public boolean setProfileOwner(String packageName, String ownerName, int userHandle) |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2417 | throws IllegalArgumentException { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2418 | if (packageName == null) { |
| 2419 | throw new NullPointerException("packageName cannot be null"); |
| 2420 | } |
| 2421 | return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle); |
| 2422 | } |
| 2423 | |
| 2424 | /** |
| 2425 | * @hide |
| 2426 | * Sets the given component as the profile owner of the given user profile. The package must |
| 2427 | * already be installed and there shouldn't be an existing profile owner registered for this |
| 2428 | * user. Only the system can call this API if the user has already completed setup. |
| 2429 | * @param admin the component name to be registered as profile owner. |
| 2430 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 2431 | * @param userHandle the userId to set the profile owner for. |
| 2432 | * @return whether the component was successfully registered as the profile owner. |
| 2433 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or |
| 2434 | * the user has already been set up. |
| 2435 | */ |
| 2436 | public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle) |
| 2437 | throws IllegalArgumentException { |
| 2438 | if (admin == null) { |
| 2439 | throw new NullPointerException("admin cannot be null"); |
| 2440 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2441 | if (mService != null) { |
| 2442 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2443 | if (ownerName == null) { |
| 2444 | ownerName = ""; |
| 2445 | } |
| 2446 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2447 | } catch (RemoteException re) { |
| 2448 | Log.w(TAG, "Failed to set profile owner", re); |
| 2449 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2450 | } |
| 2451 | } |
| 2452 | return false; |
| 2453 | } |
| 2454 | |
| 2455 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2456 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 2457 | * be used. Only the profile owner can call this. |
| 2458 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2459 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2460 | * |
| 2461 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2462 | */ |
| 2463 | public void setProfileEnabled(ComponentName admin) { |
| 2464 | if (mService != null) { |
| 2465 | try { |
| 2466 | mService.setProfileEnabled(admin); |
| 2467 | } catch (RemoteException e) { |
| 2468 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2469 | } |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2474 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 2475 | * which it is called from. Only a profile owner or device owner can call this. If this is |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 2476 | * never called by the profile or device owner, the name will be set to default values. |
| 2477 | * |
| 2478 | * @see #isProfileOwnerApp |
| 2479 | * @see #isDeviceOwnerApp |
| 2480 | * |
| 2481 | * @param profileName The name of the profile. |
| 2482 | */ |
| 2483 | public void setProfileName(ComponentName who, String profileName) { |
| 2484 | if (mService != null) { |
| 2485 | try { |
| 2486 | mService.setProfileName(who, profileName); |
| 2487 | } catch (RemoteException e) { |
| 2488 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2489 | } |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2494 | * Used to determine if a particular package is registered as the profile owner for the |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2495 | * current 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] | 2496 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2497 | * |
| 2498 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 2499 | * @return Whether or not the package is registered as the profile owner. |
| 2500 | */ |
| 2501 | public boolean isProfileOwnerApp(String packageName) { |
| 2502 | if (mService != null) { |
| 2503 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 2504 | ComponentName profileOwner = mService.getProfileOwner( |
| 2505 | Process.myUserHandle().getIdentifier()); |
| 2506 | return profileOwner != null |
| 2507 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2508 | } catch (RemoteException re) { |
| 2509 | Log.w(TAG, "Failed to check profile owner"); |
| 2510 | } |
| 2511 | } |
| 2512 | return false; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
| 2516 | * @hide |
| 2517 | * @return the packageName of the owner of the given user profile or null if no profile |
| 2518 | * owner has been set for that user. |
| 2519 | * @throws IllegalArgumentException if the userId is invalid. |
| 2520 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 2521 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2522 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2523 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 2524 | } |
| 2525 | |
| 2526 | /** |
| 2527 | * @see #getProfileOwner() |
| 2528 | * @hide |
| 2529 | */ |
| 2530 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2531 | if (mService != null) { |
| 2532 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2533 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2534 | } catch (RemoteException re) { |
| 2535 | Log.w(TAG, "Failed to get profile owner"); |
| 2536 | throw new IllegalArgumentException( |
| 2537 | "Requested profile owner for invalid userId", re); |
| 2538 | } |
| 2539 | } |
| 2540 | return null; |
| 2541 | } |
| 2542 | |
| 2543 | /** |
| 2544 | * @hide |
| 2545 | * @return the human readable name of the organisation associated with this DPM or null if |
| 2546 | * one is not set. |
| 2547 | * @throws IllegalArgumentException if the userId is invalid. |
| 2548 | */ |
| 2549 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 2550 | if (mService != null) { |
| 2551 | try { |
| 2552 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 2553 | } catch (RemoteException re) { |
| 2554 | Log.w(TAG, "Failed to get profile owner"); |
| 2555 | throw new IllegalArgumentException( |
| 2556 | "Requested profile owner for invalid userId", re); |
| 2557 | } |
| 2558 | } |
| 2559 | return null; |
| 2560 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2561 | |
| 2562 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2563 | * @hide |
| 2564 | * @param user The user for whom to fetch the profile owner name, if any. |
| 2565 | * @return the human readable name of the organisation associated with this profile owner or |
| 2566 | * null if one is not set. |
| 2567 | * @throws IllegalArgumentException if the userId is invalid. |
| 2568 | */ |
| 2569 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 2570 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2571 | if (mService != null) { |
| 2572 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 2573 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2574 | } catch (RemoteException re) { |
| 2575 | Log.w(TAG, "Failed to get profile owner"); |
| 2576 | throw new IllegalArgumentException( |
| 2577 | "Requested profile owner for invalid userId", re); |
| 2578 | } |
| 2579 | } |
| 2580 | return null; |
| 2581 | } |
| 2582 | |
| 2583 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2584 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 2585 | * intents that match a certain intent filter. This activity will remain the default intent |
| 2586 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 2587 | * the intent preferences are reset. |
| 2588 | * |
| 2589 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 2590 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 2591 | * intent handler for the filter. |
| 2592 | * |
| 2593 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 2594 | * security exception will be thrown. |
| 2595 | * |
| 2596 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2597 | * @param filter The IntentFilter for which a default handler is added. |
| 2598 | * @param activity The Activity that is added as default intent handler. |
| 2599 | */ |
| 2600 | public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, |
| 2601 | ComponentName activity) { |
| 2602 | if (mService != null) { |
| 2603 | try { |
| 2604 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 2605 | } catch (RemoteException e) { |
| 2606 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2607 | } |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | /** |
| 2612 | * 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] | 2613 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2614 | * |
| 2615 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 2616 | * exception will be thrown. |
| 2617 | * |
| 2618 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2619 | * @param packageName The name of the package for which preferences are removed. |
| 2620 | */ |
| 2621 | public void clearPackagePersistentPreferredActivities(ComponentName admin, |
| 2622 | String packageName) { |
| 2623 | if (mService != null) { |
| 2624 | try { |
| 2625 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 2626 | } catch (RemoteException e) { |
| 2627 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2628 | } |
| 2629 | } |
| 2630 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2631 | |
| 2632 | /** |
| 2633 | * Called by a profile or device owner to set the application restrictions for a given target |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2634 | * application running in the profile. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2635 | * |
| 2636 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be |
Kenny Guy | d00cfc5 | 2014-09-18 16:24:31 +0100 | [diff] [blame] | 2637 | * boolean, int, String, or String[]. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2638 | * |
| 2639 | * <p>The application restrictions are only made visible to the target application and the |
| 2640 | * profile or device owner. |
| 2641 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 2642 | * <p>If the restrictions are not available yet, but may be applied in the near future, |
| 2643 | * the admin can notify the target application of that by adding |
| 2644 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 2645 | * |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2646 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 2647 | * exception will be thrown. |
| 2648 | * |
| 2649 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2650 | * @param packageName The name of the package to update restricted settings for. |
| 2651 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 2652 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 2653 | * |
| 2654 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2655 | */ |
| 2656 | public void setApplicationRestrictions(ComponentName admin, String packageName, |
| 2657 | Bundle settings) { |
| 2658 | if (mService != null) { |
| 2659 | try { |
| 2660 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 2661 | } catch (RemoteException e) { |
| 2662 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2663 | } |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2668 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 2669 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 2670 | * trust agents but those enabled by this function call. If flag |
| 2671 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2672 | * |
| 2673 | * <p>The calling device admin must have requested |
| 2674 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2675 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2676 | * |
| 2677 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2678 | * @param target Component name of the agent to be enabled. |
| 2679 | * @param options TrustAgent-specific feature bundle. If null for any admin, agent |
| 2680 | * will be strictly disabled according to the state of the |
| 2681 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 2682 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 2683 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 2684 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2685 | */ |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2686 | public void setTrustAgentConfiguration(ComponentName admin, ComponentName target, |
| 2687 | PersistableBundle options) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2688 | if (mService != null) { |
| 2689 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2690 | mService.setTrustAgentConfiguration(admin, target, options, UserHandle.myUserId()); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2691 | } catch (RemoteException e) { |
| 2692 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2693 | } |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2698 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 2699 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 2700 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2701 | * |
| 2702 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2703 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2704 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2705 | */ |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2706 | public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin, |
| 2707 | ComponentName agent) { |
| 2708 | return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId()); |
| 2709 | } |
| 2710 | |
| 2711 | /** @hide per-user version */ |
| 2712 | public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin, |
| 2713 | ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2714 | if (mService != null) { |
| 2715 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2716 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2717 | } catch (RemoteException e) { |
| 2718 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2719 | } |
| 2720 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 2721 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2725 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 2726 | * the managed profile will be shown in the parent profile, for incoming calls. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 2727 | * |
| 2728 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 2729 | * security exception will be thrown. |
| 2730 | * |
| 2731 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2732 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 2733 | */ |
| 2734 | public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) { |
| 2735 | if (mService != null) { |
| 2736 | try { |
| 2737 | mService.setCrossProfileCallerIdDisabled(who, disabled); |
| 2738 | } catch (RemoteException e) { |
| 2739 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2740 | } |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2745 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 2746 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 2747 | * |
| 2748 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 2749 | * security exception will be thrown. |
| 2750 | * |
| 2751 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2752 | */ |
| 2753 | public boolean getCrossProfileCallerIdDisabled(ComponentName who) { |
| 2754 | if (mService != null) { |
| 2755 | try { |
| 2756 | return mService.getCrossProfileCallerIdDisabled(who); |
| 2757 | } catch (RemoteException e) { |
| 2758 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2759 | } |
| 2760 | } |
| 2761 | return false; |
| 2762 | } |
| 2763 | |
| 2764 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 2765 | * Determine whether or not caller-Id information has been disabled. |
| 2766 | * |
| 2767 | * @param userHandle The user for whom to check the caller-id permission |
| 2768 | * @hide |
| 2769 | */ |
| 2770 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 2771 | if (mService != null) { |
| 2772 | try { |
| 2773 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 2774 | } catch (RemoteException e) { |
| 2775 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2776 | } |
| 2777 | } |
| 2778 | return false; |
| 2779 | } |
| 2780 | |
| 2781 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2782 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 2783 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame^] | 2784 | * Only activity intents are supported. |
| 2785 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2786 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2787 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 2788 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 2789 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 2790 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2791 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2792 | public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2793 | if (mService != null) { |
| 2794 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2795 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2796 | } catch (RemoteException e) { |
| 2797 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2798 | } |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2803 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 2804 | * 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] | 2805 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2806 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2807 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2808 | public void clearCrossProfileIntentFilters(ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2809 | if (mService != null) { |
| 2810 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2811 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2812 | } catch (RemoteException e) { |
| 2813 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2814 | } |
| 2815 | } |
| 2816 | } |
| 2817 | |
| 2818 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 2819 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 2820 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 2821 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 2822 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 2823 | * By default the user can use any accessiblity service. When zero or more packages have |
| 2824 | * been added, accessiblity services that are not in the list and not part of the system |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 2825 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 2826 | * |
| 2827 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 2828 | * can be used, calling with an empty list only allows the builtin system's services. |
| 2829 | * |
| 2830 | * <p> System accesibility services are always available to the user the list can't modify |
| 2831 | * this. |
| 2832 | * |
| 2833 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2834 | * @param packageNames List of accessibility service package names. |
| 2835 | * |
| 2836 | * @return true if setting the restriction succeeded. It fail if there is |
| 2837 | * one or more non-system accessibility services enabled, that are not in the list. |
| 2838 | */ |
| 2839 | public boolean setPermittedAccessibilityServices(ComponentName admin, |
| 2840 | List<String> packageNames) { |
| 2841 | if (mService != null) { |
| 2842 | try { |
| 2843 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 2844 | } catch (RemoteException e) { |
| 2845 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2846 | } |
| 2847 | } |
| 2848 | return false; |
| 2849 | } |
| 2850 | |
| 2851 | /** |
| 2852 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 2853 | * |
| 2854 | * <p>An empty list means no accessibility services except system services are allowed. |
| 2855 | * Null means all accessibility services are allowed. |
| 2856 | * |
| 2857 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2858 | * @return List of accessiblity service package names. |
| 2859 | */ |
| 2860 | public List<String> getPermittedAccessibilityServices(ComponentName admin) { |
| 2861 | if (mService != null) { |
| 2862 | try { |
| 2863 | return mService.getPermittedAccessibilityServices(admin); |
| 2864 | } catch (RemoteException e) { |
| 2865 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2866 | } |
| 2867 | } |
| 2868 | return null; |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * Returns the list of accessibility services permitted by the device or profiles |
| 2873 | * owners of this user. |
| 2874 | * |
| 2875 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 2876 | * it will contain the intersection of the permitted lists for any device or profile |
| 2877 | * owners that apply to this user. It will also include any system accessibility services. |
| 2878 | * |
| 2879 | * @param userId which user to check for. |
| 2880 | * @return List of accessiblity service package names. |
| 2881 | * @hide |
| 2882 | */ |
| 2883 | @SystemApi |
| 2884 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 2885 | if (mService != null) { |
| 2886 | try { |
| 2887 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 2888 | } catch (RemoteException e) { |
| 2889 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2890 | } |
| 2891 | } |
| 2892 | return null; |
| 2893 | } |
| 2894 | |
| 2895 | /** |
| 2896 | * Called by a profile or device owner to set the permitted input methods services. When |
| 2897 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 2898 | * user the device owner or profile owner is an admin for. |
| 2899 | * |
| 2900 | * By default the user can use any input method. When zero or more packages have |
| 2901 | * been added, input method that are not in the list and not part of the system |
| 2902 | * can not be enabled by the user. |
| 2903 | * |
| 2904 | * This method will fail if it is called for a admin that is not for the foreground user |
| 2905 | * or a profile of the foreground user. |
| 2906 | * |
| 2907 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 2908 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 2909 | * |
| 2910 | * <p> System input methods are always available to the user this method can't modify this. |
| 2911 | * |
| 2912 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2913 | * @param packageNames List of input method package names. |
| 2914 | * @return true if setting the restriction succeeded. It will fail if there is |
| 2915 | * one or more input method enabled, that are not in the list or user if the foreground |
| 2916 | * user. |
| 2917 | */ |
| 2918 | public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) { |
| 2919 | if (mService != null) { |
| 2920 | try { |
| 2921 | return mService.setPermittedInputMethods(admin, packageNames); |
| 2922 | } catch (RemoteException e) { |
| 2923 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2924 | } |
| 2925 | } |
| 2926 | return false; |
| 2927 | } |
| 2928 | |
| 2929 | |
| 2930 | /** |
| 2931 | * Returns the list of permitted input methods set by this device or profile owner. |
| 2932 | * |
| 2933 | * <p>An empty list means no input methods except system input methods are allowed. |
| 2934 | * Null means all input methods are allowed. |
| 2935 | * |
| 2936 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2937 | * @return List of input method package names. |
| 2938 | */ |
| 2939 | public List<String> getPermittedInputMethods(ComponentName admin) { |
| 2940 | if (mService != null) { |
| 2941 | try { |
| 2942 | return mService.getPermittedInputMethods(admin); |
| 2943 | } catch (RemoteException e) { |
| 2944 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2945 | } |
| 2946 | } |
| 2947 | return null; |
| 2948 | } |
| 2949 | |
| 2950 | /** |
| 2951 | * Returns the list of input methods permitted by the device or profiles |
| 2952 | * owners of the current user. |
| 2953 | * |
| 2954 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 2955 | * it will contain the intersection of the permitted lists for any device or profile |
| 2956 | * owners that apply to this user. It will also include any system input methods. |
| 2957 | * |
| 2958 | * @return List of input method package names. |
| 2959 | * @hide |
| 2960 | */ |
| 2961 | @SystemApi |
| 2962 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 2963 | if (mService != null) { |
| 2964 | try { |
| 2965 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 2966 | } catch (RemoteException e) { |
| 2967 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2968 | } |
| 2969 | } |
| 2970 | return null; |
| 2971 | } |
| 2972 | |
| 2973 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 2974 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 2975 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 2976 | * created. If you need to persist an identifier for this user, use |
| 2977 | * {@link UserManager#getSerialNumberForUser}. |
| 2978 | * |
| 2979 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2980 | * @param name the user's name |
| 2981 | * @see UserHandle |
| 2982 | * @return the UserHandle object for the created user, or null if the user could not be created. |
| 2983 | */ |
| 2984 | public UserHandle createUser(ComponentName admin, String name) { |
| 2985 | try { |
| 2986 | return mService.createUser(admin, name); |
| 2987 | } catch (RemoteException re) { |
| 2988 | Log.w(TAG, "Could not create a user", re); |
| 2989 | } |
| 2990 | return null; |
| 2991 | } |
| 2992 | |
| 2993 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 2994 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 2995 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 2996 | * created. If you need to persist an identifier for this user, use |
| 2997 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 2998 | * immediately. |
| 2999 | * |
| 3000 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 3001 | * as registered as an active admin on the new user. The profile owner package will be |
| 3002 | * installed on the new user if it already is installed on the device. |
| 3003 | * |
| 3004 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 3005 | * profileOwnerComponent when onEnable is called. |
| 3006 | * |
| 3007 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3008 | * @param name the user's name |
| 3009 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3010 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 3011 | * the user. |
| 3012 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 3013 | * on the new user. |
| 3014 | * @see UserHandle |
| 3015 | * @return the UserHandle object for the created user, or null if the user could not be created. |
| 3016 | */ |
| 3017 | public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName, |
| 3018 | ComponentName profileOwnerComponent, Bundle adminExtras) { |
| 3019 | try { |
| 3020 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 3021 | adminExtras); |
| 3022 | } catch (RemoteException re) { |
| 3023 | Log.w(TAG, "Could not create a user", re); |
| 3024 | } |
| 3025 | return null; |
| 3026 | } |
| 3027 | |
| 3028 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3029 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 3030 | * not be removed. |
| 3031 | * |
| 3032 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3033 | * @param userHandle the user to remove. |
| 3034 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 3035 | */ |
| 3036 | public boolean removeUser(ComponentName admin, UserHandle userHandle) { |
| 3037 | try { |
| 3038 | return mService.removeUser(admin, userHandle); |
| 3039 | } catch (RemoteException re) { |
| 3040 | Log.w(TAG, "Could not remove user ", re); |
| 3041 | return false; |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 3046 | * Called by a device owner to switch the specified user to the foreground. |
| 3047 | * |
| 3048 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3049 | * @param userHandle the user to switch to; null will switch to primary. |
| 3050 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 3051 | * |
| 3052 | * @see Intent#ACTION_USER_FOREGROUND |
| 3053 | */ |
| 3054 | public boolean switchUser(ComponentName admin, UserHandle userHandle) { |
| 3055 | try { |
| 3056 | return mService.switchUser(admin, userHandle); |
| 3057 | } catch (RemoteException re) { |
| 3058 | Log.w(TAG, "Could not switch user ", re); |
| 3059 | return false; |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | /** |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3064 | * Called by a profile or device owner to get the application restrictions for a given target |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3065 | * application running in the profile. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3066 | * |
| 3067 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 3068 | * exception will be thrown. |
| 3069 | * |
| 3070 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3071 | * @param packageName The name of the package to fetch restricted settings of. |
| 3072 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 3073 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 3074 | * if no restrictions have been set. |
| 3075 | */ |
| 3076 | public Bundle getApplicationRestrictions(ComponentName admin, String packageName) { |
| 3077 | if (mService != null) { |
| 3078 | try { |
| 3079 | return mService.getApplicationRestrictions(admin, packageName); |
| 3080 | } catch (RemoteException e) { |
| 3081 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3082 | } |
| 3083 | } |
| 3084 | return null; |
| 3085 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3086 | |
| 3087 | /** |
| 3088 | * Called by a profile or device owner to set a user restriction specified |
| 3089 | * by the key. |
| 3090 | * <p> |
| 3091 | * The calling device admin must be a profile or device owner; if it is not, |
| 3092 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 3093 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3094 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 3095 | * with. |
| 3096 | * @param key The key of the restriction. See the constants in |
| 3097 | * {@link android.os.UserManager} for the list of keys. |
| 3098 | */ |
| 3099 | public void addUserRestriction(ComponentName admin, String key) { |
| 3100 | if (mService != null) { |
| 3101 | try { |
| 3102 | mService.setUserRestriction(admin, key, true); |
| 3103 | } catch (RemoteException e) { |
| 3104 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | /** |
| 3110 | * Called by a profile or device owner to clear a user restriction specified |
| 3111 | * by the key. |
| 3112 | * <p> |
| 3113 | * The calling device admin must be a profile or device owner; if it is not, |
| 3114 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 3115 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3116 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 3117 | * with. |
| 3118 | * @param key The key of the restriction. See the constants in |
| 3119 | * {@link android.os.UserManager} for the list of keys. |
| 3120 | */ |
| 3121 | public void clearUserRestriction(ComponentName admin, String key) { |
| 3122 | if (mService != null) { |
| 3123 | try { |
| 3124 | mService.setUserRestriction(admin, key, false); |
| 3125 | } catch (RemoteException e) { |
| 3126 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3127 | } |
| 3128 | } |
| 3129 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 3130 | |
| 3131 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3132 | * Called by device or profile owner to hide or unhide packages. When a package is hidden it |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3133 | * is unavailable for use, but the data and actual package file remain. |
| 3134 | * |
| 3135 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3136 | * @param packageName The name of the package to hide or unhide. |
| 3137 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 3138 | * unhidden. |
| 3139 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3140 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3141 | public boolean setApplicationHidden(ComponentName admin, String packageName, |
| 3142 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3143 | if (mService != null) { |
| 3144 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3145 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3146 | } catch (RemoteException e) { |
| 3147 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3148 | } |
| 3149 | } |
| 3150 | return false; |
| 3151 | } |
| 3152 | |
| 3153 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3154 | * Called by device or profile owner to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3155 | * |
| 3156 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3157 | * @param packageName The name of the package to retrieve the hidden status of. |
| 3158 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3159 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3160 | public boolean isApplicationHidden(ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3161 | if (mService != null) { |
| 3162 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3163 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3164 | } catch (RemoteException e) { |
| 3165 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3166 | } |
| 3167 | } |
| 3168 | return false; |
| 3169 | } |
| 3170 | |
| 3171 | /** |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3172 | * Called by profile or device owner to re-enable a system app that was disabled by default |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3173 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3174 | * |
| 3175 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3176 | * @param packageName The package to be re-enabled in the current profile. |
| 3177 | */ |
| 3178 | public void enableSystemApp(ComponentName admin, String packageName) { |
| 3179 | if (mService != null) { |
| 3180 | try { |
| 3181 | mService.enableSystemApp(admin, packageName); |
| 3182 | } catch (RemoteException e) { |
| 3183 | Log.w(TAG, "Failed to install package: " + packageName); |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | /** |
| 3189 | * Called by profile or device owner to re-enable system apps by intent that were disabled |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3190 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3191 | * |
| 3192 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3193 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
| 3194 | * intent will be re-enabled in the current profile. |
| 3195 | * @return int The number of activities that matched the intent and were installed. |
| 3196 | */ |
| 3197 | public int enableSystemApp(ComponentName admin, Intent intent) { |
| 3198 | if (mService != null) { |
| 3199 | try { |
| 3200 | return mService.enableSystemAppWithIntent(admin, intent); |
| 3201 | } catch (RemoteException e) { |
| 3202 | Log.w(TAG, "Failed to install packages matching filter: " + intent); |
| 3203 | } |
| 3204 | } |
| 3205 | return 0; |
| 3206 | } |
| 3207 | |
| 3208 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 3209 | * Called by a device owner or profile owner to disable account management for a specific type |
| 3210 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3211 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 3212 | * <p>The calling device admin must be a device owner or profile owner. If it is not, a |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3213 | * security exception will be thrown. |
| 3214 | * |
| 3215 | * <p>When account management is disabled for an account type, adding or removing an account |
| 3216 | * of that type will not be possible. |
| 3217 | * |
| 3218 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3219 | * @param accountType For which account management is disabled or enabled. |
| 3220 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 3221 | * enabled (false). |
| 3222 | */ |
| 3223 | public void setAccountManagementDisabled(ComponentName admin, String accountType, |
| 3224 | boolean disabled) { |
| 3225 | if (mService != null) { |
| 3226 | try { |
| 3227 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 3228 | } catch (RemoteException e) { |
| 3229 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3230 | } |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3235 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 3236 | * |
| 3237 | * <p> Account management can be disabled/enabled by calling |
| 3238 | * {@link #setAccountManagementDisabled}. |
| 3239 | * |
| 3240 | * @return a list of account types for which account management has been disabled. |
| 3241 | * |
| 3242 | * @see #setAccountManagementDisabled |
| 3243 | */ |
| 3244 | public String[] getAccountTypesWithManagementDisabled() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3245 | return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | /** |
| 3249 | * @see #getAccountTypesWithManagementDisabled() |
| 3250 | * @hide |
| 3251 | */ |
| 3252 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3253 | if (mService != null) { |
| 3254 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 3255 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3256 | } catch (RemoteException e) { |
| 3257 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | return null; |
| 3262 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3263 | |
| 3264 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3265 | * Sets which packages may enter lock task mode. |
| 3266 | * |
| 3267 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 3268 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3269 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 3270 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3271 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3272 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3273 | * |
| 3274 | * @see Activity#startLockTask() |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 3275 | * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String) |
| 3276 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3277 | */ |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3278 | public void setLockTaskPackages(ComponentName admin, String[] packages) |
| 3279 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3280 | if (mService != null) { |
| 3281 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3282 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3283 | } catch (RemoteException e) { |
| 3284 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3285 | } |
| 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3290 | * This function returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3291 | * |
| 3292 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3293 | * @hide |
| 3294 | */ |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3295 | public String[] getLockTaskPackages(ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3296 | if (mService != null) { |
| 3297 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3298 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3299 | } catch (RemoteException e) { |
| 3300 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3301 | } |
| 3302 | } |
| 3303 | return null; |
| 3304 | } |
| 3305 | |
| 3306 | /** |
| 3307 | * This function lets the caller know whether the given component is allowed to start the |
| 3308 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3309 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3310 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3311 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3312 | if (mService != null) { |
| 3313 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3314 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3315 | } catch (RemoteException e) { |
| 3316 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3317 | } |
| 3318 | } |
| 3319 | return false; |
| 3320 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3321 | |
| 3322 | /** |
| 3323 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 3324 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3325 | * <p>The settings that can be updated with this method are: |
| 3326 | * <ul> |
| 3327 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 3328 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 3329 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
| 3330 | * <li>{@link Settings.Global#BLUETOOTH_ON}</li> |
| 3331 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
| 3332 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 3333 | * <li>{@link Settings.Global#MODE_RINGER}</li> |
| 3334 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 3335 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
| 3336 | * <li>{@link Settings.Global#WIFI_ON}</li> |
| 3337 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
| 3338 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3339 | * |
| 3340 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3341 | * @param setting The name of the setting to update. |
| 3342 | * @param value The value to update the setting to. |
| 3343 | */ |
| 3344 | public void setGlobalSetting(ComponentName admin, String setting, String value) { |
| 3345 | if (mService != null) { |
| 3346 | try { |
| 3347 | mService.setGlobalSetting(admin, setting, value); |
| 3348 | } catch (RemoteException e) { |
| 3349 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | /** |
| 3355 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 3356 | * that the value of the setting is in the correct form for the setting type should be performed |
| 3357 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 3358 | * <p>The settings that can be updated by a profile or device owner with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3359 | * <ul> |
| 3360 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 3361 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3362 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 3363 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 3364 | * <p>A device owner can additionally update the following settings: |
| 3365 | * <ul> |
| 3366 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 3367 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3368 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3369 | * @param setting The name of the setting to update. |
| 3370 | * @param value The value to update the setting to. |
| 3371 | */ |
| 3372 | public void setSecureSetting(ComponentName admin, String setting, String value) { |
| 3373 | if (mService != null) { |
| 3374 | try { |
| 3375 | mService.setSecureSetting(admin, setting, value); |
| 3376 | } catch (RemoteException e) { |
| 3377 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3378 | } |
| 3379 | } |
| 3380 | } |
| 3381 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3382 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3383 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3384 | * making permission requests of a local or remote administrator of the user. |
| 3385 | * <p/> |
| 3386 | * Only a profile owner can designate the restrictions provider. |
| 3387 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3388 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 3389 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3390 | * it removes the restrictions provider previously assigned. |
| 3391 | */ |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3392 | public void setRestrictionsProvider(ComponentName admin, ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3393 | if (mService != null) { |
| 3394 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3395 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3396 | } catch (RemoteException re) { |
| 3397 | Log.w(TAG, "Failed to set permission provider on device policy service"); |
| 3398 | } |
| 3399 | } |
| 3400 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 3401 | |
| 3402 | /** |
| 3403 | * Called by profile or device owners to set the master volume mute on or off. |
| 3404 | * |
| 3405 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3406 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 3407 | */ |
| 3408 | public void setMasterVolumeMuted(ComponentName admin, boolean on) { |
| 3409 | if (mService != null) { |
| 3410 | try { |
| 3411 | mService.setMasterVolumeMuted(admin, on); |
| 3412 | } catch (RemoteException re) { |
| 3413 | Log.w(TAG, "Failed to setMasterMute on device policy service"); |
| 3414 | } |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | /** |
| 3419 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 3420 | * |
| 3421 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3422 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 3423 | */ |
| 3424 | public boolean isMasterVolumeMuted(ComponentName admin) { |
| 3425 | if (mService != null) { |
| 3426 | try { |
| 3427 | return mService.isMasterVolumeMuted(admin); |
| 3428 | } catch (RemoteException re) { |
| 3429 | Log.w(TAG, "Failed to get isMasterMute on device policy service"); |
| 3430 | } |
| 3431 | } |
| 3432 | return false; |
| 3433 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3434 | |
| 3435 | /** |
| 3436 | * Called by profile or device owners to change whether a user can uninstall |
| 3437 | * a package. |
| 3438 | * |
| 3439 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3440 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 3441 | * @param uninstallBlocked true if the user shouldn't be able to uninstall the package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3442 | */ |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 3443 | public void setUninstallBlocked(ComponentName admin, String packageName, |
| 3444 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3445 | if (mService != null) { |
| 3446 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 3447 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3448 | } catch (RemoteException re) { |
| 3449 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | /** |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 3455 | * Check whether the current user has been blocked by device policy from uninstalling a package. |
| 3456 | * Requires the caller to be the profile owner if checking a specific admin's policy. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3457 | * |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 3458 | * @param admin The name of the admin component whose blocking policy will be checked, or null |
| 3459 | * to check if any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3460 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 3461 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3462 | */ |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 3463 | public boolean isUninstallBlocked(ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3464 | if (mService != null) { |
| 3465 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 3466 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3467 | } catch (RemoteException re) { |
| 3468 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 3469 | } |
| 3470 | } |
| 3471 | return false; |
| 3472 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3473 | |
| 3474 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3475 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 3476 | * given package to be available in the parent profile. As a result the user will be able to |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3477 | * add widgets from the white-listed package running under the profile to a widget |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3478 | * host which runs under the parent profile, for example the home screen. Note that |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3479 | * a package may have zero or more provider components, where each component |
| 3480 | * provides a different widget type. |
| 3481 | * <p> |
| 3482 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
| 3483 | * </p> |
| 3484 | * |
| 3485 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3486 | * @param packageName The package from which widget providers are white-listed. |
| 3487 | * @return Whether the package was added. |
| 3488 | * |
| 3489 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3490 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 3491 | */ |
| 3492 | public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) { |
| 3493 | if (mService != null) { |
| 3494 | try { |
| 3495 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 3496 | } catch (RemoteException re) { |
| 3497 | Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re); |
| 3498 | } |
| 3499 | } |
| 3500 | return false; |
| 3501 | } |
| 3502 | |
| 3503 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3504 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 3505 | * package to be available in the parent profile. For this method to take effect the |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3506 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 3507 | * android.content.ComponentName, String)}. |
| 3508 | * <p> |
| 3509 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
| 3510 | * </p> |
| 3511 | * |
| 3512 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3513 | * @param packageName The package from which widget providers are no longer |
| 3514 | * white-listed. |
| 3515 | * @return Whether the package was removed. |
| 3516 | * |
| 3517 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3518 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 3519 | */ |
| 3520 | public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) { |
| 3521 | if (mService != null) { |
| 3522 | try { |
| 3523 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 3524 | } catch (RemoteException re) { |
| 3525 | Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re); |
| 3526 | } |
| 3527 | } |
| 3528 | return false; |
| 3529 | } |
| 3530 | |
| 3531 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3532 | * 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] | 3533 | * available in the parent profile. |
| 3534 | * |
| 3535 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3536 | * @return The white-listed package list. |
| 3537 | * |
| 3538 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3539 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3540 | */ |
| 3541 | public List<String> getCrossProfileWidgetProviders(ComponentName admin) { |
| 3542 | if (mService != null) { |
| 3543 | try { |
| 3544 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 3545 | if (providers != null) { |
| 3546 | return providers; |
| 3547 | } |
| 3548 | } catch (RemoteException re) { |
| 3549 | Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re); |
| 3550 | } |
| 3551 | } |
| 3552 | return Collections.emptyList(); |
| 3553 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3554 | } |