Event processing method and device

By introducing proxy threads to the application to receive and process input events, the application's unresponsive problem is solved and a better user experience is achieved.

CN119883668AInactive Publication Date: 2025-04-25BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311377902.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-23
Publication Date
2025-04-25
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Applications may result in unresponsiveness (ANR) when processing input events, affecting the user experience.

Method used

Introduce a proxy thread, receives input events sent by the system process, and sends completion instructions to the system process, and forwards the input events to the main thread for processing.

Benefits of technology

Effectively reduces the unresponsiveness of the application, thereby improving the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883668A_ABST
    Figure CN119883668A_ABST
Patent Text Reader

Abstract

The invention discloses an event processing method. The method can be applied to an application process. The application process may include a main thread and a proxy thread. In the embodiment of the invention, the main thread does not directly receive the input event sent by the system process, but the proxy thread receives the input event sent by the system process and sends the input event to the main thread. The proxy thread may also send completion indication information for the input event to the system process in response to receiving the input event. The method comprises the following steps of: once an input event sent by a system process is received, immediately sending completion indication information of the input event to the system process, so that the system process can receive the completion indication information of the input event within a time period corresponding to an allowed overtime response threshold value; therefore, the system process is prevented from controlling the application process to generate ANR.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to a field, and in particular to an event processing method and device. Background Art

[0002] With the development of computer technology, more and more applications have emerged. At present, when users use applications, there may be a phenomenon that the application is unresponsive. As an example, when a user uses an application installed on a terminal device, the user can trigger an operation through the terminal device, and accordingly, the terminal device can generate an input event in response to the user's triggering operation. If the application does not process the input event within a certain period of time, an application not responding (ANR) will occur.

[0003] The unresponsiveness of an application will affect the user experience of using the application. Therefore, a solution is urgently needed to solve this problem. Summary of the invention

[0004] In order to solve or at least partially solve the above technical problems, an embodiment of the present application provides an event processing method and device.

[0005] In a first aspect, an embodiment of the present application provides an event processing method, which is applied to an application process, wherein the application process includes a proxy thread and a main thread, and the method includes:

[0006] The proxy thread receives an input event sent by the system process;

[0007] In response to receiving the input event, the proxy thread sends completion indication information for the input event to the system process, and sends the input event to the main thread so that the main thread processes the input event, and the completion indication information indicates that the input event has been processed.

[0008] Optionally, the proxy thread receives an input event sent by a system process, including:

[0009] The proxy thread receives the input event sent by the system process through the first socket file descriptor.

[0010] Optionally, before the proxy thread receives the input event sent by the system process through the first socket file descriptor, the method further includes:

[0011] Obtaining a second socket file descriptor used by the main thread to communicate with the system process;

[0012] The second socket file descriptor is assigned to the proxy thread as the first socket descriptor.

[0013] Optionally, sending the input event to the main thread includes:

[0014] The input event is sent to the main thread through a third socket file descriptor.

[0015] Optionally, before sending the input event to the main thread through the third socket file descriptor, the method further includes:

[0016] The third socket file descriptor is created.

[0017] Optionally, the input event includes:

[0018] Screen click event or screen swipe event.

[0019] In a second aspect, an embodiment of the present application provides an event processing device, which is applied to a proxy thread of an application process, and the device includes:

[0020] A receiving unit, used for receiving input events sent by the system process;

[0021] A sending unit is used to send completion indication information for the input event to the system process in response to receiving the input event, and send the input event to the main thread so that the main thread can process the input event, and the completion indication information indicates that the input event has been processed.

[0022] Optionally, the receiving unit is used to:

[0023] An input event sent by the system process is received through the first socket file descriptor.

[0024] Optionally, the device further comprises:

[0025] an acquiring unit, configured to acquire a second socket file descriptor used by the main thread to communicate with the system process before receiving an input event sent by the system process through the first socket file descriptor;

[0026] The processing unit is used to assign the second socket file descriptor as the first socket descriptor to the proxy thread.

[0027] Optionally, the sending unit is used to:

[0028] The input event is sent to the main thread through a third socket file descriptor.

