blob: b4488cdd2e131b0c6be1b6ac08a68841d46fcca0 [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
19import org.xmlpull.v1.XmlPullParserException;
20
21import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
23import android.content.ComponentName;
24import android.content.Context;
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;
29import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000030import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080031import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080032import android.os.RemoteException;
33import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070034import android.os.UserHandle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080035import android.util.Log;
36
Maggie Benthallda51e682013-08-08 22:35:44 -040037import com.android.org.conscrypt.TrustedCertificateStore;
38
39import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080040import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070041import java.net.InetSocketAddress;
42import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040043import java.security.cert.CertificateException;
44import java.security.cert.CertificateFactory;
45import java.security.cert.X509Certificate;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080046import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040047import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080048
49/**
50 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080051 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080052 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080053 *
54 * <div class="special reference">
55 * <h3>Developer Guides</h3>
56 * <p>For more information about managing policies for device adminstration, read the
57 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
58 * developer guide.</p>
59 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080060 */
61public class DevicePolicyManager {
62 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080063
64 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080065 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070066
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080067 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080068 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080069 mService = IDevicePolicyManager.Stub.asInterface(
70 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
71 }
72
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080073 /** @hide */
74 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080075 DevicePolicyManager me = new DevicePolicyManager(context, handler);
76 return me.mService != null ? me : null;
77 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070078
Dianne Hackbornd6847842010-01-12 18:14:19 -080079 /**
80 * Activity action: ask the user to add a new device administrator to the system.
81 * The desired policy is the ComponentName of the policy in the
82 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
83 * bring the user through adding the device administrator to the system (or
84 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -070085 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080086 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
87 * field to provide the user with additional explanation (in addition
88 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -080089 *
90 * <p>If your administrator is already active, this will ordinarily return immediately (without
91 * user intervention). However, if your administrator has been updated and is requesting
92 * additional uses-policy flags, the user will be presented with the new list. New policies
93 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -080094 */
95 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
96 public static final String ACTION_ADD_DEVICE_ADMIN
97 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -070098
Dianne Hackbornd6847842010-01-12 18:14:19 -080099 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700100 * Activity action: send when any policy admin changes a policy.
101 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700102 *
Jim Miller284b62e2010-06-08 14:27:42 -0700103 * @hide
104 */
105 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
106 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
107
108 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800109 * The ComponentName of the administrator component.
110 *
111 * @see #ACTION_ADD_DEVICE_ADMIN
112 */
113 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700114
Dianne Hackbornd6847842010-01-12 18:14:19 -0800115 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800116 * An optional CharSequence providing additional explanation for why the
117 * admin is being added.
118 *
119 * @see #ACTION_ADD_DEVICE_ADMIN
120 */
121 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700122
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800123 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700124 * Activity action: have the user enter a new password. This activity should
125 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
126 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
127 * enter a new password that meets the current requirements. You can use
128 * {@link #isActivePasswordSufficient()} to determine whether you need to
129 * have the user select a new password in order to meet the current
130 * constraints. Upon being resumed from this activity, you can check the new
131 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800132 */
133 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
134 public static final String ACTION_SET_NEW_PASSWORD
135 = "android.app.action.SET_NEW_PASSWORD";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700136
Dianne Hackbornd6847842010-01-12 18:14:19 -0800137 /**
138 * Return true if the given administrator component is currently
139 * active (enabled) in the system.
140 */
141 public boolean isAdminActive(ComponentName who) {
142 if (mService != null) {
143 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700144 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800145 } catch (RemoteException e) {
146 Log.w(TAG, "Failed talking with device policy service", e);
147 }
148 }
149 return false;
150 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700151
Dianne Hackbornd6847842010-01-12 18:14:19 -0800152 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800153 * Return a list of all currently active device administrator's component
154 * names. Note that if there are no administrators than null may be
155 * returned.
156 */
157 public List<ComponentName> getActiveAdmins() {
158 if (mService != null) {
159 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700160 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800161 } catch (RemoteException e) {
162 Log.w(TAG, "Failed talking with device policy service", e);
163 }
164 }
165 return null;
166 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700167
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800168 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700169 * Used by package administration code to determine if a package can be stopped
170 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800171 * @hide
172 */
173 public boolean packageHasActiveAdmins(String packageName) {
174 if (mService != null) {
175 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700176 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800177 } catch (RemoteException e) {
178 Log.w(TAG, "Failed talking with device policy service", e);
179 }
180 }
181 return false;
182 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700183
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800184 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800185 * Remove a current administration component. This can only be called
186 * by the application that owns the administration component; if you
187 * try to remove someone else's component, a security exception will be
188 * thrown.
189 */
190 public void removeActiveAdmin(ComponentName who) {
191 if (mService != null) {
192 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700193 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800194 } catch (RemoteException e) {
195 Log.w(TAG, "Failed talking with device policy service", e);
196 }
197 }
198 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700199
Dianne Hackbornd6847842010-01-12 18:14:19 -0800200 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800201 * Returns true if an administrator has been granted a particular device policy. This can
202 * be used to check if the administrator was activated under an earlier set of policies,
203 * but requires additional policies after an upgrade.
204 *
205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
206 * an active administrator, or an exception will be thrown.
207 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
208 */
209 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
210 if (mService != null) {
211 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700212 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800213 } catch (RemoteException e) {
214 Log.w(TAG, "Failed talking with device policy service", e);
215 }
216 }
217 return false;
218 }
219
220 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800221 * Constant for {@link #setPasswordQuality}: the policy has no requirements
222 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800223 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800224 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800225 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700226
Dianne Hackbornd6847842010-01-12 18:14:19 -0800227 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700228 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
229 * recognition technology. This implies technologies that can recognize the identity of
230 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
231 * Note that quality constants are ordered so that higher values are more restrictive.
232 */
233 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
234
235 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800236 * Constant for {@link #setPasswordQuality}: the policy requires some kind
237 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800238 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800239 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800240 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700241
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800242 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800243 * Constant for {@link #setPasswordQuality}: the user must have entered a
244 * password containing at least numeric characters. Note that quality
245 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800246 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800247 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700248
Dianne Hackbornd6847842010-01-12 18:14:19 -0800249 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800250 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700251 * password containing at least alphabetic (or other symbol) characters.
252 * Note that quality constants are ordered so that higher values are more
253 * restrictive.
254 */
255 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700256
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700257 /**
258 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800259 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700260 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800261 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800262 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700263 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700264
Dianne Hackbornd6847842010-01-12 18:14:19 -0800265 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700266 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700267 * password containing at least a letter, a numerical digit and a special
268 * symbol, by default. With this password quality, passwords can be
269 * restricted to contain various sets of characters, like at least an
270 * uppercase letter, etc. These are specified using various methods,
271 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
272 * that quality constants are ordered so that higher values are more
273 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700274 */
275 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
276
277 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800278 * Called by an application that is administering the device to set the
279 * password restrictions it is imposing. After setting this, the user
280 * will not be able to enter a new password that is not at least as
281 * restrictive as what has been set. Note that the current password
282 * will remain until the user has set a new one, so the change does not
283 * take place immediately. To prompt the user for a new password, use
284 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700285 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800286 * <p>Quality constants are ordered so that higher values are more restrictive;
287 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800288 * the user's preference, and any other considerations) is the one that
289 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700290 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800291 * <p>The calling device admin must have requested
292 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
293 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700294 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800295 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800296 * @param quality The new desired quality. One of
297 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700298 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700299 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800300 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800301 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800302 if (mService != null) {
303 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700304 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800305 } catch (RemoteException e) {
306 Log.w(TAG, "Failed talking with device policy service", e);
307 }
308 }
309 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700310
Dianne Hackbornd6847842010-01-12 18:14:19 -0800311 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800312 * Retrieve the current minimum password quality for all admins
Dianne Hackborn254cb442010-01-27 19:23:59 -0800313 * or a particular one.
314 * @param admin The name of the admin component to check, or null to aggregate
315 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800316 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800317 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700318 return getPasswordQuality(admin, UserHandle.myUserId());
319 }
320
321 /** @hide per-user version */
322 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800323 if (mService != null) {
324 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700325 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800326 } catch (RemoteException e) {
327 Log.w(TAG, "Failed talking with device policy service", e);
328 }
329 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800330 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800331 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700332
Dianne Hackbornd6847842010-01-12 18:14:19 -0800333 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800334 * Called by an application that is administering the device to set the
335 * minimum allowed password length. After setting this, the user
336 * will not be able to enter a new password that is not at least as
337 * restrictive as what has been set. Note that the current password
338 * will remain until the user has set a new one, so the change does not
339 * take place immediately. To prompt the user for a new password, use
340 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
341 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700342 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
343 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800344 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700345 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800346 * <p>The calling device admin must have requested
347 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
348 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700349 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800351 * @param length The new desired minimum password length. A value of 0
352 * means there is no restriction.
353 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800354 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800355 if (mService != null) {
356 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700357 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800358 } catch (RemoteException e) {
359 Log.w(TAG, "Failed talking with device policy service", e);
360 }
361 }
362 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700363
Dianne Hackbornd6847842010-01-12 18:14:19 -0800364 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800365 * Retrieve the current minimum password length for all admins
366 * or a particular one.
367 * @param admin The name of the admin component to check, or null to aggregate
368 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800369 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800370 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700371 return getPasswordMinimumLength(admin, UserHandle.myUserId());
372 }
373
374 /** @hide per-user version */
375 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800376 if (mService != null) {
377 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700378 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800379 } catch (RemoteException e) {
380 Log.w(TAG, "Failed talking with device policy service", e);
381 }
382 }
383 return 0;
384 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700385
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700386 /**
387 * Called by an application that is administering the device to set the
388 * minimum number of upper case letters required in the password. After
389 * setting this, the user will not be able to enter a new password that is
390 * not at least as restrictive as what has been set. Note that the current
391 * password will remain until the user has set a new one, so the change does
392 * not take place immediately. To prompt the user for a new password, use
393 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
394 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700395 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
396 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700397 * <p>
398 * The calling device admin must have requested
399 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
400 * this method; if it has not, a security exception will be thrown.
401 *
402 * @param admin Which {@link DeviceAdminReceiver} this request is associated
403 * with.
404 * @param length The new desired minimum number of upper case letters
405 * required in the password. A value of 0 means there is no
406 * restriction.
407 */
408 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
409 if (mService != null) {
410 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700411 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700412 } catch (RemoteException e) {
413 Log.w(TAG, "Failed talking with device policy service", e);
414 }
415 }
416 }
417
418 /**
419 * Retrieve the current number of upper case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700420 * password for all admins or a particular one. This is the same value as
421 * set by {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
422 * and only applies when the password quality is
423 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700424 *
425 * @param admin The name of the admin component to check, or null to
426 * aggregate all admins.
427 * @return The minimum number of upper case letters required in the
428 * password.
429 */
430 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700431 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
432 }
433
434 /** @hide per-user version */
435 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700436 if (mService != null) {
437 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700438 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700439 } catch (RemoteException e) {
440 Log.w(TAG, "Failed talking with device policy service", e);
441 }
442 }
443 return 0;
444 }
445
446 /**
447 * Called by an application that is administering the device to set the
448 * minimum number of lower case letters required in the password. After
449 * setting this, the user will not be able to enter a new password that is
450 * not at least as restrictive as what has been set. Note that the current
451 * password will remain until the user has set a new one, so the change does
452 * not 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
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700455 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
456 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700457 * <p>
458 * The calling device admin must have requested
459 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
460 * this method; if it has not, a security exception will be thrown.
461 *
462 * @param admin Which {@link DeviceAdminReceiver} this request is associated
463 * with.
464 * @param length The new desired minimum number of lower case letters
465 * required in the password. A value of 0 means there is no
466 * restriction.
467 */
468 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
469 if (mService != null) {
470 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700471 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700472 } catch (RemoteException e) {
473 Log.w(TAG, "Failed talking with device policy service", e);
474 }
475 }
476 }
477
478 /**
479 * Retrieve the current number of lower case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700480 * password for all admins or a particular one. This is the same value as
481 * set by {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
482 * and only applies when the password quality is
483 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700484 *
485 * @param admin The name of the admin component to check, or null to
486 * aggregate all admins.
487 * @return The minimum number of lower case letters required in the
488 * password.
489 */
490 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700491 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
492 }
493
494 /** @hide per-user version */
495 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700496 if (mService != null) {
497 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700498 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700499 } catch (RemoteException e) {
500 Log.w(TAG, "Failed talking with device policy service", e);
501 }
502 }
503 return 0;
504 }
505
506 /**
507 * Called by an application that is administering the device to set the
508 * minimum number of letters required in the password. After setting this,
509 * the user will not be able to enter a new password that is not at least as
510 * restrictive as what has been set. Note that the current password will
511 * remain until the user has set a new one, so the change does not take
512 * place immediately. To prompt the user for a new password, use
513 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
514 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700515 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
516 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700517 * <p>
518 * The calling device admin must have requested
519 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
520 * this method; if it has not, a security exception will be thrown.
521 *
522 * @param admin Which {@link DeviceAdminReceiver} this request is associated
523 * with.
524 * @param length The new desired minimum number of letters required in the
525 * password. A value of 0 means there is no restriction.
526 */
527 public void setPasswordMinimumLetters(ComponentName admin, int length) {
528 if (mService != null) {
529 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700530 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700531 } catch (RemoteException e) {
532 Log.w(TAG, "Failed talking with device policy service", e);
533 }
534 }
535 }
536
537 /**
538 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700539 * admins or a particular one. This is the same value as
540 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
541 * and only applies when the password quality is
542 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700543 *
544 * @param admin The name of the admin component to check, or null to
545 * aggregate all admins.
546 * @return The minimum number of letters required in the password.
547 */
548 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700549 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
550 }
551
552 /** @hide per-user version */
553 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700554 if (mService != null) {
555 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700556 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700557 } catch (RemoteException e) {
558 Log.w(TAG, "Failed talking with device policy service", e);
559 }
560 }
561 return 0;
562 }
563
564 /**
565 * Called by an application that is administering the device to set the
566 * minimum number of numerical digits required in the password. After
567 * setting this, the user will not be able to enter a new password that is
568 * not at least as restrictive as what has been set. Note that the current
569 * password will remain until the user has set a new one, so the change does
570 * not take place immediately. To prompt the user for a new password, use
571 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
572 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700573 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
574 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700575 * <p>
576 * The calling device admin must have requested
577 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
578 * this method; if it has not, a security exception will be thrown.
579 *
580 * @param admin Which {@link DeviceAdminReceiver} this request is associated
581 * with.
582 * @param length The new desired minimum number of numerical digits required
583 * in the password. A value of 0 means there is no restriction.
584 */
585 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
586 if (mService != null) {
587 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700588 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700589 } catch (RemoteException e) {
590 Log.w(TAG, "Failed talking with device policy service", e);
591 }
592 }
593 }
594
595 /**
596 * Retrieve the current number of numerical digits required in the password
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700597 * for all admins or a particular one. This is the same value as
598 * set by {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
599 * and only applies when the password quality is
600 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700601 *
602 * @param admin The name of the admin component to check, or null to
603 * aggregate all admins.
604 * @return The minimum number of numerical digits required in the password.
605 */
606 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700607 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
608 }
609
610 /** @hide per-user version */
611 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700612 if (mService != null) {
613 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700614 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700615 } catch (RemoteException e) {
616 Log.w(TAG, "Failed talking with device policy service", e);
617 }
618 }
619 return 0;
620 }
621
622 /**
623 * Called by an application that is administering the device to set the
624 * minimum number of symbols required in the password. After setting this,
625 * the user will not be able to enter a new password that is not at least as
626 * restrictive as what has been set. Note that the current password will
627 * remain until the user has set a new one, so the change does not take
628 * place immediately. To prompt the user for a new password, use
629 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
630 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700631 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
632 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700633 * <p>
634 * The calling device admin must have requested
635 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
636 * this method; if it has not, a security exception will be thrown.
637 *
638 * @param admin Which {@link DeviceAdminReceiver} this request is associated
639 * with.
640 * @param length The new desired minimum number of symbols required in the
641 * password. A value of 0 means there is no restriction.
642 */
643 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
644 if (mService != null) {
645 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700646 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700647 } catch (RemoteException e) {
648 Log.w(TAG, "Failed talking with device policy service", e);
649 }
650 }
651 }
652
653 /**
654 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700655 * admins or a particular one. This is the same value as
656 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
657 * and only applies when the password quality is
658 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700659 *
660 * @param admin The name of the admin component to check, or null to
661 * aggregate all admins.
662 * @return The minimum number of symbols required in the password.
663 */
664 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700665 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
666 }
667
668 /** @hide per-user version */
669 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700670 if (mService != null) {
671 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700672 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700673 } catch (RemoteException e) {
674 Log.w(TAG, "Failed talking with device policy service", e);
675 }
676 }
677 return 0;
678 }
679
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700680 /**
681 * Called by an application that is administering the device to set the
682 * minimum number of non-letter characters (numerical digits or symbols)
683 * required in the password. After setting this, the user will not be able
684 * to enter a new password that is not at least as restrictive as what has
685 * been set. Note that the current password will remain until the user has
686 * set a new one, so the change does not take place immediately. To prompt
687 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
688 * setting this value. This constraint is only imposed if the administrator
689 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
690 * {@link #setPasswordQuality}. The default value is 0.
691 * <p>
692 * The calling device admin must have requested
693 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
694 * this method; if it has not, a security exception will be thrown.
695 *
696 * @param admin Which {@link DeviceAdminReceiver} this request is associated
697 * with.
698 * @param length The new desired minimum number of letters required in the
699 * password. A value of 0 means there is no restriction.
700 */
701 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
702 if (mService != null) {
703 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700704 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700705 } catch (RemoteException e) {
706 Log.w(TAG, "Failed talking with device policy service", e);
707 }
708 }
709 }
710
711 /**
712 * Retrieve the current number of non-letter characters required in the
713 * password for all admins or a particular one. This is the same value as
714 * set by {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
715 * and only applies when the password quality is
716 * {@link #PASSWORD_QUALITY_COMPLEX}.
717 *
718 * @param admin The name of the admin component to check, or null to
719 * aggregate all admins.
720 * @return The minimum number of letters required in the password.
721 */
722 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700723 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
724 }
725
726 /** @hide per-user version */
727 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700728 if (mService != null) {
729 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700730 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700731 } catch (RemoteException e) {
732 Log.w(TAG, "Failed talking with device policy service", e);
733 }
734 }
735 return 0;
736 }
737
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700738 /**
739 * Called by an application that is administering the device to set the length
740 * of the password history. After setting this, the user will not be able to
741 * enter a new password that is the same as any password in the history. Note
742 * that the current password will remain until the user has set a new one, so
743 * the change does not take place immediately. To prompt the user for a new
744 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
745 * This constraint is only imposed if the administrator has also requested
746 * either {@link #PASSWORD_QUALITY_NUMERIC},
747 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
748 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
749 *
750 * <p>
751 * The calling device admin must have requested
752 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
753 * method; if it has not, a security exception will be thrown.
754 *
755 * @param admin Which {@link DeviceAdminReceiver} this request is associated
756 * with.
757 * @param length The new desired length of password history. A value of 0
758 * means there is no restriction.
759 */
760 public void setPasswordHistoryLength(ComponentName admin, int length) {
761 if (mService != null) {
762 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700763 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700764 } catch (RemoteException e) {
765 Log.w(TAG, "Failed talking with device policy service", e);
766 }
767 }
768 }
769
770 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800771 * Called by a device admin to set the password expiration timeout. Calling this method
772 * will restart the countdown for password expiration for the given admin, as will changing
773 * the device password (for all admins).
774 *
775 * <p>The provided timeout is the time delta in ms and will be added to the current time.
776 * For example, to have the password expire 5 days from now, timeout would be
777 * 5 * 86400 * 1000 = 432000000 ms for timeout.
778 *
779 * <p>To disable password expiration, a value of 0 may be used for timeout.
780 *
Jim Millera4e28d12010-11-08 16:15:47 -0800781 * <p>The calling device admin must have requested
782 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
783 * method; if it has not, a security exception will be thrown.
784 *
785 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
786 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
787 * means there is no restriction (unlimited).
788 */
789 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
790 if (mService != null) {
791 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700792 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800793 } catch (RemoteException e) {
794 Log.w(TAG, "Failed talking with device policy service", e);
795 }
796 }
797 }
798
799 /**
Jim Miller6b857682011-02-16 16:27:41 -0800800 * Get the password expiration timeout for the given admin. The expiration timeout is the
801 * recurring expiration timeout provided in the call to
802 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
803 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -0800804 *
805 * @param admin The name of the admin component to check, or null to aggregate all admins.
806 * @return The timeout for the given admin or the minimum of all timeouts
807 */
808 public long getPasswordExpirationTimeout(ComponentName admin) {
809 if (mService != null) {
810 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700811 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800812 } catch (RemoteException e) {
813 Log.w(TAG, "Failed talking with device policy service", e);
814 }
815 }
816 return 0;
817 }
818
819 /**
820 * Get the current password expiration time for the given admin or an aggregate of
Jim Miller6b857682011-02-16 16:27:41 -0800821 * all admins if admin is null. If the password is expired, this will return the time since
822 * the password expired as a negative number. If admin is null, then a composite of all
823 * expiration timeouts is returned - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -0800824 *
825 * @param admin The name of the admin component to check, or null to aggregate all admins.
826 * @return The password expiration time, in ms.
827 */
828 public long getPasswordExpiration(ComponentName admin) {
829 if (mService != null) {
830 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700831 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800832 } catch (RemoteException e) {
833 Log.w(TAG, "Failed talking with device policy service", e);
834 }
835 }
836 return 0;
837 }
838
839 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700840 * Retrieve the current password history length for all admins
841 * or a particular one.
842 * @param admin The name of the admin component to check, or null to aggregate
843 * all admins.
844 * @return The length of the password history
845 */
846 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700847 return getPasswordHistoryLength(admin, UserHandle.myUserId());
848 }
849
850 /** @hide per-user version */
851 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700852 if (mService != null) {
853 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700854 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700855 } catch (RemoteException e) {
856 Log.w(TAG, "Failed talking with device policy service", e);
857 }
858 }
859 return 0;
860 }
861
Dianne Hackbornd6847842010-01-12 18:14:19 -0800862 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800863 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800864 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800865 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800866 * @return Returns the maximum length that the user can enter.
867 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800868 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800869 // Kind-of arbitrary.
870 return 16;
871 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700872
Dianne Hackborn254cb442010-01-27 19:23:59 -0800873 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800874 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800875 * to meet the policy requirements (quality, minimum length) that have been
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800876 * requested.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700877 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800878 * <p>The calling device admin must have requested
879 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
880 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700881 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800882 * @return Returns true if the password meets the current requirements,
883 * else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800884 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800885 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800886 if (mService != null) {
887 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700888 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800889 } catch (RemoteException e) {
890 Log.w(TAG, "Failed talking with device policy service", e);
891 }
892 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800893 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800894 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700895
Dianne Hackbornd6847842010-01-12 18:14:19 -0800896 /**
897 * Retrieve the number of times the user has failed at entering a
898 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700899 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800900 * <p>The calling device admin must have requested
901 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
902 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800903 */
904 public int getCurrentFailedPasswordAttempts() {
905 if (mService != null) {
906 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700907 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800908 } catch (RemoteException e) {
909 Log.w(TAG, "Failed talking with device policy service", e);
910 }
911 }
912 return -1;
913 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800914
915 /**
Andrew Stadler88209d12010-02-08 22:59:36 -0800916 * Setting this to a value greater than zero enables a built-in policy
917 * that will perform a device wipe after too many incorrect
918 * device-unlock passwords have been entered. This built-in policy combines
919 * watching for failed passwords and wiping the device, and requires
920 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800921 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700922 *
Andrew Stadler88209d12010-02-08 22:59:36 -0800923 * <p>To implement any other policy (e.g. wiping data for a particular
924 * application only, erasing or revoking credentials, or reporting the
925 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800926 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -0800927 * instead. Do not use this API, because if the maximum count is reached,
928 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700929 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800931 * @param num The number of failed password attempts at which point the
932 * device will wipe its data.
933 */
934 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
935 if (mService != null) {
936 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700937 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800938 } catch (RemoteException e) {
939 Log.w(TAG, "Failed talking with device policy service", e);
940 }
941 }
942 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700943
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800944 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800945 * Retrieve the current maximum number of login attempts that are allowed
946 * before the device wipes itself, for all admins
947 * or a particular one.
948 * @param admin The name of the admin component to check, or null to aggregate
949 * all admins.
950 */
951 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700952 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
953 }
954
955 /** @hide per-user version */
956 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800957 if (mService != null) {
958 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700959 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -0800960 } catch (RemoteException e) {
961 Log.w(TAG, "Failed talking with device policy service", e);
962 }
963 }
964 return 0;
965 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700966
Dianne Hackborn254cb442010-01-27 19:23:59 -0800967 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800968 * Flag for {@link #resetPassword}: don't allow other admins to change
969 * the password again until the user has entered it.
970 */
971 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700972
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800973 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800974 * Force a new device unlock password (the password needed to access the
975 * entire device, not for individual accounts) on the user. This takes
976 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800977 * The given password must be sufficient for the
978 * current password quality and length constraints as returned by
979 * {@link #getPasswordQuality(ComponentName)} and
980 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
981 * these constraints, then it will be rejected and false returned. Note
982 * that the password may be a stronger quality (containing alphanumeric
983 * characters when the requested quality is only numeric), in which case
984 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700985 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800986 * <p>The calling device admin must have requested
987 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
988 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700989 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800990 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800991 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800992 * @return Returns true if the password was applied, or false if it is
993 * not acceptable for the current constraints.
994 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800995 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800996 if (mService != null) {
997 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700998 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800999 } catch (RemoteException e) {
1000 Log.w(TAG, "Failed talking with device policy service", e);
1001 }
1002 }
1003 return false;
1004 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001005
Dianne Hackbornd6847842010-01-12 18:14:19 -08001006 /**
1007 * Called by an application that is administering the device to set the
1008 * maximum time for user activity until the device will lock. This limits
1009 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001010 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001011 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001012 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001013 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001014 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001015 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 * @param timeMs The new desired maximum time to lock in milliseconds.
1017 * A value of 0 means there is no restriction.
1018 */
1019 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1020 if (mService != null) {
1021 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001022 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001023 } catch (RemoteException e) {
1024 Log.w(TAG, "Failed talking with device policy service", e);
1025 }
1026 }
1027 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001028
Dianne Hackbornd6847842010-01-12 18:14:19 -08001029 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001030 * Retrieve the current maximum time to unlock for all admins
1031 * or a particular one.
1032 * @param admin The name of the admin component to check, or null to aggregate
1033 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001034 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001035 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001036 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1037 }
1038
1039 /** @hide per-user version */
1040 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001041 if (mService != null) {
1042 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001043 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001044 } catch (RemoteException e) {
1045 Log.w(TAG, "Failed talking with device policy service", e);
1046 }
1047 }
1048 return 0;
1049 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001050
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001052 * Make the device lock immediately, as if the lock screen timeout has
1053 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001054 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001055 * <p>The calling device admin must have requested
1056 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1057 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001059 public void lockNow() {
1060 if (mService != null) {
1061 try {
1062 mService.lockNow();
1063 } catch (RemoteException e) {
1064 Log.w(TAG, "Failed talking with device policy service", e);
1065 }
1066 }
1067 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001068
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001070 * Flag for {@link #wipeData(int)}: also erase the device's external
1071 * storage.
1072 */
1073 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1074
1075 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001076 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001077 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001078 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1079 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001080 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001081 * <p>The calling device admin must have requested
1082 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1083 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001084 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001085 * @param flags Bit mask of additional options: currently 0 and
1086 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001087 */
1088 public void wipeData(int flags) {
1089 if (mService != null) {
1090 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001091 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001092 } catch (RemoteException e) {
1093 Log.w(TAG, "Failed talking with device policy service", e);
1094 }
1095 }
1096 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001097
Dianne Hackbornd6847842010-01-12 18:14:19 -08001098 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001099 * Called by an application that is administering the device to set the
1100 * global proxy and exclusion list.
1101 * <p>
1102 * The calling device admin must have requested
1103 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1104 * this method; if it has not, a security exception will be thrown.
1105 * Only the first device admin can set the proxy. If a second admin attempts
1106 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1107 * proxy will be returned. If successful in setting the proxy, null will
1108 * be returned.
1109 * The method can be called repeatedly by the device admin alrady setting the
1110 * proxy to update the proxy and exclusion list.
1111 *
1112 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1113 * with.
1114 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1115 * Pass Proxy.NO_PROXY to reset the proxy.
1116 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001117 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1118 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001119 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001120 */
1121 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1122 List<String> exclusionList ) {
1123 if (proxySpec == null) {
1124 throw new NullPointerException();
1125 }
1126 if (mService != null) {
1127 try {
1128 String hostSpec;
1129 String exclSpec;
1130 if (proxySpec.equals(Proxy.NO_PROXY)) {
1131 hostSpec = null;
1132 exclSpec = null;
1133 } else {
1134 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1135 throw new IllegalArgumentException();
1136 }
1137 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1138 String hostName = sa.getHostName();
1139 int port = sa.getPort();
1140 StringBuilder hostBuilder = new StringBuilder();
1141 hostSpec = hostBuilder.append(hostName)
1142 .append(":").append(Integer.toString(port)).toString();
1143 if (exclusionList == null) {
1144 exclSpec = "";
1145 } else {
1146 StringBuilder listBuilder = new StringBuilder();
1147 boolean firstDomain = true;
1148 for (String exclDomain : exclusionList) {
1149 if (!firstDomain) {
1150 listBuilder = listBuilder.append(",");
1151 } else {
1152 firstDomain = false;
1153 }
1154 listBuilder = listBuilder.append(exclDomain.trim());
1155 }
1156 exclSpec = listBuilder.toString();
1157 }
1158 android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec);
1159 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001160 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001161 } catch (RemoteException e) {
1162 Log.w(TAG, "Failed talking with device policy service", e);
1163 }
1164 }
1165 return null;
1166 }
1167
1168 /**
1169 * Returns the component name setting the global proxy.
1170 * @return ComponentName object of the device admin that set the global proxy, or
1171 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001172 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001173 */
1174 public ComponentName getGlobalProxyAdmin() {
1175 if (mService != null) {
1176 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001177 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001178 } catch (RemoteException e) {
1179 Log.w(TAG, "Failed talking with device policy service", e);
1180 }
1181 }
1182 return null;
1183 }
1184
1185 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001186 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001187 * indicating that encryption is not supported.
1188 */
1189 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1190
1191 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001192 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001193 * indicating that encryption is supported, but is not currently active.
1194 */
1195 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1196
1197 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001198 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001199 * indicating that encryption is not currently active, but is currently
1200 * being activated. This is only reported by devices that support
1201 * encryption of data and only when the storage is currently
1202 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1203 * to become encrypted will never return this value.
1204 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001205 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001206
1207 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001208 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001209 * indicating that encryption is active.
1210 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001211 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001212
1213 /**
1214 * Activity action: begin the process of encrypting data on the device. This activity should
1215 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1216 * After resuming from this activity, use {@link #getStorageEncryption}
1217 * to check encryption status. However, on some devices this activity may never return, as
1218 * it may trigger a reboot and in some cases a complete data wipe of the device.
1219 */
1220 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1221 public static final String ACTION_START_ENCRYPTION
1222 = "android.app.action.START_ENCRYPTION";
1223
1224 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001225 * Widgets are enabled in keyguard
1226 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001227 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001228
1229 /**
1230 * Disable all keyguard widgets
1231 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001232 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1233
1234 /**
1235 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1236 */
1237 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1238
1239 /**
Jim Miller35207742012-11-02 15:33:20 -07001240 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001241 */
1242 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001243
1244 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001245 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001246 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001247 *
1248 * <p>When multiple device administrators attempt to control device
1249 * encryption, the most secure, supported setting will always be
1250 * used. If any device administrator requests device encryption,
1251 * it will be enabled; Conversely, if a device administrator
1252 * attempts to disable device encryption while another
1253 * device administrator has enabled it, the call to disable will
1254 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1255 *
1256 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001257 * written to other storage areas may or may not be encrypted, and this policy does not require
1258 * or control the encryption of any other storage areas.
1259 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1260 * {@code true}, then the directory returned by
1261 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1262 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001263 *
1264 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1265 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1266 * the encryption key may not be fully secured. For maximum security, the administrator should
1267 * also require (and check for) a pattern, PIN, or password.
1268 *
1269 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1270 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001271 * @return the new request status (for all active admins) - will be one of
1272 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1273 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1274 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001275 */
1276 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1277 if (mService != null) {
1278 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001279 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001280 } catch (RemoteException e) {
1281 Log.w(TAG, "Failed talking with device policy service", e);
1282 }
1283 }
1284 return ENCRYPTION_STATUS_UNSUPPORTED;
1285 }
1286
1287 /**
1288 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001289 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001290 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1292 * this will return the requested encryption setting as an aggregate of all active
1293 * administrators.
1294 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001295 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001296 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001297 if (mService != null) {
1298 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001299 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001300 } catch (RemoteException e) {
1301 Log.w(TAG, "Failed talking with device policy service", e);
1302 }
1303 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001304 return false;
1305 }
1306
1307 /**
1308 * Called by an application that is administering the device to
1309 * determine the current encryption status of the device.
1310 *
1311 * Depending on the returned status code, the caller may proceed in different
1312 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1313 * storage system does not support encryption. If the
1314 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1315 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1316 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1317 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1318 *
1319 * @return current status of encryption. The value will be one of
1320 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1321 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1322 */
1323 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001324 return getStorageEncryptionStatus(UserHandle.myUserId());
1325 }
1326
1327 /** @hide per-user version */
1328 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001329 if (mService != null) {
1330 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001331 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001332 } catch (RemoteException e) {
1333 Log.w(TAG, "Failed talking with device policy service", e);
1334 }
1335 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001336 return ENCRYPTION_STATUS_UNSUPPORTED;
1337 }
1338
1339 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001340 * Installs the given certificate as a User CA.
1341 *
1342 * @return false if the certBuffer cannot be parsed or installation is
1343 * interrupted, otherwise true
1344 * @hide
1345 */
1346 public boolean installCaCert(byte[] certBuffer) {
1347 if (mService != null) {
1348 try {
1349 return mService.installCaCert(certBuffer);
1350 } catch (RemoteException e) {
1351 Log.w(TAG, "Failed talking with device policy service", e);
1352 }
1353 }
1354 return false;
1355 }
1356
1357 /**
1358 * Uninstalls the given certificate from the list of User CAs, if present.
1359 *
1360 * @hide
1361 */
1362 public void uninstallCaCert(byte[] certBuffer) {
1363 if (mService != null) {
1364 try {
1365 mService.uninstallCaCert(certBuffer);
1366 } catch (RemoteException e) {
1367 Log.w(TAG, "Failed talking with device policy service", e);
1368 }
1369 }
1370 }
1371
1372 /**
1373 * Returns whether there are any user-installed CA certificates.
1374 *
1375 * @hide
1376 */
Maggie Benthall0469f412013-09-05 15:30:26 -04001377 public static boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001378 TrustedCertificateStore certStore = new TrustedCertificateStore();
1379 Set<String> aliases = certStore.userAliases();
1380 return aliases != null && !aliases.isEmpty();
1381 }
1382
1383 /**
1384 * Returns whether this certificate has been installed as a User CA.
1385 *
1386 * @hide
1387 */
1388 public boolean hasCaCertInstalled(byte[] certBuffer) {
1389 TrustedCertificateStore certStore = new TrustedCertificateStore();
1390 String alias;
1391 byte[] pemCert;
1392 try {
1393 CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1394 X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1395 new ByteArrayInputStream(certBuffer));
1396 return certStore.getCertificateAlias(cert) != null;
1397 } catch (CertificateException ce) {
1398 Log.w(TAG, "Could not parse certificate", ce);
1399 }
1400 return false;
1401 }
1402
1403 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001404 * Called by an application that is administering the device to disable all cameras
1405 * on the device. After setting this, no applications will be able to access any cameras
1406 * on the device.
1407 *
1408 * <p>The calling device admin must have requested
1409 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1410 * this method; if it has not, a security exception will be thrown.
1411 *
1412 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1413 * @param disabled Whether or not the camera should be disabled.
1414 */
1415 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1416 if (mService != null) {
1417 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001418 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001419 } catch (RemoteException e) {
1420 Log.w(TAG, "Failed talking with device policy service", e);
1421 }
1422 }
1423 }
1424
1425 /**
1426 * Determine whether or not the device's cameras have been disabled either by the current
1427 * admin, if specified, or all admins.
1428 * @param admin The name of the admin component to check, or null to check if any admins
1429 * have disabled the camera
1430 */
1431 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001432 return getCameraDisabled(admin, UserHandle.myUserId());
1433 }
1434
1435 /** @hide per-user version */
1436 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001437 if (mService != null) {
1438 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001439 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001440 } catch (RemoteException e) {
1441 Log.w(TAG, "Failed talking with device policy service", e);
1442 }
1443 }
1444 return false;
1445 }
1446
1447 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001448 * Called by an application that is administering the device to disable keyguard customizations,
1449 * such as widgets. After setting this, keyguard features will be disabled according to the
1450 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001451 *
1452 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001453 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001454 * this method; if it has not, a security exception will be thrown.
1455 *
1456 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001457 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1458 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
1459 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001460 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001461 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001462 if (mService != null) {
1463 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001464 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001465 } catch (RemoteException e) {
1466 Log.w(TAG, "Failed talking with device policy service", e);
1467 }
1468 }
1469 }
1470
1471 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001472 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001473 * admin, if specified, or all admins.
1474 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001475 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001476 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1477 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001478 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001479 public int getKeyguardDisabledFeatures(ComponentName admin) {
1480 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001481 }
1482
1483 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001484 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001485 if (mService != null) {
1486 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001487 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001488 } catch (RemoteException e) {
1489 Log.w(TAG, "Failed talking with device policy service", e);
1490 }
1491 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001492 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001493 }
1494
1495 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001496 * @hide
1497 */
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001498 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001499 if (mService != null) {
1500 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001501 mService.setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001502 } catch (RemoteException e) {
1503 Log.w(TAG, "Failed talking with device policy service", e);
1504 }
1505 }
1506 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001507
Dianne Hackbornd6847842010-01-12 18:14:19 -08001508 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001509 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001510 * @hide
1511 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001512 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001513 ActivityInfo ai;
1514 try {
1515 ai = mContext.getPackageManager().getReceiverInfo(cn,
1516 PackageManager.GET_META_DATA);
1517 } catch (PackageManager.NameNotFoundException e) {
1518 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1519 return null;
1520 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001521
Dianne Hackbornd6847842010-01-12 18:14:19 -08001522 ResolveInfo ri = new ResolveInfo();
1523 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001524
Dianne Hackbornd6847842010-01-12 18:14:19 -08001525 try {
1526 return new DeviceAdminInfo(mContext, ri);
1527 } catch (XmlPullParserException e) {
1528 Log.w(TAG, "Unable to parse device policy " + cn, e);
1529 return null;
1530 } catch (IOException e) {
1531 Log.w(TAG, "Unable to parse device policy " + cn, e);
1532 return null;
1533 }
1534 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001535
Dianne Hackbornd6847842010-01-12 18:14:19 -08001536 /**
1537 * @hide
1538 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001539 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1540 if (mService != null) {
1541 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001542 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001543 } catch (RemoteException e) {
1544 Log.w(TAG, "Failed talking with device policy service", e);
1545 }
1546 }
1547 }
1548
1549 /**
1550 * @hide
1551 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001552 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001553 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001554 if (mService != null) {
1555 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001556 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001557 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001558 } catch (RemoteException e) {
1559 Log.w(TAG, "Failed talking with device policy service", e);
1560 }
1561 }
1562 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001563
Dianne Hackbornd6847842010-01-12 18:14:19 -08001564 /**
1565 * @hide
1566 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001567 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001568 if (mService != null) {
1569 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001570 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001571 } catch (RemoteException e) {
1572 Log.w(TAG, "Failed talking with device policy service", e);
1573 }
1574 }
1575 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001576
Dianne Hackbornd6847842010-01-12 18:14:19 -08001577 /**
1578 * @hide
1579 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001580 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001581 if (mService != null) {
1582 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001583 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001584 } catch (RemoteException e) {
1585 Log.w(TAG, "Failed talking with device policy service", e);
1586 }
1587 }
1588 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001589
1590 /**
1591 * @hide
1592 * Sets the given package as the device owner. The package must already be installed and there
1593 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1594 * method must be called before the device is provisioned.
1595 * @param packageName the package name of the application to be registered as the device owner.
1596 * @return whether the package was successfully registered as the device owner.
1597 * @throws IllegalArgumentException if the package name is null or invalid
1598 * @throws IllegalStateException if a device owner is already registered or the device has
1599 * already been provisioned.
1600 */
1601 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1602 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001603 return setDeviceOwner(packageName, null);
1604 }
1605
1606 /**
1607 * @hide
1608 * Sets the given package as the device owner. The package must already be installed and there
1609 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1610 * method must be called before the device is provisioned.
1611 * @param packageName the package name of the application to be registered as the device owner.
1612 * @param ownerName the human readable name of the institution that owns this device.
1613 * @return whether the package was successfully registered as the device owner.
1614 * @throws IllegalArgumentException if the package name is null or invalid
1615 * @throws IllegalStateException if a device owner is already registered or the device has
1616 * already been provisioned.
1617 */
1618 public boolean setDeviceOwner(String packageName, String ownerName)
1619 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001620 if (mService != null) {
1621 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001622 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001623 } catch (RemoteException re) {
1624 Log.w(TAG, "Failed to set device owner");
1625 }
1626 }
1627 return false;
1628 }
1629
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001630
Amith Yamasani71e6c692013-03-24 17:39:28 -07001631 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001632 * Used to determine if a particular package has been registered as a Device Owner app.
1633 * A device owner app is a special device admin that cannot be deactivated by the user, once
1634 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1635 * package is currently registered as the device owner app, pass in the package name from
1636 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1637 * admin apps that want to check if they are also registered as the device owner app. The
1638 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1639 * the setup process.
1640 * @param packageName the package name of the app, to compare with the registered device owner
1641 * app, if any.
1642 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001643 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001644 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001645 if (mService != null) {
1646 try {
1647 return mService.isDeviceOwner(packageName);
1648 } catch (RemoteException re) {
1649 Log.w(TAG, "Failed to check device owner");
1650 }
1651 }
1652 return false;
1653 }
1654
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001655 /**
1656 * @hide
1657 * Redirect to isDeviceOwnerApp.
1658 */
1659 public boolean isDeviceOwner(String packageName) {
1660 return isDeviceOwnerApp(packageName);
1661 }
1662
Amith Yamasani71e6c692013-03-24 17:39:28 -07001663 /** @hide */
1664 public String getDeviceOwner() {
1665 if (mService != null) {
1666 try {
1667 return mService.getDeviceOwner();
1668 } catch (RemoteException re) {
1669 Log.w(TAG, "Failed to get device owner");
1670 }
1671 }
1672 return null;
1673 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001674
1675 /** @hide */
1676 public String getDeviceOwnerName() {
1677 if (mService != null) {
1678 try {
1679 return mService.getDeviceOwnerName();
1680 } catch (RemoteException re) {
1681 Log.w(TAG, "Failed to get device owner");
1682 }
1683 }
1684 return null;
1685 }
Adam Connors776c5552014-01-09 10:42:56 +00001686
1687 /**
1688 * @hide
1689 * Sets the given package as the profile owner of the given user profile. The package must
1690 * already be installed and there shouldn't be an existing profile owner registered for this
1691 * user. Also, this method must be called before the user has been used for the first time.
1692 * @param packageName the package name of the application to be registered as profile owner.
1693 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00001694 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00001695 * @return whether the package was successfully registered as the profile owner.
1696 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
1697 * the user has already been set up.
1698 */
Adam Connors661ec472014-02-11 13:59:46 +00001699 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00001700 throws IllegalArgumentException {
1701 if (mService != null) {
1702 try {
Adam Connors661ec472014-02-11 13:59:46 +00001703 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00001704 } catch (RemoteException re) {
1705 Log.w(TAG, "Failed to set profile owner", re);
1706 throw new IllegalArgumentException("Couldn't set profile owner.", re);
1707 }
1708 }
1709 return false;
1710 }
1711
1712 /**
1713 * Used to determine if a particular package is registered as the Profile Owner for the
1714 * current user. A profile owner is a special device admin that has additional priviledges
1715 * within the managed profile.
1716 *
1717 * @param packageName The package name of the app to compare with the registered profile owner.
1718 * @return Whether or not the package is registered as the profile owner.
1719 */
1720 public boolean isProfileOwnerApp(String packageName) {
1721 if (mService != null) {
1722 try {
1723 String profileOwnerPackage = mService.getProfileOwner(
1724 Process.myUserHandle().getIdentifier());
1725 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
1726 } catch (RemoteException re) {
1727 Log.w(TAG, "Failed to check profile owner");
1728 }
1729 }
1730 return false;
1731 }
1732
1733 /**
1734 * @hide
1735 * @return the packageName of the owner of the given user profile or null if no profile
1736 * owner has been set for that user.
1737 * @throws IllegalArgumentException if the userId is invalid.
1738 */
1739 public String getProfileOwner() throws IllegalArgumentException {
1740 if (mService != null) {
1741 try {
1742 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
1743 } catch (RemoteException re) {
1744 Log.w(TAG, "Failed to get profile owner");
1745 throw new IllegalArgumentException(
1746 "Requested profile owner for invalid userId", re);
1747 }
1748 }
1749 return null;
1750 }
1751
1752 /**
1753 * @hide
1754 * @return the human readable name of the organisation associated with this DPM or null if
1755 * one is not set.
1756 * @throws IllegalArgumentException if the userId is invalid.
1757 */
1758 public String getProfileOwnerName() throws IllegalArgumentException {
1759 if (mService != null) {
1760 try {
1761 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
1762 } catch (RemoteException re) {
1763 Log.w(TAG, "Failed to get profile owner");
1764 throw new IllegalArgumentException(
1765 "Requested profile owner for invalid userId", re);
1766 }
1767 }
1768 return null;
1769 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001770
1771 /**
1772 * Called by a profile owner or device owner to add a default intent handler activity for
1773 * intents that match a certain intent filter. This activity will remain the default intent
1774 * handler even if the set of potential event handlers for the intent filter changes and if
1775 * the intent preferences are reset.
1776 *
1777 * <p>The default disambiguation mechanism takes over if the activity is not installed
1778 * (anymore). When the activity is (re)installed, it is automatically reset as default
1779 * intent handler for the filter.
1780 *
1781 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
1782 * security exception will be thrown.
1783 *
1784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1785 * @param filter The IntentFilter for which a default handler is added.
1786 * @param activity The Activity that is added as default intent handler.
1787 */
1788 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
1789 ComponentName activity) {
1790 if (mService != null) {
1791 try {
1792 mService.addPersistentPreferredActivity(admin, filter, activity);
1793 } catch (RemoteException e) {
1794 Log.w(TAG, "Failed talking with device policy service", e);
1795 }
1796 }
1797 }
1798
1799 /**
1800 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00001801 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001802 *
1803 * <p>The calling device admin must be a profile owner. If it is not, a security
1804 * exception will be thrown.
1805 *
1806 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1807 * @param packageName The name of the package for which preferences are removed.
1808 */
1809 public void clearPackagePersistentPreferredActivities(ComponentName admin,
1810 String packageName) {
1811 if (mService != null) {
1812 try {
1813 mService.clearPackagePersistentPreferredActivities(admin, packageName);
1814 } catch (RemoteException e) {
1815 Log.w(TAG, "Failed talking with device policy service", e);
1816 }
1817 }
1818 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08001819}