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      * If this method returns {@link KeyChain#KEY_ALIAS_SELECTION_DENIED},
795      * the default {@link android.app.Activity} will not be shown and the user will not be allowed
796      * to pick anything. And the app, that called {@link KeyChain#choosePrivateKeyAlias}, will
797      * receive {@code null} back.
798      *
799      * @param context The running context as per {@link #onReceive}.
800      * @param intent The received intent as per {@link #onReceive}.
801      * @param uid The uid of the app asking for the private key and certificate pair.
802      * @param uri The URI to authenticate, may be null.
803      * @param alias The alias preselected by the client, or null.
804      * @return The private key alias to return and grant access to.
805      * @see KeyChain#choosePrivateKeyAlias
806      */
onChoosePrivateKeyAlias(@onNull Context context, @NonNull Intent intent, int uid, @Nullable Uri uri, @Nullable String alias)807     public @Nullable String onChoosePrivateKeyAlias(@NonNull Context context,
808             @NonNull Intent intent, int uid, @Nullable Uri uri, @Nullable String alias) {
809         return null;
810     }
811 
812     /**
813      * Called when the information about a pending system update is available.
814      *
815      * <p>Allows the receiver to be notified when information about a pending system update is
816      * available from the system update service. The same pending system update can trigger multiple
817      * calls to this method, so it is necessary to examine the incoming parameters for details about
818      * the update.
819      *
820      * <p>This callback is only applicable to device owners and profile owners.
821      *
822      * <p>To get further information about a pending system update (for example, whether or not the
823      * update is a security patch), the device owner or profile owner can call
824      * {@link DevicePolicyManager#getPendingSystemUpdate}.
825      *
826      * @param context The running context as per {@link #onReceive}.
827      * @param intent The received intent as per {@link #onReceive}.
828      * @param receivedTime The time as given by {@link System#currentTimeMillis()} indicating when
829      *        the current pending update was first available. -1 if no pending update is available.
830      * @see DevicePolicyManager#getPendingSystemUpdate
831      */
onSystemUpdatePending(@onNull Context context, @NonNull Intent intent, long receivedTime)832     public void onSystemUpdatePending(@NonNull Context context, @NonNull Intent intent,
833             long receivedTime) {
834     }
835 
836     /**
837      * Called when sharing a bugreport has been cancelled by the user of the device.
838      *
839      * <p>This callback is only applicable to device owners.
840      *
841      * @param context The running context as per {@link #onReceive}.
842      * @param intent The received intent as per {@link #onReceive}.
843      * @see DevicePolicyManager#requestBugreport
844      */
onBugreportSharingDeclined(@onNull Context context, @NonNull Intent intent)845     public void onBugreportSharingDeclined(@NonNull Context context, @NonNull Intent intent) {
846     }
847 
848     /**
849      * Called when the bugreport has been shared with the device administrator app.
850      *
851      * <p>This callback is only applicable to device owners.
852      *
853      * @param context The running context as per {@link #onReceive}.
854      * @param intent The received intent as per {@link #onReceive}. Contains the URI of
855      * the bugreport file (with MIME type "application/vnd.android.bugreport"), that can be accessed
856      * by calling {@link Intent#getData()}
857      * @param bugreportHash SHA-256 hash of the bugreport file.
858      * @see DevicePolicyManager#requestBugreport
859      */
onBugreportShared(@onNull Context context, @NonNull Intent intent, @NonNull String bugreportHash)860     public void onBugreportShared(@NonNull Context context, @NonNull Intent intent,
861             @NonNull String bugreportHash) {
862     }
863 
864     /**
865      * Called when the bugreport collection flow has failed.
866      *
867      * <p>This callback is only applicable to device owners.
868      *
869      * @param context The running context as per {@link #onReceive}.
870      * @param intent The received intent as per {@link #onReceive}.
871      * @param failureCode int containing failure code. One of
872      * {@link #BUGREPORT_FAILURE_FAILED_COMPLETING}
873      * or {@link #BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE}
874      * @see DevicePolicyManager#requestBugreport
875      */
onBugreportFailed(@onNull Context context, @NonNull Intent intent, @BugreportFailureCode int failureCode)876     public void onBugreportFailed(@NonNull Context context, @NonNull Intent intent,
877             @BugreportFailureCode int failureCode) {
878     }
879 
880     /**
881      * Called when a new batch of security logs can be retrieved.
882      *
883      * <p>If a secondary user or profile is created, this callback won't be received until all users
884      * become affiliated again (even if security logging is enabled).
885      * See {@link DevicePolicyManager#setAffiliationIds}
886      *
887      * <p>This callback will be re-triggered if the logs are not retrieved.
888      *
889      * <p>This callback is only applicable to device owners.
890      *
891      * @param context The running context as per {@link #onReceive}.
892      * @param intent The received intent as per {@link #onReceive}.
893      * @see DevicePolicyManager#retrieveSecurityLogs(ComponentName)
894      */
onSecurityLogsAvailable(@onNull Context context, @NonNull Intent intent)895     public void onSecurityLogsAvailable(@NonNull Context context, @NonNull Intent intent) {
896     }
897 
898     /**
899      * Called each time a new batch of network logs can be retrieved. This callback method will only
900      * ever be called when network logging is enabled. The logs can only be retrieved while network
901      * logging is enabled.
902      *
903      * <p>If a secondary user or profile is created, this callback won't be received until all users
904      * become affiliated again (even if network logging is enabled). It will also no longer be
905      * possible to retrieve the network logs batch with the most recent {@code batchToken} provided
906      * by this callback. See {@link DevicePolicyManager#setAffiliationIds}.
907      *
908      * <p>This callback is only applicable to device owners.
909      *
910      * @param context The running context as per {@link #onReceive}.
911      * @param intent The received intent as per {@link #onReceive}.
912      * @param batchToken The token representing the current batch of network logs.
913      * @param networkLogsCount The total count of events in the current batch of network logs.
914      * @see DevicePolicyManager#retrieveNetworkLogs
915      */
onNetworkLogsAvailable(@onNull Context context, @NonNull Intent intent, long batchToken, @IntRange(from = 1) int networkLogsCount)916     public void onNetworkLogsAvailable(@NonNull Context context, @NonNull Intent intent,
917             long batchToken, @IntRange(from = 1) int networkLogsCount) {
918     }
919 
920     /**
921      * Called when a user or profile is created.
922      *
923      * <p>This callback is only applicable to device owners.
924      *
925      * @param context The running context as per {@link #onReceive}.
926      * @param intent The received intent as per {@link #onReceive}.
927      * @param newUser The {@link UserHandle} of the user that has just been added.
928      */
onUserAdded(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle newUser)929     public void onUserAdded(@NonNull Context context, @NonNull Intent intent,
930             @NonNull UserHandle newUser) {
931     }
932 
933     /**
934      * Called when a user or profile is removed.
935      *
936      * <p>This callback is only applicable to device owners.
937      *
938      * @param context The running context as per {@link #onReceive}.
939      * @param intent The received intent as per {@link #onReceive}.
940      * @param removedUser The {@link UserHandle} of the user that has just been removed.
941      */
onUserRemoved(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle removedUser)942     public void onUserRemoved(@NonNull Context context, @NonNull Intent intent,
943             @NonNull UserHandle removedUser) {
944     }
945 
946     /**
947      * Called when a user or profile is started.
948      *
949      * <p>This callback is only applicable to device owners.
950      *
951      * @param context The running context as per {@link #onReceive}.
952      * @param intent The received intent as per {@link #onReceive}.
953      * @param startedUser The {@link UserHandle} of the user that has just been started.
954      */
onUserStarted(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle startedUser)955     public void onUserStarted(@NonNull Context context, @NonNull Intent intent,
956             @NonNull UserHandle startedUser) {
957     }
958 
959     /**
960      * Called when a user or profile is stopped.
961      *
962      * <p>This callback is only applicable to device owners.
963      *
964      * @param context The running context as per {@link #onReceive}.
965      * @param intent The received intent as per {@link #onReceive}.
966      * @param stoppedUser The {@link UserHandle} of the user that has just been stopped.
967      */
onUserStopped(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle stoppedUser)968     public void onUserStopped(@NonNull Context context, @NonNull Intent intent,
969             @NonNull UserHandle stoppedUser) {
970     }
971 
972     /**
973      * Called when a user or profile is switched to.
974      *
975      * <p>This callback is only applicable to device owners.
976      *
977      * @param context The running context as per {@link #onReceive}.
978      * @param intent The received intent as per {@link #onReceive}.
979      * @param switchedUser The {@link UserHandle} of the user that has just been switched to.
980      */
onUserSwitched(@onNull Context context, @NonNull Intent intent, @NonNull UserHandle switchedUser)981     public void onUserSwitched(@NonNull Context context, @NonNull Intent intent,
982             @NonNull UserHandle switchedUser) {
983     }
984 
985     /**
986      * Called on the newly assigned owner (either device owner or profile owner) when the ownership
987      * transfer has completed successfully.
988      *
989      * <p> The {@code bundle} parameter allows the original owner to pass data
990      * to the new one.
991      *
992      * @param context the running context as per {@link #onReceive}
993      * @param bundle the data to be passed to the new owner
994      */
onTransferOwnershipComplete(@onNull Context context, @Nullable PersistableBundle bundle)995     public void onTransferOwnershipComplete(@NonNull Context context,
996             @Nullable PersistableBundle bundle) {
997     }
998 
999     /**
1000      * Called on the device owner when the ownership of one of its affiliated profiles is
1001      * transferred.
1002      *
1003      * <p>This can be used when transferring both device and profile ownership when using
1004      * work profile on a fully managed device. The process would look like this:
1005      * <ol>
1006      * <li>Transfer profile ownership</li>
1007      * <li>The device owner gets notified with this callback</li>
1008      * <li>Transfer device ownership</li>
1009      * <li>Both profile and device ownerships have been transferred</li>
1010      * </ol>
1011      *
1012      * @param context the running context as per {@link #onReceive}
1013      * @param user the {@link UserHandle} of the affiliated user
1014      * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
1015      */
onTransferAffiliatedProfileOwnershipComplete(@onNull Context context, @NonNull UserHandle user)1016     public void onTransferAffiliatedProfileOwnershipComplete(@NonNull Context context,
1017             @NonNull UserHandle user) {
1018     }
1019 
1020     /**
1021      * Intercept standard device administrator broadcasts.  Implementations
1022      * should not override this method; it is better to implement the
1023      * convenience callbacks for each action.
1024      */
1025     @Override
onReceive(@onNull Context context, @NonNull Intent intent)1026     public void onReceive(@NonNull Context context, @NonNull Intent intent) {
1027         String action = intent.getAction();
1028 
1029         if (ACTION_PASSWORD_CHANGED.equals(action)) {
1030             onPasswordChanged(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1031         } else if (ACTION_PASSWORD_FAILED.equals(action)) {
1032             onPasswordFailed(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1033         } else if (ACTION_PASSWORD_SUCCEEDED.equals(action)) {
1034             onPasswordSucceeded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1035         } else if (ACTION_DEVICE_ADMIN_ENABLED.equals(action)) {
1036             onEnabled(context, intent);
1037         } else if (ACTION_DEVICE_ADMIN_DISABLE_REQUESTED.equals(action)) {
1038             CharSequence res = onDisableRequested(context, intent);
1039             if (res != null) {
1040                 Bundle extras = getResultExtras(true);
1041                 extras.putCharSequence(EXTRA_DISABLE_WARNING, res);
1042             }
1043         } else if (ACTION_DEVICE_ADMIN_DISABLED.equals(action)) {
1044             onDisabled(context, intent);
1045         } else if (ACTION_PASSWORD_EXPIRING.equals(action)) {
1046             onPasswordExpiring(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1047         } else if (ACTION_PROFILE_PROVISIONING_COMPLETE.equals(action)) {
1048             onProfileProvisioningComplete(context, intent);
1049         } else if (ACTION_CHOOSE_PRIVATE_KEY_ALIAS.equals(action)) {
1050             int uid = intent.getIntExtra(EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, -1);
1051             Uri uri = intent.getParcelableExtra(EXTRA_CHOOSE_PRIVATE_KEY_URI);
1052             String alias = intent.getStringExtra(EXTRA_CHOOSE_PRIVATE_KEY_ALIAS);
1053             String chosenAlias = onChoosePrivateKeyAlias(context, intent, uid, uri, alias);
1054             setResultData(chosenAlias);
1055         } else if (ACTION_LOCK_TASK_ENTERING.equals(action)) {
1056             String pkg = intent.getStringExtra(EXTRA_LOCK_TASK_PACKAGE);
1057             onLockTaskModeEntering(context, intent, pkg);
1058         } else if (ACTION_LOCK_TASK_EXITING.equals(action)) {
1059             onLockTaskModeExiting(context, intent);
1060         } else if (ACTION_NOTIFY_PENDING_SYSTEM_UPDATE.equals(action)) {
1061             long receivedTime = intent.getLongExtra(EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, -1);
1062             onSystemUpdatePending(context, intent, receivedTime);
1063         } else if (ACTION_BUGREPORT_SHARING_DECLINED.equals(action)) {
1064             onBugreportSharingDeclined(context, intent);
1065         } else if (ACTION_BUGREPORT_SHARE.equals(action)) {
1066             String bugreportFileHash = intent.getStringExtra(EXTRA_BUGREPORT_HASH);
1067             onBugreportShared(context, intent, bugreportFileHash);
1068         } else if (ACTION_BUGREPORT_FAILED.equals(action)) {
1069             int failureCode = intent.getIntExtra(EXTRA_BUGREPORT_FAILURE_REASON,
1070                     BUGREPORT_FAILURE_FAILED_COMPLETING);
1071             onBugreportFailed(context, intent, failureCode);
1072         } else if (ACTION_SECURITY_LOGS_AVAILABLE.equals(action)) {
1073             onSecurityLogsAvailable(context, intent);
1074         } else if (ACTION_NETWORK_LOGS_AVAILABLE.equals(action)) {
1075             long batchToken = intent.getLongExtra(EXTRA_NETWORK_LOGS_TOKEN, -1);
1076             int networkLogsCount = intent.getIntExtra(EXTRA_NETWORK_LOGS_COUNT, 0);
1077             onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount);
1078         } else if (ACTION_USER_ADDED.equals(action)) {
1079             onUserAdded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1080         } else if (ACTION_USER_REMOVED.equals(action)) {
1081             onUserRemoved(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1082         } else if (ACTION_USER_STARTED.equals(action)) {
1083             onUserStarted(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1084         } else if (ACTION_USER_STOPPED.equals(action)) {
1085             onUserStopped(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1086         } else if (ACTION_USER_SWITCHED.equals(action)) {
1087             onUserSwitched(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
1088         } else if (ACTION_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
1089             PersistableBundle bundle =
1090                     intent.getParcelableExtra(EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE);
1091             onTransferOwnershipComplete(context, bundle);
1092         } else if (ACTION_AFFILIATED_PROFILE_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
1093             onTransferAffiliatedProfileOwnershipComplete(context,
1094                     intent.getParcelableExtra(Intent.EXTRA_USER));
1095         }
1096     }
1097 }
1098