[0029] Optionally, the device further comprises:

[0030] A creating unit is used to create the third socket file descriptor before sending the input event to the main thread through the third socket file descriptor.

[0031] Optionally, the input event includes:

[0032] Screen click event or screen swipe event.

[0033] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising a processor and a memory;

[0034] The processor is used to execute instructions stored in the memory so that the electronic device executes the method described in any one of the first aspects above.

[0035] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, comprising instructions, wherein the instructions instruct a device to execute any of the methods described in the first aspect above.

[0036] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute any of the methods described in the first aspect above.

[0037] Compared with the prior art, the embodiments of the present application have the following advantages:

[0038] The embodiment of the present application provides an event processing method, which can be applied to an application process. The application process may include a main thread and a proxy thread. In the embodiment of the present application, considering that the main thread cannot process the input event sent by the system process to the main thread in time, the system process will not be able to receive the completion indication information of the input event within the time period corresponding to the timeout response threshold allowed by the system process, thereby causing the system process to control the application process to generate an ANR. Among them, the completion indication information is used to indicate that the input event has been processed. Therefore, in the embodiment of the present application, the main thread no longer directly receives the input event sent by the system process, but the proxy thread receives the input event sent by the system process and sends the input event to the main thread. The proxy thread can also send the completion indication information for the input event to the system process in response to receiving the input event. That is: once the input event sent from the system process is received, the completion indication information of the input event is immediately sent to the system process, so that the system process can receive the completion indication information of the input event within the time period corresponding to the timeout response threshold allowed by the system process, thereby avoiding the system process from controlling the application process to generate an ANR. Therefore, using this solution, ANR can be effectively reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0040] Figure 1 A schematic diagram of a processing flow of an input event provided in an embodiment of the present application;

[0041] Figure 2 A flowchart of an event processing method provided in an embodiment of the present application;

[0042] Figure 3 A schematic diagram of another event processing method provided in an embodiment of the present application;

[0043] Figure 4 A schematic diagram of the structure of an event processing device provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0045] The inventor of this application has found through research that when a user is using an application, the application may become unresponsive. As an example, when a user is using an application installed on a terminal device, the user may trigger an operation through the terminal device, and accordingly, the terminal device may generate an input event in response to the user's triggering operation. If the application does not process the input event within a certain period of time, an ANR will occur. Figure 1 To understand, Figure 1 A schematic diagram of a processing flow of an input event provided in an embodiment of the present application.

[0046] like Figure 1As shown, the system service (system_server) process can generate an input event in response to a user's trigger operation, and send the input event to the main thread of the application process through the input event distribution (InputDispatcher) thread. The main thread of the application process processes the input event, and after the processing is completed, sends a completion indication message for the input event to the input event distribution thread. Among them, after the system service process sends the input event to the main thread, it will start the timing to record the response waiting time for the input event. If the timing reaches the timeout response threshold, and the input event distribution thread has not received the completion indication message for the above input event, the system service process can control the application process to generate an ANR. Among them, the system service process controls the application process to generate an ANR, which can be to control the application process to display a prompt message that the application cannot respond in the form of a pop-up window, or to kill the application process, which is not specifically limited in the embodiments of the present application.

[0047] In a specific example, the application process and the system service process can communicate with each other through a socket file descriptor (socket fd).

[0048] The unresponsiveness of an application will affect the user experience of using the application. For example, displaying a prompt message that the application cannot respond in the form of a pop-up window will cause interference to the user. Killing the application process will prevent the user from continuing to use the application.

[0049] In order to solve the above problems, an embodiment of the present application provides an event processing method and device.

[0050] Various non-limiting implementations of the present application are described in detail below in conjunction with the accompanying drawings.

[0051] Exemplary Methods

[0052] See also Figure 2 , which is a flow chart of an event processing method provided in an embodiment of the present application. The method provided in an embodiment of the present application can be applied to an application process, and the application process can include a proxy thread and a main thread. In this embodiment, the method can include the following steps: S101-S102.

[0053] S101: The proxy thread receives an input event sent by the system process.

