Process control method, device, computer equipment and storage medium

By monitoring the operating status of the application and controlling the background process to stop frame drawing, the problem of waste of application background resources in the smart terminal is solved, and efficient resource utilization and performance improvement are achieved.

CN115113992BActive Publication Date: 2024-11-12GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110302432.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-22
Publication Date
2024-11-12
Estimated Expiration
2041-03-22

AI Technical Summary

Technical Problem

The continuous application of resources for applications in smart terminals when running in the background leads to increased CPU usage and resource waste.

Method used

By monitoring the operation status of the application, if the application switches from visible to invisible state, obtains the target process and controls its thread to stop performing background frame drawing, caches the queue to be executed by the animation processing object, and restores frame drawing when the application becomes visible again.

Benefits of technology

Reduces resource waste, reduces CPU usage, and improves terminal performance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115113992B_ABST
    Figure CN115113992B_ABST
Patent Text Reader

Abstract

The present application relates to a process control method, apparatus, computer equipment and storage medium. By obtaining the running state of a running application, if the running state of the application switches from a visible state to an invisible state, the target process corresponding to the above-mentioned application in the invisible state is obtained, and the conditions satisfied by the target process include: the corresponding interface and window are invisible; there is no corresponding notification and no corresponding component. And the thread under the above-mentioned target process is controlled to stop executing background frame drawing. Compared with the traditional method of still executing the frame drawing process of the application when the application is in the background, this solution monitors the running state of the application, and when it detects that the application switches from a visible state to an invisible state, the thread under the target process that meets the conditions in the invisible state of the application is controlled to stop executing background frame drawing, thereby achieving the effect of reducing resource waste.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a process control method, apparatus, computer equipment and storage medium. Background Art

[0002] At present, smart terminals have become one of the necessities in people's lives. Smart terminals usually have multiple applications. When each application is running, it needs to use multiple processes to realize the normal operation of the application function. When the application is running, it is divided into foreground running and background running. When the application is running in the background, it means that the user does not need to use the application temporarily. However, when the application in the smart terminal is running in the background, the application process will continue to apply for resources to execute internal logic, resulting in an increase in the CPU usage of the application and a waste of resources.

[0003] Therefore, the current process control of application programs has the defect of wasting resources. Summary of the invention

[0004] Based on this, it is necessary to provide a process control method, device, computer equipment and storage medium that can reduce resource waste in response to the above technical problems.

[0005] A process control method, the method comprising:

[0006] Get the running status of the running application;

[0007] If the running state is switched from a visible state to an invisible state, obtaining a target process of the application in the invisible state; the target process satisfies the following conditions: the corresponding interface and / or window is invisible, there is no corresponding notification, and there is no corresponding component;

[0008] The thread under the target process is controlled to stop executing background frame drawing.

[0009] In one embodiment, obtaining the running status corresponding to the running application includes:

[0010] Obtaining the process status of the process corresponding to the application;

[0011] Obtaining the perception state of the interface and the perception state of the window corresponding to the application;

[0012] Obtain the number of notifications and components corresponding to the application;

[0013] The corresponding running state of the application is obtained from the process state, the perceived state of the interface, the perceived state of the window, the number of notifications, and the number of components.

[0014] In one embodiment, the method further comprises:

[0015] Based on the running state, detect whether the application switches from a visible state to an invisible state; if it is detected that the process state value corresponding to the process switches from a first state value to a second state value, the perception state of the interface switches from a perceptible state to an imperceptible state, the perception state of the window switches from a perceptible state to an imperceptible state, the number of notifications is zero, and the number of components is zero, determine that the application switches from a visible state to an invisible state.

[0016] In one embodiment, detecting whether the application is switched from a visible state to an invisible state includes:

[0017] Detecting whether the application switches from a visible state to an invisible state at a preset time interval;

[0018] If the result of this detection is no, the preset time interval is extended to obtain a new preset time interval, and according to the new preset time interval, it is detected whether the application is switched from the visible state to the invisible state;

[0019] If the detection result is yes, the preset time interval is restored to the initial time interval.

[0020] In one embodiment, after obtaining the target process of the application in the invisible state, the method further includes:

[0021] Obtaining the interface of the target process;

[0022] The second state value is sent to the target process through the interface to trigger the target process to control the thread under it to stop background frame drawing based on the second state value.

[0023] In one embodiment, controlling the thread under the target process to stop executing background frame drawing includes:

[0024] Sending the second state value to the main thread of the target process, and sending the second state value to at least one child thread of the target process through the main thread, so that the main thread and the at least one child thread determine whether the current thread meets the condition for stopping frame drawing according to the second state value, and if so, stop executing background frame drawing of the current thread;

[0025] Among them, the conditions for stopping frame drawing include that the process status value of the process corresponding to the current thread is the second status value, the interface of the application corresponding to the current thread is invisible, the window of the application corresponding to the current thread is invisible, the number of notifications of the application corresponding to the current thread is zero, and the number of components of the application corresponding to the current thread is zero.

[0026] In one embodiment, after controlling the thread under the target process to stop background frame drawing, the method further includes:

[0027] Cache the animation processing object to-be-executed queue corresponding to the target thread under the target process; the target thread is the main thread and / or child thread that stops executing the background frame drawing of the thread;

[0028] If it is detected that the application is switched from an invisible state to a visible state, frame drawing of the target thread under the target process is restored according to the cached animation processing objects in the queue of animation processing objects to be executed.

[0029] In one embodiment, the caching of the animation processing object execution queue corresponding to the target thread under the target process includes:

[0030] caching the animation processing object corresponding to the main thread in the main thread of the target process;

[0031] In the animation processing object corresponding to the main thread, the animation processing object of the child thread is cached.

