blob: 32f51fd3127abc8cc8c3c84624a15bd9b168ef63 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
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 Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Dianne Hackbornd6847842010-01-12 18:14:19 -080019import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
21import android.content.ComponentName;
22import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010023import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000024import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.pm.ActivityInfo;
26import android.content.pm.PackageManager;
27import android.content.pm.ResolveInfo;
Amith Yamasanif20d6402014-05-24 15:34:37 -070028import android.content.RestrictionsManager;
Robin Lee66e5d962014-04-09 16:44:21 +010029import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000031import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080032import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.RemoteException;
34import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070035import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040036import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040037import android.provider.Settings;
Jim Miller50e62182014-04-23 17:25:00 -070038import android.service.trust.TrustAgentService;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.util.Log;
40
Maggie Benthallda51e682013-08-08 22:35:44 -040041import com.android.org.conscrypt.TrustedCertificateStore;
42
Jessica Hummel91da58d2014-04-10 17:39:43 +010043import org.xmlpull.v1.XmlPullParserException;
44
Maggie Benthallda51e682013-08-08 22:35:44 -040045import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070047import java.net.InetSocketAddress;
48import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040049import java.security.cert.CertificateException;
50import java.security.cert.CertificateFactory;
51import java.security.cert.X509Certificate;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080052import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040053import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054
55/**
56 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080057 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080058 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080059 *
60 * <div class="special reference">
61 * <h3>Developer Guides</h3>
62 * <p>For more information about managing policies for device adminstration, read the
63 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
64 * developer guide.</p>
65 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080066 */
67public class DevicePolicyManager {
68 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080069
70 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080071 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070072
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080073 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080074 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080075 mService = IDevicePolicyManager.Stub.asInterface(
76 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
77 }
78
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080079 /** @hide */
80 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080081 DevicePolicyManager me = new DevicePolicyManager(context, handler);
82 return me.mService != null ? me : null;
83 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070084
Dianne Hackbornd6847842010-01-12 18:14:19 -080085 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +010086 * Activity action: Used to indicate that the receiving activity is being started as part of the
87 * managed profile provisioning flow. This intent is typically sent to a mobile device
88 * management application (mdm) after the first part of the provisioning process is complete in
89 * the expectation that this app will (after optionally showing it's own UI) ultimately call
90 * {@link #ACTION_PROVISION_MANAGED_PROFILE} to complete the creation of the managed profile.
91 *
92 * <p> The intent may contain the extras {@link #EXTRA_PROVISIONING_TOKEN} and
93 * {@link #EXTRA_PROVISIONING_EMAIL_ADDRESS}.
94 */
95 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
96 public static final String ACTION_SEND_PROVISIONING_VALUES
97 = "android.app.action.ACTION_SEND_PROVISIONING_VALUES";
98
99 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000100 * Activity action: Starts the provisioning flow which sets up a managed profile.
101 * This intent will typically be sent by a mobile device management application(mdm).
102 * Managed profile provisioning creates a profile, moves the mdm to the profile,
103 * sets the mdm as the profile owner and removes all non required applications from the profile.
104 * As a profile owner the mdm than has full control over the managed profile.
105 *
106 * <p>The intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} and
107 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME}.
108 *
109 * <p> When managed provisioning has completed, an intent of the type
110 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
111 * mdm app on the managed profile.
112 *
113 * <p>Input: Nothing.</p>
114 * <p>Output: Nothing</p>
115 */
116 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
117 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000118 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000119
120 /**
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100121 * A broadcast intent with this action can be sent to ManagedProvisionning to specify that the
122 * user has already consented to the creation of the managed profile.
123 * The intent must contain the extras
124 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} and
125 * {@link #EXTRA_PROVISIONING_TOKEN}
126 * @hide
127 */
128 public static final String ACTION_PROVISIONING_USER_HAS_CONSENTED
129 = "android.app.action.USER_HAS_CONSENTED";
130
131 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132 * A String extra holding the name of the package of the mobile device management application
133 * that starts the managed provisioning flow. This package will be set as the profile owner.
134 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
135 */
136 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
137 = "deviceAdminPackageName";
138
139 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100140 * An int extra used to identify that during the current setup process the user has already
141 * consented to setting up a managed profile. This is typically received by
142 * a mobile device management application when it is started with
143 * {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
144 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. The
145 * token indicates that steps asking for user consent can be skipped as the user has previously
146 * consented.
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100147 */
148 public static final String EXTRA_PROVISIONING_TOKEN
149 = "android.app.extra.token";
150
151 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000152 * A String extra holding the default name of the profile that is created during managed profile
153 * provisioning.
154 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
155 */
156 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
157 = "defaultManagedProfileName";
158
159 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100160 * A String extra holding the email address of the profile that is created during managed
161 * profile provisioning. This is typically received by a mobile management application when it
162 * is started with {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
163 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. It
164 * is eventually passed on in an intent
165 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
166 */
167 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
168 = "android.app.extra.ManagedProfileEmailAddress";
169
170 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800171 * Activity action: ask the user to add a new device administrator to the system.
172 * The desired policy is the ComponentName of the policy in the
173 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
174 * bring the user through adding the device administrator to the system (or
175 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700176 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800177 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
178 * field to provide the user with additional explanation (in addition
179 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800180 *
181 * <p>If your administrator is already active, this will ordinarily return immediately (without
182 * user intervention). However, if your administrator has been updated and is requesting
183 * additional uses-policy flags, the user will be presented with the new list. New policies
184 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800185 */
186 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
187 public static final String ACTION_ADD_DEVICE_ADMIN
188 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700189
Dianne Hackbornd6847842010-01-12 18:14:19 -0800190 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700191 * Activity action: send when any policy admin changes a policy.
192 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700193 *
Jim Miller284b62e2010-06-08 14:27:42 -0700194 * @hide
195 */
196 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
197 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
198
199 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800200 * The ComponentName of the administrator component.
201 *
202 * @see #ACTION_ADD_DEVICE_ADMIN
203 */
204 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700205
Dianne Hackbornd6847842010-01-12 18:14:19 -0800206 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800207 * An optional CharSequence providing additional explanation for why the
208 * admin is being added.
209 *
210 * @see #ACTION_ADD_DEVICE_ADMIN
211 */
212 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700213
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800214 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700215 * Activity action: have the user enter a new password. This activity should
216 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
217 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
218 * enter a new password that meets the current requirements. You can use
219 * {@link #isActivePasswordSufficient()} to determine whether you need to
220 * have the user select a new password in order to meet the current
221 * constraints. Upon being resumed from this activity, you can check the new
222 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800223 */
224 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
225 public static final String ACTION_SET_NEW_PASSWORD
226 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000227 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100228 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
229 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000230 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100231 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000232
233 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100234 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
235 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000236 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100237 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700238
Dianne Hackbornd6847842010-01-12 18:14:19 -0800239 /**
240 * Return true if the given administrator component is currently
241 * active (enabled) in the system.
242 */
243 public boolean isAdminActive(ComponentName who) {
244 if (mService != null) {
245 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700246 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800247 } catch (RemoteException e) {
248 Log.w(TAG, "Failed talking with device policy service", e);
249 }
250 }
251 return false;
252 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700253
Dianne Hackbornd6847842010-01-12 18:14:19 -0800254 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800255 * Return a list of all currently active device administrator's component
256 * names. Note that if there are no administrators than null may be
257 * returned.
258 */
259 public List<ComponentName> getActiveAdmins() {
260 if (mService != null) {
261 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700262 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800263 } catch (RemoteException e) {
264 Log.w(TAG, "Failed talking with device policy service", e);
265 }
266 }
267 return null;
268 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700269
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800270 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700271 * Used by package administration code to determine if a package can be stopped
272 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800273 * @hide
274 */
275 public boolean packageHasActiveAdmins(String packageName) {
276 if (mService != null) {
277 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700278 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800279 } catch (RemoteException e) {
280 Log.w(TAG, "Failed talking with device policy service", e);
281 }
282 }
283 return false;
284 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700285
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800286 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800287 * Remove a current administration component. This can only be called
288 * by the application that owns the administration component; if you
289 * try to remove someone else's component, a security exception will be
290 * thrown.
291 */
292 public void removeActiveAdmin(ComponentName who) {
293 if (mService != null) {
294 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700295 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800296 } catch (RemoteException e) {
297 Log.w(TAG, "Failed talking with device policy service", e);
298 }
299 }
300 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700301
Dianne Hackbornd6847842010-01-12 18:14:19 -0800302 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800303 * Returns true if an administrator has been granted a particular device policy. This can
304 * be used to check if the administrator was activated under an earlier set of policies,
305 * but requires additional policies after an upgrade.
306 *
307 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
308 * an active administrator, or an exception will be thrown.
309 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
310 */
311 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
312 if (mService != null) {
313 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700314 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800315 } catch (RemoteException e) {
316 Log.w(TAG, "Failed talking with device policy service", e);
317 }
318 }
319 return false;
320 }
321
322 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800323 * Constant for {@link #setPasswordQuality}: the policy has no requirements
324 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800325 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800326 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800327 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700328
Dianne Hackbornd6847842010-01-12 18:14:19 -0800329 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700330 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
331 * recognition technology. This implies technologies that can recognize the identity of
332 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
333 * Note that quality constants are ordered so that higher values are more restrictive.
334 */
335 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
336
337 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800338 * Constant for {@link #setPasswordQuality}: the policy requires some kind
339 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800340 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800341 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800342 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700343
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800344 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800345 * Constant for {@link #setPasswordQuality}: the user must have entered a
346 * password containing at least numeric characters. Note that quality
347 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800348 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800349 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700350
Dianne Hackbornd6847842010-01-12 18:14:19 -0800351 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800352 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700353 * password containing at least alphabetic (or other symbol) characters.
354 * Note that quality constants are ordered so that higher values are more
355 * restrictive.
356 */
357 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700358
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700359 /**
360 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800361 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700362 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800363 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800364 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700365 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700366
Dianne Hackbornd6847842010-01-12 18:14:19 -0800367 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700368 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700369 * password containing at least a letter, a numerical digit and a special
370 * symbol, by default. With this password quality, passwords can be
371 * restricted to contain various sets of characters, like at least an
372 * uppercase letter, etc. These are specified using various methods,
373 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
374 * that quality constants are ordered so that higher values are more
375 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700376 */
377 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
378
379 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800380 * Called by an application that is administering the device to set the
381 * password restrictions it is imposing. After setting this, the user
382 * will not be able to enter a new password that is not at least as
383 * restrictive as what has been set. Note that the current password
384 * will remain until the user has set a new one, so the change does not
385 * take place immediately. To prompt the user for a new password, use
386 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700387 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800388 * <p>Quality constants are ordered so that higher values are more restrictive;
389 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800390 * the user's preference, and any other considerations) is the one that
391 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700392 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800393 * <p>The calling device admin must have requested
394 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
395 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700396 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800397 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800398 * @param quality The new desired quality. One of
399 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700400 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700401 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800402 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800403 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800404 if (mService != null) {
405 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700406 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800407 } catch (RemoteException e) {
408 Log.w(TAG, "Failed talking with device policy service", e);
409 }
410 }
411 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700412
Dianne Hackbornd6847842010-01-12 18:14:19 -0800413 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100414 * Retrieve the current minimum password quality for all admins of this user
415 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800416 * @param admin The name of the admin component to check, or null to aggregate
417 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800418 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800419 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700420 return getPasswordQuality(admin, UserHandle.myUserId());
421 }
422
423 /** @hide per-user version */
424 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800425 if (mService != null) {
426 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700427 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800428 } catch (RemoteException e) {
429 Log.w(TAG, "Failed talking with device policy service", e);
430 }
431 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800432 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800433 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700434
Dianne Hackbornd6847842010-01-12 18:14:19 -0800435 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800436 * Called by an application that is administering the device to set the
437 * minimum allowed password length. After setting this, the user
438 * will not be able to enter a new password that is not at least as
439 * restrictive as what has been set. Note that the current password
440 * will remain until the user has set a new one, so the change does not
441 * take place immediately. To prompt the user for a new password, use
442 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
443 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700444 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
445 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800446 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700447 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800448 * <p>The calling device admin must have requested
449 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
450 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700451 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800453 * @param length The new desired minimum password length. A value of 0
454 * means there is no restriction.
455 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800456 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800457 if (mService != null) {
458 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700459 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800460 } catch (RemoteException e) {
461 Log.w(TAG, "Failed talking with device policy service", e);
462 }
463 }
464 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700465
Dianne Hackbornd6847842010-01-12 18:14:19 -0800466 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100467 * Retrieve the current minimum password length for all admins of this
468 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800469 * @param admin The name of the admin component to check, or null to aggregate
470 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800471 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800472 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700473 return getPasswordMinimumLength(admin, UserHandle.myUserId());
474 }
475
476 /** @hide per-user version */
477 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800478 if (mService != null) {
479 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700480 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800481 } catch (RemoteException e) {
482 Log.w(TAG, "Failed talking with device policy service", e);
483 }
484 }
485 return 0;
486 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700487
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700488 /**
489 * Called by an application that is administering the device to set the
490 * minimum number of upper case letters required in the password. After
491 * setting this, the user will not be able to enter a new password that is
492 * not at least as restrictive as what has been set. Note that the current
493 * password will remain until the user has set a new one, so the change does
494 * not take place immediately. To prompt the user for a new password, use
495 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
496 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700497 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
498 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700499 * <p>
500 * The calling device admin must have requested
501 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
502 * this method; if it has not, a security exception will be thrown.
503 *
504 * @param admin Which {@link DeviceAdminReceiver} this request is associated
505 * with.
506 * @param length The new desired minimum number of upper case letters
507 * required in the password. A value of 0 means there is no
508 * restriction.
509 */
510 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
511 if (mService != null) {
512 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700513 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700514 } catch (RemoteException e) {
515 Log.w(TAG, "Failed talking with device policy service", e);
516 }
517 }
518 }
519
520 /**
521 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100522 * password for all admins of this user and its profiles or a particular one.
523 * This is the same value as set by
524 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700525 * and only applies when the password quality is
526 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700527 *
528 * @param admin The name of the admin component to check, or null to
529 * aggregate all admins.
530 * @return The minimum number of upper case letters required in the
531 * password.
532 */
533 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700534 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
535 }
536
537 /** @hide per-user version */
538 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700539 if (mService != null) {
540 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700541 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700542 } catch (RemoteException e) {
543 Log.w(TAG, "Failed talking with device policy service", e);
544 }
545 }
546 return 0;
547 }
548
549 /**
550 * Called by an application that is administering the device to set the
551 * minimum number of lower case letters required in the password. After
552 * setting this, the user will not be able to enter a new password that is
553 * not at least as restrictive as what has been set. Note that the current
554 * password will remain until the user has set a new one, so the change does
555 * not take place immediately. To prompt the user for a new password, use
556 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
557 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700558 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
559 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700560 * <p>
561 * The calling device admin must have requested
562 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
563 * this method; if it has not, a security exception will be thrown.
564 *
565 * @param admin Which {@link DeviceAdminReceiver} this request is associated
566 * with.
567 * @param length The new desired minimum number of lower case letters
568 * required in the password. A value of 0 means there is no
569 * restriction.
570 */
571 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
572 if (mService != null) {
573 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700574 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700575 } catch (RemoteException e) {
576 Log.w(TAG, "Failed talking with device policy service", e);
577 }
578 }
579 }
580
581 /**
582 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100583 * password for all admins of this user and its profiles or a particular one.
584 * This is the same value as set by
585 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700586 * and only applies when the password quality is
587 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700588 *
589 * @param admin The name of the admin component to check, or null to
590 * aggregate all admins.
591 * @return The minimum number of lower case letters required in the
592 * password.
593 */
594 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700595 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
596 }
597
598 /** @hide per-user version */
599 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700600 if (mService != null) {
601 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700602 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700603 } catch (RemoteException e) {
604 Log.w(TAG, "Failed talking with device policy service", e);
605 }
606 }
607 return 0;
608 }
609
610 /**
611 * Called by an application that is administering the device to set the
612 * minimum number of letters required in the password. After setting this,
613 * the user will not be able to enter a new password that is not at least as
614 * restrictive as what has been set. Note that the current password will
615 * remain until the user has set a new one, so the change does not take
616 * place immediately. To prompt the user for a new password, use
617 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
618 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700619 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
620 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700621 * <p>
622 * The calling device admin must have requested
623 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
624 * this method; if it has not, a security exception will be thrown.
625 *
626 * @param admin Which {@link DeviceAdminReceiver} this request is associated
627 * with.
628 * @param length The new desired minimum number of letters required in the
629 * password. A value of 0 means there is no restriction.
630 */
631 public void setPasswordMinimumLetters(ComponentName admin, int length) {
632 if (mService != null) {
633 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700634 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700635 } catch (RemoteException e) {
636 Log.w(TAG, "Failed talking with device policy service", e);
637 }
638 }
639 }
640
641 /**
642 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700643 * admins or a particular one. This is the same value as
644 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
645 * and only applies when the password quality is
646 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700647 *
648 * @param admin The name of the admin component to check, or null to
649 * aggregate all admins.
650 * @return The minimum number of letters required in the password.
651 */
652 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700653 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
654 }
655
656 /** @hide per-user version */
657 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700658 if (mService != null) {
659 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700660 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700661 } catch (RemoteException e) {
662 Log.w(TAG, "Failed talking with device policy service", e);
663 }
664 }
665 return 0;
666 }
667
668 /**
669 * Called by an application that is administering the device to set the
670 * minimum number of numerical digits required in the password. After
671 * setting this, the user will not be able to enter a new password that is
672 * not at least as restrictive as what has been set. Note that the current
673 * password will remain until the user has set a new one, so the change does
674 * not take place immediately. To prompt the user for a new password, use
675 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
676 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700677 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
678 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700679 * <p>
680 * The calling device admin must have requested
681 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
682 * this method; if it has not, a security exception will be thrown.
683 *
684 * @param admin Which {@link DeviceAdminReceiver} this request is associated
685 * with.
686 * @param length The new desired minimum number of numerical digits required
687 * in the password. A value of 0 means there is no restriction.
688 */
689 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
690 if (mService != null) {
691 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700692 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700693 } catch (RemoteException e) {
694 Log.w(TAG, "Failed talking with device policy service", e);
695 }
696 }
697 }
698
699 /**
700 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100701 * for all admins of this user and its profiles or a particular one.
702 * This is the same value as set by
703 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700704 * and only applies when the password quality is
705 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700706 *
707 * @param admin The name of the admin component to check, or null to
708 * aggregate all admins.
709 * @return The minimum number of numerical digits required in the password.
710 */
711 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700712 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
713 }
714
715 /** @hide per-user version */
716 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700717 if (mService != null) {
718 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700719 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700720 } catch (RemoteException e) {
721 Log.w(TAG, "Failed talking with device policy service", e);
722 }
723 }
724 return 0;
725 }
726
727 /**
728 * Called by an application that is administering the device to set the
729 * minimum number of symbols required in the password. After setting this,
730 * the user will not be able to enter a new password that is not at least as
731 * restrictive as what has been set. Note that the current password will
732 * remain until the user has set a new one, so the change does not take
733 * place immediately. To prompt the user for a new password, use
734 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
735 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700736 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
737 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700738 * <p>
739 * The calling device admin must have requested
740 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
741 * this method; if it has not, a security exception will be thrown.
742 *
743 * @param admin Which {@link DeviceAdminReceiver} this request is associated
744 * with.
745 * @param length The new desired minimum number of symbols required in the
746 * password. A value of 0 means there is no restriction.
747 */
748 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
749 if (mService != null) {
750 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700751 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700752 } catch (RemoteException e) {
753 Log.w(TAG, "Failed talking with device policy service", e);
754 }
755 }
756 }
757
758 /**
759 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700760 * admins or a particular one. This is the same value as
761 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
762 * and only applies when the password quality is
763 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700764 *
765 * @param admin The name of the admin component to check, or null to
766 * aggregate all admins.
767 * @return The minimum number of symbols required in the password.
768 */
769 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700770 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
771 }
772
773 /** @hide per-user version */
774 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700775 if (mService != null) {
776 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700777 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700778 } catch (RemoteException e) {
779 Log.w(TAG, "Failed talking with device policy service", e);
780 }
781 }
782 return 0;
783 }
784
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700785 /**
786 * Called by an application that is administering the device to set the
787 * minimum number of non-letter characters (numerical digits or symbols)
788 * required in the password. After setting this, the user will not be able
789 * to enter a new password that is not at least as restrictive as what has
790 * been set. Note that the current password will remain until the user has
791 * set a new one, so the change does not take place immediately. To prompt
792 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
793 * setting this value. This constraint is only imposed if the administrator
794 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
795 * {@link #setPasswordQuality}. The default value is 0.
796 * <p>
797 * The calling device admin must have requested
798 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
799 * this method; if it has not, a security exception will be thrown.
800 *
801 * @param admin Which {@link DeviceAdminReceiver} this request is associated
802 * with.
803 * @param length The new desired minimum number of letters required in the
804 * password. A value of 0 means there is no restriction.
805 */
806 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
807 if (mService != null) {
808 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700809 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700810 } catch (RemoteException e) {
811 Log.w(TAG, "Failed talking with device policy service", e);
812 }
813 }
814 }
815
816 /**
817 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100818 * password for all admins of this user and its profiles or a particular one.
819 * This is the same value as set by
820 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700821 * and only applies when the password quality is
822 * {@link #PASSWORD_QUALITY_COMPLEX}.
823 *
824 * @param admin The name of the admin component to check, or null to
825 * aggregate all admins.
826 * @return The minimum number of letters required in the password.
827 */
828 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700829 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
830 }
831
832 /** @hide per-user version */
833 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700834 if (mService != null) {
835 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700836 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700837 } catch (RemoteException e) {
838 Log.w(TAG, "Failed talking with device policy service", e);
839 }
840 }
841 return 0;
842 }
843
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700844 /**
845 * Called by an application that is administering the device to set the length
846 * of the password history. After setting this, the user will not be able to
847 * enter a new password that is the same as any password in the history. Note
848 * that the current password will remain until the user has set a new one, so
849 * the change does not take place immediately. To prompt the user for a new
850 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
851 * This constraint is only imposed if the administrator has also requested
852 * either {@link #PASSWORD_QUALITY_NUMERIC},
853 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
854 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
855 *
856 * <p>
857 * The calling device admin must have requested
858 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
859 * method; if it has not, a security exception will be thrown.
860 *
861 * @param admin Which {@link DeviceAdminReceiver} this request is associated
862 * with.
863 * @param length The new desired length of password history. A value of 0
864 * means there is no restriction.
865 */
866 public void setPasswordHistoryLength(ComponentName admin, int length) {
867 if (mService != null) {
868 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700869 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700870 } catch (RemoteException e) {
871 Log.w(TAG, "Failed talking with device policy service", e);
872 }
873 }
874 }
875
876 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800877 * Called by a device admin to set the password expiration timeout. Calling this method
878 * will restart the countdown for password expiration for the given admin, as will changing
879 * the device password (for all admins).
880 *
881 * <p>The provided timeout is the time delta in ms and will be added to the current time.
882 * For example, to have the password expire 5 days from now, timeout would be
883 * 5 * 86400 * 1000 = 432000000 ms for timeout.
884 *
885 * <p>To disable password expiration, a value of 0 may be used for timeout.
886 *
Jim Millera4e28d12010-11-08 16:15:47 -0800887 * <p>The calling device admin must have requested
888 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
889 * method; if it has not, a security exception will be thrown.
890 *
891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
892 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
893 * means there is no restriction (unlimited).
894 */
895 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
896 if (mService != null) {
897 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700898 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800899 } catch (RemoteException e) {
900 Log.w(TAG, "Failed talking with device policy service", e);
901 }
902 }
903 }
904
905 /**
Jim Miller6b857682011-02-16 16:27:41 -0800906 * Get the password expiration timeout for the given admin. The expiration timeout is the
907 * recurring expiration timeout provided in the call to
908 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
909 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -0800910 *
911 * @param admin The name of the admin component to check, or null to aggregate all admins.
912 * @return The timeout for the given admin or the minimum of all timeouts
913 */
914 public long getPasswordExpirationTimeout(ComponentName admin) {
915 if (mService != null) {
916 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700917 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800918 } catch (RemoteException e) {
919 Log.w(TAG, "Failed talking with device policy service", e);
920 }
921 }
922 return 0;
923 }
924
925 /**
926 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +0100927 * all admins of this user and its profiles if admin is null. If the password is
928 * expired, this will return the time since the password expired as a negative number.
929 * If admin is null, then a composite of all expiration timeouts is returned
930 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -0800931 *
932 * @param admin The name of the admin component to check, or null to aggregate all admins.
933 * @return The password expiration time, in ms.
934 */
935 public long getPasswordExpiration(ComponentName admin) {
936 if (mService != null) {
937 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700938 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800939 } catch (RemoteException e) {
940 Log.w(TAG, "Failed talking with device policy service", e);
941 }
942 }
943 return 0;
944 }
945
946 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100947 * Retrieve the current password history length for all admins of this
948 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700949 * @param admin The name of the admin component to check, or null to aggregate
950 * all admins.
951 * @return The length of the password history
952 */
953 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700954 return getPasswordHistoryLength(admin, UserHandle.myUserId());
955 }
956
957 /** @hide per-user version */
958 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700959 if (mService != null) {
960 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700961 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700962 } catch (RemoteException e) {
963 Log.w(TAG, "Failed talking with device policy service", e);
964 }
965 }
966 return 0;
967 }
968
Dianne Hackbornd6847842010-01-12 18:14:19 -0800969 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800970 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800971 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800972 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800973 * @return Returns the maximum length that the user can enter.
974 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800975 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800976 // Kind-of arbitrary.
977 return 16;
978 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700979
Dianne Hackborn254cb442010-01-27 19:23:59 -0800980 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800981 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800982 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +0100983 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700984 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800985 * <p>The calling device admin must have requested
986 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
987 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700988 *
Jessica Hummel91da58d2014-04-10 17:39:43 +0100989 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800990 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800991 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800992 if (mService != null) {
993 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700994 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800995 } catch (RemoteException e) {
996 Log.w(TAG, "Failed talking with device policy service", e);
997 }
998 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800999 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001000 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001001
Dianne Hackbornd6847842010-01-12 18:14:19 -08001002 /**
1003 * Retrieve the number of times the user has failed at entering a
1004 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001005 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001006 * <p>The calling device admin must have requested
1007 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1008 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 */
1010 public int getCurrentFailedPasswordAttempts() {
1011 if (mService != null) {
1012 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001013 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 } catch (RemoteException e) {
1015 Log.w(TAG, "Failed talking with device policy service", e);
1016 }
1017 }
1018 return -1;
1019 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001020
1021 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001022 * Setting this to a value greater than zero enables a built-in policy
1023 * that will perform a device wipe after too many incorrect
1024 * device-unlock passwords have been entered. This built-in policy combines
1025 * watching for failed passwords and wiping the device, and requires
1026 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001027 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001028 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001029 * <p>To implement any other policy (e.g. wiping data for a particular
1030 * application only, erasing or revoking credentials, or reporting the
1031 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001032 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001033 * instead. Do not use this API, because if the maximum count is reached,
1034 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001035 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001036 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001037 * @param num The number of failed password attempts at which point the
1038 * device will wipe its data.
1039 */
1040 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1041 if (mService != null) {
1042 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001043 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001044 } catch (RemoteException e) {
1045 Log.w(TAG, "Failed talking with device policy service", e);
1046 }
1047 }
1048 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001049
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001050 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001051 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001052 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001053 * or a particular one.
1054 * @param admin The name of the admin component to check, or null to aggregate
1055 * all admins.
1056 */
1057 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001058 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1059 }
1060
1061 /** @hide per-user version */
1062 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001063 if (mService != null) {
1064 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001065 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001066 } catch (RemoteException e) {
1067 Log.w(TAG, "Failed talking with device policy service", e);
1068 }
1069 }
1070 return 0;
1071 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001072
Dianne Hackborn254cb442010-01-27 19:23:59 -08001073 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001074 * Flag for {@link #resetPassword}: don't allow other admins to change
1075 * the password again until the user has entered it.
1076 */
1077 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001079 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001080 * Force a new device unlock password (the password needed to access the
1081 * entire device, not for individual accounts) on the user. This takes
1082 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001083 * The given password must be sufficient for the
1084 * current password quality and length constraints as returned by
1085 * {@link #getPasswordQuality(ComponentName)} and
1086 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1087 * these constraints, then it will be rejected and false returned. Note
1088 * that the password may be a stronger quality (containing alphanumeric
1089 * characters when the requested quality is only numeric), in which case
1090 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001091 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001092 * <p>The calling device admin must have requested
1093 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1094 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001095 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001096 * Can not be called from a managed profile.
1097 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001098 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001099 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001100 * @return Returns true if the password was applied, or false if it is
1101 * not acceptable for the current constraints.
1102 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001103 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001104 if (mService != null) {
1105 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001106 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001107 } catch (RemoteException e) {
1108 Log.w(TAG, "Failed talking with device policy service", e);
1109 }
1110 }
1111 return false;
1112 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001113
Dianne Hackbornd6847842010-01-12 18:14:19 -08001114 /**
1115 * Called by an application that is administering the device to set the
1116 * maximum time for user activity until the device will lock. This limits
1117 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001118 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001119 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001120 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001121 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001122 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001123 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001124 * @param timeMs The new desired maximum time to lock in milliseconds.
1125 * A value of 0 means there is no restriction.
1126 */
1127 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1128 if (mService != null) {
1129 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001130 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001131 } catch (RemoteException e) {
1132 Log.w(TAG, "Failed talking with device policy service", e);
1133 }
1134 }
1135 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001136
Dianne Hackbornd6847842010-01-12 18:14:19 -08001137 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001138 * Retrieve the current maximum time to unlock for all admins of this user
1139 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001140 * @param admin The name of the admin component to check, or null to aggregate
1141 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001142 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001143 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001144 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1145 }
1146
1147 /** @hide per-user version */
1148 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001149 if (mService != null) {
1150 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001151 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001152 } catch (RemoteException e) {
1153 Log.w(TAG, "Failed talking with device policy service", e);
1154 }
1155 }
1156 return 0;
1157 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001158
Dianne Hackbornd6847842010-01-12 18:14:19 -08001159 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001160 * Make the device lock immediately, as if the lock screen timeout has
1161 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001162 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001163 * <p>The calling device admin must have requested
1164 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1165 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001166 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001167 public void lockNow() {
1168 if (mService != null) {
1169 try {
1170 mService.lockNow();
1171 } catch (RemoteException e) {
1172 Log.w(TAG, "Failed talking with device policy service", e);
1173 }
1174 }
1175 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001176
Dianne Hackbornd6847842010-01-12 18:14:19 -08001177 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001178 * Flag for {@link #wipeData(int)}: also erase the device's external
1179 * storage.
1180 */
1181 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1182
1183 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001184 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001185 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001186 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1187 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001188 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001189 * <p>The calling device admin must have requested
1190 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1191 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001192 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001193 * @param flags Bit mask of additional options: currently 0 and
1194 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001195 */
1196 public void wipeData(int flags) {
1197 if (mService != null) {
1198 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001199 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001200 } catch (RemoteException e) {
1201 Log.w(TAG, "Failed talking with device policy service", e);
1202 }
1203 }
1204 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001205
Dianne Hackbornd6847842010-01-12 18:14:19 -08001206 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001207 * Called by an application that is administering the device to set the
1208 * global proxy and exclusion list.
1209 * <p>
1210 * The calling device admin must have requested
1211 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1212 * this method; if it has not, a security exception will be thrown.
1213 * Only the first device admin can set the proxy. If a second admin attempts
1214 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1215 * proxy will be returned. If successful in setting the proxy, null will
1216 * be returned.
1217 * The method can be called repeatedly by the device admin alrady setting the
1218 * proxy to update the proxy and exclusion list.
1219 *
1220 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1221 * with.
1222 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1223 * Pass Proxy.NO_PROXY to reset the proxy.
1224 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001225 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1226 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001227 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001228 */
1229 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1230 List<String> exclusionList ) {
1231 if (proxySpec == null) {
1232 throw new NullPointerException();
1233 }
1234 if (mService != null) {
1235 try {
1236 String hostSpec;
1237 String exclSpec;
1238 if (proxySpec.equals(Proxy.NO_PROXY)) {
1239 hostSpec = null;
1240 exclSpec = null;
1241 } else {
1242 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1243 throw new IllegalArgumentException();
1244 }
1245 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1246 String hostName = sa.getHostName();
1247 int port = sa.getPort();
1248 StringBuilder hostBuilder = new StringBuilder();
1249 hostSpec = hostBuilder.append(hostName)
1250 .append(":").append(Integer.toString(port)).toString();
1251 if (exclusionList == null) {
1252 exclSpec = "";
1253 } else {
1254 StringBuilder listBuilder = new StringBuilder();
1255 boolean firstDomain = true;
1256 for (String exclDomain : exclusionList) {
1257 if (!firstDomain) {
1258 listBuilder = listBuilder.append(",");
1259 } else {
1260 firstDomain = false;
1261 }
1262 listBuilder = listBuilder.append(exclDomain.trim());
1263 }
1264 exclSpec = listBuilder.toString();
1265 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001266 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1267 != android.net.Proxy.PROXY_VALID)
1268 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001269 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001270 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001271 } catch (RemoteException e) {
1272 Log.w(TAG, "Failed talking with device policy service", e);
1273 }
1274 }
1275 return null;
1276 }
1277
1278 /**
1279 * Returns the component name setting the global proxy.
1280 * @return ComponentName object of the device admin that set the global proxy, or
1281 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001282 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001283 */
1284 public ComponentName getGlobalProxyAdmin() {
1285 if (mService != null) {
1286 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001287 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001288 } catch (RemoteException e) {
1289 Log.w(TAG, "Failed talking with device policy service", e);
1290 }
1291 }
1292 return null;
1293 }
1294
1295 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001296 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001297 * indicating that encryption is not supported.
1298 */
1299 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1300
1301 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001302 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001303 * indicating that encryption is supported, but is not currently active.
1304 */
1305 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1306
1307 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001308 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001309 * indicating that encryption is not currently active, but is currently
1310 * being activated. This is only reported by devices that support
1311 * encryption of data and only when the storage is currently
1312 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1313 * to become encrypted will never return this value.
1314 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001315 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001316
1317 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001318 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001319 * indicating that encryption is active.
1320 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001321 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001322
1323 /**
1324 * Activity action: begin the process of encrypting data on the device. This activity should
1325 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1326 * After resuming from this activity, use {@link #getStorageEncryption}
1327 * to check encryption status. However, on some devices this activity may never return, as
1328 * it may trigger a reboot and in some cases a complete data wipe of the device.
1329 */
1330 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1331 public static final String ACTION_START_ENCRYPTION
1332 = "android.app.action.START_ENCRYPTION";
1333
1334 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001335 * Widgets are enabled in keyguard
1336 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001337 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001338
1339 /**
Jim Miller50e62182014-04-23 17:25:00 -07001340 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001341 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001342 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1343
1344 /**
1345 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1346 */
1347 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1348
1349 /**
Jim Miller50e62182014-04-23 17:25:00 -07001350 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1351 */
1352 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1353
1354 /**
1355 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1356 */
1357 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1358
1359 /**
1360 * Ignore {@link TrustAgentService} state on secure keyguard screens
1361 * (e.g. PIN/Pattern/Password).
1362 */
1363 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1364
1365 /**
Jim Miller35207742012-11-02 15:33:20 -07001366 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001367 */
1368 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001369
1370 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001371 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001372 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001373 *
1374 * <p>When multiple device administrators attempt to control device
1375 * encryption, the most secure, supported setting will always be
1376 * used. If any device administrator requests device encryption,
1377 * it will be enabled; Conversely, if a device administrator
1378 * attempts to disable device encryption while another
1379 * device administrator has enabled it, the call to disable will
1380 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1381 *
1382 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001383 * written to other storage areas may or may not be encrypted, and this policy does not require
1384 * or control the encryption of any other storage areas.
1385 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1386 * {@code true}, then the directory returned by
1387 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1388 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001389 *
1390 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1391 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1392 * the encryption key may not be fully secured. For maximum security, the administrator should
1393 * also require (and check for) a pattern, PIN, or password.
1394 *
1395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1396 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001397 * @return the new request status (for all active admins) - will be one of
1398 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1399 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1400 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001401 */
1402 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1403 if (mService != null) {
1404 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001405 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001406 } catch (RemoteException e) {
1407 Log.w(TAG, "Failed talking with device policy service", e);
1408 }
1409 }
1410 return ENCRYPTION_STATUS_UNSUPPORTED;
1411 }
1412
1413 /**
1414 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001415 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001416 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001417 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1418 * this will return the requested encryption setting as an aggregate of all active
1419 * administrators.
1420 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001421 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001422 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001423 if (mService != null) {
1424 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001425 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001426 } catch (RemoteException e) {
1427 Log.w(TAG, "Failed talking with device policy service", e);
1428 }
1429 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001430 return false;
1431 }
1432
1433 /**
1434 * Called by an application that is administering the device to
1435 * determine the current encryption status of the device.
1436 *
1437 * Depending on the returned status code, the caller may proceed in different
1438 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1439 * storage system does not support encryption. If the
1440 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1441 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1442 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1443 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1444 *
1445 * @return current status of encryption. The value will be one of
1446 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1447 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1448 */
1449 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001450 return getStorageEncryptionStatus(UserHandle.myUserId());
1451 }
1452
1453 /** @hide per-user version */
1454 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001455 if (mService != null) {
1456 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001457 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001458 } catch (RemoteException e) {
1459 Log.w(TAG, "Failed talking with device policy service", e);
1460 }
1461 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001462 return ENCRYPTION_STATUS_UNSUPPORTED;
1463 }
1464
1465 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001466 * Installs the given certificate as a User CA.
1467 *
1468 * @return false if the certBuffer cannot be parsed or installation is
1469 * interrupted, otherwise true
1470 * @hide
1471 */
1472 public boolean installCaCert(byte[] certBuffer) {
1473 if (mService != null) {
1474 try {
1475 return mService.installCaCert(certBuffer);
1476 } catch (RemoteException e) {
1477 Log.w(TAG, "Failed talking with device policy service", e);
1478 }
1479 }
1480 return false;
1481 }
1482
1483 /**
1484 * Uninstalls the given certificate from the list of User CAs, if present.
1485 *
1486 * @hide
1487 */
1488 public void uninstallCaCert(byte[] certBuffer) {
1489 if (mService != null) {
1490 try {
1491 mService.uninstallCaCert(certBuffer);
1492 } catch (RemoteException e) {
1493 Log.w(TAG, "Failed talking with device policy service", e);
1494 }
1495 }
1496 }
1497
1498 /**
1499 * Returns whether there are any user-installed CA certificates.
1500 *
1501 * @hide
1502 */
Maggie Benthall0469f412013-09-05 15:30:26 -04001503 public static boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001504 TrustedCertificateStore certStore = new TrustedCertificateStore();
1505 Set<String> aliases = certStore.userAliases();
1506 return aliases != null && !aliases.isEmpty();
1507 }
1508
1509 /**
1510 * Returns whether this certificate has been installed as a User CA.
1511 *
1512 * @hide
1513 */
1514 public boolean hasCaCertInstalled(byte[] certBuffer) {
1515 TrustedCertificateStore certStore = new TrustedCertificateStore();
1516 String alias;
1517 byte[] pemCert;
1518 try {
1519 CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1520 X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1521 new ByteArrayInputStream(certBuffer));
1522 return certStore.getCertificateAlias(cert) != null;
1523 } catch (CertificateException ce) {
1524 Log.w(TAG, "Could not parse certificate", ce);
1525 }
1526 return false;
1527 }
1528
1529 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001530 * Called by an application that is administering the device to disable all cameras
1531 * on the device. After setting this, no applications will be able to access any cameras
1532 * on the device.
1533 *
1534 * <p>The calling device admin must have requested
1535 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1536 * this method; if it has not, a security exception will be thrown.
1537 *
1538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1539 * @param disabled Whether or not the camera should be disabled.
1540 */
1541 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1542 if (mService != null) {
1543 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001544 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001545 } catch (RemoteException e) {
1546 Log.w(TAG, "Failed talking with device policy service", e);
1547 }
1548 }
1549 }
1550
1551 /**
1552 * Determine whether or not the device's cameras have been disabled either by the current
1553 * admin, if specified, or all admins.
1554 * @param admin The name of the admin component to check, or null to check if any admins
1555 * have disabled the camera
1556 */
1557 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001558 return getCameraDisabled(admin, UserHandle.myUserId());
1559 }
1560
1561 /** @hide per-user version */
1562 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001563 if (mService != null) {
1564 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001565 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001566 } catch (RemoteException e) {
1567 Log.w(TAG, "Failed talking with device policy service", e);
1568 }
1569 }
1570 return false;
1571 }
1572
1573 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001574 * Called by an application that is administering the device to disable keyguard customizations,
1575 * such as widgets. After setting this, keyguard features will be disabled according to the
1576 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001577 *
1578 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001579 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001580 * this method; if it has not, a security exception will be thrown.
1581 *
1582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001583 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1584 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001585 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1586 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001587 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001588 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001589 if (mService != null) {
1590 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001591 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001592 } catch (RemoteException e) {
1593 Log.w(TAG, "Failed talking with device policy service", e);
1594 }
1595 }
1596 }
1597
1598 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001599 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001600 * admin, if specified, or all admins.
1601 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001602 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001603 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1604 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001605 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001606 public int getKeyguardDisabledFeatures(ComponentName admin) {
1607 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001608 }
1609
1610 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001611 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001612 if (mService != null) {
1613 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001614 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001615 } catch (RemoteException e) {
1616 Log.w(TAG, "Failed talking with device policy service", e);
1617 }
1618 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001619 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001620 }
1621
1622 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001623 * @hide
1624 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001625 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001626 if (mService != null) {
1627 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001628 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001629 } catch (RemoteException e) {
1630 Log.w(TAG, "Failed talking with device policy service", e);
1631 }
1632 }
1633 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001634
Dianne Hackbornd6847842010-01-12 18:14:19 -08001635 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001636 * @hide
1637 */
1638 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1639 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1640 }
1641
1642 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001643 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001644 * @hide
1645 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001646 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001647 ActivityInfo ai;
1648 try {
1649 ai = mContext.getPackageManager().getReceiverInfo(cn,
1650 PackageManager.GET_META_DATA);
1651 } catch (PackageManager.NameNotFoundException e) {
1652 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1653 return null;
1654 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001655
Dianne Hackbornd6847842010-01-12 18:14:19 -08001656 ResolveInfo ri = new ResolveInfo();
1657 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001658
Dianne Hackbornd6847842010-01-12 18:14:19 -08001659 try {
1660 return new DeviceAdminInfo(mContext, ri);
1661 } catch (XmlPullParserException e) {
1662 Log.w(TAG, "Unable to parse device policy " + cn, e);
1663 return null;
1664 } catch (IOException e) {
1665 Log.w(TAG, "Unable to parse device policy " + cn, e);
1666 return null;
1667 }
1668 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001669
Dianne Hackbornd6847842010-01-12 18:14:19 -08001670 /**
1671 * @hide
1672 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001673 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1674 if (mService != null) {
1675 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001676 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001677 } catch (RemoteException e) {
1678 Log.w(TAG, "Failed talking with device policy service", e);
1679 }
1680 }
1681 }
1682
1683 /**
1684 * @hide
1685 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001686 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001687 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001688 if (mService != null) {
1689 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001690 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001691 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001692 } catch (RemoteException e) {
1693 Log.w(TAG, "Failed talking with device policy service", e);
1694 }
1695 }
1696 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001697
Dianne Hackbornd6847842010-01-12 18:14:19 -08001698 /**
1699 * @hide
1700 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001701 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001702 if (mService != null) {
1703 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001704 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001705 } catch (RemoteException e) {
1706 Log.w(TAG, "Failed talking with device policy service", e);
1707 }
1708 }
1709 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001710
Dianne Hackbornd6847842010-01-12 18:14:19 -08001711 /**
1712 * @hide
1713 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001714 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001715 if (mService != null) {
1716 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001717 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001718 } catch (RemoteException e) {
1719 Log.w(TAG, "Failed talking with device policy service", e);
1720 }
1721 }
1722 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001723
1724 /**
1725 * @hide
1726 * Sets the given package as the device owner. The package must already be installed and there
1727 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1728 * method must be called before the device is provisioned.
1729 * @param packageName the package name of the application to be registered as the device owner.
1730 * @return whether the package was successfully registered as the device owner.
1731 * @throws IllegalArgumentException if the package name is null or invalid
1732 * @throws IllegalStateException if a device owner is already registered or the device has
1733 * already been provisioned.
1734 */
1735 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1736 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001737 return setDeviceOwner(packageName, null);
1738 }
1739
1740 /**
1741 * @hide
1742 * Sets the given package as the device owner. The package must already be installed and there
1743 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1744 * method must be called before the device is provisioned.
1745 * @param packageName the package name of the application to be registered as the device owner.
1746 * @param ownerName the human readable name of the institution that owns this device.
1747 * @return whether the package was successfully registered as the device owner.
1748 * @throws IllegalArgumentException if the package name is null or invalid
1749 * @throws IllegalStateException if a device owner is already registered or the device has
1750 * already been provisioned.
1751 */
1752 public boolean setDeviceOwner(String packageName, String ownerName)
1753 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001754 if (mService != null) {
1755 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001756 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001757 } catch (RemoteException re) {
1758 Log.w(TAG, "Failed to set device owner");
1759 }
1760 }
1761 return false;
1762 }
1763
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001764
Amith Yamasani71e6c692013-03-24 17:39:28 -07001765 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001766 * Used to determine if a particular package has been registered as a Device Owner app.
1767 * A device owner app is a special device admin that cannot be deactivated by the user, once
1768 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1769 * package is currently registered as the device owner app, pass in the package name from
1770 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1771 * admin apps that want to check if they are also registered as the device owner app. The
1772 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1773 * the setup process.
1774 * @param packageName the package name of the app, to compare with the registered device owner
1775 * app, if any.
1776 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001777 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001778 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001779 if (mService != null) {
1780 try {
1781 return mService.isDeviceOwner(packageName);
1782 } catch (RemoteException re) {
1783 Log.w(TAG, "Failed to check device owner");
1784 }
1785 }
1786 return false;
1787 }
1788
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001789 /**
1790 * @hide
1791 * Redirect to isDeviceOwnerApp.
1792 */
1793 public boolean isDeviceOwner(String packageName) {
1794 return isDeviceOwnerApp(packageName);
1795 }
1796
Amith Yamasani71e6c692013-03-24 17:39:28 -07001797 /** @hide */
1798 public String getDeviceOwner() {
1799 if (mService != null) {
1800 try {
1801 return mService.getDeviceOwner();
1802 } catch (RemoteException re) {
1803 Log.w(TAG, "Failed to get device owner");
1804 }
1805 }
1806 return null;
1807 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001808
1809 /** @hide */
1810 public String getDeviceOwnerName() {
1811 if (mService != null) {
1812 try {
1813 return mService.getDeviceOwnerName();
1814 } catch (RemoteException re) {
1815 Log.w(TAG, "Failed to get device owner");
1816 }
1817 }
1818 return null;
1819 }
Adam Connors776c5552014-01-09 10:42:56 +00001820
1821 /**
1822 * @hide
1823 * Sets the given package as the profile owner of the given user profile. The package must
1824 * already be installed and there shouldn't be an existing profile owner registered for this
1825 * user. Also, this method must be called before the user has been used for the first time.
1826 * @param packageName the package name of the application to be registered as profile owner.
1827 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00001828 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00001829 * @return whether the package was successfully registered as the profile owner.
1830 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
1831 * the user has already been set up.
1832 */
Adam Connors661ec472014-02-11 13:59:46 +00001833 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00001834 throws IllegalArgumentException {
1835 if (mService != null) {
1836 try {
Adam Connors661ec472014-02-11 13:59:46 +00001837 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00001838 } catch (RemoteException re) {
1839 Log.w(TAG, "Failed to set profile owner", re);
1840 throw new IllegalArgumentException("Couldn't set profile owner.", re);
1841 }
1842 }
1843 return false;
1844 }
1845
1846 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001847 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
1848 * be used. Only the profile owner can call this.
1849 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001850 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001851 *
1852 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1853 */
1854 public void setProfileEnabled(ComponentName admin) {
1855 if (mService != null) {
1856 try {
1857 mService.setProfileEnabled(admin);
1858 } catch (RemoteException e) {
1859 Log.w(TAG, "Failed talking with device policy service", e);
1860 }
1861 }
1862 }
1863
1864 /**
Adam Connors776c5552014-01-09 10:42:56 +00001865 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001866 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00001867 * within the managed profile.
1868 *
1869 * @param packageName The package name of the app to compare with the registered profile owner.
1870 * @return Whether or not the package is registered as the profile owner.
1871 */
1872 public boolean isProfileOwnerApp(String packageName) {
1873 if (mService != null) {
1874 try {
1875 String profileOwnerPackage = mService.getProfileOwner(
1876 Process.myUserHandle().getIdentifier());
1877 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
1878 } catch (RemoteException re) {
1879 Log.w(TAG, "Failed to check profile owner");
1880 }
1881 }
1882 return false;
1883 }
1884
1885 /**
1886 * @hide
1887 * @return the packageName of the owner of the given user profile or null if no profile
1888 * owner has been set for that user.
1889 * @throws IllegalArgumentException if the userId is invalid.
1890 */
1891 public String getProfileOwner() throws IllegalArgumentException {
1892 if (mService != null) {
1893 try {
1894 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
1895 } catch (RemoteException re) {
1896 Log.w(TAG, "Failed to get profile owner");
1897 throw new IllegalArgumentException(
1898 "Requested profile owner for invalid userId", re);
1899 }
1900 }
1901 return null;
1902 }
1903
1904 /**
1905 * @hide
1906 * @return the human readable name of the organisation associated with this DPM or null if
1907 * one is not set.
1908 * @throws IllegalArgumentException if the userId is invalid.
1909 */
1910 public String getProfileOwnerName() throws IllegalArgumentException {
1911 if (mService != null) {
1912 try {
1913 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
1914 } catch (RemoteException re) {
1915 Log.w(TAG, "Failed to get profile owner");
1916 throw new IllegalArgumentException(
1917 "Requested profile owner for invalid userId", re);
1918 }
1919 }
1920 return null;
1921 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001922
1923 /**
1924 * Called by a profile owner or device owner to add a default intent handler activity for
1925 * intents that match a certain intent filter. This activity will remain the default intent
1926 * handler even if the set of potential event handlers for the intent filter changes and if
1927 * the intent preferences are reset.
1928 *
1929 * <p>The default disambiguation mechanism takes over if the activity is not installed
1930 * (anymore). When the activity is (re)installed, it is automatically reset as default
1931 * intent handler for the filter.
1932 *
1933 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
1934 * security exception will be thrown.
1935 *
1936 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1937 * @param filter The IntentFilter for which a default handler is added.
1938 * @param activity The Activity that is added as default intent handler.
1939 */
1940 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
1941 ComponentName activity) {
1942 if (mService != null) {
1943 try {
1944 mService.addPersistentPreferredActivity(admin, filter, activity);
1945 } catch (RemoteException e) {
1946 Log.w(TAG, "Failed talking with device policy service", e);
1947 }
1948 }
1949 }
1950
1951 /**
1952 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00001953 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001954 *
1955 * <p>The calling device admin must be a profile owner. If it is not, a security
1956 * exception will be thrown.
1957 *
1958 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1959 * @param packageName The name of the package for which preferences are removed.
1960 */
1961 public void clearPackagePersistentPreferredActivities(ComponentName admin,
1962 String packageName) {
1963 if (mService != null) {
1964 try {
1965 mService.clearPackagePersistentPreferredActivities(admin, packageName);
1966 } catch (RemoteException e) {
1967 Log.w(TAG, "Failed talking with device policy service", e);
1968 }
1969 }
1970 }
Robin Lee66e5d962014-04-09 16:44:21 +01001971
1972 /**
1973 * Called by a profile or device owner to set the application restrictions for a given target
1974 * application running in the managed profile.
1975 *
1976 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
1977 * {@link Boolean}, {@link String}, or {@link String}[]. The recommended format for key strings
1978 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
1979 * components such as {@link android.webkit.WebView}.
1980 *
1981 * <p>The application restrictions are only made visible to the target application and the
1982 * profile or device owner.
1983 *
1984 * <p>The calling device admin must be a profile or device owner; if it is not, a security
1985 * exception will be thrown.
1986 *
1987 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1988 * @param packageName The name of the package to update restricted settings for.
1989 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
1990 * set of active restrictions.
1991 */
1992 public void setApplicationRestrictions(ComponentName admin, String packageName,
1993 Bundle settings) {
1994 if (mService != null) {
1995 try {
1996 mService.setApplicationRestrictions(admin, packageName, settings);
1997 } catch (RemoteException e) {
1998 Log.w(TAG, "Failed talking with device policy service", e);
1999 }
2000 }
2001 }
2002
2003 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002004 * Called by the profile owner so that some intents sent in the managed profile can also be
2005 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002007 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2008 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002009 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2010 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002011 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002012 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002013 if (mService != null) {
2014 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002015 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002016 } catch (RemoteException e) {
2017 Log.w(TAG, "Failed talking with device policy service", e);
2018 }
2019 }
2020 }
2021
2022 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002023 * Called by a profile owner to remove the cross-profile intent filters from the managed profile
2024 * and from the parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2026 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002027 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002028 if (mService != null) {
2029 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002030 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002031 } catch (RemoteException e) {
2032 Log.w(TAG, "Failed talking with device policy service", e);
2033 }
2034 }
2035 }
2036
2037 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002038 * Called by a device owner to create a user with the specified name. The UserHandle returned
2039 * by this method should not be persisted as user handles are recycled as users are removed and
2040 * created. If you need to persist an identifier for this user, use
2041 * {@link UserManager#getSerialNumberForUser}.
2042 *
2043 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2044 * @param name the user's name
2045 * @see UserHandle
2046 * @return the UserHandle object for the created user, or null if the user could not be created.
2047 */
2048 public UserHandle createUser(ComponentName admin, String name) {
2049 try {
2050 return mService.createUser(admin, name);
2051 } catch (RemoteException re) {
2052 Log.w(TAG, "Could not create a user", re);
2053 }
2054 return null;
2055 }
2056
2057 /**
2058 * Called by a device owner to remove a user and all associated data. The primary user can
2059 * not be removed.
2060 *
2061 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2062 * @param userHandle the user to remove.
2063 * @return {@code true} if the user was removed, {@code false} otherwise.
2064 */
2065 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2066 try {
2067 return mService.removeUser(admin, userHandle);
2068 } catch (RemoteException re) {
2069 Log.w(TAG, "Could not remove user ", re);
2070 return false;
2071 }
2072 }
2073
2074 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002075 * Called by a profile or device owner to get the application restrictions for a given target
2076 * application running in the managed profile.
2077 *
2078 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2079 * exception will be thrown.
2080 *
2081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2082 * @param packageName The name of the package to fetch restricted settings of.
2083 * @return {@link Bundle} of settings corresponding to what was set last time
2084 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2085 * if no restrictions have been set.
2086 */
2087 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2088 if (mService != null) {
2089 try {
2090 return mService.getApplicationRestrictions(admin, packageName);
2091 } catch (RemoteException e) {
2092 Log.w(TAG, "Failed talking with device policy service", e);
2093 }
2094 }
2095 return null;
2096 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002097
2098 /**
2099 * Called by a profile or device owner to set a user restriction specified
2100 * by the key.
2101 * <p>
2102 * The calling device admin must be a profile or device owner; if it is not,
2103 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002104 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002105 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2106 * with.
2107 * @param key The key of the restriction. See the constants in
2108 * {@link android.os.UserManager} for the list of keys.
2109 */
2110 public void addUserRestriction(ComponentName admin, String key) {
2111 if (mService != null) {
2112 try {
2113 mService.setUserRestriction(admin, key, true);
2114 } catch (RemoteException e) {
2115 Log.w(TAG, "Failed talking with device policy service", e);
2116 }
2117 }
2118 }
2119
2120 /**
2121 * Called by a profile or device owner to clear a user restriction specified
2122 * by the key.
2123 * <p>
2124 * The calling device admin must be a profile or device owner; if it is not,
2125 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002126 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002127 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2128 * with.
2129 * @param key The key of the restriction. See the constants in
2130 * {@link android.os.UserManager} for the list of keys.
2131 */
2132 public void clearUserRestriction(ComponentName admin, String key) {
2133 if (mService != null) {
2134 try {
2135 mService.setUserRestriction(admin, key, false);
2136 } catch (RemoteException e) {
2137 Log.w(TAG, "Failed talking with device policy service", e);
2138 }
2139 }
2140 }
Adam Connors010cfd42014-04-16 12:48:13 +01002141
2142 /**
Julia Reynolds966881e2014-05-14 12:23:08 -04002143 * Called by device or profile owner to block or unblock packages. When a package is blocked it
2144 * is unavailable for use, but the data and actual package file remain.
2145 *
2146 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2147 * @param packageName The name of the package to block or unblock.
2148 * @param blocked {@code true} if the package should be blocked, {@code false} if it should be
2149 * unblocked.
2150 * @return boolean Whether the blocked setting of the package was successfully updated.
2151 */
2152 public boolean setApplicationBlocked(ComponentName admin, String packageName,
2153 boolean blocked) {
2154 if (mService != null) {
2155 try {
2156 return mService.setApplicationBlocked(admin, packageName, blocked);
2157 } catch (RemoteException e) {
2158 Log.w(TAG, "Failed talking with device policy service", e);
2159 }
2160 }
2161 return false;
2162 }
2163
2164 /**
2165 * Called by profile or device owner to block or unblock currently installed packages. This
2166 * should only be called by a profile or device owner running within a managed profile.
2167 *
2168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2169 * @param intent An intent matching the app(s) to be updated. All apps that resolve for this
2170 * intent will be updated in the current profile.
2171 * @param blocked {@code true} if the packages should be blocked, {@code false} if they should
2172 * be unblocked.
2173 * @return int The number of activities that matched the intent and were updated.
2174 */
2175 public int setApplicationsBlocked(ComponentName admin, Intent intent, boolean blocked) {
2176 if (mService != null) {
2177 try {
2178 return mService.setApplicationsBlocked(admin, intent, blocked);
2179 } catch (RemoteException e) {
2180 Log.w(TAG, "Failed talking with device policy service", e);
2181 }
2182 }
2183 return 0;
2184 }
2185
2186 /**
2187 * Called by device or profile owner to determine if a package is blocked.
2188 *
2189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2190 * @param packageName The name of the package to retrieve the blocked status of.
2191 * @return boolean {@code true} if the package is blocked, {@code false} otherwise.
2192 */
2193 public boolean isApplicationBlocked(ComponentName admin, String packageName) {
2194 if (mService != null) {
2195 try {
2196 return mService.isApplicationBlocked(admin, packageName);
2197 } catch (RemoteException e) {
2198 Log.w(TAG, "Failed talking with device policy service", e);
2199 }
2200 }
2201 return false;
2202 }
2203
2204 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01002205 * Called by a profile owner to disable account management for a specific type of account.
2206 *
2207 * <p>The calling device admin must be a profile owner. If it is not, a
2208 * security exception will be thrown.
2209 *
2210 * <p>When account management is disabled for an account type, adding or removing an account
2211 * of that type will not be possible.
2212 *
2213 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2214 * @param accountType For which account management is disabled or enabled.
2215 * @param disabled The boolean indicating that account management will be disabled (true) or
2216 * enabled (false).
2217 */
2218 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2219 boolean disabled) {
2220 if (mService != null) {
2221 try {
2222 mService.setAccountManagementDisabled(admin, accountType, disabled);
2223 } catch (RemoteException e) {
2224 Log.w(TAG, "Failed talking with device policy service", e);
2225 }
2226 }
2227 }
2228
2229 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002230 * Gets the array of accounts for which account management is disabled by the profile owner.
2231 *
2232 * <p> Account management can be disabled/enabled by calling
2233 * {@link #setAccountManagementDisabled}.
2234 *
2235 * @return a list of account types for which account management has been disabled.
2236 *
2237 * @see #setAccountManagementDisabled
2238 */
2239 public String[] getAccountTypesWithManagementDisabled() {
2240 if (mService != null) {
2241 try {
2242 return mService.getAccountTypesWithManagementDisabled();
2243 } catch (RemoteException e) {
2244 Log.w(TAG, "Failed talking with device policy service", e);
2245 }
2246 }
2247
2248 return null;
2249 }
justinzhang511e0d82014-03-24 16:09:24 -04002250
2251 /**
2252 * Sets which components may enter lock task mode.
2253 *
2254 * This function can only be called by the device owner or the profile owner.
2255 * @param components The list of components allowed to enter lock task mode
2256 */
2257 public void setLockTaskComponents(ComponentName[] components) throws SecurityException {
2258 if (mService != null) {
2259 try {
2260 mService.setLockTaskComponents(components);
2261 } catch (RemoteException e) {
2262 Log.w(TAG, "Failed talking with device policy service", e);
2263 }
2264 }
2265 }
2266
2267 /**
2268 * This function returns the list of components allowed to start the lock task mode.
2269 * @hide
2270 */
2271 public ComponentName[] getLockTaskComponents() {
2272 if (mService != null) {
2273 try {
2274 return mService.getLockTaskComponents();
2275 } catch (RemoteException e) {
2276 Log.w(TAG, "Failed talking with device policy service", e);
2277 }
2278 }
2279 return null;
2280 }
2281
2282 /**
2283 * This function lets the caller know whether the given component is allowed to start the
2284 * lock task mode.
2285 * @param component The component to check
2286 */
2287 public boolean isLockTaskPermitted(ComponentName component) {
2288 if (mService != null) {
2289 try {
2290 return mService.isLockTaskPermitted(component);
2291 } catch (RemoteException e) {
2292 Log.w(TAG, "Failed talking with device policy service", e);
2293 }
2294 }
2295 return false;
2296 }
Julia Reynoldsda551652014-05-14 17:15:16 -04002297
2298 /**
2299 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
2300 * of the setting is in the correct form for the setting type should be performed by the caller.
2301 *
2302 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2303 * @param setting The name of the setting to update.
2304 * @param value The value to update the setting to.
2305 */
2306 public void setGlobalSetting(ComponentName admin, String setting, String value) {
2307 if (mService != null) {
2308 try {
2309 mService.setGlobalSetting(admin, setting, value);
2310 } catch (RemoteException e) {
2311 Log.w(TAG, "Failed talking with device policy service", e);
2312 }
2313 }
2314 }
2315
2316 /**
2317 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
2318 * that the value of the setting is in the correct form for the setting type should be performed
2319 * by the caller.
2320 *
2321 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2322 * @param setting The name of the setting to update.
2323 * @param value The value to update the setting to.
2324 */
2325 public void setSecureSetting(ComponentName admin, String setting, String value) {
2326 if (mService != null) {
2327 try {
2328 mService.setSecureSetting(admin, setting, value);
2329 } catch (RemoteException e) {
2330 Log.w(TAG, "Failed talking with device policy service", e);
2331 }
2332 }
2333 }
2334
Amith Yamasanif20d6402014-05-24 15:34:37 -07002335 /**
2336 * Designates a specific broadcast receiver component as the provider for
2337 * making permission requests of a local or remote administrator of the user.
2338 * <p/>
2339 * Only a profile owner can designate the restrictions provider.
2340 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2341 * @param receiver The component name of a BroadcastReceiver that handles the
2342 * {@link RestrictionsManager#ACTION_REQUEST_PERMISSION} intent. If this param is null,
2343 * it removes the restrictions provider previously assigned.
2344 */
2345 public void setRestrictionsProvider(ComponentName admin, ComponentName receiver) {
2346 if (mService != null) {
2347 try {
2348 mService.setRestrictionsProvider(admin, receiver);
2349 } catch (RemoteException re) {
2350 Log.w(TAG, "Failed to set permission provider on device policy service");
2351 }
2352 }
2353 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002354}