The principle analysis of ANR caused by BroadcastReceiver in Android9.0 framework layer

1 Introduction



In the Android system, when some operations are performed in the app, the ActivityManagerService (AMS for short) and WindowManagerService (WMS for short) in the system will detect the response time of the App   when the app is operating the app. If the App cannot respond to screen touch or ANR occurs when the keyboard input time, or when a specific event is not processed.
The following four situations can cause ANR to occur:

    1.InputDispatching Timeout: When the app is operating, the main thread cannot respond to screen touch events or keyboard input events within 5 seconds

    2.BroadcastQueue Timeout: When the onReceive() function of the foreground broadcast (BroadcastReceiver) is executed in the app, the processing is not completed in the main thread for 10 seconds, and the background is 60 seconds.

    3. Service Timeout: In the function of the life cycle of the system Service, the response cannot be completed in the main thread within a specific time (foreground service 20s, background service 200s).

    4.ContentProvider Timeout: The publishing of ContentProvider is not completed within 10s in the main thread.
    (During the process startup process, if it happens, the process will be killed directly and the corresponding information will be cleared, and the ANR dialog box will not pop up.)
Next, we will analyze the analysis of the blocking input and no response caused by BroadcastReceiver in the main thread.

2. The core class of the principle analysis of ANR caused by BroadcastReceiver in the framework layer

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
frameworks/base/services/core/java/com/andro

Guess you like

Origin blog.csdn.net/baidu_41666295/article/details/131494569