[0032] In one embodiment, the step of resuming frame drawing of a target thread under the target process according to the cached animation processing objects in the queue of pending animation processing objects includes:

[0033] Sending traversal callback information to the main thread corresponding to the target process, triggering the main thread to resume executing frame drawing;

[0034] During the frame drawing process executed by the main thread, detecting whether the application is switched from an invisible state to a visible state,

[0035] If yes, then detecting whether the animation processing object to-be-executed queue of the child thread cached by the main thread contains an unfinished frame drawing task;

[0036] If an unfinished frame drawing task is included, an animation callback instruction is sent to the corresponding child thread, so that the corresponding child thread resumes executing the unfinished frame drawing task.

[0037] In one of the embodiments, detecting whether the application is switched from an invisible state to a visible state during the frame drawing process executed by the main thread includes:

[0038] During the frame drawing process executed by the main thread, if it is detected that the target process is a windowless process, the main thread determines whether the process state value of the target process is switched to the first state value, and if so, determines that the application is switched from an invisible state to a visible state;

[0039] If the target process is a process with a window, and the window of the target process is in a perceptible state, it is determined that the application is switched from an invisible state to a visible state.

[0040] A process control device, comprising:

[0041] A first acquisition module is used to acquire the running status of the running application;

[0042] A second acquisition module is used to acquire a target process of the application in the invisible state if the running state is switched from the visible state to the invisible state; the target process satisfies the following conditions: the corresponding interface and / or window is invisible, there is no corresponding notification, and there is no corresponding component;

[0043] The control module is used to control the thread under the target process to stop executing background frame drawing.

[0044] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0045] A computer-readable storage medium stores a computer program, which implements the steps of the above method when executed by a processor.

[0046] The above-mentioned process control method, device, computer equipment and storage medium obtain the running state of the running application. If the running state of the application switches from a visible state to an invisible state, the target process corresponding to the above-mentioned application in the invisible state is obtained, and the conditions satisfied by the target process include: the corresponding interface and window are invisible; there is no corresponding notification and no corresponding component. And the thread under the above-mentioned target process is controlled to stop executing background frame drawing. Compared with the traditional method of still executing the frame drawing process of the application when the application is in the background, this solution monitors the running state of the application. When it is detected that the application switches from a visible state to an invisible state, the thread under the target process that meets the conditions in the invisible state of the application is controlled to stop executing background frame drawing, thereby achieving the effect of reducing resource waste. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 An application environment diagram of a process control method in an embodiment;

[0048] Figure 2 A schematic diagram of a process control method in one embodiment;

[0049] Figure 3 A schematic diagram of the structure of operating status monitoring in one embodiment;

[0050] Figure 4A schematic diagram of the structure inside a process in one embodiment;

[0051] Figure 5 A schematic diagram of the structure of cross-process communication in one embodiment;

[0052] Figure 6 A schematic diagram of a process flow of thread monitoring in one embodiment;

[0053] Figure 7 A schematic diagram of a process flow of switching a windowless process state in one embodiment;

[0054] Figure 8 A schematic diagram of a process flow of switching a window process state in one embodiment;

[0055] Fig. 9 is a flow chart of a process control method in another embodiment;

[0056] Fig.10 is a timing diagram of a process control method in one embodiment;

[0057] Fig.11 is a structural block diagram of a process control device in one embodiment;

[0058] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0060] The process control method provided by this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 can obtain the running state of the application running in the terminal 102. If it is detected that the above running state switches from a visible state to an invisible state, the terminal 102 can obtain the target process that meets the conditions of the above application in the invisible state, and control the thread under the target process to stop executing background frame drawing. In addition, in one embodiment, a server 104 may also be included, and the terminal 102 communicates with the server 104 through a network. The terminal 102 can form a report on the performance and power consumption consumed when the application switches to the background, and upload it to the server 104 for storage and analysis. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.

[0061] In one embodiment, Figure 2 As shown, a process control method is provided, which is applied to Figure 1 The terminal in is used as an example to illustrate, including the following steps:

[0062] Step S202, obtaining the running status of the running application.

[0063] The running application may be an application running in the terminal 102, and the terminal 102 may include multiple running applications, and each application may have its own running state. The running state includes a visible state and an invisible state. For example, the visible state may be a state in which the application is running in the foreground and the user can interact with the application; the invisible state may be a state in which the application is running in the background and the user cannot interact with the application. The terminal 102 may obtain the running state of the above-mentioned running application. For example, the running state of the application is obtained through the relevant information of each process corresponding to the running application.

[0064] Step S204, if the running state is switched from the visible state to the invisible state, obtain the target process of the application in the invisible state; the target process meets the conditions: the corresponding interface and / or window is invisible, there is no corresponding notification and no corresponding component.

[0065] Among them, the running state can be the running state of the running application in the terminal 102. The running state of the above application can include a visible state and an invisible state, etc. The running state of the application can be switched. For example, when a running application is running in the foreground of the terminal 102 and its interface is being displayed, and the user can interact with the application through the terminal 102 at this time, the application can be in a visible state at this time; the running state of the application can also be switched. For example, if the terminal 102 is a mobile phone, the user can press the home button or the back button, and the application running in the foreground will switch to the background. At this time, the interface of the application will not be displayed, and the user cannot interact with the application through the terminal 102, so the application can be in an invisible state at this time.

