Application program ARN monitoring method and device under Android system and medium

By creating a custom FileObserver subclass in the Android system to monitor trace file events and parse ANR data, the problem of poor real-time ANR monitoring is solved, real-time ANR monitoring and cross-platform compatibility are achieved, and user experience is improved.

CN120448220APending Publication Date: 2025-08-08SHANDONG INSPUR ULTRA HD INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510540520.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-27
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

The existing application non-response (ANR) monitoring solution under Android systems has poor real-time performance, which is mainly reflected in the delay in the main thread lag detection and the delay in the generation and inspection of ANR logs, resulting in poor user experience.

Method used

By creating a custom FileObserver subclass in the system application, the creation and modification events of trace files in the system-level directory are monitored, and the BufferedReader class is used to read data related to ANR, encapsulate it into JSON format for storage, real-time monitoring is achieved.

Benefits of technology

Real-time monitoring of ANR is realized, which avoids users' long-term lag, adapts to different trace file paths of different devices, ensures cross-platform compatibility and stability, and meets the needs of real-time monitoring and efficient processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448220A_ABST
    Figure CN120448220A_ABST
Patent Text Reader

Abstract

The invention provides an application program ARN monitoring method and device under an Android system and a medium, belongs to the technical field of Android application development, and is used for solving the technical problem that an existing ARN monitoring scheme is poor in real-time performance. The method comprises the following steps of: creating a self-defined FileObserver subclass in a system application; monitoring a specific event of a trace file in a specific directory through the FileObserver subclass; and when the specific event is successfully monitored, reading data related to the ARN in a trace file by utilizing a BuffedReader class, and packaging the data related to the ARN into a JSON (JavaScript Object Notation) format to be stored. By means of the method, real-time monitoring of the application ARN is achieved, and application developers can be fed back in time to optimize and repair.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of Android application development, and in particular to a method, device, and medium for monitoring application ARNs in an Android system. Background Art

[0002] Application Not Responding (ARN) occurs when the main thread of an application is blocked for a certain period of time. At this time, the application cannot respond to user operations or complete certain tasks, affecting the user experience.

[0003] Currently, monitoring ANRs usually requires detecting main thread freezes or checking ANR logs generated by the system. However, this solution has poor real-time performance, mainly due to the following reasons:

[0004] 1) Main thread lag detection is typically based on a certain time threshold (e.g., 5 seconds). This means that the main thread lag detection mechanism is triggered only when the main thread lag exceeds this threshold. In this case, users may have already experienced noticeable application lag, but the system may not have yet activated the main thread lag detection mechanism, resulting in poor real-time monitoring of the ARN.

[0005] 2) ANR logs are generated after ANR occurs, and their generation time itself lags behind the occurrence of ARN. In addition, checking ARN logs usually requires users to manually upload or developers to actively obtain them through some mechanism. This process may also be delayed, especially when users do not report or developers do not check in time, which also leads to poor real-time monitoring of ARN. Summary of the Invention

[0006] This application provides an application ARN monitoring method, device and medium under the Android system, which is used to solve the technical problem of poor real-time performance of existing ARN monitoring solutions.

[0007] This application adopts the following technical solutions:

[0008] In the first aspect, the present application provides an application ARN monitoring method under the Android system, the method comprising: creating a custom FileObserver subclass in the system application; monitoring specific events of the trace file in a specific directory through the FileObserver subclass; when the specific event is successfully monitored, using the BufferedReader class to read the ARN-related data in the trace file, and encapsulating the ARN-related data into JSON format for storage.

[0009] In one possible implementation of the present application, specific events of trace files in a specific directory are monitored through the FileObserver subclass, including: listening to creation events and modification events of trace files in a system-level directory through the FileObserver subclass, and the creation events and the modification events constitute the specific events.

[0010] In a possible implementation of the present application, monitoring specific events of trace files in a specific directory through the FileObserver subclass also includes: initializing the FileObserver instance and starting monitoring in the onCreate phase, and stopping monitoring in the onDestroy phase.

