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