[0066] The terminal 102 can monitor the changes in the running state of the above-mentioned running application, for example, by monitoring the state of the application-related process and interface to determine the running state of the above-mentioned running application. After determining that the application is switched from a visible state to an invisible state, the terminal 102 can obtain the target process of the application in the invisible state, and the obtained target process can be a process that meets the conditions. Among them, the conditions satisfied by the target process include: if there is an interface, the corresponding interface is invisible; if there is a window, the corresponding window is invisible; if there is an interface and a window, the corresponding interface and window are both invisible; and there is no corresponding notification and no corresponding component. Among them, the interface (Activity) and the window (Window) can be set in the process to display the interface and window of the application, wherein the window can be the carrier of the interface; the state of the interface and the window can be determined according to the process state corresponding to the process, the state of the Activity and the Window; the notification (notification) and the component (widget) can be the notification and component corresponding to the application, such as the background notification of the application and the desktop component of the application, and the notification and the component can also be implemented through a specific process.

[0067] Step S206, controlling the thread under the target process to stop executing background frame drawing.

[0068] Among them, the target process can be a process that meets the conditions in the process corresponding to the application when the above-mentioned running application is in an invisible state. The above-mentioned target process may include at least one. After acquiring the target process, the terminal 102 can control the thread under the target process to stop executing background frame drawing. Among them, the thread can be the smallest unit for operation scheduling, which is included in the process and is the actual operation unit in the process. For example, the thread can be the actual operation unit for implementing frame drawing. A thread refers to a single sequential control flow in a process. Multiple threads can be concurrent in a process, and each thread executes different tasks in parallel. Among them, frame drawing (doframe) can be the application side receiving the vertical synchronization (vsync) signal from the SurfaceFlinger service, and the doframe frame drawing operation will be executed later. In doframe, the following callback types are responded to in turn, CALLBACK_INPUT (input callback), CALLBACK_ANIMATION (animation callback), CALLBACK_INSETS_ANIMATION (insert animation callback), CALLBACK_TRAVERSAL (traversal callback), CALLBACK_COMMIT (storage callback). The terminal 102 can control the target thread to skip the animation callback of the application in the doframe, so as to prevent meaningless drawing in the background of the process.

[0069] In the above process control method, by obtaining the running state of the running application, if the running state of the application switches from a visible state to an invisible state, the target process corresponding to the above application in the invisible state is obtained, and the conditions satisfied by the target process include: the corresponding interface and window are invisible; there is no corresponding notification and no corresponding component. And the thread under the above target process is controlled to stop executing background frame drawing. Compared with the traditional method of still executing the frame drawing process of the application when the application is in the background, this solution monitors the running state of the application, and when it detects that the application switches from a visible state to an invisible state, the thread under the target process that meets the conditions in the invisible state of the application is controlled to stop executing background frame drawing, thereby achieving the effect of reducing resource waste.

[0070] In one embodiment, obtaining the running status corresponding to the running application includes: obtaining the process status of the process corresponding to the application; obtaining the perception status of the interface and the perception status of the window corresponding to the application; obtaining the number of notifications and the number of components corresponding to the application; and obtaining the running status corresponding to the application from the process status, the perception status of the interface, the perception status of the window, the number of notifications and the number of components.

[0071] In this embodiment, the running application may be an application currently running in the terminal 102. The running application may include multiple running states, such as a visible state and an invisible state. The terminal 102 may obtain the running state corresponding to the running application. Figure 3 As shown, Figure 3 The figure is a schematic diagram of the structure of the running status monitoring in one embodiment. The terminal 102 can obtain the process status of the process corresponding to the above application; it can also obtain the perception status of the interface and the perception status of the window corresponding to the application; it can also obtain the number of notifications and the number of components corresponding to the application. The terminal 102 can obtain the running status corresponding to the application based on the above process status, the perception status of the interface, the perception status of the window, the number of notifications and the number of components. The above process status can be represented by the process status value (curProcState) and can be obtained through Figure 3 The AMS (ActivityManagerService, interface management service) in the above interface and window can monitor its status; the perception status of the above interface and window can be Figure 3 The WMS (WindowManagerService) in the Activity monitors its perception status, and an Activity contains a Window. The number of notifications can be obtained through Figure 3 The NMS (NotificationManagerService) in the notification management service monitors its quantity and display status; the quantity of the above components can be determined by Figure 3The AppWidgetService (application component service) in the terminal 102 monitors the number and display status of the application components. The above-mentioned interface management service, window management service, notification management service and application component management service can all be services set in the terminal 102.

[0072] Among them, after obtaining the running state of the above-mentioned running application, the terminal 102 can detect the running state to determine whether the running state of the application has changed. In order to mark the visible state of the application to the user, the state needs to be easily shared between application processes. When the application changes from visible to invisible, timeliness is not required; when it changes from invisible to visible, it needs to be timely. Therefore, in one embodiment, it also includes: based on the running state, detecting whether the application switches from a visible state to an invisible state; if it is detected that the process state value corresponding to the process switches from a first state value to a second state value, the perceptual state of the interface switches from a perceptible state to an imperceptible state, the perceptual state of the window switches from a perceptible state to an imperceptible state, the number of notifications is zero, and the number of components is zero, it is determined that the application switches from a visible state to an invisible state. In this embodiment, the terminal 102 can monitor the running state to monitor whether the application switches from a visible state to an invisible state. The terminal 102 can determine the running state of the application based on the above-mentioned process state, the perceptible state of the interface and / or window, the number of notifications of the application, and the number of components of the application. For example, the above-mentioned process state can be represented by a process state value (curProcState). Terminal 102 can use the change of the process state value to obtain the switching information of the application running state. When the application is visible, the process state value can be a first state value, and the first state value can be less than or equal to ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND. When the application is not visible, the process state value can be a second state value, and the second state value can be greater than ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND. This state value is mainly used for inter-process synchronization when the application switches from perceptible to imperceptible. The monitoring of the application by the terminal 102 may also include the monitoring of the perceived state of the interface and the perceived state of the window. For example, both the interface (Activity) and the window (Window) have corresponding states, including perceptible states and imperceptible states, etc. The terminal 102 can determine whether the interface and the window can be perceived by obtaining the relevant state values ​​in the Activity and the Window; the state of the above-mentioned interface and the window is mainly used to respond to the application when switching the perceived state, for example, when switching from imperceptible to perceptible state, to ensure timely judgment so that the logic will not misjudge the state and cause frame drawing failure. The monitoring of the application by the terminal 102 may also include the monitoring of the number of application notifications and the number of components. For example, the terminal 102 can obtain whether the application has corresponding notifications (notification) or components (widget) being displayed, so as to determine the number of notifications and components corresponding to the application; the detection of notifications and components by the terminal 102 can prevent the occurrence of cross-process display anomalies.