[0054] In the embodiment of the present application, the system process is a process of the operating system. In one example, the system process may correspond to Figure 1 The system service processes shown.

[0055] In one example, the proxy thread may receive the input event sent by the input event distribution thread of the system process. The embodiment of the present application does not specifically limit the input event, and the input event may be any event generated by an operation triggered by a user. In a specific example, the input event may include a screen click event, which refers to an event generated by the system process in response to a user clicking on the screen of a terminal device. The input event may also include a screen swipe event, which refers to an event generated by the system process in response to a swipe operation triggered by a user on the screen of a terminal device.

[0056] In one example, the proxy thread and the aforementioned system process may exchange data using a binder communication method.

[0057] In another example, the proxy thread and the aforementioned system process may communicate using the first socket fd. In other words, the proxy thread may receive input events sent by the system process through the first set of socket fds.

[0058] For this situation, in a specific example, the proxy thread may request the system process to create the first socket fd, so as to communicate with the system process based on the first socket fd.

[0059] In another specific example, the first socket fd may be obtained by modifying the second socket fd used by the main thread to communicate with the system process. Specifically, the application process may obtain the second socket fd used by the main thread to communicate with the system process. For example, the application process may obtain the second socket fd by hooking a function used by the application process to receive data. After obtaining the second socket fd, the second socket fd may be assigned to the proxy thread as the first socket fd. The second socket fd is created by the system process, and its communication counterpart is the main thread. The second socket fd may be assigned to the proxy thread as the first socket fd, and the communication counterpart of the second socket fd may be modified from the main thread to the proxy thread.

[0060] S102: In response to receiving the input event, the proxy thread sends completion indication information for the input event to the system process, and sends the input event to the main thread so that the main thread processes the input event, and the completion indication information indicates that the input event has been processed.

[0061] In response to receiving the input event, the proxy thread can immediately send the completion indication information of the input event to the system process. In a specific example, the proxy thread can obtain the event identifier of the input event, and send the event identifier and the completion indication information to the system process accordingly. Among them, sending the completion indication information to the system process accordingly can be an input event distribution thread that sends the completion indication information to the system process. In a specific example, the proxy thread can send the completion indication information of the input event to the system process through the aforementioned first socket fd.

[0062] In addition, in order to enable the input event to be processed by the main thread, the proxy thread may also send the input event to the main thread.

[0063] In one example, the proxy thread and the main thread may exchange data using binder communication.

[0064] In another example, the proxy thread and the main thread may interact with each other using a third socket fd. In other words, the proxy thread may send the input event to the main thread through the third socket fd. In this case, in a specific example, the third socket fd may be created by the application process. Specifically, the application process may create a third socket fd for the main thread and the proxy thread to communicate, so that the proxy thread can send the input event to the main thread through the third socket fd.

[0065] From the above description, it can be known that, using the solution of the embodiment of the present application, once the proxy thread receives an input event sent from the system process, it immediately sends the completion indication information of the input event to the system process, so that the system process can receive the completion indication information of the input event in time, thereby avoiding the system process controlling the application process to generate ANR. Therefore, using this solution, ANR can be effectively reduced.

[0066] In one example, after the proxy thread sends the input event to the main thread, the main thread can distribute and process the received input event. After the main thread completes processing the input event, it can send corresponding completion indication information to the proxy thread. For example, the main thread can send corresponding completion indication information to the proxy thread through the third socket fd. As an example, the proxy thread may not process the completion indication information sent by the main thread. As another example, the proxy thread may also count the completion indication information sent by the main thread, which is not specifically limited in the embodiments of the present application.

[0067] The above is an introduction to the event processing method provided in the embodiment of the present application. Figure 3 The method provided in the embodiments of the present application is described. Figure 3 A schematic diagram of another event processing method provided in an embodiment of the present application.

[0068] like Figure 3 As shown, the input event distribution thread of the system service process sends the input event to the proxy thread of the application process. After receiving the input event, the proxy thread, on the one hand, sends the input event to the main thread of the application process, and on the other hand, sends the completion indication information of the input event to the input event distribution thread, so that the system process can receive the completion indication information of the input event in time, thereby effectively reducing ANR.

