blob: ae1a4e7428e62fbc7c7572e6ce651c4c6fdb37d9 [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;
Jason Monkd7b86212014-06-16 13:15:38 -040021import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080022import android.content.ComponentName;
23import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010024import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000025import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080026import android.content.pm.ActivityInfo;
27import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Amith Yamasanif20d6402014-05-24 15:34:37 -070029import android.content.RestrictionsManager;
Julia Reynolds4a21b252014-06-04 11:11:43 -040030import android.media.AudioService;
Jason Monk03bc9912014-05-13 09:44:57 -040031import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010032import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000034import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080035import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036import android.os.RemoteException;
37import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070038import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040039import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040040import android.provider.Settings;
Jim Miller50e62182014-04-23 17:25:00 -070041import android.service.trust.TrustAgentService;
Dianne Hackbornd6847842010-01-12 18:14:19 -080042import android.util.Log;
43
Maggie Benthallda51e682013-08-08 22:35:44 -040044import com.android.org.conscrypt.TrustedCertificateStore;
45
Jessica Hummel91da58d2014-04-10 17:39:43 +010046import org.xmlpull.v1.XmlPullParserException;
47
Maggie Benthallda51e682013-08-08 22:35:44 -040048import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080049import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070050import java.net.InetSocketAddress;
51import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.security.cert.CertificateException;
53import java.security.cert.CertificateFactory;
54import java.security.cert.X509Certificate;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080055import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040056import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080057
58/**
59 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080060 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080061 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080062 *
63 * <div class="special reference">
64 * <h3>Developer Guides</h3>
65 * <p>For more information about managing policies for device adminstration, read the
66 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
67 * developer guide.</p>
68 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080069 */
70public class DevicePolicyManager {
71 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080072
73 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080074 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070075
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080076 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080077 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080078 mService = IDevicePolicyManager.Stub.asInterface(
79 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
80 }
81
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080082 /** @hide */
83 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080084 DevicePolicyManager me = new DevicePolicyManager(context, handler);
85 return me.mService != null ? me : null;
86 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070087
Dianne Hackbornd6847842010-01-12 18:14:19 -080088 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +010089 * Activity action: Used to indicate that the receiving activity is being started as part of the
90 * managed profile provisioning flow. This intent is typically sent to a mobile device
91 * management application (mdm) after the first part of the provisioning process is complete in
92 * the expectation that this app will (after optionally showing it's own UI) ultimately call
93 * {@link #ACTION_PROVISION_MANAGED_PROFILE} to complete the creation of the managed profile.
94 *
95 * <p> The intent may contain the extras {@link #EXTRA_PROVISIONING_TOKEN} and
96 * {@link #EXTRA_PROVISIONING_EMAIL_ADDRESS}.
97 */
98 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
99 public static final String ACTION_SEND_PROVISIONING_VALUES
100 = "android.app.action.ACTION_SEND_PROVISIONING_VALUES";
101
102 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000103 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000104 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100105 * <p>A managed profile allows data separation for example for the usage of a
106 * device as a personal and corporate device. The user which provisioning is started from and
107 * the managed profile share a launcher.
108 *
109 * <p>This intent will typically be sent by a mobile device management application (mdm).
110 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
111 * control over the profile
112 *
113 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
114 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000115 *
116 * <p> When managed provisioning has completed, an intent of the type
117 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Jessica Hummel9da60392014-05-21 12:32:57 +0100118 * managed profile. The intent is sent to the {@link DeviceAdminReceiver} specified in the
119 * {@link #EXTRA_DEVICE_ADMIN} exclusively.
120 *
121 * If provisioning fails, the managedProfile is removed so the device returns to its previous
122 * state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000123 *
124 * <p>Input: Nothing.</p>
125 * <p>Output: Nothing</p>
126 */
127 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
128 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000129 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130
131 /**
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100132 * A broadcast intent with this action can be sent to ManagedProvisionning to specify that the
133 * user has already consented to the creation of the managed profile.
134 * The intent must contain the extras
135 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} and
136 * {@link #EXTRA_PROVISIONING_TOKEN}
137 * @hide
138 */
139 public static final String ACTION_PROVISIONING_USER_HAS_CONSENTED
Nicolas Prevotfb8a98d2014-06-10 17:59:27 +0100140 = "android.app.action.ACTION_PROVISIONING_USER_HAS_CONSENTED";
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100141
142 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000143 * A String extra holding the name of the package of the mobile device management application
144 * that starts the managed provisioning flow. This package will be set as the profile owner.
145 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
146 */
147 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100148 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000149
150 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100151 * An int extra used to identify that during the current setup process the user has already
152 * consented to setting up a managed profile. This is typically received by
153 * a mobile device management application when it is started with
154 * {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
155 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. The
156 * token indicates that steps asking for user consent can be skipped as the user has previously
157 * consented.
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100158 */
159 public static final String EXTRA_PROVISIONING_TOKEN
160 = "android.app.extra.token";
161
162 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000163 * A String extra holding the default name of the profile that is created during managed profile
164 * provisioning.
165 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
166 */
167 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100168 = "android.app.extra.defaultManagedProfileName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000169
170 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100171 * A String extra holding the email address of the profile that is created during managed
172 * profile provisioning. This is typically received by a mobile management application when it
173 * is started with {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
174 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. It
175 * is eventually passed on in an intent
176 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
177 */
178 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
179 = "android.app.extra.ManagedProfileEmailAddress";
180
181 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800182 * Activity action: ask the user to add a new device administrator to the system.
183 * The desired policy is the ComponentName of the policy in the
184 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
185 * bring the user through adding the device administrator to the system (or
186 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700187 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800188 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
189 * field to provide the user with additional explanation (in addition
190 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800191 *
192 * <p>If your administrator is already active, this will ordinarily return immediately (without
193 * user intervention). However, if your administrator has been updated and is requesting
194 * additional uses-policy flags, the user will be presented with the new list. New policies
195 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800196 */
197 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
198 public static final String ACTION_ADD_DEVICE_ADMIN
199 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700200
Dianne Hackbornd6847842010-01-12 18:14:19 -0800201 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700202 * Activity action: send when any policy admin changes a policy.
203 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700204 *
Jim Miller284b62e2010-06-08 14:27:42 -0700205 * @hide
206 */
207 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
208 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
209
210 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800211 * The ComponentName of the administrator component.
212 *
213 * @see #ACTION_ADD_DEVICE_ADMIN
214 */
215 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700216
Dianne Hackbornd6847842010-01-12 18:14:19 -0800217 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800218 * An optional CharSequence providing additional explanation for why the
219 * admin is being added.
220 *
221 * @see #ACTION_ADD_DEVICE_ADMIN
222 */
223 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700224
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800225 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700226 * Activity action: have the user enter a new password. This activity should
227 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
228 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
229 * enter a new password that meets the current requirements. You can use
230 * {@link #isActivePasswordSufficient()} to determine whether you need to
231 * have the user select a new password in order to meet the current
232 * constraints. Upon being resumed from this activity, you can check the new
233 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800234 */
235 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
236 public static final String ACTION_SET_NEW_PASSWORD
237 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000238 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100239 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
240 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000241 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100242 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000243
244 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100245 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
246 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000247 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100248 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700249
Dianne Hackbornd6847842010-01-12 18:14:19 -0800250 /**
251 * Return true if the given administrator component is currently
252 * active (enabled) in the system.
253 */
254 public boolean isAdminActive(ComponentName who) {
255 if (mService != null) {
256 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700257 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800258 } catch (RemoteException e) {
259 Log.w(TAG, "Failed talking with device policy service", e);
260 }
261 }
262 return false;
263 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700264
Dianne Hackbornd6847842010-01-12 18:14:19 -0800265 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800266 * Return a list of all currently active device administrator's component
267 * names. Note that if there are no administrators than null may be
268 * returned.
269 */
270 public List<ComponentName> getActiveAdmins() {
271 if (mService != null) {
272 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700273 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800274 } catch (RemoteException e) {
275 Log.w(TAG, "Failed talking with device policy service", e);
276 }
277 }
278 return null;
279 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700280
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800281 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700282 * Used by package administration code to determine if a package can be stopped
283 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800284 * @hide
285 */
286 public boolean packageHasActiveAdmins(String packageName) {
287 if (mService != null) {
288 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700289 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800290 } catch (RemoteException e) {
291 Log.w(TAG, "Failed talking with device policy service", e);
292 }
293 }
294 return false;
295 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700296
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800297 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800298 * Remove a current administration component. This can only be called
299 * by the application that owns the administration component; if you
300 * try to remove someone else's component, a security exception will be
301 * thrown.
302 */
303 public void removeActiveAdmin(ComponentName who) {
304 if (mService != null) {
305 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700306 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800307 } catch (RemoteException e) {
308 Log.w(TAG, "Failed talking with device policy service", e);
309 }
310 }
311 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700312
Dianne Hackbornd6847842010-01-12 18:14:19 -0800313 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800314 * Returns true if an administrator has been granted a particular device policy. This can
315 * be used to check if the administrator was activated under an earlier set of policies,
316 * but requires additional policies after an upgrade.
317 *
318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
319 * an active administrator, or an exception will be thrown.
320 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
321 */
322 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
323 if (mService != null) {
324 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700325 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800326 } catch (RemoteException e) {
327 Log.w(TAG, "Failed talking with device policy service", e);
328 }
329 }
330 return false;
331 }
332
333 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800334 * Constant for {@link #setPasswordQuality}: the policy has no requirements
335 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800336 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800337 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800338 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700339
Dianne Hackbornd6847842010-01-12 18:14:19 -0800340 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700341 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
342 * recognition technology. This implies technologies that can recognize the identity of
343 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
344 * Note that quality constants are ordered so that higher values are more restrictive.
345 */
346 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
347
348 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800349 * Constant for {@link #setPasswordQuality}: the policy requires some kind
350 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800351 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800352 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800353 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700354
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800355 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800356 * Constant for {@link #setPasswordQuality}: the user must have entered a
357 * password containing at least numeric characters. Note that quality
358 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800359 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800360 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700361
Dianne Hackbornd6847842010-01-12 18:14:19 -0800362 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800363 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700364 * password containing at least alphabetic (or other symbol) characters.
365 * Note that quality constants are ordered so that higher values are more
366 * restrictive.
367 */
368 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700369
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700370 /**
371 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800372 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700373 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800374 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800375 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700376 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700377
Dianne Hackbornd6847842010-01-12 18:14:19 -0800378 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700379 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700380 * password containing at least a letter, a numerical digit and a special
381 * symbol, by default. With this password quality, passwords can be
382 * restricted to contain various sets of characters, like at least an
383 * uppercase letter, etc. These are specified using various methods,
384 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
385 * that quality constants are ordered so that higher values are more
386 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700387 */
388 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
389
390 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800391 * Called by an application that is administering the device to set the
392 * password restrictions it is imposing. After setting this, the user
393 * will not be able to enter a new password that is not at least as
394 * restrictive as what has been set. Note that the current password
395 * will remain until the user has set a new one, so the change does not
396 * take place immediately. To prompt the user for a new password, use
397 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700398 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800399 * <p>Quality constants are ordered so that higher values are more restrictive;
400 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800401 * the user's preference, and any other considerations) is the one that
402 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700403 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800404 * <p>The calling device admin must have requested
405 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
406 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700407 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800409 * @param quality The new desired quality. One of
410 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700411 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700412 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800413 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800414 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800415 if (mService != null) {
416 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700417 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800418 } catch (RemoteException e) {
419 Log.w(TAG, "Failed talking with device policy service", e);
420 }
421 }
422 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700423
Dianne Hackbornd6847842010-01-12 18:14:19 -0800424 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100425 * Retrieve the current minimum password quality for all admins of this user
426 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800427 * @param admin The name of the admin component to check, or null to aggregate
428 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800429 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800430 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700431 return getPasswordQuality(admin, UserHandle.myUserId());
432 }
433
434 /** @hide per-user version */
435 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800436 if (mService != null) {
437 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700438 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800439 } catch (RemoteException e) {
440 Log.w(TAG, "Failed talking with device policy service", e);
441 }
442 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800443 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800444 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700445
Dianne Hackbornd6847842010-01-12 18:14:19 -0800446 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800447 * Called by an application that is administering the device to set the
448 * minimum allowed password length. After setting this, the user
449 * will not be able to enter a new password that is not at least as
450 * restrictive as what has been set. Note that the current password
451 * will remain until the user has set a new one, so the change does not
452 * take place immediately. To prompt the user for a new password, use
453 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
454 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700455 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
456 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800457 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700458 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800459 * <p>The calling device admin must have requested
460 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
461 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700462 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800463 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800464 * @param length The new desired minimum password length. A value of 0
465 * means there is no restriction.
466 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800467 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800468 if (mService != null) {
469 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700470 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800471 } catch (RemoteException e) {
472 Log.w(TAG, "Failed talking with device policy service", e);
473 }
474 }
475 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700476
Dianne Hackbornd6847842010-01-12 18:14:19 -0800477 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100478 * Retrieve the current minimum password length for all admins of this
479 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800480 * @param admin The name of the admin component to check, or null to aggregate
481 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800482 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800483 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700484 return getPasswordMinimumLength(admin, UserHandle.myUserId());
485 }
486
487 /** @hide per-user version */
488 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800489 if (mService != null) {
490 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700491 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800492 } catch (RemoteException e) {
493 Log.w(TAG, "Failed talking with device policy service", e);
494 }
495 }
496 return 0;
497 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700498
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700499 /**
500 * Called by an application that is administering the device to set the
501 * minimum number of upper case letters required in the password. After
502 * setting this, the user will not be able to enter a new password that is
503 * not at least as restrictive as what has been set. Note that the current
504 * password will remain until the user has set a new one, so the change does
505 * not take place immediately. To prompt the user for a new password, use
506 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
507 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700508 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
509 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700510 * <p>
511 * The calling device admin must have requested
512 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
513 * this method; if it has not, a security exception will be thrown.
514 *
515 * @param admin Which {@link DeviceAdminReceiver} this request is associated
516 * with.
517 * @param length The new desired minimum number of upper case letters
518 * required in the password. A value of 0 means there is no
519 * restriction.
520 */
521 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
522 if (mService != null) {
523 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700524 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700525 } catch (RemoteException e) {
526 Log.w(TAG, "Failed talking with device policy service", e);
527 }
528 }
529 }
530
531 /**
532 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100533 * password for all admins of this user and its profiles or a particular one.
534 * This is the same value as set by
535 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700536 * and only applies when the password quality is
537 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700538 *
539 * @param admin The name of the admin component to check, or null to
540 * aggregate all admins.
541 * @return The minimum number of upper case letters required in the
542 * password.
543 */
544 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700545 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
546 }
547
548 /** @hide per-user version */
549 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700550 if (mService != null) {
551 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700552 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700553 } catch (RemoteException e) {
554 Log.w(TAG, "Failed talking with device policy service", e);
555 }
556 }
557 return 0;
558 }
559
560 /**
561 * Called by an application that is administering the device to set the
562 * minimum number of lower case letters required in the password. After
563 * setting this, the user will not be able to enter a new password that is
564 * not at least as restrictive as what has been set. Note that the current
565 * password will remain until the user has set a new one, so the change does
566 * not take place immediately. To prompt the user for a new password, use
567 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
568 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700569 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
570 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700571 * <p>
572 * The calling device admin must have requested
573 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
574 * this method; if it has not, a security exception will be thrown.
575 *
576 * @param admin Which {@link DeviceAdminReceiver} this request is associated
577 * with.
578 * @param length The new desired minimum number of lower case letters
579 * required in the password. A value of 0 means there is no
580 * restriction.
581 */
582 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
583 if (mService != null) {
584 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700585 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700586 } catch (RemoteException e) {
587 Log.w(TAG, "Failed talking with device policy service", e);
588 }
589 }
590 }
591
592 /**
593 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100594 * password for all admins of this user and its profiles or a particular one.
595 * This is the same value as set by
596 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700597 * and only applies when the password quality is
598 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700599 *
600 * @param admin The name of the admin component to check, or null to
601 * aggregate all admins.
602 * @return The minimum number of lower case letters required in the
603 * password.
604 */
605 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700606 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
607 }
608
609 /** @hide per-user version */
610 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700611 if (mService != null) {
612 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700613 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700614 } catch (RemoteException e) {
615 Log.w(TAG, "Failed talking with device policy service", e);
616 }
617 }
618 return 0;
619 }
620
621 /**
622 * Called by an application that is administering the device to set the
623 * minimum number of letters required in the password. After setting this,
624 * the user will not be able to enter a new password that is not at least as
625 * restrictive as what has been set. Note that the current password will
626 * remain until the user has set a new one, so the change does not take
627 * place immediately. To prompt the user for a new password, use
628 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
629 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700630 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
631 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700632 * <p>
633 * The calling device admin must have requested
634 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
635 * this method; if it has not, a security exception will be thrown.
636 *
637 * @param admin Which {@link DeviceAdminReceiver} this request is associated
638 * with.
639 * @param length The new desired minimum number of letters required in the
640 * password. A value of 0 means there is no restriction.
641 */
642 public void setPasswordMinimumLetters(ComponentName admin, int length) {
643 if (mService != null) {
644 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700645 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700646 } catch (RemoteException e) {
647 Log.w(TAG, "Failed talking with device policy service", e);
648 }
649 }
650 }
651
652 /**
653 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700654 * admins or a particular one. This is the same value as
655 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
656 * and only applies when the password quality is
657 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700658 *
659 * @param admin The name of the admin component to check, or null to
660 * aggregate all admins.
661 * @return The minimum number of letters required in the password.
662 */
663 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700664 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
665 }
666
667 /** @hide per-user version */
668 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700669 if (mService != null) {
670 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700671 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700672 } catch (RemoteException e) {
673 Log.w(TAG, "Failed talking with device policy service", e);
674 }
675 }
676 return 0;
677 }
678
679 /**
680 * Called by an application that is administering the device to set the
681 * minimum number of numerical digits required in the password. After
682 * setting this, the user will not be able to enter a new password that is
683 * not at least as restrictive as what has been set. Note that the current
684 * password will remain until the user has set a new one, so the change does
685 * not take place immediately. To prompt the user for a new password, use
686 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
687 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700688 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
689 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700690 * <p>
691 * The calling device admin must have requested
692 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
693 * this method; if it has not, a security exception will be thrown.
694 *
695 * @param admin Which {@link DeviceAdminReceiver} this request is associated
696 * with.
697 * @param length The new desired minimum number of numerical digits required
698 * in the password. A value of 0 means there is no restriction.
699 */
700 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
701 if (mService != null) {
702 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700703 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700704 } catch (RemoteException e) {
705 Log.w(TAG, "Failed talking with device policy service", e);
706 }
707 }
708 }
709
710 /**
711 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100712 * for all admins of this user and its profiles or a particular one.
713 * This is the same value as set by
714 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700715 * and only applies when the password quality is
716 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700717 *
718 * @param admin The name of the admin component to check, or null to
719 * aggregate all admins.
720 * @return The minimum number of numerical digits required in the password.
721 */
722 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700723 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
724 }
725
726 /** @hide per-user version */
727 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700728 if (mService != null) {
729 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700730 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700731 } catch (RemoteException e) {
732 Log.w(TAG, "Failed talking with device policy service", e);
733 }
734 }
735 return 0;
736 }
737
738 /**
739 * Called by an application that is administering the device to set the
740 * minimum number of symbols required in the password. After setting this,
741 * the user will not be able to enter a new password that is not at least as
742 * restrictive as what has been set. Note that the current password will
743 * remain until the user has set a new one, so the change does not take
744 * place immediately. To prompt the user for a new password, use
745 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
746 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700747 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
748 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700749 * <p>
750 * The calling device admin must have requested
751 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
752 * this method; if it has not, a security exception will be thrown.
753 *
754 * @param admin Which {@link DeviceAdminReceiver} this request is associated
755 * with.
756 * @param length The new desired minimum number of symbols required in the
757 * password. A value of 0 means there is no restriction.
758 */
759 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
760 if (mService != null) {
761 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700762 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700763 } catch (RemoteException e) {
764 Log.w(TAG, "Failed talking with device policy service", e);
765 }
766 }
767 }
768
769 /**
770 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700771 * admins or a particular one. This is the same value as
772 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
773 * and only applies when the password quality is
774 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700775 *
776 * @param admin The name of the admin component to check, or null to
777 * aggregate all admins.
778 * @return The minimum number of symbols required in the password.
779 */
780 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700781 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
782 }
783
784 /** @hide per-user version */
785 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700786 if (mService != null) {
787 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700788 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700789 } catch (RemoteException e) {
790 Log.w(TAG, "Failed talking with device policy service", e);
791 }
792 }
793 return 0;
794 }
795
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700796 /**
797 * Called by an application that is administering the device to set the
798 * minimum number of non-letter characters (numerical digits or symbols)
799 * required in the password. After setting this, the user will not be able
800 * to enter a new password that is not at least as restrictive as what has
801 * been set. Note that the current password will remain until the user has
802 * set a new one, so the change does not take place immediately. To prompt
803 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
804 * setting this value. This constraint is only imposed if the administrator
805 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
806 * {@link #setPasswordQuality}. The default value is 0.
807 * <p>
808 * The calling device admin must have requested
809 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
810 * this method; if it has not, a security exception will be thrown.
811 *
812 * @param admin Which {@link DeviceAdminReceiver} this request is associated
813 * with.
814 * @param length The new desired minimum number of letters required in the
815 * password. A value of 0 means there is no restriction.
816 */
817 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
818 if (mService != null) {
819 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700820 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700821 } catch (RemoteException e) {
822 Log.w(TAG, "Failed talking with device policy service", e);
823 }
824 }
825 }
826
827 /**
828 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100829 * password for all admins of this user and its profiles or a particular one.
830 * This is the same value as set by
831 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700832 * and only applies when the password quality is
833 * {@link #PASSWORD_QUALITY_COMPLEX}.
834 *
835 * @param admin The name of the admin component to check, or null to
836 * aggregate all admins.
837 * @return The minimum number of letters required in the password.
838 */
839 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700840 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
841 }
842
843 /** @hide per-user version */
844 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700845 if (mService != null) {
846 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700847 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700848 } catch (RemoteException e) {
849 Log.w(TAG, "Failed talking with device policy service", e);
850 }
851 }
852 return 0;
853 }
854
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700855 /**
856 * Called by an application that is administering the device to set the length
857 * of the password history. After setting this, the user will not be able to
858 * enter a new password that is the same as any password in the history. Note
859 * that the current password will remain until the user has set a new one, so
860 * the change does not take place immediately. To prompt the user for a new
861 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
862 * This constraint is only imposed if the administrator has also requested
863 * either {@link #PASSWORD_QUALITY_NUMERIC},
864 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
865 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
866 *
867 * <p>
868 * The calling device admin must have requested
869 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
870 * method; if it has not, a security exception will be thrown.
871 *
872 * @param admin Which {@link DeviceAdminReceiver} this request is associated
873 * with.
874 * @param length The new desired length of password history. A value of 0
875 * means there is no restriction.
876 */
877 public void setPasswordHistoryLength(ComponentName admin, int length) {
878 if (mService != null) {
879 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700880 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700881 } catch (RemoteException e) {
882 Log.w(TAG, "Failed talking with device policy service", e);
883 }
884 }
885 }
886
887 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800888 * Called by a device admin to set the password expiration timeout. Calling this method
889 * will restart the countdown for password expiration for the given admin, as will changing
890 * the device password (for all admins).
891 *
892 * <p>The provided timeout is the time delta in ms and will be added to the current time.
893 * For example, to have the password expire 5 days from now, timeout would be
894 * 5 * 86400 * 1000 = 432000000 ms for timeout.
895 *
896 * <p>To disable password expiration, a value of 0 may be used for timeout.
897 *
Jim Millera4e28d12010-11-08 16:15:47 -0800898 * <p>The calling device admin must have requested
899 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
900 * method; if it has not, a security exception will be thrown.
901 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100902 * <p> Note that setting the password will automatically reset the expiration time for all
903 * active admins. Active admins do not need to explicitly call this method in that case.
904 *
Jim Millera4e28d12010-11-08 16:15:47 -0800905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
906 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
907 * means there is no restriction (unlimited).
908 */
909 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
910 if (mService != null) {
911 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700912 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800913 } catch (RemoteException e) {
914 Log.w(TAG, "Failed talking with device policy service", e);
915 }
916 }
917 }
918
919 /**
Jim Miller6b857682011-02-16 16:27:41 -0800920 * Get the password expiration timeout for the given admin. The expiration timeout is the
921 * recurring expiration timeout provided in the call to
922 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
923 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -0800924 *
925 * @param admin The name of the admin component to check, or null to aggregate all admins.
926 * @return The timeout for the given admin or the minimum of all timeouts
927 */
928 public long getPasswordExpirationTimeout(ComponentName admin) {
929 if (mService != null) {
930 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700931 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800932 } catch (RemoteException e) {
933 Log.w(TAG, "Failed talking with device policy service", e);
934 }
935 }
936 return 0;
937 }
938
939 /**
940 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +0100941 * all admins of this user and its profiles if admin is null. If the password is
942 * expired, this will return the time since the password expired as a negative number.
943 * If admin is null, then a composite of all expiration timeouts is returned
944 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -0800945 *
946 * @param admin The name of the admin component to check, or null to aggregate all admins.
947 * @return The password expiration time, in ms.
948 */
949 public long getPasswordExpiration(ComponentName admin) {
950 if (mService != null) {
951 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700952 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800953 } catch (RemoteException e) {
954 Log.w(TAG, "Failed talking with device policy service", e);
955 }
956 }
957 return 0;
958 }
959
960 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100961 * Retrieve the current password history length for all admins of this
962 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700963 * @param admin The name of the admin component to check, or null to aggregate
964 * all admins.
965 * @return The length of the password history
966 */
967 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700968 return getPasswordHistoryLength(admin, UserHandle.myUserId());
969 }
970
971 /** @hide per-user version */
972 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700973 if (mService != null) {
974 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700975 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700976 } catch (RemoteException e) {
977 Log.w(TAG, "Failed talking with device policy service", e);
978 }
979 }
980 return 0;
981 }
982
Dianne Hackbornd6847842010-01-12 18:14:19 -0800983 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800984 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800985 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800986 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800987 * @return Returns the maximum length that the user can enter.
988 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800989 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800990 // Kind-of arbitrary.
991 return 16;
992 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700993
Dianne Hackborn254cb442010-01-27 19:23:59 -0800994 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800995 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800996 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +0100997 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700998 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800999 * <p>The calling device admin must have requested
1000 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1001 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001002 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001003 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001004 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001005 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001006 if (mService != null) {
1007 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001008 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 } catch (RemoteException e) {
1010 Log.w(TAG, "Failed talking with device policy service", e);
1011 }
1012 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001013 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001015
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 /**
1017 * Retrieve the number of times the user has failed at entering a
1018 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001019 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001020 * <p>The calling device admin must have requested
1021 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1022 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001023 */
1024 public int getCurrentFailedPasswordAttempts() {
1025 if (mService != null) {
1026 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001027 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001028 } catch (RemoteException e) {
1029 Log.w(TAG, "Failed talking with device policy service", e);
1030 }
1031 }
1032 return -1;
1033 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001034
1035 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001036 * Setting this to a value greater than zero enables a built-in policy
1037 * that will perform a device wipe after too many incorrect
1038 * device-unlock passwords have been entered. This built-in policy combines
1039 * watching for failed passwords and wiping the device, and requires
1040 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001041 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001042 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001043 * <p>To implement any other policy (e.g. wiping data for a particular
1044 * application only, erasing or revoking credentials, or reporting the
1045 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001046 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001047 * instead. Do not use this API, because if the maximum count is reached,
1048 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001049 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001050 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001051 * @param num The number of failed password attempts at which point the
1052 * device will wipe its data.
1053 */
1054 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1055 if (mService != null) {
1056 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001057 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001058 } catch (RemoteException e) {
1059 Log.w(TAG, "Failed talking with device policy service", e);
1060 }
1061 }
1062 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001063
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001064 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001065 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001066 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001067 * or a particular one.
1068 * @param admin The name of the admin component to check, or null to aggregate
1069 * all admins.
1070 */
1071 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001072 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1073 }
1074
1075 /** @hide per-user version */
1076 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001077 if (mService != null) {
1078 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001079 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001080 } catch (RemoteException e) {
1081 Log.w(TAG, "Failed talking with device policy service", e);
1082 }
1083 }
1084 return 0;
1085 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001086
Dianne Hackborn254cb442010-01-27 19:23:59 -08001087 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001088 * Flag for {@link #resetPassword}: don't allow other admins to change
1089 * the password again until the user has entered it.
1090 */
1091 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001092
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001093 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001094 * Force a new device unlock password (the password needed to access the
1095 * entire device, not for individual accounts) on the user. This takes
1096 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001097 * The given password must be sufficient for the
1098 * current password quality and length constraints as returned by
1099 * {@link #getPasswordQuality(ComponentName)} and
1100 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1101 * these constraints, then it will be rejected and false returned. Note
1102 * that the password may be a stronger quality (containing alphanumeric
1103 * characters when the requested quality is only numeric), in which case
1104 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001105 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001106 * <p>The calling device admin must have requested
1107 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1108 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001109 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001110 * Can not be called from a managed profile.
1111 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001112 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001113 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001114 * @return Returns true if the password was applied, or false if it is
1115 * not acceptable for the current constraints.
1116 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001117 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001118 if (mService != null) {
1119 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001120 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001121 } catch (RemoteException e) {
1122 Log.w(TAG, "Failed talking with device policy service", e);
1123 }
1124 }
1125 return false;
1126 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001127
Dianne Hackbornd6847842010-01-12 18:14:19 -08001128 /**
1129 * Called by an application that is administering the device to set the
1130 * maximum time for user activity until the device will lock. This limits
1131 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001132 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001133 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001134 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001135 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001136 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001138 * @param timeMs The new desired maximum time to lock in milliseconds.
1139 * A value of 0 means there is no restriction.
1140 */
1141 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1142 if (mService != null) {
1143 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001144 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001145 } catch (RemoteException e) {
1146 Log.w(TAG, "Failed talking with device policy service", e);
1147 }
1148 }
1149 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001150
Dianne Hackbornd6847842010-01-12 18:14:19 -08001151 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001152 * Retrieve the current maximum time to unlock for all admins of this user
1153 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001154 * @param admin The name of the admin component to check, or null to aggregate
1155 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001156 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001157 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001158 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1159 }
1160
1161 /** @hide per-user version */
1162 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001163 if (mService != null) {
1164 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001165 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
1170 return 0;
1171 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001172
Dianne Hackbornd6847842010-01-12 18:14:19 -08001173 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001174 * Make the device lock immediately, as if the lock screen timeout has
1175 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001176 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001177 * <p>The calling device admin must have requested
1178 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1179 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001180 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001181 public void lockNow() {
1182 if (mService != null) {
1183 try {
1184 mService.lockNow();
1185 } catch (RemoteException e) {
1186 Log.w(TAG, "Failed talking with device policy service", e);
1187 }
1188 }
1189 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001190
Dianne Hackbornd6847842010-01-12 18:14:19 -08001191 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001192 * Flag for {@link #wipeData(int)}: also erase the device's external
1193 * storage.
1194 */
1195 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1196
1197 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001198 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001199 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001200 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1201 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001202 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001203 * <p>The calling device admin must have requested
1204 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1205 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001206 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001207 * @param flags Bit mask of additional options: currently 0 and
1208 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001209 */
1210 public void wipeData(int flags) {
1211 if (mService != null) {
1212 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001213 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001214 } catch (RemoteException e) {
1215 Log.w(TAG, "Failed talking with device policy service", e);
1216 }
1217 }
1218 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001219
Dianne Hackbornd6847842010-01-12 18:14:19 -08001220 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001221 * Called by an application that is administering the device to set the
1222 * global proxy and exclusion list.
1223 * <p>
1224 * The calling device admin must have requested
1225 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1226 * this method; if it has not, a security exception will be thrown.
1227 * Only the first device admin can set the proxy. If a second admin attempts
1228 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1229 * proxy will be returned. If successful in setting the proxy, null will
1230 * be returned.
1231 * The method can be called repeatedly by the device admin alrady setting the
1232 * proxy to update the proxy and exclusion list.
1233 *
1234 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1235 * with.
1236 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1237 * Pass Proxy.NO_PROXY to reset the proxy.
1238 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001239 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1240 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001241 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001242 */
1243 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1244 List<String> exclusionList ) {
1245 if (proxySpec == null) {
1246 throw new NullPointerException();
1247 }
1248 if (mService != null) {
1249 try {
1250 String hostSpec;
1251 String exclSpec;
1252 if (proxySpec.equals(Proxy.NO_PROXY)) {
1253 hostSpec = null;
1254 exclSpec = null;
1255 } else {
1256 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1257 throw new IllegalArgumentException();
1258 }
1259 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1260 String hostName = sa.getHostName();
1261 int port = sa.getPort();
1262 StringBuilder hostBuilder = new StringBuilder();
1263 hostSpec = hostBuilder.append(hostName)
1264 .append(":").append(Integer.toString(port)).toString();
1265 if (exclusionList == null) {
1266 exclSpec = "";
1267 } else {
1268 StringBuilder listBuilder = new StringBuilder();
1269 boolean firstDomain = true;
1270 for (String exclDomain : exclusionList) {
1271 if (!firstDomain) {
1272 listBuilder = listBuilder.append(",");
1273 } else {
1274 firstDomain = false;
1275 }
1276 listBuilder = listBuilder.append(exclDomain.trim());
1277 }
1278 exclSpec = listBuilder.toString();
1279 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001280 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1281 != android.net.Proxy.PROXY_VALID)
1282 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001283 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001284 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001285 } catch (RemoteException e) {
1286 Log.w(TAG, "Failed talking with device policy service", e);
1287 }
1288 }
1289 return null;
1290 }
1291
1292 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001293 * Set a network-independent global HTTP proxy. This is not normally what you want
1294 * for typical HTTP proxies - they are generally network dependent. However if you're
1295 * doing something unusual like general internal filtering this may be useful. On
1296 * a private network where the proxy is not accessible, you may break HTTP using this.
1297 *
1298 * <p>This method requires the caller to be the device owner.
1299 *
1300 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1301 * @see ProxyInfo
1302 *
1303 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1304 * with.
1305 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1306 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1307 */
1308 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1309 if (mService != null) {
1310 try {
1311 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1312 } catch (RemoteException e) {
1313 Log.w(TAG, "Failed talking with device policy service", e);
1314 }
1315 }
1316 }
1317
1318 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001319 * Returns the component name setting the global proxy.
1320 * @return ComponentName object of the device admin that set the global proxy, or
1321 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001322 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001323 */
1324 public ComponentName getGlobalProxyAdmin() {
1325 if (mService != null) {
1326 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001327 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001328 } catch (RemoteException e) {
1329 Log.w(TAG, "Failed talking with device policy service", e);
1330 }
1331 }
1332 return null;
1333 }
1334
1335 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001336 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001337 * indicating that encryption is not supported.
1338 */
1339 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1340
1341 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001342 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001343 * indicating that encryption is supported, but is not currently active.
1344 */
1345 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1346
1347 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001348 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001349 * indicating that encryption is not currently active, but is currently
1350 * being activated. This is only reported by devices that support
1351 * encryption of data and only when the storage is currently
1352 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1353 * to become encrypted will never return this value.
1354 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001355 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001356
1357 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001358 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001359 * indicating that encryption is active.
1360 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001361 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001362
1363 /**
1364 * Activity action: begin the process of encrypting data on the device. This activity should
1365 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1366 * After resuming from this activity, use {@link #getStorageEncryption}
1367 * to check encryption status. However, on some devices this activity may never return, as
1368 * it may trigger a reboot and in some cases a complete data wipe of the device.
1369 */
1370 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1371 public static final String ACTION_START_ENCRYPTION
1372 = "android.app.action.START_ENCRYPTION";
1373
1374 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001375 * Widgets are enabled in keyguard
1376 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001377 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001378
1379 /**
Jim Miller50e62182014-04-23 17:25:00 -07001380 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001381 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001382 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1383
1384 /**
1385 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1386 */
1387 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1388
1389 /**
Jim Miller50e62182014-04-23 17:25:00 -07001390 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1391 */
1392 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1393
1394 /**
1395 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1396 */
1397 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1398
1399 /**
1400 * Ignore {@link TrustAgentService} state on secure keyguard screens
1401 * (e.g. PIN/Pattern/Password).
1402 */
1403 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1404
1405 /**
Jim Miller35207742012-11-02 15:33:20 -07001406 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001407 */
1408 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001409
1410 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001411 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001412 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001413 *
1414 * <p>When multiple device administrators attempt to control device
1415 * encryption, the most secure, supported setting will always be
1416 * used. If any device administrator requests device encryption,
1417 * it will be enabled; Conversely, if a device administrator
1418 * attempts to disable device encryption while another
1419 * device administrator has enabled it, the call to disable will
1420 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1421 *
1422 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001423 * written to other storage areas may or may not be encrypted, and this policy does not require
1424 * or control the encryption of any other storage areas.
1425 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1426 * {@code true}, then the directory returned by
1427 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1428 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001429 *
1430 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1431 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1432 * the encryption key may not be fully secured. For maximum security, the administrator should
1433 * also require (and check for) a pattern, PIN, or password.
1434 *
1435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1436 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001437 * @return the new request status (for all active admins) - will be one of
1438 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1439 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1440 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001441 */
1442 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1443 if (mService != null) {
1444 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001445 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001446 } catch (RemoteException e) {
1447 Log.w(TAG, "Failed talking with device policy service", e);
1448 }
1449 }
1450 return ENCRYPTION_STATUS_UNSUPPORTED;
1451 }
1452
1453 /**
1454 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001455 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001456 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001457 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1458 * this will return the requested encryption setting as an aggregate of all active
1459 * administrators.
1460 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001461 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001462 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001463 if (mService != null) {
1464 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001465 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001466 } catch (RemoteException e) {
1467 Log.w(TAG, "Failed talking with device policy service", e);
1468 }
1469 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001470 return false;
1471 }
1472
1473 /**
1474 * Called by an application that is administering the device to
1475 * determine the current encryption status of the device.
1476 *
1477 * Depending on the returned status code, the caller may proceed in different
1478 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1479 * storage system does not support encryption. If the
1480 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1481 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1482 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1483 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1484 *
1485 * @return current status of encryption. The value will be one of
1486 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1487 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1488 */
1489 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001490 return getStorageEncryptionStatus(UserHandle.myUserId());
1491 }
1492
1493 /** @hide per-user version */
1494 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001495 if (mService != null) {
1496 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001497 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001498 } catch (RemoteException e) {
1499 Log.w(TAG, "Failed talking with device policy service", e);
1500 }
1501 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001502 return ENCRYPTION_STATUS_UNSUPPORTED;
1503 }
1504
1505 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001506 * Installs the given certificate as a User CA.
1507 *
1508 * @return false if the certBuffer cannot be parsed or installation is
1509 * interrupted, otherwise true
1510 * @hide
1511 */
1512 public boolean installCaCert(byte[] certBuffer) {
1513 if (mService != null) {
1514 try {
1515 return mService.installCaCert(certBuffer);
1516 } catch (RemoteException e) {
1517 Log.w(TAG, "Failed talking with device policy service", e);
1518 }
1519 }
1520 return false;
1521 }
1522
1523 /**
1524 * Uninstalls the given certificate from the list of User CAs, if present.
1525 *
1526 * @hide
1527 */
1528 public void uninstallCaCert(byte[] certBuffer) {
1529 if (mService != null) {
1530 try {
1531 mService.uninstallCaCert(certBuffer);
1532 } catch (RemoteException e) {
1533 Log.w(TAG, "Failed talking with device policy service", e);
1534 }
1535 }
1536 }
1537
1538 /**
1539 * Returns whether there are any user-installed CA certificates.
1540 *
1541 * @hide
1542 */
Maggie Benthall0469f412013-09-05 15:30:26 -04001543 public static boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001544 TrustedCertificateStore certStore = new TrustedCertificateStore();
1545 Set<String> aliases = certStore.userAliases();
1546 return aliases != null && !aliases.isEmpty();
1547 }
1548
1549 /**
1550 * Returns whether this certificate has been installed as a User CA.
1551 *
1552 * @hide
1553 */
1554 public boolean hasCaCertInstalled(byte[] certBuffer) {
1555 TrustedCertificateStore certStore = new TrustedCertificateStore();
1556 String alias;
1557 byte[] pemCert;
1558 try {
1559 CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1560 X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1561 new ByteArrayInputStream(certBuffer));
1562 return certStore.getCertificateAlias(cert) != null;
1563 } catch (CertificateException ce) {
1564 Log.w(TAG, "Could not parse certificate", ce);
1565 }
1566 return false;
1567 }
1568
1569 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001570 * Called by an application that is administering the device to disable all cameras
1571 * on the device. After setting this, no applications will be able to access any cameras
1572 * on the device.
1573 *
1574 * <p>The calling device admin must have requested
1575 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1576 * this method; if it has not, a security exception will be thrown.
1577 *
1578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1579 * @param disabled Whether or not the camera should be disabled.
1580 */
1581 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1582 if (mService != null) {
1583 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001584 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001585 } catch (RemoteException e) {
1586 Log.w(TAG, "Failed talking with device policy service", e);
1587 }
1588 }
1589 }
1590
1591 /**
1592 * Determine whether or not the device's cameras have been disabled either by the current
1593 * admin, if specified, or all admins.
1594 * @param admin The name of the admin component to check, or null to check if any admins
1595 * have disabled the camera
1596 */
1597 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001598 return getCameraDisabled(admin, UserHandle.myUserId());
1599 }
1600
1601 /** @hide per-user version */
1602 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001603 if (mService != null) {
1604 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001605 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001606 } catch (RemoteException e) {
1607 Log.w(TAG, "Failed talking with device policy service", e);
1608 }
1609 }
1610 return false;
1611 }
1612
1613 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001614 * Called by an application that is administering the device to disable keyguard customizations,
1615 * such as widgets. After setting this, keyguard features will be disabled according to the
1616 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001617 *
1618 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001619 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001620 * this method; if it has not, a security exception will be thrown.
1621 *
1622 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001623 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1624 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001625 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1626 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001627 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001628 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001629 if (mService != null) {
1630 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001631 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001632 } catch (RemoteException e) {
1633 Log.w(TAG, "Failed talking with device policy service", e);
1634 }
1635 }
1636 }
1637
1638 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001639 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001640 * admin, if specified, or all admins.
1641 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001642 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001643 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1644 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001645 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001646 public int getKeyguardDisabledFeatures(ComponentName admin) {
1647 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001648 }
1649
1650 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001651 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001652 if (mService != null) {
1653 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001654 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001655 } catch (RemoteException e) {
1656 Log.w(TAG, "Failed talking with device policy service", e);
1657 }
1658 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001659 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001660 }
1661
1662 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001663 * @hide
1664 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001665 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001666 if (mService != null) {
1667 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001668 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001669 } catch (RemoteException e) {
1670 Log.w(TAG, "Failed talking with device policy service", e);
1671 }
1672 }
1673 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001674
Dianne Hackbornd6847842010-01-12 18:14:19 -08001675 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001676 * @hide
1677 */
1678 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1679 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1680 }
1681
1682 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001683 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001684 * @hide
1685 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001686 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001687 ActivityInfo ai;
1688 try {
1689 ai = mContext.getPackageManager().getReceiverInfo(cn,
1690 PackageManager.GET_META_DATA);
1691 } catch (PackageManager.NameNotFoundException e) {
1692 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1693 return null;
1694 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001695
Dianne Hackbornd6847842010-01-12 18:14:19 -08001696 ResolveInfo ri = new ResolveInfo();
1697 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001698
Dianne Hackbornd6847842010-01-12 18:14:19 -08001699 try {
1700 return new DeviceAdminInfo(mContext, ri);
1701 } catch (XmlPullParserException e) {
1702 Log.w(TAG, "Unable to parse device policy " + cn, e);
1703 return null;
1704 } catch (IOException e) {
1705 Log.w(TAG, "Unable to parse device policy " + cn, e);
1706 return null;
1707 }
1708 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001709
Dianne Hackbornd6847842010-01-12 18:14:19 -08001710 /**
1711 * @hide
1712 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001713 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1714 if (mService != null) {
1715 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001716 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001717 } catch (RemoteException e) {
1718 Log.w(TAG, "Failed talking with device policy service", e);
1719 }
1720 }
1721 }
1722
1723 /**
1724 * @hide
1725 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001726 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001727 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001728 if (mService != null) {
1729 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001730 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001731 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001732 } catch (RemoteException e) {
1733 Log.w(TAG, "Failed talking with device policy service", e);
1734 }
1735 }
1736 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001737
Dianne Hackbornd6847842010-01-12 18:14:19 -08001738 /**
1739 * @hide
1740 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001741 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001742 if (mService != null) {
1743 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001744 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001745 } catch (RemoteException e) {
1746 Log.w(TAG, "Failed talking with device policy service", e);
1747 }
1748 }
1749 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001750
Dianne Hackbornd6847842010-01-12 18:14:19 -08001751 /**
1752 * @hide
1753 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001754 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001755 if (mService != null) {
1756 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001757 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001758 } catch (RemoteException e) {
1759 Log.w(TAG, "Failed talking with device policy service", e);
1760 }
1761 }
1762 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001763
1764 /**
1765 * @hide
1766 * Sets the given package as the device owner. The package must already be installed and there
1767 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1768 * method must be called before the device is provisioned.
1769 * @param packageName the package name of the application to be registered as the device owner.
1770 * @return whether the package was successfully registered as the device owner.
1771 * @throws IllegalArgumentException if the package name is null or invalid
1772 * @throws IllegalStateException if a device owner is already registered or the device has
1773 * already been provisioned.
1774 */
1775 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1776 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001777 return setDeviceOwner(packageName, null);
1778 }
1779
1780 /**
1781 * @hide
1782 * Sets the given package as the device owner. The package must already be installed and there
1783 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1784 * method must be called before the device is provisioned.
1785 * @param packageName the package name of the application to be registered as the device owner.
1786 * @param ownerName the human readable name of the institution that owns this device.
1787 * @return whether the package was successfully registered as the device owner.
1788 * @throws IllegalArgumentException if the package name is null or invalid
1789 * @throws IllegalStateException if a device owner is already registered or the device has
1790 * already been provisioned.
1791 */
1792 public boolean setDeviceOwner(String packageName, String ownerName)
1793 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001794 if (mService != null) {
1795 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001796 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001797 } catch (RemoteException re) {
1798 Log.w(TAG, "Failed to set device owner");
1799 }
1800 }
1801 return false;
1802 }
1803
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001804
Amith Yamasani71e6c692013-03-24 17:39:28 -07001805 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001806 * Used to determine if a particular package has been registered as a Device Owner app.
1807 * A device owner app is a special device admin that cannot be deactivated by the user, once
1808 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1809 * package is currently registered as the device owner app, pass in the package name from
1810 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1811 * admin apps that want to check if they are also registered as the device owner app. The
1812 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1813 * the setup process.
1814 * @param packageName the package name of the app, to compare with the registered device owner
1815 * app, if any.
1816 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001817 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001818 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001819 if (mService != null) {
1820 try {
1821 return mService.isDeviceOwner(packageName);
1822 } catch (RemoteException re) {
1823 Log.w(TAG, "Failed to check device owner");
1824 }
1825 }
1826 return false;
1827 }
1828
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001829 /**
1830 * @hide
1831 * Redirect to isDeviceOwnerApp.
1832 */
1833 public boolean isDeviceOwner(String packageName) {
1834 return isDeviceOwnerApp(packageName);
1835 }
1836
Jason Monkb0dced82014-06-06 14:36:20 -04001837 /**
1838 * Clears the current device owner. The caller must be the device owner.
1839 *
1840 * This function should be used cautiously as once it is called it cannot
1841 * be undone. The device owner can only be set as a part of device setup
1842 * before setup completes.
1843 */
1844 public void clearDeviceOwnerApp() {
1845 if (mService != null) {
1846 try {
1847 mService.clearDeviceOwner(mContext.getPackageName());
1848 } catch (RemoteException re) {
1849 Log.w(TAG, "Failed to clear device owner");
1850 }
1851 }
1852 }
1853
Amith Yamasani71e6c692013-03-24 17:39:28 -07001854 /** @hide */
1855 public String getDeviceOwner() {
1856 if (mService != null) {
1857 try {
1858 return mService.getDeviceOwner();
1859 } catch (RemoteException re) {
1860 Log.w(TAG, "Failed to get device owner");
1861 }
1862 }
1863 return null;
1864 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001865
1866 /** @hide */
1867 public String getDeviceOwnerName() {
1868 if (mService != null) {
1869 try {
1870 return mService.getDeviceOwnerName();
1871 } catch (RemoteException re) {
1872 Log.w(TAG, "Failed to get device owner");
1873 }
1874 }
1875 return null;
1876 }
Adam Connors776c5552014-01-09 10:42:56 +00001877
1878 /**
1879 * @hide
1880 * Sets the given package as the profile owner of the given user profile. The package must
1881 * already be installed and there shouldn't be an existing profile owner registered for this
1882 * user. Also, this method must be called before the user has been used for the first time.
1883 * @param packageName the package name of the application to be registered as profile owner.
1884 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00001885 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00001886 * @return whether the package was successfully registered as the profile owner.
1887 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
1888 * the user has already been set up.
1889 */
Adam Connors661ec472014-02-11 13:59:46 +00001890 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00001891 throws IllegalArgumentException {
1892 if (mService != null) {
1893 try {
Adam Connors661ec472014-02-11 13:59:46 +00001894 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00001895 } catch (RemoteException re) {
1896 Log.w(TAG, "Failed to set profile owner", re);
1897 throw new IllegalArgumentException("Couldn't set profile owner.", re);
1898 }
1899 }
1900 return false;
1901 }
1902
1903 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001904 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
1905 * be used. Only the profile owner can call this.
1906 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001907 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001908 *
1909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1910 */
1911 public void setProfileEnabled(ComponentName admin) {
1912 if (mService != null) {
1913 try {
1914 mService.setProfileEnabled(admin);
1915 } catch (RemoteException e) {
1916 Log.w(TAG, "Failed talking with device policy service", e);
1917 }
1918 }
1919 }
1920
1921 /**
Adam Connors776c5552014-01-09 10:42:56 +00001922 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001923 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00001924 * within the managed profile.
1925 *
1926 * @param packageName The package name of the app to compare with the registered profile owner.
1927 * @return Whether or not the package is registered as the profile owner.
1928 */
1929 public boolean isProfileOwnerApp(String packageName) {
1930 if (mService != null) {
1931 try {
1932 String profileOwnerPackage = mService.getProfileOwner(
1933 Process.myUserHandle().getIdentifier());
1934 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
1935 } catch (RemoteException re) {
1936 Log.w(TAG, "Failed to check profile owner");
1937 }
1938 }
1939 return false;
1940 }
1941
1942 /**
1943 * @hide
1944 * @return the packageName of the owner of the given user profile or null if no profile
1945 * owner has been set for that user.
1946 * @throws IllegalArgumentException if the userId is invalid.
1947 */
1948 public String getProfileOwner() throws IllegalArgumentException {
1949 if (mService != null) {
1950 try {
1951 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
1952 } catch (RemoteException re) {
1953 Log.w(TAG, "Failed to get profile owner");
1954 throw new IllegalArgumentException(
1955 "Requested profile owner for invalid userId", re);
1956 }
1957 }
1958 return null;
1959 }
1960
1961 /**
1962 * @hide
1963 * @return the human readable name of the organisation associated with this DPM or null if
1964 * one is not set.
1965 * @throws IllegalArgumentException if the userId is invalid.
1966 */
1967 public String getProfileOwnerName() throws IllegalArgumentException {
1968 if (mService != null) {
1969 try {
1970 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
1971 } catch (RemoteException re) {
1972 Log.w(TAG, "Failed to get profile owner");
1973 throw new IllegalArgumentException(
1974 "Requested profile owner for invalid userId", re);
1975 }
1976 }
1977 return null;
1978 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001979
1980 /**
1981 * Called by a profile owner or device owner to add a default intent handler activity for
1982 * intents that match a certain intent filter. This activity will remain the default intent
1983 * handler even if the set of potential event handlers for the intent filter changes and if
1984 * the intent preferences are reset.
1985 *
1986 * <p>The default disambiguation mechanism takes over if the activity is not installed
1987 * (anymore). When the activity is (re)installed, it is automatically reset as default
1988 * intent handler for the filter.
1989 *
1990 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
1991 * security exception will be thrown.
1992 *
1993 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1994 * @param filter The IntentFilter for which a default handler is added.
1995 * @param activity The Activity that is added as default intent handler.
1996 */
1997 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
1998 ComponentName activity) {
1999 if (mService != null) {
2000 try {
2001 mService.addPersistentPreferredActivity(admin, filter, activity);
2002 } catch (RemoteException e) {
2003 Log.w(TAG, "Failed talking with device policy service", e);
2004 }
2005 }
2006 }
2007
2008 /**
2009 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002010 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002011 *
2012 * <p>The calling device admin must be a profile owner. If it is not, a security
2013 * exception will be thrown.
2014 *
2015 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2016 * @param packageName The name of the package for which preferences are removed.
2017 */
2018 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2019 String packageName) {
2020 if (mService != null) {
2021 try {
2022 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2023 } catch (RemoteException e) {
2024 Log.w(TAG, "Failed talking with device policy service", e);
2025 }
2026 }
2027 }
Robin Lee66e5d962014-04-09 16:44:21 +01002028
2029 /**
2030 * Called by a profile or device owner to set the application restrictions for a given target
2031 * application running in the managed profile.
2032 *
2033 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
2034 * {@link Boolean}, {@link String}, or {@link String}[]. The recommended format for key strings
2035 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2036 * components such as {@link android.webkit.WebView}.
2037 *
2038 * <p>The application restrictions are only made visible to the target application and the
2039 * profile or device owner.
2040 *
2041 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2042 * exception will be thrown.
2043 *
2044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2045 * @param packageName The name of the package to update restricted settings for.
2046 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2047 * set of active restrictions.
2048 */
2049 public void setApplicationRestrictions(ComponentName admin, String packageName,
2050 Bundle settings) {
2051 if (mService != null) {
2052 try {
2053 mService.setApplicationRestrictions(admin, packageName, settings);
2054 } catch (RemoteException e) {
2055 Log.w(TAG, "Failed talking with device policy service", e);
2056 }
2057 }
2058 }
2059
2060 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002061 * Called by the profile owner so that some intents sent in the managed profile can also be
2062 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002064 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2065 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002066 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2067 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002068 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002069 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002070 if (mService != null) {
2071 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002072 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002073 } catch (RemoteException e) {
2074 Log.w(TAG, "Failed talking with device policy service", e);
2075 }
2076 }
2077 }
2078
2079 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002080 * Called by a profile owner to remove the cross-profile intent filters from the managed profile
2081 * and from the parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002082 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2083 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002084 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002085 if (mService != null) {
2086 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002087 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002088 } catch (RemoteException e) {
2089 Log.w(TAG, "Failed talking with device policy service", e);
2090 }
2091 }
2092 }
2093
2094 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002095 * Called by a device owner to create a user with the specified name. The UserHandle returned
2096 * by this method should not be persisted as user handles are recycled as users are removed and
2097 * created. If you need to persist an identifier for this user, use
2098 * {@link UserManager#getSerialNumberForUser}.
2099 *
2100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2101 * @param name the user's name
2102 * @see UserHandle
2103 * @return the UserHandle object for the created user, or null if the user could not be created.
2104 */
2105 public UserHandle createUser(ComponentName admin, String name) {
2106 try {
2107 return mService.createUser(admin, name);
2108 } catch (RemoteException re) {
2109 Log.w(TAG, "Could not create a user", re);
2110 }
2111 return null;
2112 }
2113
2114 /**
Jason Monk03978a42014-06-10 15:05:30 -04002115 * Called by a device owner to create a user with the specified name. The UserHandle returned
2116 * by this method should not be persisted as user handles are recycled as users are removed and
2117 * created. If you need to persist an identifier for this user, use
2118 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2119 * immediately.
2120 *
2121 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2122 * as registered as an active admin on the new user. The profile owner package will be
2123 * installed on the new user if it already is installed on the device.
2124 *
2125 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2126 * profileOwnerComponent when onEnable is called.
2127 *
2128 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2129 * @param name the user's name
2130 * @param ownerName the human readable name of the organisation associated with this DPM.
2131 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2132 * the user.
2133 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2134 * on the new user.
2135 * @see UserHandle
2136 * @return the UserHandle object for the created user, or null if the user could not be created.
2137 */
2138 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2139 ComponentName profileOwnerComponent, Bundle adminExtras) {
2140 try {
2141 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2142 adminExtras);
2143 } catch (RemoteException re) {
2144 Log.w(TAG, "Could not create a user", re);
2145 }
2146 return null;
2147 }
2148
2149 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002150 * Called by a device owner to remove a user and all associated data. The primary user can
2151 * not be removed.
2152 *
2153 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2154 * @param userHandle the user to remove.
2155 * @return {@code true} if the user was removed, {@code false} otherwise.
2156 */
2157 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2158 try {
2159 return mService.removeUser(admin, userHandle);
2160 } catch (RemoteException re) {
2161 Log.w(TAG, "Could not remove user ", re);
2162 return false;
2163 }
2164 }
2165
2166 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002167 * Called by a profile or device owner to get the application restrictions for a given target
2168 * application running in the managed profile.
2169 *
2170 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2171 * exception will be thrown.
2172 *
2173 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2174 * @param packageName The name of the package to fetch restricted settings of.
2175 * @return {@link Bundle} of settings corresponding to what was set last time
2176 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2177 * if no restrictions have been set.
2178 */
2179 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2180 if (mService != null) {
2181 try {
2182 return mService.getApplicationRestrictions(admin, packageName);
2183 } catch (RemoteException e) {
2184 Log.w(TAG, "Failed talking with device policy service", e);
2185 }
2186 }
2187 return null;
2188 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002189
2190 /**
2191 * Called by a profile or device owner to set a user restriction specified
2192 * by the key.
2193 * <p>
2194 * The calling device admin must be a profile or device owner; if it is not,
2195 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002196 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002197 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2198 * with.
2199 * @param key The key of the restriction. See the constants in
2200 * {@link android.os.UserManager} for the list of keys.
2201 */
2202 public void addUserRestriction(ComponentName admin, String key) {
2203 if (mService != null) {
2204 try {
2205 mService.setUserRestriction(admin, key, true);
2206 } catch (RemoteException e) {
2207 Log.w(TAG, "Failed talking with device policy service", e);
2208 }
2209 }
2210 }
2211
2212 /**
2213 * Called by a profile or device owner to clear a user restriction specified
2214 * by the key.
2215 * <p>
2216 * The calling device admin must be a profile or device owner; if it is not,
2217 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002218 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002219 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2220 * with.
2221 * @param key The key of the restriction. See the constants in
2222 * {@link android.os.UserManager} for the list of keys.
2223 */
2224 public void clearUserRestriction(ComponentName admin, String key) {
2225 if (mService != null) {
2226 try {
2227 mService.setUserRestriction(admin, key, false);
2228 } catch (RemoteException e) {
2229 Log.w(TAG, "Failed talking with device policy service", e);
2230 }
2231 }
2232 }
Adam Connors010cfd42014-04-16 12:48:13 +01002233
2234 /**
Julia Reynolds966881e2014-05-14 12:23:08 -04002235 * Called by device or profile owner to block or unblock packages. When a package is blocked it
2236 * is unavailable for use, but the data and actual package file remain.
2237 *
2238 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2239 * @param packageName The name of the package to block or unblock.
2240 * @param blocked {@code true} if the package should be blocked, {@code false} if it should be
2241 * unblocked.
2242 * @return boolean Whether the blocked setting of the package was successfully updated.
2243 */
2244 public boolean setApplicationBlocked(ComponentName admin, String packageName,
2245 boolean blocked) {
2246 if (mService != null) {
2247 try {
2248 return mService.setApplicationBlocked(admin, packageName, blocked);
2249 } catch (RemoteException e) {
2250 Log.w(TAG, "Failed talking with device policy service", e);
2251 }
2252 }
2253 return false;
2254 }
2255
2256 /**
2257 * Called by profile or device owner to block or unblock currently installed packages. This
2258 * should only be called by a profile or device owner running within a managed profile.
2259 *
2260 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2261 * @param intent An intent matching the app(s) to be updated. All apps that resolve for this
2262 * intent will be updated in the current profile.
2263 * @param blocked {@code true} if the packages should be blocked, {@code false} if they should
2264 * be unblocked.
2265 * @return int The number of activities that matched the intent and were updated.
2266 */
2267 public int setApplicationsBlocked(ComponentName admin, Intent intent, boolean blocked) {
2268 if (mService != null) {
2269 try {
2270 return mService.setApplicationsBlocked(admin, intent, blocked);
2271 } catch (RemoteException e) {
2272 Log.w(TAG, "Failed talking with device policy service", e);
2273 }
2274 }
2275 return 0;
2276 }
2277
2278 /**
2279 * Called by device or profile owner to determine if a package is blocked.
2280 *
2281 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2282 * @param packageName The name of the package to retrieve the blocked status of.
2283 * @return boolean {@code true} if the package is blocked, {@code false} otherwise.
2284 */
2285 public boolean isApplicationBlocked(ComponentName admin, String packageName) {
2286 if (mService != null) {
2287 try {
2288 return mService.isApplicationBlocked(admin, packageName);
2289 } catch (RemoteException e) {
2290 Log.w(TAG, "Failed talking with device policy service", e);
2291 }
2292 }
2293 return false;
2294 }
2295
2296 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01002297 * Called by a profile owner to disable account management for a specific type of account.
2298 *
2299 * <p>The calling device admin must be a profile owner. If it is not, a
2300 * security exception will be thrown.
2301 *
2302 * <p>When account management is disabled for an account type, adding or removing an account
2303 * of that type will not be possible.
2304 *
2305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2306 * @param accountType For which account management is disabled or enabled.
2307 * @param disabled The boolean indicating that account management will be disabled (true) or
2308 * enabled (false).
2309 */
2310 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2311 boolean disabled) {
2312 if (mService != null) {
2313 try {
2314 mService.setAccountManagementDisabled(admin, accountType, disabled);
2315 } catch (RemoteException e) {
2316 Log.w(TAG, "Failed talking with device policy service", e);
2317 }
2318 }
2319 }
2320
2321 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002322 * Gets the array of accounts for which account management is disabled by the profile owner.
2323 *
2324 * <p> Account management can be disabled/enabled by calling
2325 * {@link #setAccountManagementDisabled}.
2326 *
2327 * @return a list of account types for which account management has been disabled.
2328 *
2329 * @see #setAccountManagementDisabled
2330 */
2331 public String[] getAccountTypesWithManagementDisabled() {
2332 if (mService != null) {
2333 try {
2334 return mService.getAccountTypesWithManagementDisabled();
2335 } catch (RemoteException e) {
2336 Log.w(TAG, "Failed talking with device policy service", e);
2337 }
2338 }
2339
2340 return null;
2341 }
justinzhang511e0d82014-03-24 16:09:24 -04002342
2343 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002344 * Sets which packages may enter lock task mode.
2345 *
2346 * <p>Any packages that shares uid with an allowed package will also be allowed
2347 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04002348 *
2349 * This function can only be called by the device owner or the profile owner.
Jason Monkd7b86212014-06-16 13:15:38 -04002350 * @param packages The list of packages allowed to enter lock task mode
2351 *
2352 * @see Activity#startLockTask()
justinzhang511e0d82014-03-24 16:09:24 -04002353 */
Jason Monkd7b86212014-06-16 13:15:38 -04002354 public void setLockTaskPackages(String[] packages) throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04002355 if (mService != null) {
2356 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002357 mService.setLockTaskPackages(packages);
justinzhang511e0d82014-03-24 16:09:24 -04002358 } catch (RemoteException e) {
2359 Log.w(TAG, "Failed talking with device policy service", e);
2360 }
2361 }
2362 }
2363
2364 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002365 * This function returns the list of packages allowed to start the lock task mode.
justinzhang511e0d82014-03-24 16:09:24 -04002366 * @hide
2367 */
Jason Monkd7b86212014-06-16 13:15:38 -04002368 public String[] getLockTaskPackages() {
justinzhang511e0d82014-03-24 16:09:24 -04002369 if (mService != null) {
2370 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002371 return mService.getLockTaskPackages();
justinzhang511e0d82014-03-24 16:09:24 -04002372 } catch (RemoteException e) {
2373 Log.w(TAG, "Failed talking with device policy service", e);
2374 }
2375 }
2376 return null;
2377 }
2378
2379 /**
2380 * This function lets the caller know whether the given component is allowed to start the
2381 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04002382 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04002383 */
Jason Monkd7b86212014-06-16 13:15:38 -04002384 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04002385 if (mService != null) {
2386 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002387 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04002388 } catch (RemoteException e) {
2389 Log.w(TAG, "Failed talking with device policy service", e);
2390 }
2391 }
2392 return false;
2393 }
Julia Reynoldsda551652014-05-14 17:15:16 -04002394
2395 /**
2396 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
2397 * of the setting is in the correct form for the setting type should be performed by the caller.
2398 *
2399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2400 * @param setting The name of the setting to update.
2401 * @param value The value to update the setting to.
2402 */
2403 public void setGlobalSetting(ComponentName admin, String setting, String value) {
2404 if (mService != null) {
2405 try {
2406 mService.setGlobalSetting(admin, setting, value);
2407 } catch (RemoteException e) {
2408 Log.w(TAG, "Failed talking with device policy service", e);
2409 }
2410 }
2411 }
2412
2413 /**
2414 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
2415 * that the value of the setting is in the correct form for the setting type should be performed
2416 * by the caller.
2417 *
2418 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2419 * @param setting The name of the setting to update.
2420 * @param value The value to update the setting to.
2421 */
2422 public void setSecureSetting(ComponentName admin, String setting, String value) {
2423 if (mService != null) {
2424 try {
2425 mService.setSecureSetting(admin, setting, value);
2426 } catch (RemoteException e) {
2427 Log.w(TAG, "Failed talking with device policy service", e);
2428 }
2429 }
2430 }
2431
Amith Yamasanif20d6402014-05-24 15:34:37 -07002432 /**
2433 * Designates a specific broadcast receiver component as the provider for
2434 * making permission requests of a local or remote administrator of the user.
2435 * <p/>
2436 * Only a profile owner can designate the restrictions provider.
2437 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2438 * @param receiver The component name of a BroadcastReceiver that handles the
2439 * {@link RestrictionsManager#ACTION_REQUEST_PERMISSION} intent. If this param is null,
2440 * it removes the restrictions provider previously assigned.
2441 */
2442 public void setRestrictionsProvider(ComponentName admin, ComponentName receiver) {
2443 if (mService != null) {
2444 try {
2445 mService.setRestrictionsProvider(admin, receiver);
2446 } catch (RemoteException re) {
2447 Log.w(TAG, "Failed to set permission provider on device policy service");
2448 }
2449 }
2450 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04002451
2452 /**
2453 * Called by profile or device owners to set the master volume mute on or off.
2454 *
2455 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2456 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
2457 */
2458 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
2459 if (mService != null) {
2460 try {
2461 mService.setMasterVolumeMuted(admin, on);
2462 } catch (RemoteException re) {
2463 Log.w(TAG, "Failed to setMasterMute on device policy service");
2464 }
2465 }
2466 }
2467
2468 /**
2469 * Called by profile or device owners to check whether the master volume mute is on or off.
2470 *
2471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2472 * @return {@code true} if master volume is muted, {@code false} if it's not.
2473 */
2474 public boolean isMasterVolumeMuted(ComponentName admin) {
2475 if (mService != null) {
2476 try {
2477 return mService.isMasterVolumeMuted(admin);
2478 } catch (RemoteException re) {
2479 Log.w(TAG, "Failed to get isMasterMute on device policy service");
2480 }
2481 }
2482 return false;
2483 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002484}