[0073] If the terminal 102 can detect that the process status value switches from the first status value to the second status value, the perception state of the interface switches from a perceptible state to an imperceptible state, the perception state of the window switches from a perceptible state to an imperceptible state, the number of notifications is zero and the number of components is zero, then the terminal 102 can determine that the application switches from a visible state to an invisible state.

[0074] Through the above embodiments, the terminal 102 can determine the running state of the application based on the process state of the application, the perception state of the application interface and / or window, the number of notifications and the number of components of the application, and can detect whether the application has switched states based on the above conditions, such as switching to an invisible state, so that the terminal 102 can stop background frame drawing in the invisible state, thereby reducing resource consumption.

[0075] In one embodiment, detecting whether an application switches from a visible state to an invisible state includes: detecting whether the application switches from a visible state to an invisible state at a preset time interval; if the detection result is no, extending the preset time interval to obtain a new preset time interval, and detecting whether the application switches from a visible state to an invisible state according to the new preset time interval; if the detection result is yes, restoring the preset time interval to an initial time interval.

[0076] In this embodiment, the terminal 102 can detect whether the application switches its running state, for example, whether it switches from a visible state to an invisible state. However, if the terminal 102 makes a judgment every time the application draws a frame, it will consume a lot of performance. For example, when the application has components or notifications in the background, the terminal 102 will consume a lot of resources by querying the number of notifications and components during multiple detections. Therefore, considering that when the application switches from visible to invisible, the restriction does not need to be timely, the terminal 102 can detect the switch from visible to invisible by means of interval judgment. For example, the terminal 102 can detect whether the application switches from a visible state to an invisible state according to a preset time interval. If the detection result of the last detection is no, that is, it is not necessary to limit frame drawing, and the time of the last detection is less than the preset time interval from the current time, the terminal 102 can skip the detection; if the result of the last detection is no, and the time of the last detection is greater than or equal to the preset time interval from the current time, then a judgment is performed. If the result of this detection is no, that is, it is not necessary to limit frame drawing, the terminal 102 can extend the preset time interval, for example, adjust the preset time interval to twice the original, obtain a new preset time interval, and detect whether the application switches from a visible state to an invisible state based on the new time interval. Among them, the value of the preset time interval can be within a preset range, for example, the minimum value can be 10 seconds, and the maximum value can be 2 minutes. If the terminal 102 detects that the result of the above-mentioned current detection is yes, that is, it is necessary to limit frame drawing, the terminal 102 can restore the preset time interval to the initial value, such as the minimum value. In addition, if the terminal 102 detects that the last detection result is yes, that is, frame drawing restriction is required, and the frame drawing process is currently occurring, then regardless of whether the time of the last detection and the current time reach the preset time interval, the terminal 102 can directly detect the running status of the application.

[0077] Through this embodiment, the terminal 102 can detect whether the application is switched from the visible state to the invisible state at a preset time interval, thereby achieving the effect of reducing resource consumption of detection.

[0078] In one embodiment, after obtaining the target process applied in the invisible state, it also includes: obtaining the interface of the target process; sending the second state value to the target process through the interface to trigger the target process to control the thread under it to stop background frame drawing based on the second state value.

[0079] In this embodiment, the above application may include multiple processes, and the number of the above target processes may also include multiple processes. The terminal 102 needs to monitor the state changes of the application across processes. When the terminal 102 determines that the target process of the application is in an invisible state, the terminal 102 can obtain the corresponding interface of the target process, and send the second state value corresponding to the invisible state to the target process through the obtained interface, so as to trigger the target process to control the thread under it to stop background frame drawing based on the second state value. For example, Figure 4 As shown, Figure 4 It is a schematic diagram of the structure inside a process in an embodiment. An application can be identified by a corresponding application (uid), and can include multiple processes (AppProcess), each of which can include a main thread (ApplicationThread) and a sub-thread, etc., wherein each thread can include a Choreographer (animation processing object) object, for example, the main thread includes the Main Choreographer (main animation processing object), and the sub-thread includes the Other Choreographer (other animation processing object). Choreographer is a thread-level singleton and has the function of processing the current thread message loop queue. It is responsible for coordinating the work of the three events of animation, input and drawing, that is, it can be an animation processing object.

[0080] For the visible status of the cross-process monitoring application, you can Figure 5 As shown, Figure 5 It is a structural diagram of cross-process communication in an embodiment. Terminal 102 can add a buried point in the updateUidsLocked method of OomAdjuster. The curProcState of uid will be updated here. Through the uid terminal 102 can find the corresponding ProcessRecord (process information), and then find the interface object IApplicationThread of each process ActivityThread. Through the dispatchUidCurProcState method added in the interface, the procstate (process state value) of the current uid is distributed to each process. In ActivityThread, terminal 102 caches the Choreographer object of the main thread of the process. When uid calls back dispatchUidCurProcState due to a change in the visible state, that is, when the process state is returned, ActivityThread will write the current state to the local cache. If the current state changes from invisible to visible, an animation callback will be reissued to the Choreographer object of the main thread. At this time, the main thread will notify the child thread to draw again, thereby achieving cross-process association.