[0069] Exemplary Devices

[0070] Based on the method provided in the above embodiment, the embodiment of the present application further provides a device, which is described below in conjunction with the accompanying drawings.

[0071] See also Figure 4 , which is a structural diagram of an event processing device provided in an embodiment of the present application. Figure 4 The device 400 shown can be applied to a proxy thread of an application process. The device can specifically include, for example: a receiving unit 401 and a sending unit 402 .

[0072] The receiving unit 401 is used to receive an input event sent by a system process;

[0073] The sending unit 402 is used to send completion indication information for the input event to the system process in response to receiving the input event, and send the input event to the main thread so that the main thread can process the input event, and the completion indication information indicates that the input event has been processed.

[0074] Optionally, the receiving unit 401 is configured to:

[0075] An input event sent by the system process is received through the first socket file descriptor.

[0076] Optionally, the device further comprises:

[0077] an acquiring unit, configured to acquire a second socket file descriptor used by the main thread to communicate with the system process before receiving an input event sent by the system process through the first socket file descriptor;

[0078] The processing unit is used to assign the second socket file descriptor as the first socket descriptor to the proxy thread.

[0079] Optionally, the sending unit 402 is configured to:

[0080] The input event is sent to the main thread through a third socket file descriptor.

[0081] Optionally, the device further comprises:

[0082] A creating unit is used to create the third socket file descriptor before sending the input event to the main thread through the third socket file descriptor.

[0083] Optionally, the input event includes:

[0084] Screen click event or screen swipe event.

[0085] Since the device 400 is a device corresponding to the method provided in the above method embodiment, the specific implementation of each unit of the device 400 is based on the same concept as the above method embodiment. Therefore, for the specific implementation of each unit of the device 400, reference can be made to the description part of the above method embodiment, which will not be repeated here.

[0086] The embodiment of the present application also provides an electronic device, the electronic device comprising a processor and a memory;

[0087] The processor is used to execute instructions stored in the memory so that the electronic device executes the event processing method provided by the above method embodiment.

[0088] An embodiment of the present application provides a computer-readable storage medium, including instructions, wherein the instructions instruct a device to execute the event processing method provided by the above method embodiment.

[0089] An embodiment of the present application provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the event processing method provided by the above method embodiment.

[0090] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0091] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

[0092] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims

1. An event processing method, characterized in that: Applied to an application process, the application process includes a proxy thread and a main thread, the method includes: The proxy thread receives an input event sent by the system process; In response to receiving the input event, the proxy thread sends completion indication information for the input event to the system process, and sends the input event to the main thread so that the main thread processes the input event, and the completion indication information indicates that the input event has been processed.

2. The method according to claim 1, characterized in that The proxy thread receives the input event sent by the system process, including: The proxy thread receives the input event sent by the system process through the first socket file descriptor.

3. The method according to claim 2, characterized in that Before the proxy thread receives the input event sent by the system process through the first socket file descriptor, the method further includes: Obtaining a second socket file descriptor used by the main thread to communicate with the system process; The second socket file descriptor is assigned to the proxy thread as the first socket descriptor.

4. The method according to claim 1, characterized in that The sending the input event to the main thread includes: The input event is sent to the main thread through a third socket file descriptor.

5. The method according to claim 4, characterized in that Before sending the input event to the main thread through the third socket file descriptor, the method further includes: The third socket file descriptor is created.

6. The method according to claim 1, characterized in that The input events include: Screen click event or screen swipe event.

7. An event processing device, characterized in that: A proxy thread applied to an application process, the device comprising: A receiving unit, used for receiving input events sent by the system process; A sending unit is used to send completion indication information for the input event to the system process in response to receiving the input event, and send the input event to the main thread so that the main thread can process the input event, and the completion indication information indicates that the input event has been processed.

8. The device according to claim 7, characterized in that The receiving unit is used for: An input event sent by the system process is received through the first socket file descriptor.

9. An electronic device, characterized in that: The electronic device comprises a processor and a memory; The processor is configured to execute instructions stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: The method comprises instructions for instructing a device to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Message transmission method and device

    CN106911557A