[0011] In one possible implementation of the present application, when the specific event is successfully monitored, the method further includes: determining that the trace file has changed; triggering the onEvent callback in the FileObserver subclass, and parsing the callback trace file to obtain data related to the ARN in the trace file.

[0012] In one possible implementation of the present application, the callback trace file is parsed to obtain the data related to ARN in the trace file, including: using the BufferedReader class to read the trace file; locating the application package name where the ANR occurs based on the Cmd line field, and further extracting the timestamp, thread stack information and basic device information of the ANR occurrence to obtain the data related to ARN.

[0013] In a possible implementation of the present application, locating the application package name where the ANR occurs according to the Cmd line field includes: locating the application package name where the ANR occurs in the first process of the trace file according to the Cmd line field.

[0014] In a possible implementation of the present application, the method further includes: lightweight storage of the ARN-related data encapsulated in JSON format, including temporarily storing the ARN-related data in a SharedPreferences class.

[0015] In a possible implementation of the present application, the method further includes: periodically uploading the data related to the ARN to a server.

[0016] In the second aspect, the present application also provides an application ARN monitoring device under the Android system, the device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, so that the at least one processor can execute: creating a custom FileObserver subclass in the system application; monitoring specific events of the trace file in a specific directory through the FileObserver subclass; when the specific event is successfully monitored, using the BufferedReader class to read the ARN-related data in the trace file, and encapsulating the ARN-related data into JSON format for storage.

[0017] In a third aspect, the present application also provides a non-volatile computer storage medium having computer-executable instructions stored thereon, wherein the computer-executable instructions are configured to execute: creating a custom FileObserver subclass in a system application; monitoring specific events of a trace file in a specific directory through the FileObserver subclass; and upon successfully monitoring the specific event, using the BufferedReader class to read the ARN-related data in the trace file, and encapsulating the ARN-related data into JSON format for storage.

[0018] The present application provides an application ARN monitoring method, device, and medium for Android system, which have the following beneficial effects:

[0019] This application monitors the creation or modification events of trace files in the system-level directory by creating a FileObserver subclass in the system application. When these events are detected, the trace file is called back and parsed to extract data related to ARN, thereby realizing real-time monitoring of ARN, avoiding the delay line by detecting the main thread jam or checking the ARN log solution, and realizing real-time monitoring of ARN so that the subsequent processing flow can be carried out quickly when ARN is monitored, avoiding the user's experience of long-term jams when using the application and causing a bad experience. In addition, the ARN monitoring solution in this application can also adapt to the path differences of trace files on different devices, ensuring cross-platform compatibility and stability, while meeting the real-time monitoring and efficient processing requirements of ANR. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in this application or the prior art, the following briefly introduces the drawings required for the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments described in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0021] Figure 1 This is a flow chart of an application ARN monitoring method under the Android system provided by this application;

[0022] Figure 2 This is a structural diagram of an application ARN monitoring device under the Android system provided in this application. DETAILED DESCRIPTION

[0023] In order to enable those skilled in the art to better understand the technical solutions of this application, the technical solutions of this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.

[0024] This application relates to an ANR monitoring method, device, and medium under the Android system. By creating a custom FileObserver subclass, the creation and modification events of trace files in the system-level directory are monitored, and the stack information and device parameters when the ANR occurs are encapsulated into structured JSON data. SharedPreferences is used for local caching, and data temporary storage and periodic upload are supported through various storage media such as USB flash drives and ROM, thereby achieving real-time monitoring of ARN.

[0025] The method in this application is described in detail below with reference to the accompanying drawings.

[0026] Figure 1 This application provides a flow chart of an ARN monitoring method for an application under the Android system, such as Figure 1 As shown, the ARN monitoring method in this application includes at least the following execution steps:

[0027] Step 101: Create a custom FileObserver subclass in the system application.

[0028] An ANR occurs when the application's main thread is blocked for a certain period of time, preventing user operations and impacting the user experience. When an application experiences an ANR on the Android system, the system generates trace files in a fixed directory. These files record thread stack information at the time of the ANR. However, ordinary applications do not have access to the files in this directory. However, system-level applications can use FileObserver objects to monitor file changes in these directories.