[0081] Through this embodiment, the terminal 102 can set a trigger mechanism to achieve cross-process state synchronization through interface communication when the state changes, thereby improving the efficiency of operating state monitoring.

[0082] In one embodiment, controlling the thread under the target process to stop executing background frame drawing includes: sending a second status value to the main thread of the target process, and sending the second status value to at least one child thread of the target process through the main thread, so that the main thread and the at least one child thread determine whether the current thread meets the conditions for stopping frame drawing according to the second status value, and if so, stop executing background frame drawing of the current thread; wherein the conditions for stopping frame drawing include that the process status value of the process corresponding to the current thread is the second status value, the interface of the application corresponding to the current thread is invisible, the window of the application corresponding to the current thread is invisible, the number of notifications of the application corresponding to the current thread is zero, and the number of components of the application corresponding to the current thread is zero.

[0083] In this embodiment, after determining the target process, the terminal 102 can control the threads under the target process to stop executing background frame drawing. The terminal 102 can send the second state value representing the invisible state to the main thread of the target process, and send the second state value to at least one child thread corresponding to the target process through the main thread, so that the main thread and the at least one child thread determine whether the thread meets the condition of stopping frame drawing according to the second state value, and if so, stop executing the background frame drawing of the thread. That is, each thread in the target process can make a separate judgment to determine whether it is necessary to stop frame drawing, wherein the condition of stopping frame drawing includes that the process state value of the process corresponding to the thread is the second state value, the interface of the application corresponding to the thread is invisible, the window of the application corresponding to the thread is invisible, the number of notifications of the application corresponding to the thread is zero, and the number of components of the application corresponding to the thread is zero.

[0084] Specifically, in the same process, each thread can apply for its own unique Choreographer object. For this, we cache the Choreographer objects applied by other child threads in the main thread. When the thread doframe, since in the frame drawing, there may be a scenario where the main thread does not draw but the child thread draws, the terminal 102 can make each thread determine the visible state of the current application separately. If the above conditions are met, it is determined to be invisible, and the animation callback is not executed, and other types of callbacks can continue to execute. Among them, according to the Choreographer process combined with the summarized problem information, it can be determined that the application continuously applies for vsync (vertical synchronization) events in the background through the postframeCallback interface, and executes the animation type callback, wherein the animation callback is the default type of postframeCallback, and the postframeCallback is executed again in the callback to ensure that the process can continuously execute the doframe operation. In view of the principle of minimum change, when the application has been judged to be imperceptible, the terminal 102 can skip all Choreographer objects in the process to execute the animation type callback to break the above cycle and stop the execution of background frame drawing.

[0085] The above thread execution judgment process can be as follows: Figure 6 As shown, Figure 6 The figure is a flowchart of thread monitoring in one embodiment. During the frame drawing process of the thread, the thread first determines whether the corresponding process is a whitelist process. The process in the whitelist may not be restricted from frame drawing, and the whitelist can be set according to the actual situation; if it is not a whitelist process, the thread determines whether it needs to perform detection immediately to prevent the detection from consuming performance too frequently, and adjusts the preset time interval according to the result; the thread determines whether the current thread is in a perceptible state from five aspects, namely whether the corProState priority of the entire uid is high enough, whether the Activity and window of the process are visible, whether the uid has a corresponding component, and whether the uid has a corresponding notification; and according to the above detection results, it is determined whether an animation callback, that is, frame drawing, is required; if the thread is the main thread, and doframe is switched from an imperceptible state to a perceptible state, the terminal 102 can re-execute postFramCallback through other sub-threads that were suspended before the main thread zero, thereby resuming the frame drawing process of the sub-thread.

[0086] Through this embodiment, the terminal 102 can control each thread in the target process to individually determine whether it meets the condition for stopping frame drawing, and stop drawing the threads that meet the condition for stopping frame drawing, thereby achieving the effect of reducing performance resource consumption.

[0087] In one embodiment, after controlling the thread under the target process to stop background frame drawing, it also includes: caching the animation processing object to-be-executed queue corresponding to the target thread under the target process; the target thread is the main thread and / or child thread that stops executing the background frame drawing of this thread; if it is detected that the application switches from an invisible state to a visible state, the frame drawing of the target thread under the target process is resumed according to the animation processing objects in the cached animation processing object to-be-executed queue.

[0088] In this embodiment, when the application is not visible, the terminal 102 can control each thread under the target process to stop background frame drawing, and can also cache the animation processing object to-be-executed queue corresponding to the target thread under the target process, such as the Choreographer object to-be-executed queue, wherein the above-mentioned target thread is the main thread and / or sub-thread that stops executing the background frame drawing of this thread, that is, the thread that stops frame drawing. For example, in one embodiment, caching the animation processing object to-be-executed queue corresponding to the target thread under the target process includes: caching the animation processing object corresponding to the main thread in the main thread of the target process; caching the animation processing object of the sub-thread in the animation processing object corresponding to the main thread. In this embodiment, the terminal 102 can cache the animation processing object corresponding to the main thread, that is, the Choreographer object, in the main thread of the target process, and cache the animation processing object of the sub-thread in the animation processing object corresponding to the main thread.

