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