Information sending method, electronic equipment and storage medium
By creating child threads in the main thread of the electronic device, specifically used to send window information, the problem of abnormal effects of function in inter-process communication is solved, and the data volume and frequency are optimized through filtering and frame-interval transmission, and the window information synchronization is solved stability issues.
Patent Information
- Application Number
- CN202310617998.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-29
- Publication Date
- 2024-11-29
AI Technical Summary
In electronic devices, when cross-process communication between processes, if a function of one process falls into an abnormal state, it will affect the operation of other functions, resulting in performance problems, and the amount of data is large when the window information is synchronized, resulting in stability problems.
By creating child threads in the main thread, specifically used to perform tasks that send window information, ensuring that the exception state does not affect the operation of other functions, and reducing the amount of data and sending frequency by filtering and frame-by-frame transmission of window information.
This avoids performance problems caused by function exception state, optimizes load conditions, and reduces the occurrence of stability problems.
Smart Images

Figure CN119045980A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an information sending method, an electronic device and a storage medium. Background Art
[0002] With the development of computer technology, electronic devices such as mobile phones and tablet computers have become an indispensable part of people's daily lives. Various application windows can be displayed on the screen of the electronic device, bringing users a good visual and operating experience.
[0003] Currently, different processes in electronic devices can transmit window information through cross-process communication. However, when a function in a process used to send window information to other processes falls into an abnormal state, it will affect the operation of other functions in the process, causing performance problems. Summary of the invention
[0004] The present application provides an information sending method, an electronic device and a storage medium, which can avoid performance problems caused by an abnormal state of a first function. The technical solution is as follows:
[0005] In a first aspect, a method for sending information is provided. In the method, a main thread of a first process creates a first sub-thread and a second sub-thread. The main thread runs a first function to pass first target information to the first sub-thread. After receiving the first target information passed by the main thread, the first sub-thread sends the first target information to the second process.
[0006] The first process is a process that can obtain window information. For example, the first process can be a SurfaceFlinger process. Of course, the first process can also be other processes that can obtain window information.
[0007] The first sub-thread can be called by the main thread through the first function, and cannot be called by the main thread through other functions except the first function. In this case, the first sub-thread is used to independently execute the sending task of the first function. The main thread can call the first sub-thread to execute the sending task only when running the first function, and the main thread cannot call the first sub-thread when running other functions.
[0008] The second sub-thread can be called by the main thread through a second function other than the first function. In this case, the second sub-thread is used to execute the sending task of the second function. The main thread can call the second sub-thread to execute the sending task when running the second function. Optionally, the second sub-thread cannot be called by the main thread through other functions other than the second function. In this case, the second sub-thread is used to execute the sending task of the second function alone; or the second sub-thread can be called by the main thread through other functions other than the first function and the second function. In this case, the second sub-thread is to execute the sending task of each of the multiple functions in series.
[0009] The main thread can at least run the first function and the second function, one of the first function and the second function is used to send window information to the second process, and the other is used to instruct the second process to release the buffer space. The second process is a process other than the first process. The second processes corresponding to the first function and the second function can be the same or different. For example, the first function can be the updateInputFlinger function, and the second function can be the ReleaseBuffer function. In this case, the second process corresponding to the first function is the process that needs window information, and the second process corresponding to the second function is the process that needs to release the buffer space; or, the first function can be the ReleaseBuffer function, and the second function can be the updateInputFlinger function. In this case, the second process corresponding to the first function is the process that needs to release the buffer space, and the second process corresponding to the second function is the process that needs window information. For example, the process that needs window information can be the SystemServer process, and the SystemServer process includes the InputDispatcher thread, and the InputDispatcher thread can distribute touch events according to the window information.
[0010] The first target information is information that the first function needs to send to the second process. For example, if the first function is used to send window information to the second process, the first target information is the target window information. Alternatively, if the first function is used to instruct the second process to release buffer space, the first target information is buffer space release information. The target window information may be window information of some or all windows displayed by the electronic device.
[0011] In the present application, the main thread can call the first sub-thread to execute the sending task by running the first function, and the main thread can call the second sub-thread to execute the sending task by running the second function. The operation of the first sub-thread and the second sub-thread does not affect each other, so the abnormal state of one of the first function and the second function will not affect the operation of the other function, thereby avoiding performance problems caused by the abnormal state of the first function or the second function.
[0012] Optionally, the first function is used to send window information to the second process, and the first target information is target window information. The main thread runs the first function to perform the following operations: obtaining current window information; determining target window information according to the current window information, and the target window information is other window information in the current window information except the window information containing the preset window type; if it is determined according to the current window information that the window has changed, calling the first child thread according to the target window information to pass the target window information to the first child thread.
[0013] For example, the preset window type may be a window type that the user cannot directly operate on the screen, such as the preset window type may include one or more of an invisible window type, a non-input channel window type, and the like.
[0014] In the present application, the target window information sent by the first function to the second process is obtained by filtering the current window information. After filtering, the amount of window information that needs to be sent to the second process is greatly reduced, thereby optimizing the load situation and avoiding stability problems to a certain extent.
[0015] Optionally, the first function is used to send window information to the second process, and the first target information is the target window information. After the first sub-thread receives the first target information transmitted by the main thread, the operation of sending the first target information to the second process can be: after the first sub-thread receives the target window information transmitted by the main thread, determine the time interval between the moment when the target window information is received and the moment when the window information was last sent to the second process; and send the target window information to the second process according to the time interval.
[0016] In the present application, the first sub-thread may send the target window information to the second process according to the time interval between the time when the target window information is received and the time when the window information was last sent to the second process, so as to reduce the frequency of sending the window information.
[0017] Among them, the operation of the first sub-thread sending the target window information to the second process according to the time interval can be: the first sub-thread sends the target window information to the second process when the time interval is greater than or equal to the first time length; when the time interval is less than the first time length, if the next window information is not received within the first time length after receiving the target window information, the target window information is sent to the second process.
[0018] The first duration is greater than the frame interval of the display screen. Optionally, the first duration may also be less than or equal to m times the frame interval, where m is greater than 1, such as m may be 2, 3, and so on.
[0019] In the present application, after the first sub-thread receives the target window information, it sends the target window information to the second process only when the time interval between the moment of receiving the target window information and the moment of sending the window information last time is greater than the frame interval time of the display screen. In this way, the window information can be sent every other frame, thereby reducing the frequency of sending the window information, optimizing the load situation, and avoiding stability problems.
[0020] It should be noted that, when the first duration is greater than m-1 times the frame time interval and less than or equal to m times the frame time interval, the first sub-thread sends window information to the second process at least once every m-1 image frames. For example, when the first duration is greater than the frame time interval and less than or equal to 2 times the frame time interval, the first sub-thread sends window information to the second process at least once every one image frame.
[0021] Furthermore, when the time interval is less than the first duration, if the first subthread does not receive the next window information within the first duration after receiving the target window information, the target window information is sent to the second process. In this case, since the first duration is greater than the frame interval, the first subthread sends the window information to the second process at least once every frame interval, thereby reducing the frequency of sending the window information, optimizing the load condition, and avoiding stability problems.
[0022] Optionally, after receiving the target window information, the first subthread may store the target window information in the task queue and wait for the first time period if the time interval between the time when the target window information is received and the time when the window information is last sent to the second process is less than the first time period. Afterwards, if the first subthread does not receive the next window information within the first time period after receiving the target window information, the target window information in the task queue is sent to the second process; if the first subthread receives the next window information within the first time period after receiving the target window information, the target window information in the task queue is discarded and the next window information is sent to the second process.
[0023] It can be understood that the window information in the task queue is the window information that the first child thread has received and has not yet sent to the second process. In this case, after the first child thread receives the target window information transmitted by the main thread, it can first determine whether there is window information in the task queue. If there is window information in the task queue, it indicates that the target window information is at least separated from the window information sent to the second process last time by the window information existing in the task queue, that is, it indicates that the time interval between the moment when the first child thread receives the target window information and the moment when the window information was sent to the second process last time is at least greater than the frame time interval, so the first child thread can discard the window information in the task queue and send the target window information to the second process. If there is no window information in the task queue, the time interval between the moment when the target window information is received and the moment when the window information was sent to the second process last time can be determined, and the target window information is sent to the second process according to the time interval. In this way, a quick judgment on whether the target window information can be sent can be realized through the task queue.
[0024] Optionally, if the main thread receives a first message, the target variable is set to a first variable value, and the first message is used to indicate the start of the startup and exit animations of the application; if the main thread receives a second message, the target variable is set to a second variable value, and the second message is used to indicate the end of the startup and exit animations.
[0025] In this case, after the first child thread receives the target window information transmitted by the main thread, if it is determined that the target variable is the second variable value, the target window information is sent to the second process; if it is determined that the target variable is the first variable value, the time interval between the time when the target window information is received and the time when the window information was last sent to the second process can be determined, and the target window information is sent to the second process according to the time interval.
[0026] In this application, a load reduction solution can be implemented by sending window information every other frame when the application is in the process of starting and exiting animations. The start-up and exit animations refer to the animations when the application is started or exited. Since there is a high probability that no operation will be performed on the window when the application is in the process of starting and exiting animations, sending window information every other frame in this scenario will not affect the user's operation.
[0027] Optionally, if the main thread receives the first message, the operation of setting the target variable to the first variable value may be: if the main thread receives the first message and determines that the refresh rate of the display screen is greater than or equal to the preset refresh rate, the target variable is set to the first variable value.
[0028] In this application, a load reduction solution of sending window information every other frame can be implemented when the application is in the startup and exit animation and the refresh rate of the display screen is greater than or equal to the preset refresh rate. The preset refresh rate can be set in advance, and the preset refresh rate can be set larger, for example, the preset refresh rate can be 90Hz, 120Hz, etc. Since the refresh rate of the display screen is greater than or equal to the preset refresh rate, that is, the refresh rate of the display screen is high, sending window information every other frame will not cause lag in this scenario.
[0029] Optionally, if the main thread does not receive the second message within a second period of time after setting the target variable to the first variable value, the main thread sets the target variable to the second variable value.
[0030] If the main thread does not receive the second message within the second time period after setting the target variable to the first variable value, it means that the effective time of the load reduction plan has reached the second time period, that is, the effective time of the load reduction plan has been too long. In this case, the main thread has not received the second message, which means that some errors may have occurred. Therefore, in this case, the main thread can actively close the load reduction plan, that is, the main thread can set the target variable to the second variable value. Optionally, in this case, the main thread can also print logs so that technical personnel can confirm abnormal situations in time according to the logs.
[0031] Optionally, the operation of the first sub-thread sending the first target information to the second process may be: the first sub-thread sends the first target information to the second process through a binder driver.
[0032] Specifically, the first child thread can carry the first target information in a binder message and send it to the binder driver. After receiving the binder message, the binder driver can send the binder message to the binder thread in the binder thread pool of the second process for processing. Optionally, the binder thread can pass the first target information in the binder message to other threads in the second process for processing. For example, the first target information is the target window information, and the second process can be the SystemServer process. The SystemServer process includes the InputDispatcher thread. After the binder thread in the SystemServer process receives the binder message sent by the binder driver, it can pass the target window information in the binder message to the InputDispatcher thread. The InputDispatcher thread can distribute touch events according to the target window information.
[0033] In the second aspect, a method for sending information is provided. In this method, the main thread of the SurfaceFlinger process creates a third child thread, and the third child thread can be called by the main thread through the updateInputFlinger function. The main thread runs the updateInputFlinger function to perform operations: obtain current window information, determine target window information based on the current window information, and pass the target window information to the third child thread, where the target window information is other window information in the current window information except for the window information containing the preset window type. After receiving the target window information passed by the main thread, the third child thread sends the target window information to the second process.
[0034] For example, the third sub-thread may be the first sub-thread or the second sub-thread described above. Alternatively, the third sub-thread can be called by the main thread through the ReleaseBuffer function, that is, the third sub-thread can serially execute the sending tasks of the updateInputFlinger function and the ReleaseBuffer function.
[0035] The preset window type may be pre-set, such as by a technician according to relevant requirements. For example, the preset window type may be a window type that a user cannot directly operate on the screen, such as a preset window type may include one or more of an invisible window type, a non-input channel window type, and the like.
[0036] In the present application, the target window information sent by the updateInputFlinger function to the second process is obtained by filtering the current window information. After filtering, the amount of window information that needs to be sent to the second process is greatly reduced, thereby optimizing the load situation and avoiding stability problems to a certain extent.
[0037] Optionally, when the main thread runs the updateInputFlinger function, after obtaining the target window information, the third sub-thread can be directly called according to the target window information to pass the target window information to the third sub-thread. Alternatively, when the main thread runs the updateInputFlinger function, after obtaining the target window information, the third sub-thread can be called according to the target window information when it is determined that the window has changed according to the current window information to pass the target window information to the third sub-thread. That is, the third sub-thread can be called to send the target window information to the second process when the window changes. In this way, the frequency of sending window information can be reduced, the load situation can be optimized, and stability problems can be avoided.
[0038] In a third aspect, an electronic device is provided, wherein the structure of the electronic device includes a processor and a memory, wherein the memory is used to store a program that supports the electronic device to execute the information sending method provided in the first aspect or the second aspect, and to store data involved in implementing the information sending method described in the first aspect or the second aspect. The processor is configured to execute the program stored in the memory. The electronic device may also include a communication bus, wherein the communication bus is used to establish a connection between the processor and the memory.
[0039] In a fourth aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is run on a computer, the computer executes the information sending method described in the first aspect or the second aspect.
[0040] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the information sending method described in the first aspect or the second aspect.
[0041] The technical effects obtained by the third, fourth and fifth aspects are similar to those obtained by the corresponding technical means in the first or second aspects, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 This is a first thread state schematic diagram provided in an embodiment of the present application;
[0043] Figure 2 This is a second thread state schematic diagram provided in an embodiment of the present application;
[0044] Figure 3 It is a schematic diagram of the third thread state and log record provided in an embodiment of the present application;
[0045] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application;
[0046] Figure 5 is a block diagram of a software system of an electronic device provided in an embodiment of the present application;
[0047] Figure 6 This is a flow chart of a first information sending method provided by an embodiment of the present application;
[0048] Figure 7 is a flow chart of a second information sending method provided in an embodiment of the present application;
[0049] Figure 8 This is a schematic diagram of the fourth thread state provided in an embodiment of the present application;
[0050] Fig. 9 This is a schematic diagram of sending window information provided by an embodiment of the present application;
[0051] Fig.10 This is a fifth thread state schematic diagram provided in an embodiment of the present application;
[0052] Fig.11 is a flowchart of a third information sending method provided in an embodiment of the present application;
[0053] Fig.12 This is a flowchart of the fourth information sending method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0055] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.
[0056] The phrases such as "one embodiment" or "some embodiments" described in the present application mean that the specific features, structures or characteristics described in the embodiment are included in one or more embodiments of the present application. Therefore, the phrases such as "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments" that appear in the differences in the present application do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. In addition, the terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0057] Before explaining the embodiments of the present application in detail, the application scenarios of the embodiments of the present application are first described.
[0058] With the increasing popularity of various applications, windows of multiple applications can be displayed on the screens of electronic devices such as mobile phones and tablet computers, bringing users a good visual and operating experience.
[0059] At present, some threads running in electronic devices need to obtain the current window information of the electronic device in order to implement relevant processing accordingly. For example, in the process of handling touch events (i.e., touch events) of electronic devices, the InputReander thread and the InputDispatcher thread running in the electronic device are mainly involved, wherein the touch events include but are not limited to click events, sliding events, etc. After the user touches the screen of the electronic device, the InputReander thread can read the touch event, and then notify the InputDispatcher thread to distribute the touch event. When distributing the touch event, the InputDispatcher thread can first determine the window corresponding to the touch event based on the window information and the position of the touch event, and then distribute the touch event to the corresponding window. It can be seen that in the process of handling touch events, it is very important for the InputDispatcher thread to obtain window information.
[0060] In the related technology, a SurfaceFlinger process runs in the electronic device, and an updateInputFlinger function runs in the SurfaceFlinger process. The updateInputFlinger function is used to obtain the current window information of the electronic device and synchronize the window information to the InputDispatcher thread. The InputDispatcher thread runs in the SystemServer (system service) process. Among them, the SurfaceFlinger process can complete the synchronization of window information through asynchronous binder communication. Specifically, by running the updateInputFlinger function, the SurfaceFlinger process can send the binder message carrying window information to the binder thread in the binder thread pool of the SystemServer process through the binder driver, and the binder thread will pass the window information to the InputDispatcher thread.
[0061] For example, in Figure 1In the thread state diagram shown, the updateInputFlinger function is running in the surfaceflinger thread in the SurfaceFlinger process. By running the updateInputFlinger function, the surfaceflinger thread can send the binder message carrying window information to the binder thread in the SystemServer process through the binder driver, and the binder thread will pass the window information to the InputDispatcher thread.
[0062] However, this approach has the following two problems:
[0063] On the one hand, in addition to the updateInputFlinger function, other functions are also running in the SurfaceFlinger process, including but not limited to the ReleaseBuffer function. The main function of the ReleaseBuffer function is to release the used buffer space (i.e., buffer) for the next use. All functions running in the SurfaceFlinger process will call the same child thread to perform the sending task. For example, the SurfaceFlinger process can call the child thread to send the window information to the InputDispatcher thread after getting the window information by running the updateInputFlinger function, and the SurfaceFlinger process can also call the child thread to send information by running the ReleaseBuffer function. In this case, if the updateInputFlinger function falls into an abnormal state, it will affect the operation of the ReleaseBuffer function and cause performance problems.
[0064] For example, in Figure 2In the thread state diagram shown, the SurfaceFlinger process calls the child thread "surfaceflinger2773" to perform the sending task when running the updateInputFlinger function and the ReleaseBuffer function, and the child thread "surfaceflinger2773" executes the sending task of the updateInputFlinger function and the sending task of the ReleaseBuffer function in series. In this case, if the child thread "surfaceflinger2773" encounters an abnormal state during the execution of the sending task of the updateInputFlinger function, such as the Uninterruptible sleep (D) state, the execution time of the sending task of the updateInputFlinger function will be longer, thereby causing the sending task of the ReleaseBuffer function to be delayed and unable to be executed for a long time. This will affect the release of the buffer, resulting in buffer accumulation, and other threads will not be able to get the buffer for a long time, which will cause performance problems.
[0065] On the other hand, when synchronizing window information, the updateInputFlinger function synchronizes all current window information of the electronic device, including the window information of visible windows and invisible windows. This will result in a large amount of data for the window information synchronized at a time, which will also result in a large amount of data for a single binder message, leading to stability issues. For example, when the updateInputFlinger function needs to synchronize window information to the InputDispatcher thread, once the running time of a certain updateInputFlinger function is long, it will cause the accumulation of binder messages. Since the size of the binder thread pool of the SystemServer process is limited, and the SystemServer process itself also requires a lot of communication, when the data volume of a single binder message is large, when a large number of accumulated binder messages flow into the binder thread pool of the SystemServer process in a short period of time, the binder thread pool of the SystemServer process will be filled up or even directly stuck, causing stability issues.
[0066] For example, in Figure 3In the thread status diagram shown in Figure (a), the binder thread pool of the SystemServer process includes the binder thread "binder2798" and the binder thread "binder3802". The SurfaceFlinger process calls the child thread "surfaceflinger2773" to perform the sending task by running the updateInputFlinger function, wherein the child thread "surfaceflinger2773" can send the binder message carrying the window information to the binder thread in the SystemServer process through the binder driver for processing. In this case, if the processing time of a binder message is long, it will cause the binder messages received by the binder driver to accumulate, for example, Figure 3 As shown in Figure (a), the child thread "surfaceflinger2773" sends binder message A to the binder driver, and the binder driver sends binder message A to the binder thread "binder3802" for processing. During the processing of binder message A, the child thread "surfaceflinger2773" sends binder message B to the binder driver. After the processing of binder message A is completed, the binder driver can continue to send binder message B to the binder thread "binder3802" for processing. However, the processing time of binder message B is relatively long. During the processing of binder message B, the child thread "surfaceflinger2773" sends a large number of binder messages to the binder driver, resulting in the accumulation of binder messages. After the processing of binder message B is completed, the binder driver sends the accumulated large number of binder messages to the binder thread "binder2798" for processing. Since the data volume of a single binder message is large, when a large number of accumulated binder messages flow into the binder thread "binder2798" in a short period of time, the binder thread pool of the SystemServer process will be filled up or even directly stuck, causing stability problems. Figure 3 In the log record shown in Figure (b), when a large number of accumulated binder messages flow into the binder thread pool of the SystemServer process in a short period of time, the binder communication between the child thread "surfaceflinger2773" in the SurfaceFlinger process "surfaceflinger2849" and the SystemServer process "systemserver2793" fails, causing stability issues.
[0067] To this end, the embodiment of the present application provides a method for sending information. On the one hand, the sending task of the updateInputFlinger function or the sending task of the ReleaseBuffer function is split into separate sub-threads to avoid the abnormal state of the updateInputFlinger function affecting the operation of the ReleaseBuffer function and causing performance problems. On the other hand, the load situation is optimized and stability problems are avoided by reducing the amount of window information sent at a time and / or reducing the frequency of sending window information.
[0068] The information sending method provided in the embodiment of the present application can be executed by an electronic device. Various applications can be installed in the electronic device, and the electronic device can display windows of various applications. For example, the electronic device can be a mobile phone, a PDA, a tablet computer, a laptop computer, a vehicle-mounted device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR) device, a virtual reality (virtual reality, VR) device, etc., and the embodiment of the present application does not limit this.
[0069] Figure 4 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0070] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0071] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0072] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0073] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0074] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0075] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created by the electronic device 100 during use (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0076] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The USB interface 130 can also be used to connect other devices, such as AR devices, etc.
[0077] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device 100 through the power management module 141.
[0078] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and provides power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193 and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0079] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0080] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0081] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0082] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0083] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0084] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is an integer greater than 1.
[0085] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor 180K can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0086] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0087] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.
[0088] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is an integer greater than 1.
[0089] The electronic device 100 can implement audio functions, such as music playback, recording, etc., through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D and the application processor.
[0090] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0091] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.
[0092] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. Touch operations acting on different areas of the display screen 194 can also correspond to different vibration feedback effects. Different application scenarios (such as: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0093] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.
[0094] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is an integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
[0095] Next, the software system of the electronic device 100 will be described.
[0096] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software system of the electronic device 100.
[0097] Figure 5 1 is a block diagram of a software system of an electronic device 100 provided in an embodiment of the present application. Figure 5 The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into an application layer, an application framework layer, an Android runtime (AndroidRuntime) and a system layer, and a kernel layer.
[0098] The application layer can include a series of application packages. Figure 5 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0099] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0100] like Figure 5As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc. The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make these data accessible to applications. These data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build the display interface of the application, and the display interface can be composed of one or more views, for example, including a view for displaying a text message notification icon, including a view for displaying text, and including a view for displaying pictures. The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of an icon or scroll bar text, such as a notification of an application running in the background. The notification manager can also be a notification that appears on the screen in the form of a dialog window, such as a text message in the status bar, a reminder sound, an electronic device vibrating, an indicator light flashing, etc.
[0101] like Figure 5 As shown, the application framework layer may also run a first process and a second process, and the first process and the second process may perform asynchronous binder communication.
[0102] In some embodiments, the first process may obtain window information, and send the window information to the second process through asynchronous binder communication, so that the second process can perform relevant processing accordingly.
[0103] For example, the first process may be a SurfaceFlinger process. The second process may be a SystemServer process. The SurfaceFlinger process may receive graphics data from multiple sources and synthesize the graphics data and send them to the display screen for rendering. The SystemServer process may create and run the core services of the system. The SurfaceFlinger process and the SystemServer process may perform asynchronous binder communication. Specifically, the updateInputFlinger function runs in the SurfaceFlinger process, and the InputDispatcher thread exists in the SystemServer process. By running the updateInputFlinger function, the SurfaceFlinger process may obtain window information and send the window information to the InputDispatcher thread in the SystemServer process through asynchronous binder communication, so that the InputDispatcher thread may distribute touch events according to the window information.
[0104] In some other embodiments, the first process may send the buffer space release information to the second process through asynchronous binder communication to instruct the second process to release the buffer space.
[0105] For example, the first process may be a SurfaceFlinger process. The second process may be a process to which a RenderThread thread belongs. The RenderThread thread is used to draw image frames. The SurfaceFlinger process and the process to which the RenderThread thread belongs may perform asynchronous binder communication. Specifically, a ReleaseBuffer function is running in the SurfaceFlinger process. By running the ReleaseBuffer function, the SurfaceFlinger process may send buffer space release information to the RenderThread thread through asynchronous binder communication to instruct the RenderThread thread to release the buffer space.
[0106] Android Runtime includes core libraries and virtual machines. Android Runtime is responsible for scheduling and management of the Android system. The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0107] The system layer can include multiple functional modules, such as: surface manager, media library, 3D graphics processing library (such as: OpenGL ES), 2D graphics engine (such as: SGL), etc. The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc. The 2D graphics engine is a drawing engine for 2D drawing.
[0108] The kernel layer is the layer between hardware and software. The kernel layer can include display drivers, camera drivers, audio drivers, sensor drivers, binder drivers, etc.
[0109] The first process and the second process in the application framework layer can realize asynchronous binder communication through the binder driver. Specifically, the second process can have a binder thread pool. The first process can carry the above window information or buffer space release information in a binder message and send it to the binder driver, and the binder driver can send the binder message to the binder thread in the binder thread pool of the second process for processing.
[0110] For example, the first process may be a SurfaceFlinger process. The second process may be a SystemServer process. The updateInputFlinger function runs in the SurfaceFlinger process, and the InputDispatcher thread exists in the SystemServer process. By running the updateInputFlinger function, the SurfaceFlinger process can obtain window information and carry the window information in a binder message to the binder driver. The binder driver can send the binder message to the binder thread in the binder thread pool of the SystemServer process. The binder thread can pass the window information to the InputDispatcher thread, so that the InputDispatcher thread can distribute touch events according to the window information.
[0111] For another example, the first process may be the SurfaceFlinger process. The second process may be the process to which the RenderThread thread belongs. The ReleaseBuffer function runs in the SurfaceFlinger process. By running the ReleaseBuffer function, the SurfaceFlinger process may carry the buffer space release information in the binder message and send it to the binder driver. The binder driver may send the binder message to the binder thread in the binder thread pool of the process to which the RenderThread thread belongs. The binder thread may pass the buffer space release information to the RenderThread thread. After receiving the buffer space release information, the RenderThread thread may release the buffer space.
[0112] The information sending method provided in the embodiment of the present application is described below.
[0113] Figure 6 is a flow chart of an information sending method provided by an embodiment of the present application, and the method is applied to an electronic device. Figure 6 , the method comprises the following steps:
[0114] Step 601: The main thread of the first process creates a first sub-thread and a second sub-thread.
[0115] The first process is a process that can obtain window information. The window information may include window information of some or all windows displayed by the electronic device, such as window information of visible windows and window information of invisible windows. The window information may include information such as window position, window size, window type, etc., which is not limited in the embodiments of the present application.
[0116] For example, the first process may be a SurfaceFlinger process. Of course, the first process may also be other processes that can obtain window information, and the embodiments of the present application do not make a sole limitation on this.
[0117] After the electronic device creates the first process, the main thread of the first process starts to run. The main thread can create a first sub-thread and a second sub-thread during the running process.
[0118] The first sub-thread can be called by the main thread through the first function, and cannot be called by the main thread through other functions except the first function. In this case, the first sub-thread is used to independently execute the sending task of the first function. The main thread can call the first sub-thread to execute the sending task only when running the first function, and the main thread cannot call the first sub-thread when running other functions.
[0119] The second sub-thread can be called by the main thread through a second function other than the first function. In this case, the second sub-thread is used to execute the sending task of the second function. The main thread can call the second sub-thread to execute the sending task when running the second function. Optionally, the second sub-thread cannot be called by the main thread through other functions other than the second function. In this case, the second sub-thread is used to execute the sending task of the second function alone; or the second sub-thread can be called by the main thread through other functions other than the first function and the second function. In this case, the second sub-thread is to execute the sending task of each of the multiple functions in series.
[0120] In an embodiment of the present application, the main thread is capable of running at least a first function and a second function, one of the first function and the second function is used to send window information to the second process, and the other is used to instruct the second process to release buffer space. The second process is a process other than the first process. The second processes corresponding to the first function and the second function may be the same or different. For example, the first function may be an updateInputFlinger function, and the second function may be a ReleaseBuffer function. In this case, the second process corresponding to the first function is a process that requires window information, and the second process corresponding to the second function is a process that requires buffer space to be released; or, the first function may be a ReleaseBuffer function, and the second function may be an updateInputFlinger function. In this case, the second process corresponding to the first function is a process that requires buffer space to be released, and the second process corresponding to the second function is a process that requires window information.
[0121] In the embodiment of the present application, the main thread can call the first sub-thread to execute the sending task by running the first function, and the main thread can call the second sub-thread to execute the sending task by running the second function. The operation of the first sub-thread and the second sub-thread does not affect each other, so the abnormal state of one of the first function and the second function will not affect the operation of the other function, thereby avoiding performance problems caused by the abnormal state of the first function or the second function.
[0122] Step 602: The main thread runs a first function to pass first target information to a first child thread.
[0123] When the main thread runs the first function, it can call the first child thread according to the first target information to pass the first target information to the first child thread. The first target information is the information that the first function needs to send to the second process. For example, if the first function is used to send window information to the second process, the first target information is the target window information. Or, if the first function is used to instruct the second process to release the buffer space, the first target information is the buffer space release information.
[0124] Step 603: After receiving the first target information transmitted by the main thread, the first sub-thread sends the first target information to the second process.
[0125] After receiving the first target information transmitted by the main thread, the first sub-thread can execute the sending task of the first function to send the first target information to the second process.
[0126] In some embodiments, the first child thread may send the first target information to the second process through the binder driver. Specifically, the first child thread may carry the first target information in a binder message and send it to the binder driver. After receiving the binder message, the binder driver may send the binder message to a binder thread in a binder thread pool of the second process for processing. In some embodiments, the binder thread may pass the first target information in the binder message to other threads in the second process for processing.
[0127] Optionally, the main thread runs the second function to pass the second target information to the second child thread. When the main thread runs the second function, it can call the second child thread according to the second target information to pass the second target information to the second child thread. The second target information is information that the second function needs to send to the second process. For example, if the second function is used to send window information to the second process, the second target information is the target window information. Alternatively, if the second function is used to instruct the second process to release buffer space, the second target information is buffer space release information.
[0128] After receiving the second target information transmitted by the main thread, the second sub-thread sends the second target information to the second process. That is, after receiving the second target information transmitted by the main thread, the second sub-thread can execute the sending task of the second function to send the second target information to the second process.
[0129] In some embodiments, the second child thread may send the second target information to the second process through the binder driver. Specifically, the second child thread may carry the second target information in a binder message and send it to the binder driver. After receiving the binder message, the binder driver may send the binder message to a binder thread in a binder thread pool of the second process for processing. In some embodiments, the binder thread may pass the second target information in the binder message to other threads in the second process for processing.
[0130] In an embodiment of the present application, the main thread of the first process can run the first function and the second function, one of the first function and the second function is used to send window information to the second process, and the other is used to instruct the second process to release buffer space. The main thread can create a first sub-thread and a second sub-thread, the first sub-thread is used to execute the sending task of the first function alone, and the second sub-thread is used to execute the sending task of the second function. The operation of the first sub-thread and the second sub-thread does not affect each other, so the abnormal state of one of the first function and the second function will not affect the operation of the other function, thereby avoiding performance problems caused by the abnormal state of the first function or the second function.
[0131] The following takes the first function as a function for sending window information to the second process and the first target information as target window information as an example to exemplarily illustrate the above information sending method.
[0132] The information sending method is applied to the scenario where the first process in the electronic device sends window information to the second process. It should be noted that the display screen of the electronic device will continuously refresh the screen image when displaying, and the refresh rate of the display screen refers to the number of times the screen image is refreshed per second. The screen image displayed by the display screen each time can be called an image frame. Every time the first process obtains the graphic data of an image frame, the graphic data can be sent to the display screen for rendering, thereby completing the display of the image frame. In addition, every time the first process obtains the graphic data of an image frame, the corresponding window information can also be obtained according to the graphic data, and the window information is sent to the second process. Optionally, the first process can use an asynchronous binder communication method when sending the window information to the second process. Specifically, the first process can send a binder message carrying the window information to a binder driver, and the binder driver can send the binder message to a binder thread in the binder thread pool of the second process.
[0133] Figure 7 is a flow chart of an information sending method provided by an embodiment of the present application, and the method is applied to an electronic device. Figure 7 , the method comprises the following steps:
[0134] Step 701: The main thread of the first process creates a first child thread. The first child thread can be called by the main thread through a first function, but cannot be called by the main thread through other functions except the first function.
[0135] The first process is a process that can obtain window information. The window information may include window information of some or all windows displayed by the electronic device, such as window information of visible windows and window information of invisible windows. The window information may include information such as window position, window size, window type, etc., which is not limited in the embodiments of the present application.
[0136] For example, the first process may be a SurfaceFlinger process. Of course, the first process may also be other processes that can obtain window information, and the embodiments of the present application do not make a sole limitation on this.
[0137] After the electronic device creates the first process, the main thread of the first process starts to run. The main thread can create a first sub-thread during the running process. The first sub-thread is used to independently execute the sending task of the first function. That is, the main thread can only call the first sub-thread through the first function to execute the sending task, and cannot call the first sub-thread through other functions.
[0138] The first function is used to send window information to the second process. That is, when the main thread runs the first function, it can obtain window information and call the first child thread to send the window information to the second process. For example, the first function can be the updateInputFlinger function. Of course, the first function can also be other functions that can send window information, and the embodiment of the present application does not limit this to a single function.
[0139] In the embodiment of the present application, the main thread of the first process creates a first sub-thread that is only used to execute the sending task of the first function, so that the sending task of the first function is split from the main thread to a separate sub-thread. In this case, the abnormal state of the first function will not affect the operation of other functions in the main thread, thereby avoiding performance problems caused by the abnormal state of the first function.
[0140] Furthermore, the main thread may also create a second child thread. The second child thread can be called by the main thread through a second function. That is, the second child thread can execute the sending task of the second function. The second function is different from the first function. For example, the second function may be a ReleaseBuffer function. Of course, the second function may also be other functions in the main thread except the first function. The embodiment of the present application does not make a sole limitation on this.
[0141] Optionally, the main thread can only call the second sub-thread through the second function, in which case the second sub-thread executes the sending task of the second function alone. Alternatively, the main thread can not only call the second sub-thread through the second function, but also call the second sub-thread through at least one other function except the first function and the second function, in which case the second sub-thread executes the sending task of each of the multiple functions in series.
[0142] For example, the first process is the SurfaceFlinger process, the first function is the updateInputFlinger function, and the second function is the ReleaseBuffer function. Figure 8 In the thread state diagram shown, the SurfaceFlinger process has a main thread "surfaceflinger1653". The main thread "surfaceflinger1653" creates a first sub-thread "surfaceflinger2688" and a second sub-thread "surfaceflinger2689" during operation. Among them, the first sub-thread is used to execute the sending task of the updateInputFlinger function alone, and the second sub-thread is used to execute the sending task of the ReleaseBuffer function. The operation of the first sub-thread and the second sub-thread does not affect each other. In this case, even if the first sub-thread "surfaceflinger2688" encounters an abnormal state when executing the sending task of the updateInputFlinger function, it will not affect the execution of the sending task of the ReleaseBuffer function by the second sub-thread "surfaceflinger2689", thereby avoiding performance problems.
[0143] Step 702: The main thread runs a first function to pass target window information to the first child thread.
[0144] When the main thread runs the first function, it can obtain the target window information and call the first sub-thread according to the target window information to pass the target window information to the first sub-thread.
[0145] The target window information may be window information of part or all of the windows displayed by the electronic device, and the target window information is window information that the first function needs to send to the second process.
[0146] In some embodiments, the main thread can obtain current window information when running the first function. For example, when the main thread obtains the graphic data of the current image frame to be rendered, it can obtain the window information of all windows contained in the current image frame as the current window information according to the graphic data by running the first function. Optionally, when the main thread runs the first function, it can also determine whether the window displayed by the electronic device has changed according to the current window information. Specifically, when the current window information is different from the historical window information (i.e., the window information of all windows contained in the previous image frame), it can be determined that the window displayed by the electronic device has changed. When the current window information is the same as the historical window information, it can be determined that the window displayed by the electronic device has not changed.
[0147] Optionally, when the main thread runs the first function, the current window information can be directly determined as the target window information; or, the target window information can be determined based on the current window information, and the target window information is other window information in the current window information except the window information containing the preset window type, that is, the current window information can be filtered, and the other window information in the current window information except the window information containing the preset window type can be determined as the target window information.
[0148] The preset window type may be pre-set, such as by a technician according to relevant requirements. For example, the preset window type may be a window type that a user cannot directly operate on the screen, such as a preset window type may include one or more of an invisible window type (NOT_VISIBLE), a non-input channel window type (NO_INPUT_CHANNEL), and the like.
[0149] In the embodiment of the present application, the target window information sent by the first function to the second process is obtained by filtering the current window information. After filtering, the amount of window information that needs to be sent to the second process is greatly reduced, and the amount of binder messages carrying window information that need to be sent to the second process subsequently is also reduced, thereby optimizing the load situation and avoiding stability problems to a certain extent.
[0150] For example, as shown in Table 1 below, the data amount of the current window information that needs to be sent in the related art is greater than or equal to the data amount of the target window information that needs to be sent in the embodiment of the present application. Moreover, as the number of open applications increases, compared with the related art, the data amount of the target window information that needs to be sent can be reduced to a great extent by filtering the current window information, thus avoiding stability problems to a certain extent.
[0151] Table 1
[0152]
[0153]
[0154] It should be noted that the embodiment of the present application only uses Table 1 above as an example to illustrate the data volume of the window information, and Table 1 above does not constitute a limitation on the embodiment of the present application.
[0155] For example, the first process is the SurfaceFlinger process, the first function is the updateInputFlinger function, and the second process is the SystemServer process. Even if the running time of a certain updateInputFlinger function is long, it will cause the accumulation of binder messages. However, since the data volume of the binder messages in the embodiment of the present application is small, the total data volume of the accumulated binder messages is also small. In this case, when the accumulated binder messages flow into the binder thread pool of the SystemServer process in a short time, the binder thread pool of the SystemServer process will not be filled up, and no stability problem will be caused.
[0156] When the main thread runs the first function, it can call the first sub-thread according to the target window information after acquiring the target window information to pass the target window information to the first sub-thread, so that the first sub-thread can send the target window information to the second process.
[0157] In some embodiments, when the main thread runs the first function, the first sub-thread can be directly called according to the target window information after obtaining the target window information. Alternatively, when the main thread runs the first function, after obtaining the target window information, the first sub-thread can be called according to the target window information when it is determined that the window has changed according to the current window information. That is, the first sub-thread can be called to send the target window information to the second process when the window changes, so that the frequency of sending window information can be reduced, the load situation can be optimized, and stability problems can be avoided.
[0158] Step 703: After receiving the target window information transmitted by the main thread, the first sub-thread sends the target window information to the second process.
[0159] After receiving the target window information transmitted by the main thread, the first sub-thread can execute the sending task of the first function to send the target window information to the second process.
[0160] The second process is a process that needs to perform relevant processing according to the window information. For example, the second process can be a SystemServer process, and the SystemServer process includes an InputDispatcher thread, and the InputDispatcher thread can distribute touch events according to the window information. Of course, the second process can also be other processes that need to perform relevant processing according to the window information, and the embodiments of the present application do not limit this to a single process.
[0161] In some embodiments, the first child thread can send target window information to the second process through the binder driver. Specifically, the first child thread can carry the target window information in a binder message and send it to the binder driver. After the binder driver receives the binder message, it can send the binder message to the binder thread in the binder thread pool of the second process for processing. In some embodiments, the binder thread can pass the target window information in the binder message to other threads in the second process for processing. For example, the second process can be a SystemServer process, and the SystemServer process includes an InputDispatcher thread. After the binder thread in the SystemServer process receives the binder message sent by the binder driver, it can pass the target window information in the binder message to the InputDispatcher thread. The InputDispatcher thread can distribute touch events according to the target window information.
[0162] Optionally, the operation of step 703 may include the following steps (1) to (3):
[0163] (1) After receiving the target window information transmitted by the main thread, the first sub-thread determines the time interval between the time when the target window information is received and the time when the window information is last sent to the second process.
[0164] After the first subthread sends window information to the second process each time, the sending time can be recorded. In this way, after receiving the target window information, the first subthread can determine the time interval between the time when the target window information is received and the recorded sending time (i.e., the time when the window information was last sent to the second process).
[0165] Afterwards, the first subthread may send the target window information to the second process according to the time interval. Specifically, the first subthread may execute the following step (2) when the time interval is greater than or equal to the first duration; and may execute the following step (3) when the time interval is less than the first duration.
[0166] (2) The first sub-thread sends the target window information to the second process when the time interval is greater than or equal to the first duration.
[0167] The first duration can be pre-set, such as the first duration can be pre-set according to the frame interval time of the display screen of the electronic device. For example, the first duration can be greater than the frame interval time of the display screen. Further, the first duration can also be less than or equal to m times the frame interval time, m is greater than 1, such as m can be 2, 3, etc. For example, the first duration can be greater than the frame interval time of the display screen and less than or equal to 2 times the frame interval time. In this case, if the refresh rate of the display screen of the electronic device is 90Hz (hertz), the frame interval time of the display screen is 1000÷90≈11.1ms (milliseconds), the first duration can be greater than 11.1ms and less than or equal to 22.2ms, such as the first duration can be 16ms. Alternatively, if the refresh rate of the display screen of the electronic device is 120Hz, the frame interval time of the display screen is 1000÷120≈8.3ms, the first duration can be greater than 8.3ms and less than or equal to 16.6ms, such as the first duration can be 16ms.
[0168] In an embodiment of the present application, after the first sub-thread receives the target window information, it sends the target window information to the second process only when the time interval between the moment of receiving the target window information and the moment of last sending the window information is greater than the frame interval time of the display screen. In this way, the window information can be sent every other frame, thereby reducing the frequency of sending the window information, optimizing the load situation, and avoiding stability problems.
[0169] It should be noted that, when the first duration is greater than m-1 times the frame time interval and less than or equal to m times the frame time interval, the first sub-thread sends window information to the second process at least once every m-1 image frames. For example, when the first duration is greater than the frame time interval and less than or equal to 2 times the frame time interval, the first sub-thread sends window information to the second process at least once every one image frame. Assume that there are three consecutive image frames: image frame 1, image frame 2, and image frame 3. After the first sub-thread sends the target window information of image frame 1 to the second process, if the first sub-thread receives the target window information of image frame 2, it will not send the target window information of image frame 2 to the second process, but will send the target window information of image frame 3 to the second process when receiving the target window information of image frame 3. In this way, the intermittent sending of window information to the second process is achieved.
[0170] (3) When the time interval is less than the first duration, the first sub-thread waits for the target window information for the first duration.
[0171] If the first sub-thread does not receive the next window information while waiting for the first time period for the target window information, that is, if the first sub-thread does not receive the next window information within the first time period after receiving the target window information, the first sub-thread can send the target window information to the second process. In this case, since the first time period is greater than the frame interval, the first sub-thread sends the window information to the second process at least once every frame interval, thereby reducing the frequency of sending the window information, optimizing the load situation, and avoiding stability problems.
[0172] If the first sub-thread receives the next window information while waiting for the target window information for the first time duration, since the time interval between two adjacent image frames is the frame time interval, the time interval between the moment when the first sub-thread receives the next window information and the moment when the window information was last sent to the second process will be greater than the frame time interval, that is, greater than the first time duration, so the first sub-thread can send the next window information to the second process. In other words, if the first sub-thread receives the next window information while waiting for the target window information for the first time duration, the next window information can be directly sent to the second process.
[0173] For example, Fig. 9 As shown, assuming that the first time length is 16ms. After the first child thread receives the target window information, if it is determined that the time interval between the time when the target window information is received and the time when the window information was last sent to the second process is less than 16ms, the first child thread will wait for the target window information for 16ms. Fig. 9 As shown in Figure (a) in FIG. 1 , if the first child thread receives the next window information during the waiting process of the target window information, the waiting of the target window information will be interrupted. In this case, the first child thread discards the target window information and sends the next window information to the second process. Or, Fig. 9 As shown in Figure (b), if the first child thread has not received the next window information during the waiting process of the target window information, the first child thread can automatically send the target window information to the second process after the waiting timeout.
[0174] Optionally, after receiving the target window information transmitted by the main thread, the first sub-thread may store the target window information in the task queue and wait for the first time period if the time interval between the time when the target window information is received and the time when the window information is last sent to the second process is less than the first time period. Afterwards, if the first sub-thread does not receive the next window information within the first time period after receiving the target window information, the target window information in the task queue is sent to the second process; if the first sub-thread receives the next window information within the first time period after receiving the target window information, the target window information in the task queue is discarded and the next window information is sent to the second process.
[0175] It can be understood that the window information in the task queue is the window information that the first child thread has received and has not yet sent to the second process. In this case, after the first child thread receives the target window information transmitted by the main thread in the above step (1), it can first determine whether there is window information in the task queue. If there is window information in the task queue, it indicates that the target window information is at least separated from the window information sent to the second process last time by the window information existing in the task queue, that is, it indicates that the time interval between the moment when the first child thread receives the target window information and the moment when the window information was sent to the second process last time is at least greater than the frame time interval, so the first child thread can discard the window information in the task queue and directly send the target window information to the second process. If there is no window information in the task queue, the first child thread can perform the operation of determining the time interval between the moment when the target window information is received and the moment when the window information was sent to the second process last time in step (1) and the subsequent steps (2) and (3). In this way, a quick judgment on whether the target window information can be sent can be achieved through the task queue.
[0176] It should be noted that the embodiment of the present application can send window information to the second process every other frame through the above steps (1) to (3). In this case, even if the running time of the first function is relatively long, it will not cause excessive accumulation of binder messages. Therefore, when a small amount of accumulated binder messages flow into the binder thread pool of the second process in a short time, the binder thread pool of the second process will not be filled up, and no stability problem will be caused.
[0177] The embodiment of the present application implements a load reduction scheme when the first child thread sends window information through the above steps (1) to (3). In some embodiments, the load reduction scheme can be implemented in all scenarios, that is, the first child thread can execute the above steps (1) to (3) every time it receives a window information transmitted by the main thread. In other embodiments, the load reduction scheme can be implemented only in some scenarios, and in other scenarios, the received window information is directly sent to the second process.
[0178] Optionally, the load reduction solution can be implemented when the application is in the process of starting and exiting animations, which refers to the animations when the application is started or exited. Since there is a high probability that no window operation will occur when the application is in the process of starting and exiting animations, sending window information every other frame in this scenario will not affect user operations.
[0179] Alternatively, the load reduction solution can be implemented when the application is in the startup and exit animation and the refresh rate of the display screen is greater than or equal to the preset refresh rate. The preset refresh rate can be set in advance, and the preset refresh rate can be set larger. For example, the preset refresh rate can be 90Hz, 120Hz, etc., which is not limited in the embodiments of the present application. Since the refresh rate of the display screen is greater than or equal to the preset refresh rate, that is, the refresh rate of the display screen is high, sending window information every other frame will not cause lag in this scenario.
[0180] Next, the process of implementing the load reduction solution in the above two scenarios is described in detail, which may specifically include the following steps A to B:
[0181] Step A: If the main thread receives the first message, the target variable is set to the first variable value.
[0182] The first message is used to indicate the start of the application's startup and exit animations. For example, the first message may be a binder message. Optionally, the electronic device may include a target module, which may detect whether the application is in the startup animation or the exit animation. If the target module detects that the application is in the beginning stage of the startup animation or the exit animation, the first message may be sent to the main thread to indicate the start of the application's startup and exit animations.
[0183] After receiving the first message, the main thread can set the target variable to the first variable value. The target variable is used to indicate whether to use the load reduction scheme. When the target variable is the first variable value, it indicates that the load reduction scheme is used. When the target variable is the second variable value, it indicates that the load reduction scheme is not used. The first variable value is different from the second variable value, such as the first variable value can be true, and the second variable value can be false.
[0184] In some embodiments, after receiving the first message, the main thread may directly set the target variable to the first variable value. In other embodiments, after receiving the first message, the main thread may first determine whether the refresh rate of the display screen is greater than or equal to the preset refresh rate, and if the refresh rate of the display screen is greater than or equal to the preset refresh rate, then set the target variable to the first variable value, and if the refresh rate of the display screen is less than the preset refresh rate, then do not change the variable value of the target variable, that is, keep the target variable as the second variable value.
[0185] Optionally, if the target module detects that the application ends the startup animation or exit animation, a second message may be sent to the main thread, the second message is used to indicate the end of the startup and exit animation of the application, and the second message may be a binder message. After receiving the second message, the main thread may directly set the target variable to the second variable value.
[0186] In some embodiments, if the main thread does not receive the second message within a second period of time after setting the target variable to the first variable value, the target variable may be set to the second variable value.
[0187] The second duration can be set in advance, and the second duration can be set to be relatively large, such as 2 seconds, 3 seconds, etc. Optionally, the second duration can be greater than the maximum duration of the start-up exit animation.
[0188] The main thread sets the target variable to the first variable value, indicating that the load reduction scheme has been started. In this case, the main thread can record the effective time of the load reduction scheme, that is, record how long it has been after the target variable is set to the first variable value. If the main thread does not receive the second message within the second time period after setting the target variable to the first variable value, it means that the effective time of the load reduction scheme has reached the second time period, that is, the effective time of the load reduction scheme has exceeded the maximum duration of the start-up exit animation. In this case, the main thread has not received the second message, which means that some errors may have occurred. Therefore, in this case, the main thread can actively close the load reduction scheme, that is, the main thread can set the target variable to the second variable value. Optionally, in this case, the main thread can also print logs so that technical personnel can confirm abnormal situations in time according to the logs.
[0189] Step B: After the first sub-thread receives the target window information transmitted by the main thread, if it is determined that the target variable is the first variable value, the load reduction solution provided by the above steps (1) to (3) is executed.
[0190] If it is determined that the target variable is the second variable value, it means that the load reduction solution cannot be used currently, and the first child thread can directly send the target window information to the second process.
[0191] For example, the first process is the SurfaceFlinger process, the first function is the updateInputFlinger function, and the second function is the ReleaseBuffer function. Fig.10 In the thread state diagram shown in FIG. 1 , the SurfaceFlinger process has a first child thread "surfaceflinger2688", which is used to execute the sending task of the updateInputFlinger function alone. Fig.10 As shown in Figure (a) in FIG. 1 , when the application is not in the process of starting and exiting the animation, the first child thread can send the window information of each image frame to the second process. Fig.10 As shown in Figure (b), when the application is in the process of starting the exit animation, the first child thread can use the load reduction solution to send window information to the second process every other frame.
[0192] It should be noted that in the embodiments of the present application, the window information that needs to be sent to the second process can be obtained by filtering the current window information, and / or, a load reduction scheme can be used to send the window information to the second process every other frame. In this way, the amount of data of the window information that needs to be sent at a time is reduced and / or the frequency of sending the window information is reduced, which also reduces the amount of data of a single binder message and / or reduces the frequency of sending the binder message, thereby optimizing the load situation and avoiding stability problems.
[0193] In an embodiment of the present application, the main thread of the first process creates a first child thread. Afterwards, the main thread runs the first function to obtain target window information and calls the first child thread according to the target window information. After receiving the target window information transmitted by the main thread, the first child thread sends the target window information to the second process. Since the first child thread can only be called by the main thread through the first function and cannot be called by the main thread through other functions, the abnormal state of the first function will not affect the operation of other functions in the main thread, thereby avoiding performance problems caused by the abnormal state of the first function.
[0194] The following takes the first function as a function for instructing the second process to release the buffer space and the first target information as buffer space release information as an example to exemplarily illustrate the above information sending method.
[0195] Fig.11 is a flow chart of an information sending method provided by an embodiment of the present application, and the method is applied to an electronic device. Fig.11 , the method comprises the following steps:
[0196] Step 1101: The main thread of the first process creates a first child thread. The first child thread can be called by the main thread through a first function, but cannot be called by the main thread through any function other than the first function.
[0197] The first process is a process that can obtain window information. The window information may include window information of some or all windows displayed by the electronic device, such as window information of visible windows and window information of invisible windows. The window information may include information such as window position, window size, window type, etc., which is not limited in the embodiments of the present application.
[0198] For example, the first process may be a SurfaceFlinger process. Of course, the first process may also be other processes that can obtain window information, and the embodiments of the present application do not make a sole limitation on this.
[0199] After the electronic device creates the first process, the main thread of the first process starts to run. The main thread can create a first sub-thread during the running process. The first sub-thread is used to independently execute the sending task of the first function. That is, the main thread can only call the first sub-thread through the first function to execute the sending task, and cannot call the first sub-thread through other functions.
[0200] The first function is used to instruct the second process to release the buffer space. That is, when the main thread runs the first function, it can call the first child thread to send buffer space release information to the second process. For example, the first function can be a ReleaseBuffer function. Of course, the first function can also be other functions that can instruct the process to release the buffer space. This embodiment of the application does not limit this to anything.
[0201] In the embodiment of the present application, the main thread of the first process creates a first sub-thread that is only used to execute the sending task of the first function, so that the sending task of the first function is split from the main thread to a separate sub-thread. In this case, the abnormal state of other functions in the main thread will not affect the operation of the first function, thereby avoiding performance problems caused by the abnormal state of other functions.
[0202] Furthermore, the main thread may also create a second child thread. The second child thread may be called by the main thread through a second function. That is, the second child thread may execute the sending task of the second function. The second function is different from the first function. For example, the second function may be an updateInputFlinger function. Of course, the second function may also be other functions in the main thread except the first function. The embodiment of the present application does not make a sole limitation on this.
[0203] Optionally, the main thread can only call the second sub-thread through the second function, in which case the second sub-thread executes the sending task of the second function alone. Alternatively, the main thread can not only call the second sub-thread through the second function, but also call the second sub-thread through at least one other function except the first function and the second function, in which case the second sub-thread executes the sending task of each of the multiple functions in series.
[0204] Step 1102: The main thread runs the first function to pass buffer space release information to the first sub-thread.
[0205] When the main thread runs the first function, it can call the first sub-thread according to the buffer space release information to pass the buffer space release information to the first sub-thread. The buffer space release information is used to indicate the release of the buffer space.
[0206] Step 1103: After receiving the buffer space release information transmitted by the main thread, the first sub-thread sends the buffer space release information to the second process.
[0207] After receiving the buffer space release information transmitted by the main thread, the first sub-thread can execute the sending task of the first function to send the buffer space release information to the second process.
[0208] The second process is a process that needs to release the buffer space. For example, the second process may be a process to which the RenderThread thread belongs. Of course, the second process may also be other processes that need to release the buffer space, and the embodiment of the present application does not make a sole limitation on this.
[0209] In some embodiments, the first sub-thread may send buffer space release information to the second process through the binder driver. Specifically, the first sub-thread may carry the buffer space release information in a binder message and send it to the binder driver. After receiving the binder message, the binder driver may send the binder message to a binder thread in the binder thread pool of the second process for processing. In some embodiments, the binder thread may pass the buffer space release information in the binder message to other threads in the second process for processing. For example, the second process may be the process to which the RenderThread thread belongs. After the binder thread in the process to which the RenderThread thread belongs receives the binder message sent by the binder driver, the buffer space release information in the binder message may be passed to the RenderThread thread. The RenderThread thread may release the buffer space according to the buffer space release information.
[0210] In an embodiment of the present application, the main thread of the first process creates a first child thread. Afterwards, the main thread runs the first function to call the first child thread according to the buffer space release information. After receiving the buffer space release information transmitted by the main thread, the first child thread sends the buffer space release information to the second process. Since the first child thread can only be called by the main thread through the first function and cannot be called by the main thread through other functions, the abnormal state of other functions in the main thread will not affect the operation of the first function, thereby avoiding performance problems caused by the abnormal state of other functions.
[0211] The following describes an information sending method provided in an embodiment of the present application.
[0212] Fig.12 is a flow chart of an information sending method provided by an embodiment of the present application, and the method is applied to an electronic device. Fig.12 , the method comprises the following steps:
[0213] Step 1201: The main thread of the SurfaceFlinger process creates a third child thread, and the third child thread can be called by the main thread through the updateInputFlinger function.
[0214] After the electronic device creates the SurfaceFlinger process, the main thread of the SurfaceFlinger process starts running. The main thread can create a third sub-thread during the running process. The third sub-thread is used to execute the sending task of the updateInputFlinger function. In some embodiments, the third sub-thread can be the first sub-thread or the second sub-thread described above. In other embodiments, the third sub-thread can be called by the main thread through the ReleaseBuffer function, that is, the third sub-thread can execute the sending tasks of the updateInputFlinger function and the ReleaseBuffer function in serial.
[0215] Step 1202: The main thread runs the updateInputFlinger function to perform the following operations: obtaining current window information, determining target window information based on the current window information, and passing the target window information to the third child thread. The target window information is other window information in the current window information except for the window information containing the preset window type.
[0216] When the main thread runs the updateInputFlinger function, the current window information can be obtained. For example, when the main thread obtains the graphic data of the current image frame to be rendered, the window information of all windows contained in the current image frame can be obtained as the current window information by running the updateInputFlinger function according to the graphic data. Optionally, when the main thread runs the updateInputFlinger function, it can also determine whether the window displayed by the electronic device has changed according to the current window information. Specifically, when the current window information is different from the historical window information (i.e., the window information of all windows contained in the previous image frame), it can be determined that the window displayed by the electronic device has changed. When the current window information is the same as the historical window information, it can be determined that the window displayed by the electronic device has not changed.
[0217] When the main thread runs the updateInputFlinger function, the current window information can be filtered, and other window information except the window information containing the preset window type in the current window information can be determined as the target window information.
[0218] The preset window type may be pre-set, such as by a technician according to relevant requirements. For example, the preset window type may be a window type that a user cannot directly operate on the screen, such as a preset window type may include one or more of an invisible window type, a non-input channel window type, and the like.
[0219] In the embodiment of the present application, the target window information sent by the updateInputFlinger function to the second process is obtained by filtering the current window information. After filtering, the amount of window information data that needs to be sent to the second process is greatly reduced, and the amount of binder messages carrying window information that need to be sent to the second process subsequently is also reduced, thereby optimizing the load situation and avoiding stability problems to a certain extent.
[0220] In this case, even if the running time of a certain updateInputFlinger function is long, resulting in the accumulation of binder messages, since the data volume of the binder messages in the embodiment of the present application is small, the total data volume of the accumulated binder messages is also small. In this case, when the accumulated binder messages flow into the binder thread pool of the second process in a short time, the binder thread pool of the second process will not be filled up, and no stability problem will be caused.
[0221] When the main thread runs the updateInputFlinger function, it can call the third child thread according to the target window information after obtaining the target window information to pass the target window information to the third child thread, so that the third child thread can send the target window information to the second process.
[0222] In some embodiments, when the main thread runs the updateInputFlinger function, the third sub-thread can be directly called according to the target window information after obtaining the target window information. Alternatively, when the main thread runs the updateInputFlinger function, after obtaining the target window information, the third sub-thread can be called according to the target window information when it is determined that the window has changed according to the current window information. That is, the third sub-thread can be called to send the target window information to the second process when the window changes, so that the frequency of sending window information can be reduced, the load situation can be optimized, and stability problems can be avoided.
[0223] Step 1203: After receiving the target window information transmitted by the main thread, the third sub-thread sends the target window information to the second process.
[0224] After receiving the target window information transmitted by the main thread, the third sub-thread can execute the sending task of the updateInputFlinger function to send the target window information to the second process.
[0225] The second process is a process that needs to perform relevant processing according to the window information. For example, the second process can be a SystemServer process, and the SystemServer process includes an InputDispatcher thread, and the InputDispatcher thread can distribute touch events according to the window information. Of course, the second process can also be other processes that need to perform relevant processing according to the window information, and the embodiments of the present application do not limit this to a single process.
[0226] In some embodiments, the third child thread can send the target window information to the second process through the binder driver. Specifically, the third child thread can carry the target window information in the binder message and send it to the binder driver. After the binder driver receives the binder message, it can send the binder message to the binder thread in the binder thread pool of the second process for processing. In some embodiments, the binder thread can pass the target window information in the binder message to other threads in the second process for processing. For example, the second process can be a SystemServer process, and the SystemServer process includes an InputDispatcher thread. After the binder thread in the SystemServer process receives the binder message sent by the binder driver, it can pass the target window information in the binder message to the InputDispatcher thread. The InputDispatcher thread can distribute touch events according to the target window information.
[0227] In an embodiment of the present application, the main thread of the SurfaceFlinger process creates a third child thread, and the third child thread can be called by the main thread through the updateInputFlinger function. The main thread runs the updateInputFlinger function to perform operations: obtain the current window information, determine the target window information based on the current window information, and pass the target window information to the third child thread. The target window information is other window information in the current window information except for the window information containing the preset window type. After receiving the target window information passed by the main thread, the third child thread sends the target window information to the second process. In an embodiment of the present application, the target window information sent by the updateInputFlinger function to the second process is obtained by filtering the current window information. After filtering, the amount of window information data that needs to be sent to the second process is greatly reduced, thereby optimizing the load situation and avoiding stability problems to a certain extent.
[0228] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (such as: coaxial cable, optical fiber, data subscriber line (Digital Subscriber Line, DSL)) or wireless (such as: infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access, or a data storage device such as a server or data center that includes one or more available media integrations. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital versatile disc (DVD)), or a semiconductor medium (such as a solid state disk (SSD)).
[0229] The above are optional embodiments provided for the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the technical scope disclosed in the present application shall be included in the protection scope of the present application.
Claims
1. A method for sending information, characterized in that: The method comprises: A main thread of a first process creates a first child thread and a second child thread, wherein the first child thread can be called by the main thread through a first function and cannot be called by the main thread through other functions except the first function, and the second child thread can be called by the main thread through a second function except the first function, wherein one of the first function and the second function is used to send window information to a second process, and the other is used to instruct the second process to release buffer space; The main thread runs the first function to pass the first target information to the first child thread; After receiving the first target information transmitted by the main thread, the first sub-thread sends the first target information to the second process.
2. The method according to claim 1, characterized in that The first function is used to send window information to the second process, the first target information is target window information, and the main thread runs the first function to perform the following operations: Get the current window information; Determine the target window information according to the current window information, where the target window information is other window information in the current window information except the window information including the preset window type; If it is determined according to the current window information that the window has changed, the first sub-thread is called according to the target window information to pass the target window information to the first sub-thread.
3. The method according to claim 2, characterized in that The preset window type includes one or more of an invisible window type and a non-input channel window type.
4. The method according to any one of claims 1 to 3, characterized in that: The first function is used to send window information to the second process, the first target information is target window information, and after the first sub-thread receives the first target information transmitted by the main thread, sending the first target information to the second process includes: After receiving the target window information transmitted by the main thread, the first sub-thread determines the time interval between the time when the target window information is received and the time when the window information was last sent to the second process, and sends the target window information to the second process according to the time interval.
5. The method according to claim 4, characterized in that The first sub-thread sends the target window information to the second process according to the time interval, including: The first sub-thread sends the target window information to the second process when the time interval is greater than or equal to a first duration, and the first duration is greater than a frame interval of a display screen; When the time interval is less than the first duration, if the first sub-thread does not receive the next window information within the first duration after receiving the target window information, the target window information is sent to the second process.
6. The method according to any one of claims 1 to 3, characterized in that: The first function is used to send window information to the second process, the first target information is target window information, and after the first sub-thread receives the first target information transmitted by the main thread, sending the first target information to the second process includes: After the first sub-thread receives the target window information transmitted by the main thread, if there is window information in the task queue, the first sub-thread discards the window information in the task queue and sends the target window information to the second process; if there is no window information in the task queue, the first sub-thread determines the time interval between the time when the target window information is received and the time when the window information was last sent to the second process, and sends the target window information to the second process according to the time interval; wherein the window information in the task queue is the window information that has been received by the first sub-thread and has not yet been sent to the second process.
7. The method according to claim 6, characterized in that The first sub-thread sends the target window information to the second process according to the time interval, including: The first sub-thread sends the target window information to the second process when the time interval is greater than or equal to a first duration, and the first duration is greater than a frame interval of a display screen; When the time interval is less than the first duration, the first sub-thread stores the target window information in the task queue, and if the next window information is not received within the first duration after receiving the target window information, the first sub-thread sends the target window information in the task queue to the second process.
8. The method according to claim 5 or 7, characterized in that The first duration is less than or equal to twice the frame interval.
9. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: If the main thread receives the first message, the target variable is set to the first variable value, and the first message is used to indicate the start and exit animation of the application program; If the main thread receives a second message, the target variable is set to a second variable value, and the second message is used to indicate the end of the start-up and exit animation effect; The first function is used to send window information to the second process, the first target information is target window information, and after the first sub-thread receives the first target information transmitted by the main thread, sending the first target information to the second process includes: After the first sub-thread receives the target window information transmitted by the main thread, if it is determined that the target variable is the second variable value, the target window information is sent to the second process; if it is determined that the target variable is the first variable value, the time interval between the time when the target window information is received and the time when the window information was last sent to the second process is determined, and the target window information is sent to the second process according to the time interval.
10. The method according to claim 9, characterized in that If the main thread receives the first message, the target variable is set to the first variable value, including: If the main thread receives the first message and determines that the refresh rate of the display screen is greater than or equal to the preset refresh rate, the target variable is set to the first variable value.
11. The method according to claim 9 or 10, characterized in that The method further comprises: If the main thread does not receive the second message within a second period of time after setting the target variable to the first variable value, the main thread sets the target variable to the second variable value.
12. The method according to any one of claims 1 to 11, characterized in that: The first sub-thread sends the first target information to the second process, including: The first sub-thread sends the first target information to the second process through a binder driver.
13. The method according to any one of claims 1 to 12, characterized in that: The first process is a SurfaceFlinger process, one of the first function and the second function is an updateInputFlinger function, and the other is a ReleaseBuffer function, and the updateInputFlinger function is used to send window information to an InputDispatcher thread in a SystemServer process.
14. A method for sending information, characterized in that: The method comprises: The main thread of the SurfaceFlinger process creates a third child thread, and the third child thread can be called by the main thread through the updateInputFlinger function; The main thread runs the updateInputFlinger function to perform the following operations: obtaining current window information, determining the target window information according to the current window information, and passing the target window information to the third sub-thread, wherein the target window information is other window information in the current window information except the window information including the preset window type; After receiving the target window information transmitted by the main thread, the third sub-thread sends the target window information to the second process.
15. The method according to claim 14, characterized in that The transmitting the target window information to the third sub-thread comprises: If it is determined according to the current window information that the window has changed, the target window information is passed to the third sub-thread.
16. The method according to claim 14 or 15, characterized in that The preset window type includes one or more of an invisible window type and a non-input channel window type.
17. An electronic device, characterized in that: The electronic device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the method according to any one of claims 1 to 16 when executed by the processor.
18. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the method according to any one of claims 1 to 16.
Citation Information
Cited By
Information sending method, electronic device, and storage medium
EP4600824A1
Information sending method, electronic device, and storage medium
WO2024244470A1