[0089] After caching the above-mentioned animation processing object to be executed queue, the terminal 102 can continue to monitor the state change of the application. If it is detected that the application switches from an invisible state to a visible state, the terminal 102 can restore the frame drawing of the target thread under the target process according to the animation processing objects in the cached animation processing object to be executed queue. For example, in one embodiment, according to the animation processing objects in the cached animation processing object to be executed queue, the frame drawing of the target thread under the target process is restored, including: sending traversal callback information to the main thread corresponding to the target process to trigger the main thread to resume the execution of frame drawing; during the main thread's frame drawing process, detecting whether the application switches from an invisible state to a visible state, if so, detecting whether the animation processing object to be executed queue of the child thread cached by the main thread contains an unfinished frame drawing task; if it contains an unfinished frame drawing task, sending an animation callback instruction to the corresponding child thread to enable the corresponding child thread to resume the execution of the unfinished frame drawing task. In this embodiment, the terminal 102 can use the animation object to be executed queue to restore the thread's frame drawing process. Terminal 102 can send traversal callback information to the main thread corresponding to the target process, such as sending a TRAVERSAL type callback, thereby triggering the main thread to resume frame drawing. During the frame drawing process, the main thread can detect whether the application has switched from an invisible state to a visible state, that is, the main thread performs an additional judgment. If the result is yes, that is, the application has switched to a visible state, the terminal 102 can detect whether the animation processing object to-be-executed queue of the child thread cached by the main thread contains an unfinished frame drawing task. If it contains an unfinished frame drawing task, the main thread can send an animation callback instruction to the corresponding child thread, so that the corresponding child thread can resume the execution of the unfinished frame drawing task.

[0090] Specifically, when the above-mentioned invisible application is switched to the foreground, according to the system process, only the main thread will receive the traversal callback information sent by the system, that is, the TRAVELSAL type callback. Therefore, during the main thread's doframe frame drawing process, the main thread will additionally determine whether the current application has switched from an invisible state to a visible state. If so, it will check the animation processing object execution queue of other threads cached previously, that is, the Choreographer object execution queue, to detect whether there are any unexecuted animation callbacks. If so, an animation callback will be reissued to the Choreographer object to restart its frame drawing process. In particular, when this process has no window, the main thread will determine whether the current curProcState has changed during doframe frame drawing, and if so, it will also reissue animation callbacks to each cached thread.

[0091] Through the above embodiment, the terminal 102 can quickly restart the frame drawing of each thread through the animation processing object to be executed queue when the application switches from an invisible state to a visible state, thereby improving the processing efficiency of thread frame drawing restart.

[0092] In one embodiment, during the frame drawing process executed by the main thread, detecting whether the application switches from an invisible state to a visible state includes: during the frame drawing process executed by the main thread, if it is detected that the target process is a windowless process, determining through the main thread whether the process state value of the target process switches to a first state value, and if so, determining that the application switches from an invisible state to a visible state; if the target process is a windowed process and the window of the target process is in a perceptible state, determining that the application switches from an invisible state to a visible state.

[0093] In this embodiment, the main thread can additionally detect whether the application is switched from an invisible state to a visible state when executing frame drawing. The terminal 102 can make the main thread detect whether the target process is a window process when executing frame drawing; Figure 7 As shown, Figure 7 The figure is a flowchart of the state switching of a windowless process in an embodiment. If the main thread detects that the target process is a windowless process, the terminal 102 can determine whether the process state value of the target process is switched to the first state value through the main thread. If so, it is determined that the application is switched from the invisible state to the visible state. Specifically, the terminal 102 can first update the curProstate of the application process to the main thread of the process. If it is switched to the visible state at this time, the main thread executes a postFrameCallback to restart the process frame drawing process without an interface; the terminal 102 can also determine whether the process is an isCare (white list) process through the main thread. If not, it determines whether the preset time interval of the detection is met, and adjusts the time interval of the next detection according to the result. If detection is required, the terminal 102 determines whether it is currently in an imperceptible state (toCheck) through the main thread. If it is in an imperceptible state, the frame drawing process is skipped; and when the thread is the main thread and the current process state value is switched to a high priority, that is, the first state value, the terminal 102 can execute postFrameCallback for the animation processing object of the previously suspended child thread through the main thread, thereby restarting the frame drawing process of the child thread.

[0094] like Figure 8 As shown, Figure 8The figure is a flowchart of the state switching of a window process in one embodiment. If the main thread detects that the application is a window process and the target process window is in a perceptible state, it can be determined that the application is switched from an invisible state to a visible state. Specifically, the terminal 102 can first update the perceptible state of the application process, for example, by updating through a TRAVELSAL type callback, and determine whether it is a whitelist process. If not, it determines whether the preset time interval for detection is met, and adjusts the time interval for the next detection according to the result. If detection is required, the terminal 102 determines whether the current application is in an imperceptible state, and if so, skips the frame drawing process. In addition, if the current thread is the main thread, the main thread can execute postFrameCallback to the animation processing object of the previously paused child thread when the window switches from an imperceptible state to a perceptible state, thereby restarting the frame drawing process of the child thread.

[0095] Through this embodiment, the terminal 102 can determine whether the application is switched from an invisible state to a visible state based on different judgment criteria based on whether the process has a window, thereby achieving the effect of improving the response efficiency of the state switching.

[0096] In one embodiment, Fig. 9 As shown, Fig. 9 FIG. 1 is a flow chart of a process control method in another embodiment. The timing chart of the above method can be as follows: Fig.10 As shown, Fig.10 This is a timing diagram of a process control method in an embodiment. It includes the following processes:

[0097] When a process is started, the terminal 102 may cache the animation processing object (Choreographer) of the main thread in the main thread (activityThread) of each process, and cache the animation processing objects of other threads of the process in the animation processing object of the main thread.

[0098] When the application switches from the visible state to the invisible state, the terminal 102 can first detect whether the application is a whitelist application. If it is not a whitelist application, each child thread of the process can determine whether the current process state value (curProstate) is less than ActivityManager.PROCESS_STATE_IMPORTANT_F--OREGROUND, that is, whether it is the second state value, whether the interface (activity) of the current process is visible, whether the current process window (window) is visible, whether the current application identifier (uid) has a corresponding notification, and whether the current application identifier has a corresponding component (widget). If none of them exists, the frame drawing (doframe) process is skipped.

