• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app.admin;
18 
19 import android.accounts.AccountManager;
20 import android.annotation.BroadcastBehavior;
21 import android.annotation.IntDef;
22 import android.annotation.IntRange;
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 import android.annotation.SdkConstant;
26 import android.annotation.SdkConstant.SdkConstantType;
27 import android.app.Service;
28 import android.content.BroadcastReceiver;
29 import android.content.ComponentName;
30 import android.content.Context;
31 import android.content.Intent;
32 import android.net.Uri;
33 import android.os.Bundle;
34 import android.os.PersistableBundle;
35 import android.os.Process;
36 import android.os.UserHandle;
37 import android.security.KeyChain;
38 
39 import java.lang.annotation.Retention;
40 import java.lang.annotation.RetentionPolicy;
41 
42 /**
43  * Base class for implementing a device administration component.  This
44  * class provides a convenience for interpreting the raw intent actions
45  * that are sent by the system.
46  *
47  * <p>The callback methods, like the base
48  * {@link BroadcastReceiver#onReceive(Context, Intent) BroadcastReceiver.onReceive()}
49  * method, happen on the main thread of the process.  Thus long running
50  * operations must be done on another thread.  Note that because a receiver
51  * is done once returning from its receive function, such long-running operations
52  * should probably be done in a {@link Service}.
53  *
54  * <p>When publishing your DeviceAdmin subclass as a receiver, it must
55  * handle {@link #ACTION_DEVICE_ADMIN_ENABLED} and require the
56  * {@link android.Manifest.permission#BIND_DEVICE_ADMIN} permission.  A typical
57  * manifest entry would look like:</p>
58  *
59  * {@sample development/samples/ApiDemos/AndroidManifest.xml device_admin_declaration}
60  *
61  * <p>The meta-data referenced here provides addition information specific
62  * to the device administrator, as parsed by the {@link DeviceAdminInfo} class.
63  * A typical file would be:</p>
64  *
65  * {@sample development/samples/ApiDemos/res/xml/device_admin_sample.xml meta_data}
66  *
67  * <div class="special reference">
68  * <h3>Developer Guides</h3>
69  * <p>For more information about device administration, read the
70  * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
71  * developer guide.</p>
72  * </div>
73  */
74 public class DeviceAdminReceiver extends BroadcastReceiver {
75     private static String TAG = "DevicePolicy";
76     private static boolean localLOGV = false;
77 
78     /**
79      * This is the primary action that a device administrator must implement to be
80      * allowed to manage a device.  This will be set to the receiver
81      * when the user enables it for administration.  You will generally
82      * handle this in {@link DeviceAdminReceiver#onEnabled(Context, Intent)}.  To be
83      * supported, the receiver must also require the
84      * {@link android.Manifest.permission#BIND_DEVICE_ADMIN} permission so
85      * that other applications can not abuse it.
86      */
87     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
88     @BroadcastBehavior(explicitOnly = true)
89     public static final String ACTION_DEVICE_ADMIN_ENABLED
90             = "android.app.action.DEVICE_ADMIN_ENABLED";
91 
92     /**
93      * Action sent to a device administrator when the user has requested to
94      * disable it, but before this has actually been done.  This gives you
95      * a chance to supply a message to the user about the impact of
96      * disabling your admin, by setting the extra field
97      * {@link #EXTRA_DISABLE_WARNING} in the result Intent.  If not set,
98      * no warning will be displayed.  If set, the given text will be shown
99      * to the user before they disable your admin.
100      */
101     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
102     @BroadcastBehavior(explicitOnly = true)
103     public static final String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED
104             = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED";
105 
106     /**
107      * A CharSequence that can be shown to the user informing them of the
108      * impact of disabling your admin.
109      *
110      * @see #ACTION_DEVICE_ADMIN_DISABLE_REQUESTED
111      */
112     public static final String EXTRA_DISABLE_WARNING = "android.app.extra.DISABLE_WARNING";
113 
114     /**
115      * Action sent to a device administrator when the user has disabled
116      * it.  Upon return, the application no longer has access to the
117      * protected device policy manager APIs.  You will generally
118      * handle this in {@link DeviceAdminReceiver#onDisabled(Context, Intent)}.  Note
119      * that this action will be
120      * sent the receiver regardless of whether it is explicitly listed in
121      * its intent filter.
122      */
123     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
124     @BroadcastBehavior(explicitOnly = true)
125     public static final String ACTION_DEVICE_ADMIN_DISABLED
126             = "android.app.action.DEVICE_ADMIN_DISABLED";
127 
128     /**
129      * Action sent to a device administrator when the user has changed the password of their device
130      * or profile challenge.  You can at this point check the characteristics
131      * of the new password with {@link DevicePolicyManager#isActivePasswordSufficient()
132      * DevicePolicyManager.isActivePasswordSufficient()}.
133      * You will generally
134      * handle this in {@link DeviceAdminReceiver#onPasswordChanged(Context, Intent, UserHandle)}.
135      *
136      * <p>The calling device admin must have requested
137      * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to receive
138      * this broadcast.
139      */
140     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
141     @BroadcastBehavior(explicitOnly = true)
142     public static final String ACTION_PASSWORD_CHANGED
143             = "android.app.action.ACTION_PASSWORD_CHANGED";
144 
145     /**
146      * Action sent to a device administrator when the user has entered an incorrect device
147      * or profile challenge password.  You can at this point check the
148      * number of failed password attempts there have been with
149      * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts
150      * DevicePolicyManager.getCurrentFailedPasswordAttempts()}.  You will generally
151      * handle this in {@link DeviceAdminReceiver#onPasswordFailed(Context, Intent, UserHandle)}.
152      *
153      * <p>The calling device admin must have requested
154      * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive
155      * this broadcast.
156      */
157     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
158     @BroadcastBehavior(explicitOnly = true)
159     public static final String ACTION_PASSWORD_FAILED
160             = "android.app.action.ACTION_PASSWORD_FAILED";
161 
162     /**
163      * Action sent to a device administrator when the user has successfully entered their device
164      * or profile challenge password, after failing one or more times.  You will generally
165      * handle this in {@link DeviceAdminReceiver#onPasswordSucceeded(Context, Intent, UserHandle)}.
166      *
167      * <p>The calling device admin must have requested
168      * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive
169      * this broadcast.
170      */
171     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
172     @BroadcastBehavior(explicitOnly = true)
173     public static final String ACTION_PASSWORD_SUCCEEDED
174             = "android.app.action.ACTION_PASSWORD_SUCCEEDED";
175 
176     /**
177      * Action periodically sent to a device administrator when the device or profile challenge
178      * password is expiring.  You will generally
179      * handle this in {@link DeviceAdminReceiver#onPasswordExpiring(Context, Intent, UserHandle)}.
180      *
181      * <p>The calling device admin must have requested
182      * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to receive
183      * this broadcast.
184      */
185     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
186     @BroadcastBehavior(explicitOnly = true)
187     public static final String ACTION_PASSWORD_EXPIRING
188             = "android.app.action.ACTION_PASSWORD_EXPIRING";
189 
190     /**
191      * Action sent to a device administrator to notify that the device is entering
192      * lock task mode.  The extra {@link #EXTRA_LOCK_TASK_PACKAGE}
193      * will describe the package using lock task mode.
194      *
195      * <p>The calling device admin must be the device owner or profile
196      * owner to receive this broadcast.
197      *
198      * @see DevicePolicyManager#isLockTaskPermitted(String)
199      */
200     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
201     @BroadcastBehavior(explicitOnly = true)
202     public static final String ACTION_LOCK_TASK_ENTERING
203             = "android.app.action.LOCK_TASK_ENTERING";
204 
205     /**
206      * Action sent to a device administrator to notify that the device is exiting
207      * lock task mode.
208      *
209      * <p>The calling device admin must be the device owner or profile
210      * owner to receive this broadcast.
211      *
212      * @see DevicePolicyManager#isLockTaskPermitted(String)
213      */
214     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
215     @BroadcastBehavior(explicitOnly = true)
216     public static final String ACTION_LOCK_TASK_EXITING
217             = "android.app.action.LOCK_TASK_EXITING";
218 
219     /**
220      * A string containing the name of the package entering lock task mode.
221      *
222      * @see #ACTION_LOCK_TASK_ENTERING
223      */
224     public static final String EXTRA_LOCK_TASK_PACKAGE =
225             "android.app.extra.LOCK_TASK_PACKAGE";
226 
227     /**
228      * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
229      * or managed device has completed successfully.
230      *
231      * <p>The broadcast is limited to the profile that will be managed by the application that
232      * requested provisioning. In the device owner case the profile is the primary user.
233      * The broadcast will also be limited to the {@link DeviceAdminReceiver} component
234      * specified in the original intent or NFC bump that started the provisioning process
235      * (see {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE
236      * DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE}).
237      *
238      * <p>A device admin application which listens to this intent can find out if the device was
239      * provisioned for the device owner or profile owner case by calling respectively
240      * {@link android.app.admin.DevicePolicyManager#isDeviceOwnerApp} and
241      * {@link android.app.admin.DevicePolicyManager#isProfileOwnerApp}. You will generally handle
242      * this in {@link DeviceAdminReceiver#onProfileProvisioningComplete}.
243      *
244      * @see DevicePolicyManager#ACTION_PROVISIONING_SUCCESSFUL
245      */
246     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
247     @BroadcastBehavior(explicitOnly = true)
248     public static final String ACTION_PROFILE_PROVISIONING_COMPLETE =
249             "android.app.action.PROFILE_PROVISIONING_COMPLETE";
250 
251     /**
252      * Action sent to a device administrator to notify that the device user
253      * has declined sharing a bugreport.
254      *
255      * <p>The calling device admin must be the device owner to receive this broadcast.
256      * @see DevicePolicyManager#requestBugreport
257      * @hide
258      */
259     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
260     @BroadcastBehavior(explicitOnly = true)
261     public static final String ACTION_BUGREPORT_SHARING_DECLINED =
262             "android.app.action.BUGREPORT_SHARING_DECLINED";
263 
264     /**
265      * Action sent to a device administrator to notify that the collection of a bugreport
266      * has failed.
267      *
268      * <p>The calling device admin must be the device owner to receive this broadcast.
269      * @see DevicePolicyManager#requestBugreport
270      * @hide
271      */
272     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
273     @BroadcastBehavior(explicitOnly = true)
274     public static final String ACTION_BUGREPORT_FAILED = "android.app.action.BUGREPORT_FAILED";
275 
276     /**
277      * Action sent to a device administrator to share the bugreport.
278      *
279      * <p>The calling device admin must be the device owner to receive this broadcast.
280      * @see DevicePolicyManager#requestBugreport
281      * @hide
282      */
283     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
284     @BroadcastBehavior(explicitOnly = true)
285     public static final String ACTION_BUGREPORT_SHARE =
286             "android.app.action.BUGREPORT_SHARE";
287 
288     /**
289      * Broadcast action: notify that a new batch of security logs is ready to be collected.
290      * @hide
291      */
292     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
293     @BroadcastBehavior(explicitOnly = true)
294     public static final String ACTION_SECURITY_LOGS_AVAILABLE
295             = "android.app.action.SECURITY_LOGS_AVAILABLE";
296 
297     /**
298      * Broadcast action: notify that a new batch of network logs is ready to be collected.
299      * @see DeviceAdminReceiver#onNetworkLogsAvailable
300      * @see DelegatedAdminReceiver#onNetworkLogsAvailable
301      */
302     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
303     @BroadcastBehavior(explicitOnly = true)
304     public static final String ACTION_NETWORK_LOGS_AVAILABLE
305             = "android.app.action.NETWORK_LOGS_AVAILABLE";
306 
307     /**
308      * A {@code long} containing a token of the current batch of network logs, that has to be used
309      * to retrieve the batch of logs by the device owner.
310      *
311      * @see #ACTION_NETWORK_LOGS_AVAILABLE
312      * @see DevicePolicyManager#retrieveNetworkLogs
313      * @hide
314      */
315     public static final String EXTRA_NETWORK_LOGS_TOKEN =
316             "android.app.extra.EXTRA_NETWORK_LOGS_TOKEN";
317 
318     /**
319      * An {@code int} count representing a total count of network logs inside the current batch of
320      * network logs.
321      *
322      * @see #ACTION_NETWORK_LOGS_AVAILABLE
323      * @hide
324      */
325     public static final String EXTRA_NETWORK_LOGS_COUNT =
326             "android.app.extra.EXTRA_NETWORK_LOGS_COUNT";
327 
328     /**
329      * Broadcast action: notify the device owner that a user or profile has been added.
330      * Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
331      * the new user.
332      * @hide
333      */
334     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
335     @BroadcastBehavior(explicitOnly = true)
336     public static final String ACTION_USER_ADDED = "android.app.action.USER_ADDED";
337 
338     /**
339      * Broadcast action: notify the device owner that a user or profile has been removed.
340      * Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
341      * the user.
342      * @hide
343      */
344     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
345     @BroadcastBehavior(explicitOnly = true)
346     public static final String ACTION_USER_REMOVED = "android.app.action.USER_REMOVED";
347 
348     /**
349      * Broadcast action: notify the device owner that a user or profile has been started.
350      * Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
351      * the user.
352      * @hide
353      */
354     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
355     @BroadcastBehavior(explicitOnly = true)
356     public static final String ACTION_USER_STARTED = "android.app.action.USER_STARTED";
357 
358     /**
359      * Broadcast action: notify the device owner that a user or profile has been stopped.
360      * Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
361      * the user.
362      * @hide
363      */
364     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
365     @BroadcastBehavior(explicitOnly = true)
366     public static final String ACTION_USER_STOPPED = "android.app.action.USER_STOPPED";
367 
368     /**
369      * Broadcast action: notify the device owner that a user or profile has been switched to.
370      * Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
371      * the user.
372      * @hide
373      */
374     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
375     @BroadcastBehavior(explicitOnly = true)
376     public static final String ACTION_USER_SWITCHED = "android.app.action.USER_SWITCHED";
377 
378     /**
379      * A string containing the SHA-256 hash of the bugreport file.
380      *
381      * @see #ACTION_BUGREPORT_SHARE
382      * @hide
383      */
384     public static final String EXTRA_BUGREPORT_HASH = "android.app.extra.BUGREPORT_HASH";
385 
386     /**
387      * An {@code int} failure code representing the reason of the bugreport failure. One of
388      * {@link #BUGREPORT_FAILURE_FAILED_COMPLETING}
389      * or {@link #BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE}
390      *
391      * @see #ACTION_BUGREPORT_FAILED
392      * @hide
393      */
394     public static final String EXTRA_BUGREPORT_FAILURE_REASON =
395             "android.app.extra.BUGREPORT_FAILURE_REASON";
396 
397     /**
398      * An interface representing reason of bugreport failure.
399      *
400      * @see #EXTRA_BUGREPORT_FAILURE_REASON
401      * @hide
402      */
403     @Retention(RetentionPolicy.SOURCE)
404     @IntDef(prefix = { "BUGREPORT_FAILURE_" }, value = {
405             BUGREPORT_FAILURE_FAILED_COMPLETING,
406             BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE
407     })
408     public @interface BugreportFailureCode {}
409 
410     /**
411      * Bugreport completion process failed.
412      *
413      * <p>If this error code is received, the requesting of bugreport can be retried.
414      * @see DevicePolicyManager#requestBugreport
415      */
416     public static final int BUGREPORT_FAILURE_FAILED_COMPLETING = 0;
417 
418     /**
419      * Bugreport has been created, but is no longer available for collection.
420      *
421      * <p>This error likely occurs because the user of the device hasn't consented to share
422      * the bugreport for a long period after its creation.
423      *
424      * <p>If this error code is received, the requesting of bugreport can be retried.
425      * @see DevicePolicyManager#requestBugreport
426      */
427     public static final int BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE = 1;
428 
429     /**
430      * Broadcast action: notify that some app is attempting to choose a KeyChain key.
431      * @see DeviceAdminReceiver#onChoosePrivateKeyAlias
432      * @see DelegatedAdminReceiver#onChoosePrivateKeyAlias
433      */
434     public static final String ACTION_CHOOSE_PRIVATE_KEY_ALIAS =
435             "android.app.action.CHOOSE_PRIVATE_KEY_ALIAS";
436 
437     /** @hide */
438     public static final String EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID =
439             "android.app.extra.CHOOSE_PRIVATE_KEY_SENDER_UID";
440 
441     /** @hide */
442     public static final String EXTRA_CHOOSE_PRIVATE_KEY_URI =
443             "android.app.extra.CHOOSE_PRIVATE_KEY_URI";
444 
445     /** @hide */
446     public static final String EXTRA_CHOOSE_PRIVATE_KEY_ALIAS =
447             "android.app.extra.CHOOSE_PRIVATE_KEY_ALIAS";
448 
449     /** @hide */
450     public static final String EXTRA_CHOOSE_PRIVATE_KEY_RESPONSE =
451             "android.app.extra.CHOOSE_PRIVATE_KEY_RESPONSE";
452 
453     /**
454      * Broadcast action: notify device owner that there is a pending system update.
455      * @hide
456      */
457     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
458     @BroadcastBehavior(explicitOnly = true)
459     public static final String ACTION_NOTIFY_PENDING_SYSTEM_UPDATE =
460             "android.app.action.NOTIFY_PENDING_SYSTEM_UPDATE";
461 
462     /**
463      * A long type extra for {@link #onSystemUpdatePending} recording the system time as given by
464      * {@link System#currentTimeMillis()} when the current pending system update is first available.
465      * @hide
466      */
467     public static final String EXTRA_SYSTEM_UPDATE_RECEIVED_TIME =
468             "android.app.extra.SYSTEM_UPDATE_RECEIVED_TIME";
469 
470     /**
471      * Name under which a DevicePolicy component publishes information
472      * about itself.  This meta-data must reference an XML resource containing
473      * a device-admin tag.
474      */
475     //  TO DO: describe syntax.
476     public static final String DEVICE_ADMIN_META_DATA = "android.app.device_admin";
477 
478     /**
479      * Broadcast action: notify the newly transferred administrator that the transfer
480      * from the original administrator was successful.
481      *
482      * @hide
483      */
484     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
485     public static final String ACTION_TRANSFER_OWNERSHIP_COMPLETE =
486             "android.app.action.TRANSFER_OWNERSHIP_COMPLETE";
487 
488     /**
489      * Broadcast action: notify the device owner that the ownership of one of its affiliated
490      * profiles is transferred.
491      *
492      * @hide
493      */
494     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
495     public static final String ACTION_AFFILIATED_PROFILE_TRANSFER_OWNERSHIP_COMPLETE =
496             "android.app.action.AFFILIATED_PROFILE_TRANSFER_OWNERSHIP_COMPLETE";
497 
498     /**
499      * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
500      * allows a mobile device management application to pass data to the management application
501      * instance after owner transfer.
502      *
503      * <p>If the transfer is successful, the new owner receives the data in
504      * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}.
505      * The bundle is not changed during the ownership transfer.
506      *
507      * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
508      */
509     public static final String EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE =
510             "android.app.extra.TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE";
511 
512     private DevicePolicyManager mManager;
513     private ComponentName mWho;
514 
515     /**
516      * Retrieve the DevicePolicyManager interface for this administrator to work
517      * with the system.
518      */
getManager(@onNull Context context)519     public @NonNull DevicePolicyManager getManager(@NonNull Context context) {
520         if (mManager != null) {
521             return mManager;
522         }
523         mManager = (DevicePolicyManager)context.getSystemService(
524                 Context.DEVICE_POLICY_SERVICE);
525         return mManager;
526     }
527 
528     /**
529      * Retrieve the ComponentName describing who this device administrator is, for
530      * use in {@link DevicePolicyManager} APIs that require the administrator to
531      * identify itself.
532      */
getWho(@onNull Context context)533     public @NonNull ComponentName getWho(@NonNull Context context) {
534         if (mWho != null) {
535             return mWho;
536         }
537         mWho = new ComponentName(context, getClass());
538         return mWho;
539     }
540 
541     /**
542      * Called after the administrator is first enabled, as a result of
543      * receiving {@link #ACTION_DEVICE_ADMIN_ENABLED}.  At this point you
544      * can use {@link DevicePolicyManager} to set your desired policies.
545      *
546      * <p> If the admin is activated by a device owner, then the intent
547      * may contain private extras that are relevant to user setup.
548      * {@see DevicePolicyManager#createAndManageUser(ComponentName, String, ComponentName,
549      *      PersistableBundle, int)}
550      *
551      * @param context The running context as per {@link #onReceive}.
552      * @param intent The received intent as per {@link #onReceive}.
553      */
onEnabled(@onNull Context context, @NonNull Intent intent)554     public void onEnabled(@NonNull Context context, @NonNull Intent intent) {
555     }
556 
557     /**
558      * Called when the user has asked to disable the administrator, as a result of
559      * receiving {@link #ACTION_DEVICE_ADMIN_DISABLE_REQUESTED}, giving you
560      * a chance to present a warning message to them.  The message is returned
561      * as the result; if null is returned (the default implementation), no
562      * message will be displayed.
563      * @param context The running context as per {@link #onReceive}.
564      * @param intent The received intent as per {@link #onReceive}.
565      * @return Return the warning message to display to the user before
566      * being disabled; if null is returned, no message is displayed.
567      */
onDisableRequested(@onNull Context context, @NonNull Intent intent)568     public @Nullable CharSequence onDisableRequested(@NonNull Context context,
569             @NonNull Intent intent) {
570         return null;
571     }
572 
573     /**
574      * Called prior to the administrator being disabled, as a result of
575      * receiving {@link #ACTION_DEVICE_ADMIN_DISABLED}.  Upon return, you
576      * can no longer use the protected parts of the {@link DevicePolicyManager}
577      * API.
578      * @param context The running context as per {@link #onReceive}.
579      * @param intent The received intent as per {@link #onReceive}.
580      */
onDisabled(@onNull Context context, @NonNull Intent intent)581     public void onDisabled(@NonNull Context context, @NonNull Intent intent) {
582     }
583 
584     /**
585      * Called after the user has changed their device or profile challenge password, as a result of
586      * receiving {@link #ACTION_PASSWORD_CHANGED}.  At this point you
587      * can use {@link DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
588      * to retrieve the active password characteristics.
589      * @param context The running context as per {@link #onReceive}.
590      * @param intent The received intent as per {@link #onReceive}.
591      *
592      * @deprecated From {@link android.os.Build.VERSION_CODES#O}, use
593      *             {@link #onPasswordChanged(Context, Intent, UserHandle)} instead.
594      */
595     @Deprecated
onPasswordChanged(@onNull Context context, @NonNull Intent intent)596     public void onPasswordChanged(@NonNull Context context, @NonNull Intent intent) {
597     }
598 
599     /**
600      * Called after the user has changed their device or profile challenge password, as a result of
601      * receiving {@link #ACTION_PASSWORD_CHANGED}.  At this point you
602      * can use {@link DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
603      * to retrieve the active password characteristics.
604      * @param context The running context as per {@link #onReceive}.
605      * @param intent The received intent as per {@link #onReceive}.
606      * @param user The user or profile for whom the password changed. To see whether this
607      *        user is the current profile or a parent user, check for equality with
608      *        {@link Process#myUserHandle}.
609      */
onPasswordChanged(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle user)610     public void onPasswordChanged(@NonNull Context context, @NonNull Intent intent,
611             @NonNull UserHandle user) {
612         onPasswordChanged(context, intent);
613     }
614 
615     /**
616      * Called after the user has failed at entering their device or profile challenge password,
617      * as a result of receiving {@link #ACTION_PASSWORD_FAILED}.  At this point you can use
618      * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts()} to retrieve the number of
619      * failed password attempts.
620      * @param context The running context as per {@link #onReceive}.
621      * @param intent The received intent as per {@link #onReceive}.
622      *
623      * @deprecated From {@link android.os.Build.VERSION_CODES#O}, use
624      *             {@link #onPasswordFailed(Context, Intent, UserHandle)} instead.
625      */
626     @Deprecated
onPasswordFailed(@onNull Context context, @NonNull Intent intent)627     public void onPasswordFailed(@NonNull Context context, @NonNull Intent intent) {
628     }
629 
630     /**
631      * Called after the user has failed at entering their device or profile challenge password,
632      * as a result of receiving {@link #ACTION_PASSWORD_FAILED}.  At this point you can use
633      * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts()} to retrieve the number of
634      * failed password attempts.
635      * @param context The running context as per {@link #onReceive}.
636      * @param intent The received intent as per {@link #onReceive}.
637      * @param user The user or profile for whom the password check failed. To see whether this
638      *        user is the current profile or a parent user, check for equality with
639      *        {@link Process#myUserHandle}.
640      */
onPasswordFailed(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle user)641     public void onPasswordFailed(@NonNull Context context, @NonNull Intent intent,
642             @NonNull UserHandle user) {
643         onPasswordFailed(context, intent);
644     }
645 
646     /**
647      * Called after the user has succeeded at entering their device or profile challenge password,
648      * as a result of receiving {@link #ACTION_PASSWORD_SUCCEEDED}.  This will
649      * only be received the first time they succeed after having previously
650      * failed.
651      * @param context The running context as per {@link #onReceive}.
652      * @param intent The received intent as per {@link #onReceive}.
653      *
654      * @deprecated From {@link android.os.Build.VERSION_CODES#O}, use
655      *             {@link #onPasswordSucceeded(Context, Intent, UserHandle)} instead.
656      */
657     @Deprecated
onPasswordSucceeded(@onNull Context context, @NonNull Intent intent)658     public void onPasswordSucceeded(@NonNull Context context, @NonNull Intent intent) {
659     }
660 
661     /**
662      * Called after the user has succeeded at entering their device or profile challenge password,
663      * as a result of receiving {@link #ACTION_PASSWORD_SUCCEEDED}.  This will
664      * only be received the first time they succeed after having previously
665      * failed.
666      * @param context The running context as per {@link #onReceive}.
667      * @param intent The received intent as per {@link #onReceive}.
668      * @param user The user of profile for whom the password check succeeded.  To see whether this
669      *        user is the current profile or a parent user, check for equality with
670      *        {@link Process#myUserHandle}.
671      */
onPasswordSucceeded(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle user)672     public void onPasswordSucceeded(@NonNull Context context, @NonNull Intent intent,
673             @NonNull UserHandle user) {
674         onPasswordSucceeded(context, intent);
675     }
676 
677     /**
678      * Called periodically when the device or profile challenge password is about to expire
679      * or has expired.  It will typically be called at these times: on device boot, once per day
680      * before the password expires, and at the time when the password expires.
681      *
682      * <p>If the password is not updated by the user, this method will continue to be called
683      * once per day until the password is changed or the device admin disables password expiration.
684      *
685      * <p>The admin will typically post a notification requesting the user to change their password
686      * in response to this call. The actual password expiration time can be obtained by calling
687      * {@link DevicePolicyManager#getPasswordExpiration(ComponentName) }
688      *
689      * <p>The admin should be sure to take down any notifications it posted in response to this call
690      * when it receives {@link DeviceAdminReceiver#onPasswordChanged(Context, Intent) }.
691      *
692      * @param context The running context as per {@link #onReceive}.
693      * @param intent The received intent as per {@link #onReceive}.
694      *
695      * @deprecated From {@link android.os.Build.VERSION_CODES#O}, use
696      *             {@link #onPasswordExpiring(Context, Intent, UserHandle)} instead.
697      */
698     @Deprecated
onPasswordExpiring(@onNull Context context, @NonNull Intent intent)699     public void onPasswordExpiring(@NonNull Context context, @NonNull Intent intent) {
700     }
701 
702     /**
703      * Called periodically when the device or profile challenge password is about to expire
704      * or has expired.  It will typically be called at these times: on device boot, once per day
705      * before the password expires, and at the time when the password expires.
706      *
707      * <p>If the password is not updated by the user, this method will continue to be called
708      * once per day until the password is changed or the device admin disables password expiration.
709      *
710      * <p>The admin will typically post a notification requesting the user to change their password
711      * in response to this call. The actual password expiration time can be obtained by calling
712      * {@link DevicePolicyManager#getPasswordExpiration(ComponentName) }
713      *
714      * <p>The admin should be sure to take down any notifications it posted in response to this call
715      * when it receives {@link DeviceAdminReceiver#onPasswordChanged(Context, Intent, UserHandle) }.
716      *
717      * @param context The running context as per {@link #onReceive}.
718      * @param intent The received intent as per {@link #onReceive}.
719      * @param user The user or profile for whom the password is expiring. To see whether this
720      *        user is the current profile or a parent user, check for equality with
721      *        {@link Process#myUserHandle}.
722      */
onPasswordExpiring(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle user)723     public void onPasswordExpiring(@NonNull Context context, @NonNull Intent intent,
724             @NonNull UserHandle user) {
725         onPasswordExpiring(context, intent);
726     }
727 
728     /**
729      * Called when provisioning of a managed profile or managed device has completed successfully.
730      *
731      * <p> As a prerequisite for the execution of this callback the {@link DeviceAdminReceiver} has
732      * to declare an intent filter for {@link #ACTION_PROFILE_PROVISIONING_COMPLETE}.
733      * Its component must also be specified in the {@link DevicePolicyManager#EXTRA_DEVICE_ADMIN}
734      * of the {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} intent that started the
735      * managed provisioning.
736      *
737      * <p>When provisioning of a managed profile is complete, the managed profile is hidden until
738      * the profile owner calls {@link DevicePolicyManager#setProfileEnabled(ComponentName admin)}.
739      * Typically a profile owner will enable the profile when it has finished any additional setup
740      * such as adding an account by using the {@link AccountManager} and calling APIs to bring the
741      * profile into the desired state.
742      *
743      * <p> Note that provisioning completes without waiting for any server interactions, so the
744      * profile owner needs to wait for data to be available if required (e.g. Android device IDs or
745      * other data that is set as a result of server interactions).
746      *
747      * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
748      * completed, along with this callback the activity intent
749      * {@link DevicePolicyManager#ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the same
750      * application.
751      *
752      * @param context The running context as per {@link #onReceive}.
753      * @param intent The received intent as per {@link #onReceive}.
754      */
onProfileProvisioningComplete(@onNull Context context, @NonNull Intent intent)755     public void onProfileProvisioningComplete(@NonNull Context context, @NonNull Intent intent) {
756     }
757 
758     /**
759      * Called during provisioning of a managed device to allow the device initializer to perform
760      * user setup steps.
761      *
762      * @param context The running context as per {@link #onReceive}.
763      * @param intent The received intent as per {@link #onReceive}.
764      * @deprecated Do not use
765      */
766     @Deprecated
onReadyForUserInitialization(@onNull Context context, @NonNull Intent intent)767     public void onReadyForUserInitialization(@NonNull Context context, @NonNull Intent intent) {
768     }
769 
770     /**
771      * Called when a device is entering lock task mode.
772      *
773      * @param context The running context as per {@link #onReceive}.
774      * @param intent The received intent as per {@link #onReceive}.
775      * @param pkg The authorized package using lock task mode.
776      */
onLockTaskModeEntering(@onNull Context context, @NonNull Intent intent, @NonNull String pkg)777     public void onLockTaskModeEntering(@NonNull Context context, @NonNull Intent intent,
778             @NonNull String pkg) {
779     }
780 
781     /**
782      * Called when a device is exiting lock task mode.
783      *
784      * @param context The running context as per {@link #onReceive}.
785      * @param intent The received intent as per {@link #onReceive}.
786      */
onLockTaskModeExiting(@onNull Context context, @NonNull Intent intent)787     public void onLockTaskModeExiting(@NonNull Context context, @NonNull Intent intent) {
788     }
789 
790     /**
791      * Allows this receiver to select the alias for a private key and certificate pair for
792      * authentication. If this method returns null, the default {@link android.app.Activity} will be
793      * shown that lets the user pick a private key and certificate pair.
794      *
795      * @param context The running context as per {@link #onReceive}.
796      * @param intent The received intent as per {@link #onReceive}.
797      * @param uid The uid of the app asking for the private key and certificate pair.
798      * @param uri The URI to authenticate, may be null.
799      * @param alias The alias preselected by the client, or null.
800      * @return The private key alias to return and grant access to.
801      * @see KeyChain#choosePrivateKeyAlias
802      */
onChoosePrivateKeyAlias(@onNull Context context, @NonNull Intent intent, int uid, @Nullable Uri uri, @Nullable String alias)803     public @Nullable String onChoosePrivateKeyAlias(@NonNull Context context,
804             @NonNull Intent intent, int uid, @Nullable Uri uri, @Nullable String alias) {
805         return null;
806     }
807 
808     /**
809      * Called when the information about a pending system update is available.
810      *
811      * <p>Allows the receiver to be notified when information about a pending system update is
812      * available from the system update service. The same pending system update can trigger multiple
813      * calls to this method, so it is necessary to examine the incoming parameters for details about
814      * the update.
815      *
816      * <p>This callback is only applicable to device owners and profile owners.
817      *
818      * <p>To get further information about a pending system update (for example, whether or not the
819      * update is a security patch), the device owner or profile owner can call
820      * {@link DevicePolicyManager#getPendingSystemUpdate}.
821      *
822      * @param context The running context as per {@link #onReceive}.
823      * @param intent The received intent as per {@link #onReceive}.
824      * @param receivedTime The time as given by {@link System#currentTimeMillis()} indicating when
825      *        the current pending update was first available. -1 if no pending update is available.
826      * @see DevicePolicyManager#getPendingSystemUpdate
827      */
onSystemUpdatePending(@onNull Context context, @NonNull Intent intent, long receivedTime)828     public void onSystemUpdatePending(@NonNull Context context, @NonNull Intent intent,
829             long receivedTime) {
830     }
831 
832     /**
833      * Called when sharing a bugreport has been cancelled by the user of the device.
834      *
835      * <p>This callback is only applicable to device owners.
836      *
837      * @param context The running context as per {@link #onReceive}.
838      * @param intent The received intent as per {@link #onReceive}.
839      * @see DevicePolicyManager#requestBugreport
840      */
onBugreportSharingDeclined(@onNull Context context, @NonNull Intent intent)841     public void onBugreportSharingDeclined(@NonNull Context context, @NonNull Intent intent) {
842     }
843 
844     /**
845      * Called when the bugreport has been shared with the device administrator app.
846      *
847      * <p>This callback is only applicable to device owners.
848      *
849      * @param context The running context as per {@link #onReceive}.
850      * @param intent The received intent as per {@link #onReceive}. Contains the URI of
851      * the bugreport file (with MIME type "application/vnd.android.bugreport"), that can be accessed
852      * by calling {@link Intent#getData()}
853      * @param bugreportHash SHA-256 hash of the bugreport file.
854      * @see DevicePolicyManager#requestBugreport
855      */
onBugreportShared(@onNull Context context, @NonNull Intent intent, @NonNull String bugreportHash)856     public void onBugreportShared(@NonNull Context context, @NonNull Intent intent,
857             @NonNull String bugreportHash) {
858     }
859 
860     /**
861      * Called when the bugreport collection flow has failed.
862      *
863      * <p>This callback is only applicable to device owners.
864      *
865      * @param context The running context as per {@link #onReceive}.
866      * @param intent The received intent as per {@link #onReceive}.
867      * @param failureCode int containing failure code. One of
868      * {@link #BUGREPORT_FAILURE_FAILED_COMPLETING}
869      * or {@link #BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE}
870      * @see DevicePolicyManager#requestBugreport
871      */
onBugreportFailed(@onNull Context context, @NonNull Intent intent, @BugreportFailureCode int failureCode)872     public void onBugreportFailed(@NonNull Context context, @NonNull Intent intent,
873             @BugreportFailureCode int failureCode) {
874     }
875 
876     /**
877      * Called when a new batch of security logs can be retrieved.
878      *
879      * <p>If a secondary user or profile is created, this callback won't be received until all users
880      * become affiliated again (even if security logging is enabled).
881      * See {@link DevicePolicyManager#setAffiliationIds}
882      *
883      * <p>This callback will be re-triggered if the logs are not retrieved.
884      *
885      * <p>This callback is only applicable to device owners.
886      *
887      * @param context The running context as per {@link #onReceive}.
888      * @param intent The received intent as per {@link #onReceive}.
889      * @see DevicePolicyManager#retrieveSecurityLogs(ComponentName)
890      */
onSecurityLogsAvailable(@onNull Context context, @NonNull Intent intent)891     public void onSecurityLogsAvailable(@NonNull Context context, @NonNull Intent intent) {
892     }
893 
894     /**
895      * Called each time a new batch of network logs can be retrieved. This callback method will only
896      * ever be called when network logging is enabled. The logs can only be retrieved while network
897      * logging is enabled.
898      *
899      * <p>If a secondary user or profile is created, this callback won't be received until all users
900      * become affiliated again (even if network logging is enabled). It will also no longer be
901      * possible to retrieve the network logs batch with the most recent {@code batchToken} provided
902      * by this callback. See {@link DevicePolicyManager#setAffiliationIds}.
903      *
904      * <p>This callback is only applicable to device owners.
905      *
906      * @param context The running context as per {@link #onReceive}.
907      * @param intent The received intent as per {@link #onReceive}.
908      * @param batchToken The token representing the current batch of network logs.
909      * @param networkLogsCount The total count of events in the current batch of network logs.
910      * @see DevicePolicyManager#retrieveNetworkLogs
911      */
onNetworkLogsAvailable(@onNull Context context, @NonNull Intent intent, long batchToken, @IntRange(from = 1) int networkLogsCount)912     public void onNetworkLogsAvailable(@NonNull Context context, @NonNull Intent intent,
913             long batchToken, @IntRange(from = 1) int networkLogsCount) {
914     }
915 
916     /**
917      * Called when a user or profile is created.
918      *
919      * <p>This callback is only applicable to device owners.
920      *
921      * @param context The running context as per {@link #onReceive}.
922      * @param intent The received intent as per {@link #onReceive}.
923      * @param newUser The {@link UserHandle} of the user that has just been added.
924      */
onUserAdded(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle newUser)925     public void onUserAdded(@NonNull Context context, @NonNull Intent intent,
926             @NonNull UserHandle newUser) {
927     }
928 
929     /**
930      * Called when a user or profile is removed.
931      *
932      * <p>This callback is only applicable to device owners.
933      *
934      * @param context The running context as per {@link #onReceive}.
935      * @param intent The received intent as per {@link #onReceive}.
936      * @param removedUser The {@link UserHandle} of the user that has just been removed.
937      */
onUserRemoved(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle removedUser)938     public void onUserRemoved(@NonNull Context context, @NonNull Intent intent,
939             @NonNull UserHandle removedUser) {
940     }
941 
942     /**
943      * Called when a user or profile is started.
944      *
945      * <p>This callback is only applicable to device owners.
946      *
947      * @param context The running context as per {@link #onReceive}.
948      * @param intent The received intent as per {@link #onReceive}.
949      * @param startedUser The {@link UserHandle} of the user that has just been started.
950      */
onUserStarted(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle startedUser)951     public void onUserStarted(@NonNull Context context, @NonNull Intent intent,
952             @NonNull UserHandle startedUser) {
953     }
954 
955     /**
956      * Called when a user or profile is stopped.
957      *
958      * <p>This callback is only applicable to device owners.
959      *
960      * @param context The running context as per {@link #onReceive}.
961      * @param intent The received intent as per {@link #onReceive}.
962      * @param stoppedUser The {@link UserHandle} of the user that has just been stopped.
963      */
onUserStopped(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle stoppedUser)964     public void onUserStopped(@NonNull Context context, @NonNull Intent intent,
965             @NonNull UserHandle stoppedUser) {
966     }
967 
968     /**
969      * Called when a user or profile is switched to.
970      *
971      * <p>This callback is only applicable to device owners.
972      *
973      * @param context The running context as per {@link #onReceive}.
974      * @param intent The received intent as per {@link #onReceive}.
975      * @param switchedUser The {@link UserHandle} of the user that has just been switched to.
976      */
onUserSwitched(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle switchedUser)977     public void onUserSwitched(@NonNull Context context, @NonNull Intent intent,
978             @NonNull UserHandle switchedUser) {
979     }
980 
981     /**
982      * Called on the newly assigned owner (either device owner or profile owner) when the ownership
983      * transfer has completed successfully.
984      *
985      * <p> The {@code bundle} parameter allows the original owner to pass data
986      * to the new one.
987      *
988      * @param context the running context as per {@link #onReceive}
989      * @param bundle the data to be passed to the new owner
990      */
onTransferOwnershipComplete(@onNull Context context, @Nullable PersistableBundle bundle)991     public void onTransferOwnershipComplete(@NonNull Context context,
992             @Nullable PersistableBundle bundle) {
993     }
994 
995     /**
996      * Called on the device owner when the ownership of one of its affiliated profiles is
997      * transferred.
998      *
999      * <p>This can be used when transferring both device and profile ownership when using
1000      * work profile on a fully managed device. The process would look like this:
1001      * <ol>
1002      * <li>Transfer profile ownership</li>
1003      * <li>The device owner gets notified with this callback</li>
1004      * <li>Transfer device ownership</li>
1005      * <li>Both profile and device ownerships have been transferred</li>
1006      * </ol>
1007      *
1008      * @param context the running context as per {@link #onReceive}
1009      * @param user the {@link UserHandle} of the affiliated user
1010      * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
1011      */
onTransferAffiliatedProfileOwnershipComplete(@onNull Context context, @NonNull UserHandle user)1012     public void onTransferAffiliatedProfileOwnershipComplete(@NonNull Context context,
1013             @NonNull UserHandle user) {
1014     }
1015 
1016     /**
1017      * Intercept standard device administrator broadcasts.  Implementations
1018      * should not override this method; it is better to implement the
1019      * convenience callbacks for each action.
1020      */
1021     @Override
onReceive(@onNull Context context, @NonNull Intent intent)1022     public void onReceive(@NonNull Context context, @NonNull Intent intent) {
1023         String action = intent.getAction();
1024 
1025         if (ACTION_PASSWORD_CHANGED.equals(action)) {
1026             onPasswordChanged(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1027         } else if (ACTION_PASSWORD_FAILED.equals(action)) {
1028             onPasswordFailed(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1029         } else if (ACTION_PASSWORD_SUCCEEDED.equals(action)) {
1030             onPasswordSucceeded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1031         } else if (ACTION_DEVICE_ADMIN_ENABLED.equals(action)) {
1032             onEnabled(context, intent);
1033         } else if (ACTION_DEVICE_ADMIN_DISABLE_REQUESTED.equals(action)) {
1034             CharSequence res = onDisableRequested(context, intent);
1035             if (res != null) {
1036                 Bundle extras = getResultExtras(true);
1037                 extras.putCharSequence(EXTRA_DISABLE_WARNING, res);
1038             }
1039         } else if (ACTION_DEVICE_ADMIN_DISABLED.equals(action)) {
1040             onDisabled(context, intent);
1041         } else if (ACTION_PASSWORD_EXPIRING.equals(action)) {
1042             onPasswordExpiring(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1043         } else if (ACTION_PROFILE_PROVISIONING_COMPLETE.equals(action)) {
1044             onProfileProvisioningComplete(context, intent);
1045         } else if (ACTION_CHOOSE_PRIVATE_KEY_ALIAS.equals(action)) {
1046             int uid = intent.getIntExtra(EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, -1);
1047             Uri uri = intent.getParcelableExtra(EXTRA_CHOOSE_PRIVATE_KEY_URI);
1048             String alias = intent.getStringExtra(EXTRA_CHOOSE_PRIVATE_KEY_ALIAS);
1049             String chosenAlias = onChoosePrivateKeyAlias(context, intent, uid, uri, alias);
1050             setResultData(chosenAlias);
1051         } else if (ACTION_LOCK_TASK_ENTERING.equals(action)) {
1052             String pkg = intent.getStringExtra(EXTRA_LOCK_TASK_PACKAGE);
1053             onLockTaskModeEntering(context, intent, pkg);
1054         } else if (ACTION_LOCK_TASK_EXITING.equals(action)) {
1055             onLockTaskModeExiting(context, intent);
1056         } else if (ACTION_NOTIFY_PENDING_SYSTEM_UPDATE.equals(action)) {
1057             long receivedTime = intent.getLongExtra(EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, -1);
1058             onSystemUpdatePending(context, intent, receivedTime);
1059         } else if (ACTION_BUGREPORT_SHARING_DECLINED.equals(action)) {
1060             onBugreportSharingDeclined(context, intent);
1061         } else if (ACTION_BUGREPORT_SHARE.equals(action)) {
1062             String bugreportFileHash = intent.getStringExtra(EXTRA_BUGREPORT_HASH);
1063             onBugreportShared(context, intent, bugreportFileHash);
1064         } else if (ACTION_BUGREPORT_FAILED.equals(action)) {
1065             int failureCode = intent.getIntExtra(EXTRA_BUGREPORT_FAILURE_REASON,
1066                     BUGREPORT_FAILURE_FAILED_COMPLETING);
1067             onBugreportFailed(context, intent, failureCode);
1068         } else if (ACTION_SECURITY_LOGS_AVAILABLE.equals(action)) {
1069             onSecurityLogsAvailable(context, intent);
1070         } else if (ACTION_NETWORK_LOGS_AVAILABLE.equals(action)) {
1071             long batchToken = intent.getLongExtra(EXTRA_NETWORK_LOGS_TOKEN, -1);
1072             int networkLogsCount = intent.getIntExtra(EXTRA_NETWORK_LOGS_COUNT, 0);
1073             onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount);
1074         } else if (ACTION_USER_ADDED.equals(action)) {
1075             onUserAdded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1076         } else if (ACTION_USER_REMOVED.equals(action)) {
1077             onUserRemoved(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1078         } else if (ACTION_USER_STARTED.equals(action)) {
1079             onUserStarted(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1080         } else if (ACTION_USER_STOPPED.equals(action)) {
1081             onUserStopped(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1082         } else if (ACTION_USER_SWITCHED.equals(action)) {
1083             onUserSwitched(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1084         } else if (ACTION_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
1085             PersistableBundle bundle =
1086                     intent.getParcelableExtra(EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE);
1087             onTransferOwnershipComplete(context, bundle);
1088         } else if (ACTION_AFFILIATED_PROFILE_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
1089             onTransferAffiliatedProfileOwnershipComplete(context,
1090                     intent.getParcelableExtra(Intent.EXTRA_USER));
1091         }
1092     }
1093 }
1094