blob: e9cce51ec2a468b66f982b4ecc50f2a703b5d4cb [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
Jessica Hummel9da60392014-05-21 12:32:57 +010019import android.accounts.AccountManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080020import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080022import android.app.Service;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.content.BroadcastReceiver;
24import android.content.ComponentName;
25import android.content.Context;
26import android.content.Intent;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080027import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080028
29/**
30 * Base class for implementing a device administration component. This
31 * class provides a convenience for interpreting the raw intent actions
32 * that are sent by the system.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000033 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080034 * <p>The callback methods, like the base
35 * {@link BroadcastReceiver#onReceive(Context, Intent) BroadcastReceiver.onReceive()}
36 * method, happen on the main thread of the process. Thus long running
37 * operations must be done on another thread. Note that because a receiver
38 * is done once returning from its receive function, such long-running operations
39 * should probably be done in a {@link Service}.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000040 *
Dianne Hackbornd6847842010-01-12 18:14:19 -080041 * <p>When publishing your DeviceAdmin subclass as a receiver, it must
42 * handle {@link #ACTION_DEVICE_ADMIN_ENABLED} and require the
43 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN} permission. A typical
44 * manifest entry would look like:</p>
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000045 *
Dianne Hackbornab8a8ed2010-01-29 19:03:06 -080046 * {@sample development/samples/ApiDemos/AndroidManifest.xml device_admin_declaration}
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000047 *
Dianne Hackbornd6847842010-01-12 18:14:19 -080048 * <p>The meta-data referenced here provides addition information specific
49 * to the device administrator, as parsed by the {@link DeviceAdminInfo} class.
50 * A typical file would be:</p>
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000051 *
Andrew Stadler88209d12010-02-08 22:59:36 -080052 * {@sample development/samples/ApiDemos/res/xml/device_admin_sample.xml meta_data}
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080053 *
54 * <div class="special reference">
55 * <h3>Developer Guides</h3>
56 * <p>For more information about device administration, 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 */
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080061public class DeviceAdminReceiver extends BroadcastReceiver {
Dianne Hackbornd6847842010-01-12 18:14:19 -080062 private static String TAG = "DevicePolicy";
Joe Onorato43a17652011-04-06 19:22:23 -070063 private static boolean localLOGV = false;
Dianne Hackbornd6847842010-01-12 18:14:19 -080064
65 /**
66 * This is the primary action that a device administrator must implement to be
67 * allowed to manage a device. This will be set to the receiver
68 * when the user enables it for administration. You will generally
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080069 * handle this in {@link DeviceAdminReceiver#onEnabled(Context, Intent)}. To be
Dianne Hackbornd6847842010-01-12 18:14:19 -080070 * supported, the receiver must also require the
71 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN} permission so
72 * that other applications can not abuse it.
73 */
74 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
75 public static final String ACTION_DEVICE_ADMIN_ENABLED
76 = "android.app.action.DEVICE_ADMIN_ENABLED";
77
78 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080079 * Action sent to a device administrator when the user has requested to
80 * disable it, but before this has actually been done. This gives you
81 * a chance to supply a message to the user about the impact of
82 * disabling your admin, by setting the extra field
83 * {@link #EXTRA_DISABLE_WARNING} in the result Intent. If not set,
84 * no warning will be displayed. If set, the given text will be shown
85 * to the user before they disable your admin.
86 */
87 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
88 public static final String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED
89 = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED";
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000090
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080091 /**
92 * A CharSequence that can be shown to the user informing them of the
93 * impact of disabling your admin.
94 *
95 * @see #ACTION_DEVICE_ADMIN_DISABLE_REQUESTED
96 */
97 public static final String EXTRA_DISABLE_WARNING = "android.app.extra.DISABLE_WARNING";
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +000098
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080099 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 * Action sent to a device administrator when the user has disabled
101 * it. Upon return, the application no longer has access to the
102 * protected device policy manager APIs. You will generally
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800103 * handle this in {@link DeviceAdminReceiver#onDisabled(Context, Intent)}. Note
Dianne Hackbornd6847842010-01-12 18:14:19 -0800104 * that this action will be
105 * sent the receiver regardless of whether it is explicitly listed in
106 * its intent filter.
107 */
108 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
109 public static final String ACTION_DEVICE_ADMIN_DISABLED
110 = "android.app.action.DEVICE_ADMIN_DISABLED";
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000111
Dianne Hackbornd6847842010-01-12 18:14:19 -0800112 /**
113 * Action sent to a device administrator when the user has changed the
114 * password of their device. You can at this point check the characteristics
Dianne Hackborn254cb442010-01-27 19:23:59 -0800115 * of the new password with {@link DevicePolicyManager#isActivePasswordSufficient()
116 * DevicePolicyManager.isActivePasswordSufficient()}.
117 * You will generally
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800118 * handle this in {@link DeviceAdminReceiver#onPasswordChanged}.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000119 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800120 * <p>The calling device admin must have requested
121 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to receive
122 * this broadcast.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800123 */
124 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
125 public static final String ACTION_PASSWORD_CHANGED
126 = "android.app.action.ACTION_PASSWORD_CHANGED";
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000127
Dianne Hackbornd6847842010-01-12 18:14:19 -0800128 /**
129 * Action sent to a device administrator when the user has failed at
130 * attempted to enter the password. You can at this point check the
131 * number of failed password attempts there have been with
Dianne Hackborn254cb442010-01-27 19:23:59 -0800132 * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts
Dianne Hackbornd6847842010-01-12 18:14:19 -0800133 * DevicePolicyManager.getCurrentFailedPasswordAttempts()}. You will generally
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800134 * handle this in {@link DeviceAdminReceiver#onPasswordFailed}.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000135 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800136 * <p>The calling device admin must have requested
137 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive
138 * this broadcast.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800139 */
140 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
141 public static final String ACTION_PASSWORD_FAILED
142 = "android.app.action.ACTION_PASSWORD_FAILED";
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000143
Dianne Hackbornd6847842010-01-12 18:14:19 -0800144 /**
145 * Action sent to a device administrator when the user has successfully
146 * entered their password, after failing one or more times.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000147 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800148 * <p>The calling device admin must have requested
149 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive
150 * this broadcast.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800151 */
152 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
153 public static final String ACTION_PASSWORD_SUCCEEDED
154 = "android.app.action.ACTION_PASSWORD_SUCCEEDED";
Jim Millera4e28d12010-11-08 16:15:47 -0800155
156 /**
157 * Action periodically sent to a device administrator when the device password
Jim Miller6b857682011-02-16 16:27:41 -0800158 * is expiring.
Jim Millera4e28d12010-11-08 16:15:47 -0800159 *
160 * <p>The calling device admin must have requested
161 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to receive
162 * this broadcast.
163 */
164 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
165 public static final String ACTION_PASSWORD_EXPIRING
166 = "android.app.action.ACTION_PASSWORD_EXPIRING";
167
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000168 /**
Jason Monk35c62a42014-06-17 10:24:47 -0400169 * Action sent to a device administrator to notify that the device is entering
Jason Monk48aacba2014-08-13 16:29:08 -0400170 * lock task mode from an authorized package. The extra {@link #EXTRA_LOCK_TASK_PACKAGE}
171 * will describe the authorized package using lock task mode.
Jason Monk35c62a42014-06-17 10:24:47 -0400172 *
Jason Monk48aacba2014-08-13 16:29:08 -0400173 * @see DevicePolicyManager#isLockTaskPermitted(String)
Jason Monk35c62a42014-06-17 10:24:47 -0400174 *
175 * <p>The calling device admin must be the device owner or profile
176 * owner to receive this broadcast.
177 */
178 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jason Monk48aacba2014-08-13 16:29:08 -0400179 public static final String ACTION_LOCK_TASK_ENTERING
Jason Monk5503a552014-09-04 14:14:37 -0400180 = "android.app.action.LOCK_TASK_ENTERING";
Jason Monk35c62a42014-06-17 10:24:47 -0400181
182 /**
Jason Monk48aacba2014-08-13 16:29:08 -0400183 * Action sent to a device administrator to notify that the device is exiting
184 * lock task mode from an authorized package.
Jason Monk35c62a42014-06-17 10:24:47 -0400185 *
Jason Monk48aacba2014-08-13 16:29:08 -0400186 * @see DevicePolicyManager#isLockTaskPermitted(String)
187 *
188 * <p>The calling device admin must be the device owner or profile
189 * owner to receive this broadcast.
Jason Monk35c62a42014-06-17 10:24:47 -0400190 */
Jason Monk48aacba2014-08-13 16:29:08 -0400191 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
192 public static final String ACTION_LOCK_TASK_EXITING
Jason Monk5503a552014-09-04 14:14:37 -0400193 = "android.app.action.LOCK_TASK_EXITING";
Jason Monk35c62a42014-06-17 10:24:47 -0400194
195 /**
196 * A boolean describing whether the device is currently entering or exiting
197 * lock task mode.
198 *
199 * @see #ACTION_LOCK_TASK_CHANGED
200 */
201 public static final String EXTRA_LOCK_TASK_PACKAGE =
202 "android.app.extra.LOCK_TASK_PACKAGE";
203
204 /**
Jessica Hummel9da60392014-05-21 12:32:57 +0100205 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
206 * or managed device has completed successfully.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000207 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100208 * <p>The broadcast is limited to the profile that will be managed by the application that
209 * requested provisioning. In the device owner case the profile is the primary user.
210 * The broadcast will also be limited to the {@link DeviceAdminReceiver} component
211 * specified in the original intent or NFC bump that started the provisioning process
212 * (@see DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE).
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100213 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100214 * <p>A device admin application which listens to this intent can find out if the device was
215 * provisioned for the device owner or profile owner case by calling respectively
216 * {@link android.app.admin.DevicePolicyManager#isDeviceOwnerApp} and
217 * {@link android.app.admin.DevicePolicyManager#isProfileOwnerApp}.
218 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000219 * <p>Input: Nothing.</p>
220 * <p>Output: Nothing</p>
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000221 */
222 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jessica Hummelf72078b2014-03-06 16:13:12 +0000223 public static final String ACTION_PROFILE_PROVISIONING_COMPLETE =
Jessica Hummel56692162014-09-10 15:12:11 +0100224 "android.app.action.PROFILE_PROVISIONING_COMPLETE";
225
226 /**
Ken Wakasaf76a50c2012-03-09 19:56:35 +0900227 * Name under which a DevicePolicy component publishes information
Dianne Hackbornd6847842010-01-12 18:14:19 -0800228 * about itself. This meta-data must reference an XML resource containing
229 * a device-admin tag. XXX TO DO: describe syntax.
230 */
231 public static final String DEVICE_ADMIN_META_DATA = "android.app.device_admin";
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000232
Dianne Hackbornd6847842010-01-12 18:14:19 -0800233 private DevicePolicyManager mManager;
234 private ComponentName mWho;
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000235
Dianne Hackbornd6847842010-01-12 18:14:19 -0800236 /**
237 * Retrieve the DevicePolicyManager interface for this administrator to work
238 * with the system.
239 */
240 public DevicePolicyManager getManager(Context context) {
241 if (mManager != null) {
242 return mManager;
243 }
244 mManager = (DevicePolicyManager)context.getSystemService(
245 Context.DEVICE_POLICY_SERVICE);
246 return mManager;
247 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000248
Dianne Hackbornd6847842010-01-12 18:14:19 -0800249 /**
250 * Retrieve the ComponentName describing who this device administrator is, for
251 * use in {@link DevicePolicyManager} APIs that require the administrator to
252 * identify itself.
253 */
254 public ComponentName getWho(Context context) {
255 if (mWho != null) {
256 return mWho;
257 }
258 mWho = new ComponentName(context, getClass());
259 return mWho;
260 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000261
Dianne Hackbornd6847842010-01-12 18:14:19 -0800262 /**
263 * Called after the administrator is first enabled, as a result of
264 * receiving {@link #ACTION_DEVICE_ADMIN_ENABLED}. At this point you
265 * can use {@link DevicePolicyManager} to set your desired policies.
Jason Monk03978a42014-06-10 15:05:30 -0400266 *
267 * <p> If the admin is activated by a device owner, then the intent
268 * may contain private extras that are relevant to user setup.
269 * {@see DevicePolicyManager#createAndInitializeUser(ComponentName, String, String,
270 * ComponentName, Intent)}
271 *
Dianne Hackbornd6847842010-01-12 18:14:19 -0800272 * @param context The running context as per {@link #onReceive}.
273 * @param intent The received intent as per {@link #onReceive}.
274 */
275 public void onEnabled(Context context, Intent intent) {
276 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000277
Dianne Hackbornd6847842010-01-12 18:14:19 -0800278 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800279 * Called when the user has asked to disable the administrator, as a result of
280 * receiving {@link #ACTION_DEVICE_ADMIN_DISABLE_REQUESTED}, giving you
281 * a chance to present a warning message to them. The message is returned
282 * as the result; if null is returned (the default implementation), no
283 * message will be displayed.
284 * @param context The running context as per {@link #onReceive}.
285 * @param intent The received intent as per {@link #onReceive}.
286 * @return Return the warning message to display to the user before
287 * being disabled; if null is returned, no message is displayed.
288 */
289 public CharSequence onDisableRequested(Context context, Intent intent) {
290 return null;
291 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000292
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800293 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800294 * Called prior to the administrator being disabled, as a result of
295 * receiving {@link #ACTION_DEVICE_ADMIN_DISABLED}. Upon return, you
296 * can no longer use the protected parts of the {@link DevicePolicyManager}
297 * API.
298 * @param context The running context as per {@link #onReceive}.
299 * @param intent The received intent as per {@link #onReceive}.
300 */
301 public void onDisabled(Context context, Intent intent) {
302 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000303
Dianne Hackbornd6847842010-01-12 18:14:19 -0800304 /**
305 * Called after the user has changed their password, as a result of
306 * receiving {@link #ACTION_PASSWORD_CHANGED}. At this point you
307 * can use {@link DevicePolicyManager#getCurrentFailedPasswordAttempts()
308 * DevicePolicyManager.getCurrentFailedPasswordAttempts()}
309 * to retrieve the active password characteristics.
310 * @param context The running context as per {@link #onReceive}.
311 * @param intent The received intent as per {@link #onReceive}.
312 */
313 public void onPasswordChanged(Context context, Intent intent) {
314 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000315
Dianne Hackbornd6847842010-01-12 18:14:19 -0800316 /**
317 * Called after the user has failed at entering their current password, as a result of
318 * receiving {@link #ACTION_PASSWORD_FAILED}. At this point you
319 * can use {@link DevicePolicyManager} to retrieve the number of failed
320 * password attempts.
321 * @param context The running context as per {@link #onReceive}.
322 * @param intent The received intent as per {@link #onReceive}.
323 */
324 public void onPasswordFailed(Context context, Intent intent) {
325 }
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000326
Dianne Hackbornd6847842010-01-12 18:14:19 -0800327 /**
328 * Called after the user has succeeded at entering their current password,
329 * as a result of receiving {@link #ACTION_PASSWORD_SUCCEEDED}. This will
330 * only be received the first time they succeed after having previously
331 * failed.
332 * @param context The running context as per {@link #onReceive}.
333 * @param intent The received intent as per {@link #onReceive}.
334 */
335 public void onPasswordSucceeded(Context context, Intent intent) {
336 }
Jim Millera4e28d12010-11-08 16:15:47 -0800337
338 /**
339 * Called periodically when the password is about to expire or has expired. It will typically
Jim Miller6b857682011-02-16 16:27:41 -0800340 * be called at these times: on device boot, once per day before the password expires,
341 * and at the time when the password expires.
Jim Millera4e28d12010-11-08 16:15:47 -0800342 *
343 * <p>If the password is not updated by the user, this method will continue to be called
344 * once per day until the password is changed or the device admin disables password expiration.
345 *
346 * <p>The admin will typically post a notification requesting the user to change their password
347 * in response to this call. The actual password expiration time can be obtained by calling
348 * {@link DevicePolicyManager#getPasswordExpiration(ComponentName) }
349 *
350 * <p>The admin should be sure to take down any notifications it posted in response to this call
351 * when it receives {@link DeviceAdminReceiver#onPasswordChanged(Context, Intent) }.
352 *
353 * @param context The running context as per {@link #onReceive}.
354 * @param intent The received intent as per {@link #onReceive}.
355 */
356 public void onPasswordExpiring(Context context, Intent intent) {
357 }
358
Dianne Hackbornd6847842010-01-12 18:14:19 -0800359 /**
Jessica Hummel9da60392014-05-21 12:32:57 +0100360 * Called when provisioning of a managed profile or managed device has completed successfully.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000361 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100362 * <p> As a prerequisit for the execution of this callback the (@link DeviceAdminReceiver} has
363 * to declare an intent filter for {@link #ACTION_PROFILE_PROVISIONING_COMPLETE}.
364 * Its component must also be specified in the {@link DevicePolicyManager#EXTRA_DEVICE_ADMIN}
365 * of the {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} intent that started the
366 * managed provisioning.
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000367 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100368 * <p>When provisioning is complete, the managed profile is hidden until the profile owner
369 * calls {DevicePolicyManager#setProfileEnabled(ComponentName admin)}. Typically a profile
370 * owner will enable the profile when it has finished any additional setup such as adding an
371 * account by using the {@link AccountManager} and calling apis to bring the profile into the
372 * desired state.
373 *
374 * <p> Note that provisioning completes without waiting for any server interactions, so the
375 * profile owner needs to wait for data to be available if required (e.g android device ids or
376 * other data that is set as a result of server interactions).
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000377 *
378 * @param context The running context as per {@link #onReceive}.
379 * @param intent The received intent as per {@link #onReceive}.
380 */
381 public void onProfileProvisioningComplete(Context context, Intent intent) {
382 }
383
384 /**
Jason Monk48aacba2014-08-13 16:29:08 -0400385 * Called when a device is entering lock task mode by a package authorized
386 * by {@link DevicePolicyManager#isLockTaskPermitted(String)}
Jason Monk35c62a42014-06-17 10:24:47 -0400387 *
388 * @param context The running context as per {@link #onReceive}.
389 * @param intent The received intent as per {@link #onReceive}.
Jason Monk35c62a42014-06-17 10:24:47 -0400390 * @param pkg If entering, the authorized package using lock task mode, otherwise null.
391 */
Jason Monk48aacba2014-08-13 16:29:08 -0400392 public void onLockTaskModeEntering(Context context, Intent intent, String pkg) {
393 }
394
395 /**
396 * Called when a device is exiting lock task mode by a package authorized
397 * by {@link DevicePolicyManager#isLockTaskPermitted(String)}
398 *
399 * @param context The running context as per {@link #onReceive}.
400 * @param intent The received intent as per {@link #onReceive}.
401 */
402 public void onLockTaskModeExiting(Context context, Intent intent) {
Jason Monk35c62a42014-06-17 10:24:47 -0400403 }
404
405 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800406 * Intercept standard device administrator broadcasts. Implementations
407 * should not override this method; it is better to implement the
408 * convenience callbacks for each action.
409 */
410 @Override
411 public void onReceive(Context context, Intent intent) {
412 String action = intent.getAction();
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000413
Dianne Hackbornd6847842010-01-12 18:14:19 -0800414 if (ACTION_PASSWORD_CHANGED.equals(action)) {
415 onPasswordChanged(context, intent);
416 } else if (ACTION_PASSWORD_FAILED.equals(action)) {
417 onPasswordFailed(context, intent);
418 } else if (ACTION_PASSWORD_SUCCEEDED.equals(action)) {
419 onPasswordSucceeded(context, intent);
420 } else if (ACTION_DEVICE_ADMIN_ENABLED.equals(action)) {
421 onEnabled(context, intent);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800422 } else if (ACTION_DEVICE_ADMIN_DISABLE_REQUESTED.equals(action)) {
423 CharSequence res = onDisableRequested(context, intent);
424 if (res != null) {
425 Bundle extras = getResultExtras(true);
426 extras.putCharSequence(EXTRA_DISABLE_WARNING, res);
427 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800428 } else if (ACTION_DEVICE_ADMIN_DISABLED.equals(action)) {
429 onDisabled(context, intent);
Jim Millera4e28d12010-11-08 16:15:47 -0800430 } else if (ACTION_PASSWORD_EXPIRING.equals(action)) {
431 onPasswordExpiring(context, intent);
Jessica Hummel8cdb6fc2014-03-03 14:14:51 +0000432 } else if (ACTION_PROFILE_PROVISIONING_COMPLETE.equals(action)) {
433 onProfileProvisioningComplete(context, intent);
Jason Monk48aacba2014-08-13 16:29:08 -0400434 } else if (ACTION_LOCK_TASK_ENTERING.equals(action)) {
Jason Monk35c62a42014-06-17 10:24:47 -0400435 String pkg = intent.getStringExtra(EXTRA_LOCK_TASK_PACKAGE);
Jason Monk48aacba2014-08-13 16:29:08 -0400436 onLockTaskModeEntering(context, intent, pkg);
437 } else if (ACTION_LOCK_TASK_EXITING.equals(action)) {
438 onLockTaskModeExiting(context, intent);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800439 }
440 }
441}