[0099] In particular, when the process is a process without a window and is a child thread performing frame drawing, the terminal 102 may distribute the curProcState corresponding to the application to the ActivityThread of the process, and then the thread determines the attribute and stops doframe.

[0100] When the terminal 102 detects that the application switches from invisible to visible, if the process has an interface, wms will send a TRAVERSAL type callback to the Choreographer object of the process through the view drawing process. When the main thread responds to this callback, the main thread can determine whether the current application switches from invisible to visible. If so, it will check the status of each sub-thread at the same time and restart the previously restricted sub-thread drawing process.

[0101] When the process has no interface, when OomAdjuster adjusts the process status value of the application, it will distribute the current state change to the ActivityThread of each process of the application. Since it becomes visible at this time, the ActivityThread will reissue an animation callback (animation callback) for the Choreographer object of the main thread for restart, and mark that the process status value has changed at this time. When the main thread responds to this frame drawing (doframe), it will determine whether the current process status value has changed. If so, it will reissue an animation callback for the previously restricted child thread.

[0102] Through this embodiment, the terminal 102 monitors the running status of the application, and when it detects that the application switches from a visible state to an invisible state, it controls the thread under the target process that meets the conditions in the invisible state of the application to stop executing background frame drawing, thereby achieving the effect of reducing resource waste.

[0103] It should be understood that although Figure 2 , Figure 6-Figure 9 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2 , Figure 6-Figure 9 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.

[0104] In one embodiment, Fig.11 As shown, a process control device is provided, including: a first acquisition module 500, a second acquisition module 502 and a control module 504, wherein:

[0105] The first acquisition module 500 is used to acquire the running status of the running application.

[0106] The second acquisition module 502 is used to acquire the target process of the application in the invisible state if the running state is switched from the visible state to the invisible state; the target process meets the conditions: the corresponding interface and / or window is invisible, there is no corresponding notification and no corresponding component.

[0107] The control module 504 is used to control the thread under the target process to stop executing background frame drawing.

[0108] In one embodiment, the above-mentioned first acquisition module 500 is specifically used to obtain the process status of the process corresponding to the application; obtain the perception status of the interface and the perception status of the window corresponding to the application; obtain the number of notifications and the number of components corresponding to the application; and obtain the corresponding running status of the application from the process status, the perception status of the interface, the perception status of the window, the number of notifications and the number of components.

[0109] In one embodiment, the above-mentioned device also includes: a detection module, which is used to detect whether the application switches from a visible state to an invisible state based on the running state; if it is detected that the process state value corresponding to the process switches from a first state value to a second state value, the perception state of the interface switches from a perceptible state to an imperceptible state, the perception state of the window switches from a perceptible state to an imperceptible state, the number of notifications is zero, and the number of components is zero, it is determined that the application switches from a visible state to an invisible state.

[0110] In one embodiment, the above-mentioned detection module is specifically used to detect whether the application switches from a visible state to an invisible state according to a preset time interval; if the detection result is no, the preset time interval is extended to obtain a new preset time interval, and based on the new preset time interval, detect whether the application switches from a visible state to an invisible state; if the detection result is yes, the preset time interval is restored to the initial time interval.

[0111] In one embodiment, the above-mentioned device also includes: a third acquisition module, which is used to obtain the interface of the target process; through the interface, the second status value is sent to the target process to trigger the target process to control the thread under it to stop background frame drawing based on the second status value.

[0112] In one embodiment, the control module 504 is specifically used to send the second status value to the main thread of the target process, and send the second status value to at least one child thread of the target process through the main thread, so that the main thread and the at least one child thread determine whether the current thread meets the conditions for stopping frame drawing according to the second status value, and if so, stop executing background frame drawing of the current thread; wherein the conditions for stopping frame drawing include that the process status value of the process corresponding to the current thread is the second status value, the interface of the application corresponding to the current thread is invisible, the window of the application corresponding to the current thread is invisible, the number of notifications of the application corresponding to the current thread is zero, and the number of components of the application corresponding to the current thread is zero.

[0113] In one embodiment, the above-mentioned device also includes: a recovery module, which is used to cache the animation processing object to-be-executed queue corresponding to the target thread under the target process; the target thread is the main thread and / or child thread that stops executing the background frame drawing of this thread; if it is detected that the application switches from an invisible state to a visible state, the frame drawing of the target thread under the target process is restored according to the animation processing objects in the cached animation processing object to-be-executed queue.

[0114] In one embodiment, the above-mentioned recovery module is specifically used to cache the animation processing object corresponding to the main thread in the main thread of the target process; and cache the animation processing object of the child thread in the animation processing object corresponding to the main thread.

[0115] In one embodiment, the above-mentioned recovery module is specifically used to send traversal callback information to the main thread corresponding to the target process, triggering the main thread to resume frame drawing; during the main thread's frame drawing process, detect whether the application is switched from an invisible state to a visible state, and if so, detect whether the animation processing object to-be-executed queue of the child thread cached by the main thread contains an unfinished frame drawing task; if it contains an unfinished frame drawing task, send an animation callback instruction to the corresponding child thread to enable the corresponding child thread to resume executing the unfinished frame drawing task.

[0116] In one embodiment, the above-mentioned recovery module is specifically used for, during the frame drawing process executed by the main thread, if it is detected that the target process is a windowless process, determining through the main thread whether the process state value of the target process is switched to the first state value, and if so, determining that the application is switched from an invisible state to a visible state; if the target process is a windowed process and the window of the target process is in a perceptible state, determining that the application is switched from an invisible state to a visible state.