[0029] Therefore, this application implements ARN monitoring by first creating a custom FileObserver subclass in the system application. The creation method or process can be implemented through existing technologies or algorithms, and this application will not go into details here.

[0030] Step 102: Monitor specific events of trace files in a specific directory through the FileObserver subclass.

[0031] In one possible implementation of this application, after a FileObserver subclass is created, it is used to monitor specific events of trace files in a system-level directory. These specific events include at least one or more of creation and modification events. In one example, the created FileObserver subclass is assigned a directory to monitor trace files. This directory is typically located under / data / anr / , but may vary between devices. The FileObserver instance is initialized and monitoring is started during the onCreate phase, and monitoring is stopped during the onDestroy phase.

[0032] Step 103: When a specific event is successfully monitored, the BufferedReader class is used to read the data related to the ARN in the trace file, and the data related to the ARN is encapsulated into JSON format for storage.

[0033] In one possible implementation of the present application, when a creation event and / or modification event is detected in a trace file under a system-level directory, that is, when a change in the trace file is detected, the onEvent callback in the FileObserver subclass is triggered, and the callback trace file is parsed and processed. Specifically, the BufferedReader class is first used to read the trace file, and the application package name where the ANR occurs is located based on the Cmd line field, and the timestamp, thread stack information and basic device information of the ANR are further extracted to obtain data related to the ARN.

[0034] Furthermore, the ARN-related data obtained in the above process is encapsulated into a JSON format data and stored in a lightweight manner. In an example, the JSON format data is temporarily stored in the SharedPreferences class and is periodically uploaded to the server together with other types of data.

[0035] Through the above solution, real-time monitoring and data collection of ARN can be achieved.

[0036] In order to explain the solution in this application in more detail, this application also provides the following supplementary description:

[0037] In system applications that perform global monitoring and collection, create a custom FileObserver subclass and specify the directory where trace files are located. This directory is typically / data / anr / but may vary between devices. Create this subclass object during the application's onCreate method to start monitoring; stop monitoring during onDestroy. Monitored event types include create (CREATE) and modify (MODIFY). When a file in the directory undergoes either of these changes, the onEvent callback in FileObserver is triggered. Override this method to process the trace file within this callback.

[0038] First, use BufferedReader to read the trace file where the changes have been monitored, and extract the application package name that records the occurrence of ANR. Because the file contains not only the application process where the ANR occurred, but also other applications that were alive at the time, but the system usually puts the ANR process into the first queue first, so the first process in the trace file often corresponds to the ANR process. The package name starts with Cmd line, find this key line, extract the package name and record it. Then extract the record of the ANR occurrence time and the corresponding stack information, and obtain some basic information about the device, encapsulate it into a JSON format data, and use lightweight storage SharedPreferences to temporarily store it, and then upload it to the server periodically together with other types of data.

[0039] Based on the same inventive concept, this application also provides an application ARN monitoring device under the Android system, whose structure is as follows: Figure 2 shown.

[0040] Figure 2 This is a schematic diagram of the structure of an application ARN monitoring device under the Android system provided by this application. Figure 2As shown, the application ARN monitoring device 200 under the Android system in this application specifically includes: at least one processor 201; and a memory 203 that is communicatively connected to the at least one processor 201 (connected via a bus 202); wherein the memory 203 stores instructions that can be executed by the at least one processor 201, so that the at least one processor 201 can execute an application ARN monitoring method under the Android system as described in the above embodiment.

[0041] In one possible implementation of the present application, the aforementioned processor is used to execute, create a custom FileObserver subclass in the system application; monitor specific events of the trace file in a specific directory through the FileObserver subclass; when the specific event is successfully monitored, use the BufferedReader class to read the ARN-related data in the trace file, and encapsulate the ARN-related data into JSON format for storage.

[0042] In addition, the present application also provides a non-volatile computer storage medium on which computer-executable instructions are stored, and the computer-executable instructions are configured to execute: creating a custom FileObserver subclass in the system application; monitoring specific events of the trace file in a specific directory through the FileObserver subclass; when the specific event is successfully monitored, using the BufferedReader class to read the ARN-related data in the trace file, and encapsulating the ARN-related data into JSON format for storage.