[0117] For the specific definition of the process control device, please refer to the definition of the process control method above, which will not be repeated here. Each module in the above process control device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0118] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.12 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a process control method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0119] Those skilled in the art will understand that Fig.12 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0120] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the above-mentioned process control method when executing the computer program.

[0121] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned process control method is implemented.

[0122] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0123] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0124] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A process control method, characterized in that: The method comprises: Get the running status of the running application; If the running state is switched from a visible state to an invisible state, obtaining a target process of the application in the invisible state; the target process satisfies the following conditions: the corresponding interface and / or window is invisible, there is no corresponding notification, and there is no corresponding component; Controlling the thread under the target process to stop executing background frame drawing, including: sending a second state value to the main thread of the target process, and sending the second state value to at least one child thread of the target process through the main thread, so that the main thread and the at least one child thread determine whether the thread meets the condition of stopping frame drawing according to the second state value, and if so, stop executing background frame drawing of the thread; Among them, the second status value represents the process status value corresponding to the target process when the application is invisible; the conditions for stopping frame drawing include that the process status value of the process corresponding to the current thread is the second status value, the interface of the application corresponding to the current thread is invisible, the window of the application corresponding to the current thread is invisible, the number of notifications of the application corresponding to the current thread is zero, and the number of components of the application corresponding to the current thread is zero.

2. The method according to claim 1, characterized in that The obtaining the running status corresponding to the running application includes: Obtaining the process status of the process corresponding to the application; Obtaining the perception state of the interface and the perception state of the window corresponding to the application; Obtain the number of notifications and components corresponding to the application; The corresponding running state of the application is obtained from the process state, the perceived state of the interface, the perceived state of the window, the number of notifications, and the number of components.

3. The method according to claim 2, characterized in that The method further comprises: Based on the running state, detect whether the application switches from a visible state to an invisible state; if it is detected that the process state value corresponding to the process switches from a first state value to a second state value, the perception state of the interface switches from a perceptible state to an imperceptible state, the perception state of the window switches from a perceptible state to an imperceptible state, the number of notifications is zero, and the number of components is zero, determine that the application switches from a visible state to an invisible state.

4. The method according to claim 3, characterized in that The detecting whether the application is switched from a visible state to an invisible state includes: Detecting whether the application switches from a visible state to an invisible state at a preset time interval; If the result of this detection is no, the preset time interval is extended to obtain a new preset time interval, and according to the new preset time interval, it is detected whether the application is switched from the visible state to the invisible state; If the detection result is yes, the preset time interval is restored to the initial time interval.

5. The method according to claim 3, characterized in that: After obtaining the target process of the application in the invisible state, the method further includes: Obtaining the interface of the target process; The second state value is sent to the target process through the interface to trigger the target process to control the thread under it to stop background frame drawing based on the second state value.

6. The method according to claim 3, characterized in that After controlling the thread under the target process to stop background frame drawing, the method further includes: Cache the animation processing object to-be-executed queue corresponding to the target thread under the target process; the target thread is the main thread and / or child thread that stops executing the background frame drawing of the thread; If it is detected that the application is switched from an invisible state to a visible state, frame drawing of the target thread under the target process is restored according to the cached animation processing objects in the queue of animation processing objects to be executed.

7. The method according to claim 6, characterized in that The cache of the animation processing object execution queue corresponding to the target thread under the target process includes: caching the animation processing object corresponding to the main thread in the main thread of the target process; In the animation processing object corresponding to the main thread, the animation processing object of the child thread is cached.

8. The method according to claim 7, characterized in that The step of restoring the frame drawing of the target thread under the target process according to the cached animation processing objects in the queue to be executed includes: Sending traversal callback information to the main thread corresponding to the target process, triggering the main thread to resume executing frame drawing; During the frame drawing process executed by the main thread, detecting whether the application is switched from an invisible state to a visible state, If yes, then detecting whether the animation processing object to-be-executed queue of the child thread cached by the main thread contains an unfinished frame drawing task; If an unfinished frame drawing task is included, an animation callback instruction is sent to the corresponding child thread, so that the corresponding child thread resumes executing the unfinished frame drawing task.

9. The method according to claim 8, characterized in that The detecting whether the application is switched from an invisible state to a visible state during the frame drawing execution of the main thread includes: During the frame drawing process executed by the main thread, if it is detected that the target process is a windowless process, the main thread determines whether the process state value of the target process is switched to the first state value, and if so, determines that the application is switched from an invisible state to a visible state; If the target process is a process with a window, and the window of the target process is in a perceptible state, it is determined that the application is switched from an invisible state to a visible state.

10. A process control device, characterized in that: The device comprises: A first acquisition module is used to acquire the running status of the running application; A second acquisition module is used to acquire a target process of the application in the invisible state if the running state is switched from the visible state to the invisible state; the target process satisfies the following conditions: the corresponding interface and / or window is invisible, there is no corresponding notification, and there is no corresponding component; a control module, used for controlling the thread under the target process to stop executing background frame drawing, specifically used for sending a second state value to the main thread of the target process, and sending the second state value to at least one child thread of the target process through the main thread, so that the main thread and the at least one child thread determine whether the thread meets the condition of stopping frame drawing according to the second state value, and if so, stop executing background frame drawing of the thread; Among them, the second status value represents the process status value corresponding to the target process when the application is invisible; the conditions for stopping frame drawing include that the process status value of the process corresponding to the current thread is the second status value, the interface of the application corresponding to the current thread is invisible, the window of the application corresponding to the current thread is invisible, the number of notifications of the application corresponding to the current thread is zero, and the number of components of the application corresponding to the current thread is zero.

11. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 9 are implemented.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.