[0043] The various embodiments in this application are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the device embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.

[0044] The device and method provided in this application correspond one to one, so the device also has similar beneficial technical effects as its corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the device will not be repeated here.

[0045] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.

[0046] In the description of the implementation methods or examples provided in the present application, it should be understood that if the terms "up", "down", "front", "back", "left" and "right" are used to indicate directions or positional relationships, they are based on the directions or positional relationships shown in the accompanying drawings. They are only used to facilitate the description of the present invention and simplify the description, and do not indicate or imply that the positions or elements referred to must have a specific direction, be constructed and operate in a specific direction. Therefore, they should not be understood as limitations of the present disclosure.

[0047] It should be noted that, in the embodiments or examples provided in the present application, relational terms such as first and second, etc., are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. It should also be noted that the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of further restrictions, an element defined by the statement "comprising a ..." does not exclude the presence of other identical elements in the process, method, commodity or device comprising the element.

[0048] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included in the protection scope of the present application.

Claims

1. A method for monitoring application ARN in Android system, characterized in that: The method comprises: Create a custom FileObserver subclass in the system application; Monitor specific events of trace files in a specific directory through the FileObserver subclass; When the specific event is successfully monitored, the BufferedReader class is used to read the data related to the ARN in the trace file, and the data related to the ARN is encapsulated into JSON format for storage.

2. The method for monitoring application ARN in an Android system according to claim 1, wherein: The FileObserver subclass monitors specific events of trace files in a specific directory, including: The creation event and modification event of the trace file in the system-level directory are monitored by the FileObserver subclass, and the creation event and the modification event constitute the specific event.

3. The method for monitoring application ARN in an Android system according to claim 2, wherein: Monitoring specific events of trace files in a specific directory through the FileObserver subclass also includes: Initialize the FileObserver instance and start monitoring in the onCreate phase, and stop monitoring in the onDestroy phase.

4. The method for monitoring application ARN in an Android system according to claim 1, wherein: When the specific event is successfully monitored, the method further includes: Determine whether the trace file has changed; The onEvent callback in the FileObserver subclass is triggered, and the trace file of the callback is parsed to obtain the data related to the ARN in the trace file.

5. The method for monitoring application ARN in an Android system according to claim 4, wherein: Parse the callback trace file to obtain data related to the ARN in the trace file, including: Use the BufferedReader class to read the trace file; The application package name where the ANR occurs is located based on the Cmd line field, and the timestamp, thread stack information, and basic device information of the ANR are further extracted to obtain the data related to the ARN.

6. The method for monitoring application ARN in an Android system according to claim 5, wherein: Locate the application package name where the ANR occurs based on the Cmd line field, including: Locate the application package name where the ANR occurs in the first process of the trace file based on the Cmd line field.

7. The method for monitoring application ARN in an Android system according to claim 1, wherein: The method further comprises: The ARN-related data encapsulated in JSON format is lightweight stored, including temporarily storing the ARN-related data in a SharedPreferences class.

8. The method for monitoring application ARN in an Android system according to claim 7, wherein: The method further comprises: The data related to the ARN is periodically uploaded to the server.

9. An application ARN monitoring device under the Android system, characterized in that: The device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, so as to enable the at least one processor to perform: Create a custom FileObserver subclass in the system application; Monitor specific events of trace files in a specific directory through the FileObserver subclass; When the specific event is successfully monitored, the BufferedReader class is used to read the data related to the ARN in the trace file, and the data related to the ARN is encapsulated into JSON format for storage.

10. A non-volatile computer storage medium having computer executable instructions stored thereon, characterized in that: The computer-executable instructions are configured to: Create a custom FileObserver subclass in the system application; Monitor specific events of trace files in a specific directory through the FileObserver subclass; When the specific event is successfully monitored, the BufferedReader class is used to read the data related to the ARN in the trace file, and the data related to the ARN is encapsulated into JSON format for storage.