Method for executing drawing operation, electronic device and readable medium
By judging the status and drawing behavior of the application and prohibiting it from requesting VSYNC signals, the resource waste caused by invalid drawing of the background application is solved, and the system resource saving and equipment energy efficiency improvement are achieved.
Patent Information
- Application Number
- CN202311837572.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-24
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2042-06-24
AI Technical Summary
Applications on electronic devices perform invalid drawing operations in the background state, wasting system resources, increasing heat generation and power consumption.
By determining whether the application is in the background state and whether an invalid background drawing is performed, the application is prohibited from requesting the VSYNC signal, thereby avoiding invalid drawing operations.
It effectively avoids the application performing invalid drawing operations in the background state, saves system resources, and reduces the heating and power consumption of electronic devices.
Smart Images

Figure CN118400459B_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application with the application date of June 24, 2022, application number 202210722559.X, and invention name “Method for executing drawing operations, electronic device and readable medium”. Technical Field
[0002] The present application relates to the field of electronic technology, and in particular to a method for executing a drawing operation, an electronic device, a computer program product, and a computer-readable storage medium. Background Art
[0003] There are more and more applications configured on electronic devices such as mobile phones. However, due to the limitation of the screen size of electronic devices, electronic devices can only display the display interface of one or several applications in a period of time. Other applications that are started but whose display interface is not displayed on the screen of the electronic device are in the background state.
[0004] When an application is in the background state, it still occupies the system resources of the electronic device, such as memory, CPU computing load, etc., to perform drawing operations. However, an application in the background state does not provide a visual interface or view for the user, and the drawing operations it performs are invalid drawing operations. The application's invalid drawing operations will waste the system resources of the electronic device and increase the heat generation and power consumption of the electronic device. Summary of the invention
[0005] The present application provides a method for executing a drawing operation, an electronic device, a computer program product, and a computer-readable storage medium, the purpose of which is to prevent an application program of an electronic device from executing invalid drawing operations, wasting system resources of the electronic device, and increasing heat generation and power consumption of the electronic device.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] In a first aspect, the present application provides a method for executing a drawing operation, which is applied to an electronic device, and the electronic device is configured with an application. The method for executing a drawing operation provided by the present application includes: the electronic device determines that the application applies for a vertical synchronization VSYNC signal request, and the VSYNC signal is used to trigger the application to perform a drawing operation; the electronic device determines that the application is in a background state and is performing invalid background drawing; the electronic device prohibits the application from requesting a VSYNC signal.
[0008] It can be seen from the above content that: when an electronic device determines that an application is requesting a VSYNC signal, it determines whether the application should be prohibited from requesting a VSYNC signal by determining whether the application is in the background state and whether the application is performing invalid background drawing. When the application is in the background state and performing invalid background drawing, the electronic device prohibits the application from requesting a VSYNC signal to prevent the application from performing drawing operations to refresh the interface, which wastes the system resources of the electronic device and increases the heat generation and power consumption of the electronic device.
[0009] In a possible implementation, before the electronic device prohibits the application from requesting a VSYNC signal, the method for executing the drawing operation further includes: the electronic device determining that the application is a third-party application, and the third-party application is not an application provided by the electronic device system.
[0010] In the above possible implementation, since the system applications and system services of the electronic device also need to display the interface when in the background state, the request for the VSYNC signal cannot be prohibited. Therefore, before the electronic device prohibits the application from requesting the VSYNC signal, it must first determine that the application requesting the VSYNC signal is the third application.
[0011] In one possible implementation, the electronic device determines whether an application is in a background state by: the electronic device obtains a flag configured for the application, wherein the flag configured for the application is synchronized with the state of the application; the electronic device determines whether the application is in a background state by using the flag configured for the application; wherein the flag configured for the application is a first value, and the electronic device determines that the application is in a background state.
[0012] In the above possible implementation, the flag bit configured by the electronic device for the application is synchronized with the state of the application, that is, follows the state of the application. When the application is in the background state, the flag bit is a first value, such as false, and when the application is in the foreground state, the flag bit is a second value, such as true.
[0013] In one possible implementation, the manner in which an electronic device determines whether an application is in a background state includes: the electronic device uses parameters in a file system of the application to determine whether the application is in a background state; wherein, if the parameters in the file system of the application are greater than a first value, the electronic device determines that the application is in a background state; the electronic device uses parameters of a system process of the electronic device for the application to determine whether the application is in a background state; wherein, if the parameters of the system process of the electronic device for the application are greater than a second value, the electronic device determines that the application is in a background state; or, the electronic device uses variables in the application process to determine whether the application is in a background state; wherein, if the variables in the application process are greater than a second value, the electronic device determines that the application is in a background state.
[0014] In one possible implementation, the manner in which an electronic device determines that an application is in a background state includes: the electronic device obtains a flag bit configured for the application, as well as parameters in the file system of the application, parameters of the system process of the electronic device for the application, and at least one of variables in the application process, wherein the flag bit configured for the application is synchronized with the state of the application; the electronic device determines whether the application is in the background state by using the flag bit configured for the application, as well as parameters in the file system of the application, parameters of the system process of the electronic device for the application, and at least one of variables in the application process; wherein the flag bit configured for the application is a first value, and at least one of the parameters in the file system of the application, parameters of the system process of the electronic device for the application, and variables in the application process meet the requirement that the application is in the background state, and the electronic device determines that the application is in the background state.
[0015] In one possible implementation, the manner in which an electronic device determines whether an application is performing invalid background drawing includes: the electronic device determines whether the number of times the application completes drawing within a predetermined time period reaches a threshold; wherein, if the electronic device determines that the number of times the application completes drawing within the preset time period reaches a threshold, then the electronic device determines that the application is performing invalid background drawing.
[0016] In one possible implementation, the electronic device determines that before the application performs invalid post-effect drawing, the process also includes: when the electronic device determines that when the application requests a VSYNC signal, the shielding interval is not opened, wherein the shielding interval is opened and the electronic device prohibits the application from requesting a VSYNC signal within the time period indicated by the shielding interval.
[0017] In a possible implementation, after the electronic device prohibits the application from requesting the VSYNC signal, the method further includes: the electronic device turning on a shielding interval.
[0018] In the above possible implementation manner, the electronic device sets a shielding interval. After the electronic device opens the shielding interval, multiple requests for VSYNC signals by the application program for background drawing within the shielding interval can be prohibited.
[0019] In a possible implementation, after the electronic device determines that the application program requests a vertical synchronization VSYNC signal, the process further includes: if the electronic device determines that the application program is in the background state and the shielding interval is in the open state, the application program is prohibited from requesting the VSYNC signal.
[0020] In a possible implementation, before the electronic device prohibits the application from requesting the VSYNC signal, the process further includes: the electronic device determines that the moment when the application applies for requesting the VSYNC signal is outside the background delay interval.
[0021] In the above possible implementation manner, when the application switches to the background state, there may be a need to display the window of the application due to some reasons within a certain period of time, and the request for the VSYNC signal cannot be prohibited. Therefore, before the electronic device prohibits the application from requesting the VSYNC signal, it is necessary to determine that the moment when the application applies for the VSYNC signal is outside the background delay interval.
[0022] In one possible implementation, after the electronic device determines that the application is applying for a vertical synchronization VSYNC signal, it also includes: the electronic device determines that the application is in the background state, and determines that the moment when the application is applying for a VSYNC signal is not outside the background delay interval, and the electronic device switches to the background delay interval for a preset time, wherein the electronic device allows the application to request a VSYNC signal within the preset time of switching to the background delay interval.
[0023] In a possible implementation, the method further includes: the electronic device determining that an application program requests drawing; and the electronic device determining that the application program is in a background state and is performing invalid background drawing, prohibiting the application program from requesting a VSYNC signal.
[0024] In the above possible implementations, when an application executes multiple processes, it may involve applying for a VSYNC signal. If the application is in the background state, and the application applies for a VSYNC signal, which comes from the drawing request process executed by the application, the problem of SyncBarrier will appear. The SyncBarrier problem will cause the synchronization message in the drawing request process to be blocked and unable to execute when the application switches from the background state to the foreground state, and then the application cannot apply for a VSYNC signal, causing the screen displayed by the application on the screen of the electronic device to freeze. Therefore, when the electronic device determines that the application has applied for a drawing request, the electronic device also determines that the application is in the background state and is performing invalid background drawing, and prohibits the application from requesting a VSYNC signal.
[0025] In a second aspect, the present application provides an electronic device comprising: one or more processors, a memory and a display screen; the memory and the display screen are coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the execution method of the drawing operation as described in any one of the first aspects.
[0026] In a third aspect, the present application provides a computer-readable storage medium for storing a computer program. When the computer program is executed, it is specifically used to implement a method for executing a drawing operation as described in any one of the first aspects.
[0027] In a fourth aspect, the present application provides a computer program product. When the computer program product is run on a computer, the computer executes the method for executing the drawing operation as described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A diagram showing the foreground and background states of an application configured on a mobile phone provided in an embodiment of the present application;
[0029] Figure 2 A hardware structure diagram of an electronic device provided in an embodiment of the present application;
[0030] Figure 3 A software architecture diagram of an electronic device provided in an embodiment of the present application;
[0031] Figure 4 The timing diagram of setting the flag boolean isVisible when the third-party application of the electronic device is switched to the foreground state;
[0032] Figure 5The timing diagram of setting the flag boolean isVisible when the third-party application of the electronic device switches to the background state;
[0033] Figure 6 A timing diagram of application state switching and background drawing detection provided in an embodiment of the present application;
[0034] Figure 7 A flowchart of a method for executing a drawing operation provided in an embodiment of the present application;
[0035] Figure 8 A flowchart of an electronic device provided in an embodiment of the present application detecting whether an application meets the feature recognition requirements of background drawing;
[0036] Fig. 9 A flowchart of a method for executing a drawing operation provided by another embodiment of the present application;
[0037] Fig.10 A timing diagram of background drawing detection provided in an embodiment of the present application;
[0038] Fig.11 A flowchart of a method for executing a drawing operation provided by another embodiment of the present application. DETAILED DESCRIPTION
[0039] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. The terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the embodiments of the present application, "one or more" refers to one, two or more; "and / or" describes the association relationship of the associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0040] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0041] The multiple involved in the embodiments of the present application means greater than or equal to two. It should be noted that in the description of the embodiments of the present application, the words "first", "second", etc. are only used for the purpose of distinguishing the description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying an order.
[0042] Currently, mobile phones and other electronic devices are equipped with multiple applications. Depending on whether the application directly interacts with the user, the application state can be divided into the foreground state and the background state. When the application is in the foreground state, its interface is visible to the user, and the user can input operations on the application interface. When the application is in the background state, its interface is invisible to the user.
[0043] Generally, if the application meets any of the following three conditions, the application is in the foreground state, otherwise the application is in the background state. The three conditions are: the application has a visible activity, the application has a foreground service, and other foreground applications are associated with the application.
[0044] For example, Figure 1 A diagram showing the foreground and background states of applications configured on a mobile phone.
[0045] Figure 1 (a) in the figure shows the interface of the phone application in the foreground state. The user can instruct the phone to open the phone application by clicking the icon of the phone application on the phone screen, pressing a specific physical button or button combination, inputting voice, making air gestures, etc. After the phone application is started, the phone application is in the foreground state, and its interface can be displayed on the phone screen.
[0046] After the application is started, if the user exits the application by inputting an operation on the phone screen, but if the process of the application is not released, the state of the application will be switched to the background state. Of course, the user can also input an operation on the phone screen to find the application in the background state on the phone.
[0047] For example, a user Figure 1 As shown in (a), a swipe up operation is input on the lower edge of the mobile phone screen. In response to the swipe up operation input by the user, the mobile phone displays the launched application on the screen. The launched application can be understood as: the mobile phone has an application process running, and the application process has not been released. Therefore, the launched applications displayed on the screen will include: applications in the background state and applications in the foreground state. For example, Figure 1 (b) shows multiple launched applications displayed on the phone screen. Users can Figure 1 A sliding operation is input on the display interface of the multiple launched applications shown in (b) to achieve sliding display of the interfaces of the multiple launched applications. Figure 1 (b) and (c) show multiple launched applications, with the phone application in the foreground and the message application and gallery application in the background.
[0048] It should be noted that users can also Figure 1 On the display interface of multiple launched applications shown in (b), a click operation on the application interface is input to control the mobile phone screen to display the application interface in full screen. Of course, if the mobile phone screen displays the interface of the application in the background state in full screen, the state of the application will be switched to the foreground state.
[0049] After each application is started, when the application needs to display a visual interface or view for the first time, at least one choreographer belonging to the application will be generated.
[0050] When the application needs to refresh the interface or view, Choreographer will request a vertical synchronization (VSYNC) signal from the image synthesizer (SurfaceFlinger). After receiving the VSYNC signal sent by SurfaceFlinger, Choreographer can start drawing operations.
[0051] Surface Flinger is usually set in the system library of the software framework of the electronic device, and is used to generate the interface or view layer of the application when called by the application. In some embodiments, Surface Flinger generates a software VSYNC model based on receiving the hardware VSYNC signal sent by the display driver. The software VSYNC model is used to generate a VSYNC signal according to the VSYNC cycle simulated by the software VSYNC model based on the hardware VSYNC signal when receiving a request sent by the application. The VSYNC signal is used to control the rhythm of drawing and rendering of the display screen and layer synthesis, that is, to control the rhythm of the application performing drawing operations, and of course, it also triggers the application to perform drawing operations.
[0052] The software VSYNC model receives multiple hardware VSYNC signals and simulates a VSYNC cycle according to the frequency of the received hardware VSYNC signals.
[0053] After receiving the VSYNC signal, Choreographer will process the event tasks of the application through the doFrame callback method to complete the drawing operation. Usually, the event tasks of the application may include four event tasks. Among them, the four event tasks are CALLBACK_INPUT, CALLBACK_ANIMATION, CALLBACK_TRAVERSAL and CALLBACK_COMMIT. The doFrame callback method includes four doCallBacks callback methods, which are used to process the above four event tasks respectively. Of course, after receiving the VSYNC signal, Choreographer is not limited to processing the above four event tasks through the doFrame callback method.
[0054] CALLBACK_INPUT is an input event task, where the input event task is the data that the application encapsulates and distributes the input event to Choreographer. The input event can be the interaction between the user and the application received by the application. For example, the input event can be the user clicking on an interactive control of the application, or the user sliding on the interface of the application (swiping up and down, sliding left and right, etc.), or the user's voice input, etc., which are not limited here. After determining the input event, the application performs preliminary processing on the input event, generates an input event task corresponding to the input event, and passes the input event task to Choreographer.
[0055] CALLBACK_ANIMATION is an animation event task, which is the data required by the application to calculate the animation (Animation). Among them, animation can include: view animation (View Animation), frame animation (Drawable Animation), property animation (Property Animation), etc.
[0056] CALLBACK_TRAVERSAL is a layout event task, which is used to participate in Choreographer to calculate the drawing data of the view or interface. The calculated drawing data will be submitted to other modules of the application to determine the width, height, position, shape, etc. of the content displayed in the view.
[0057] CALLBACK_COMMIT is a commit event task, which is used to mark that Choreographer has completed the drawing operation corresponding to a vertical synchronization signal.
[0058] Mobile phones and other electronic devices will not determine whether the application requesting the VSYNC signal really needs to perform drawing operations. After any application of the electronic device requests the VSYNC signal from Surface Flinger, Surface Flinger will distribute the VSYNC signal to it. In addition, users can open multiple applications when using electronic devices. However, due to the size of the screen of the electronic device, at a certain moment, the user can only display the interface of one or a few applications on the screen, and the application that is opened but whose interface is not displayed on the screen will switch to the background state. For applications in the background state, since the process of the application has not been released, it still holds Choreographer. When the application performs certain operations in the background, it will also trigger Choreographer to perform drawing operations.
[0059] Since the application in the background state has no view or interface to display to the user, the result of the drawing operation performed by the application in the background state will not be perceived by the user. In addition, since the Choreographer of the application in the background state will only be assigned animation event tasks, when the application in the background state performs a drawing operation, it actually only processes the animation event task. Therefore, the drawing operation performed by the application in the background state can be considered as an invalid drawing operation.
[0060] For users, when an electronic device displays the interface of an application, it is necessary for the application to perform a drawing operation to refresh the interface; however, when the electronic device turns off the display of the application interface and before the electronic device displays the interface of the application again, the application performs a drawing operation to refresh the interface, which wastes system resources of the electronic device and increases the heat and power consumption of the electronic device.
[0061] Based on this, an embodiment of the present application provides a method for executing a drawing operation, so that when an application requests drawing or a VSYNC signal, it is detected that the application is in the background state, belongs to a third-party application, and the request for drawing or the VSYNC signal is to perform an invalid background drawing operation, then the application is prohibited from requesting a VSYNC signal.
[0062] Among them, third-party applications are different from system applications. System applications refer to applications that are pre-installed on electronic devices and are applications that come with the electronic device system. When an electronic device is turned on for the first time, the desktop of the electronic device will display the icon of the system application. Third-party applications refer to applications produced by a third party and need to be installed by the user on the electronic device.
[0063] The method for executing the drawing operation provided in the embodiment of the present application can be applied to electronic devices such as mobile phones, tablet computers, laptops, ultra-mobile personal computers (UMPCs), handheld computers, netbooks, personal digital assistants (PDAs), wearable electronic devices, and smart watches.
[0064] The following uses a mobile phone as an example to introduce the hardware structure of the electronic device of the embodiment of the present application.
[0065] Figure 2 This is an example of the composition of an electronic device provided in an embodiment of the present application. Figure 2 As shown, the electronic device 200 may include a processor 210, an internal memory 220, a display screen 230, an antenna 1, an antenna 2, a mobile communication module 240, and a wireless communication module 250, etc.
[0066] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 200. In other embodiments, the electronic device 200 may include more or fewer components than shown in the figure, or combine some components, or separate 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.
[0067] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, a smart sensor hub (sensor hub) and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.
[0068] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 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 210, and thus improves the efficiency of the system.
[0069] The internal memory 220 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 210 executes various functional applications and data processing of the electronic device 200 by running the instructions stored in the internal memory 220. The internal memory 220 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 during the use of the electronic device 200 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 220 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. The processor 210 executes various functional applications and data processing of the electronic device 200 by running the instructions stored in the internal memory 220, and / or the instructions stored in the memory provided in the processor.
[0070] In some embodiments, the internal memory 220 stores instructions for executing a method for executing a drawing operation. The processor 210 can execute the instructions stored in the internal memory 220 to detect that the application is in a background state, is a third-party application, and that the drawing or VSYNC signal requested is to perform an invalid background drawing operation, and then prohibit the application from requesting a VSYNC signal.
[0071] The electronic device implements the display function through a GPU, a display screen 230, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 230 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 210 may include one or more GPUs, which execute program instructions to generate or change display information.
[0072] The display screen 230 is used to display images, videos, etc. The display screen 230 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 may include 1 or N display screens 230, where N is a positive integer greater than 2.
[0073] The wireless communication function of the electronic device 200 can be implemented through the antenna 1, the antenna 2, the mobile communication module 240, the wireless communication module 250, the modem processor and the baseband processor.
[0074] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 200 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 2 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.
[0075] The mobile communication module 240 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 200. The mobile communication module 240 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 240 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 240 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 240 can be set in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 240 can be set in the same device as at least some of the modules of the processor 210.
[0076] The wireless communication module 250 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 200. The wireless communication module 250 can be one or more devices integrating at least one communication processing module. The wireless communication module 250 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 210. The wireless communication module 250 can also receive the signal to be sent from the processor 210, modulate the frequency of the signal, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0077] In addition, on top of the above components, the foldable electronic device runs an operating system, such as an iOS operating system, an Android operating system, a Windows operating system, etc. Applications can be installed and run on the operating system.
[0078] Figure 3 It is a software structure block diagram of the foldable electronic device according to an embodiment of the present application.
[0079] 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 four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.
[0080] The application layer can include a series of application packages. Figure 3 As shown, the application package may include applications such as gallery, map, calendar, call, and message.
[0081] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 3 As shown, the application framework layer may include a window manager, a content provider, a telephony manager, a resource manager, a notification manager, a view system, a Surface Flinger API, and the like.
[0082] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0083] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0084] The phone manager is used to provide communication functions for electronic devices, such as the management of call status (including answering, hanging up, etc.).
[0085] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0086] The notification manager enables applications to display notification information in the status bar. It 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 a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0087] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0088] Surface Flinger API is the interface of the image synthesizer (Surface Flinger). Applications at the application layer can call Surface Flinger through Surface Flinger API and control the operation of Surface Flinger.
[0089] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system. In some embodiments of the present application, the application cold start will run in the Android runtime, and the Android runtime will obtain the optimized file status parameters of the application. Then, the Android runtime can determine whether the optimized file is outdated due to system upgrades based on the optimized file status parameters, and return the judgment result to the application management module.
[0090] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0091] The application layer and the application framework layer run in a 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 functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0092] The system library may include multiple functional modules, such as a surface manager, a 3D graphics processing library (such as OpenGL ES), a 2D graphics engine (such as SGL), and Surface Flinger.
[0093] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0094] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis and layer processing.
[0095] A 2D graphics engine is a drawing engine for 2D drawings.
[0096] Surface Flinger is as mentioned above and will not be repeated here.
[0097] The kernel layer is a layer between hardware and software. The kernel layer at least includes a display driver, etc. In some embodiments, the display driver is used to control the display screen to display images.
[0098] The hardware layer may include the aforementioned foldable electronic device hardware components. Figure 3 Shown the display.
[0099] It should be noted that although the embodiments of the present application are described using the Android system as an example, its basic principles are also applicable to electronic devices based on operating systems such as iOS and Windows.
[0100] The following combination Figure 4 , the process of executing the drawing operation provided in the embodiment of the present application is introduced.
[0101] First of all, it should be noted that third-party applications in electronic devices are all configured with a flag bit booleanisVisible, which is used to indicate the status of the application of the electronic device. boolean isVisible = true, indicating that the application is in the foreground state; boolean isVisible = false, indicating that the application is in the background state.
[0102] Generally, the flag bit boolean isVisible configured for the third-party application can be saved in the ActivityThread.java file. Of course, the flag bit boolean isVisible configured for the third-party application is not limited to being saved only in the ActivityThread.java file.
[0103] When a third-party application in an electronic device is running, its state may switch from the foreground state to the background state, and from the background state to the foreground state. When the third-party application switches to the foreground state, the flag bit boolean isVisible configured for the third-party application will be set to true; and when the third-party application switches to the background state, the flag bit boolean isVisible configured for the third-party application will be set to false.
[0104] The following combination Figure 4 and Figure 5 , when a third-party application of an electronic device switches state, the setting of the flag boolean isVisible is introduced. Figure 4 This is a timing diagram for setting the flag boolean isVisible when a third-party application in an electronic device is switched to the foreground state; Figure 5This is a timing diagram of setting the flag boolean isVisible when the third-party application is switched to the background state.
[0105] The user starts a third-party application in an electronic device and controls its interface to be visible. The electronic device will Figure 4 The calling relationship between the functions shown is used to switch the third-party application to the foreground state. Initially, the electronic device uses the onTransact function in the Binder.java file to call the dispatchAppVisibility function in the IWindow_Stub.java file in the electronic device. When the electronic device executes handleAppVisibility, the electronic device sets the flag boolean isVisible in the ActivityThread.java file to true.
[0106] It should be noted that, because the third-party application is switched to the foreground state, after the electronic device executes handleAppVisibility, the third-party application will request a VSYNC signal. Therefore, when the electronic device executes handleAppVisibility, the electronic device sets the flag boolean isVisible in the ActivityThread.java file to true, which can avoid the flag boolean isVisible being maintained as false, causing the electronic device to adopt the execution method of the drawing operation provided by the embodiment of the present application, and mistakenly identify the third-party application as the background state because the flag boolean isVisible is maintained as false, and control the drawing operation of the third-party application by prohibiting the request for the VSYNC signal.
[0107] The user input operation controls the third-party application to switch to the background state, and the electronic device follows the following steps: Figure 5The calling relationship between the functions shown is used to implement the switching of the third-party application to the background state. When the electronic device executes updateProcessState, the electronic device sets the flag boolean isVisible in the ActivityThread.java file to false. In some embodiments, when the electronic device executes updateProcessState, it can delay for a period of time and then set the flag boolean isVisible to false. In some embodiments, it can be delayed for 1 second. In other embodiments, when the electronic device executes updateProcessState, it sets the flag boolean isVisible to false, but the flag is set to false and it takes a period of time to take effect. The delay period can also be 1 second.
[0108] It should be noted that the electronic device delays for a period of time before setting the flag boolean isVisible to false, or sets the flag boolean isVisible to false and delays for a period of time before taking effect, in order to avoid UI actions near ActivityStop. When a third-party application switches to the background state, there will be a need to display the window of the third-party application based on some reasons, such as the pop-up dialog of a third-party application of the input method type in the background state, and the need for a floating window to pop up when the third-party application is in the background state. After the third-party application switches to the background state, there is a delay before setting the flag boolean isVisible to false. This can avoid the flag booleanisVisible being set to false, which will prevent the third-party application from being identified as being in the background state, and the drawing operation of the third-party application from being controlled by prohibiting the request for the VSYNC signal, resulting in the inability to display the window of the third-party application.
[0109] Of course, when the system application in the electronic device switches to the foreground state, the electronic device also executes the following Figure 4 When the system application switches to the background state, the electronic device also executes the following Figure 5 The calling relationship between the functions shown in the figure. In the embodiment of the present application, a third-party application is used as an example for introduction.
[0110] The following introduces the reason why the third-party application in the electronic device is configured with a flag bit boolean isVisible to mark the status of the third-party application.
[0111] A third-party application in an electronic device is started by a user. When the third-party application needs to refresh the interface or view, Choreographer will request a VSYNC signal from Surface Flinger. After receiving the VSYNC signal sent by Surface Flinger, Choreographer starts to perform drawing operations. For ease of explanation, the third-party application that requests a VSYNC signal in an electronic device is referred to as the first application below.
[0112] In order to prevent the first application from performing drawing operations that are not perceived by the user (referred to as background drawing) when the first application is in the background state, after the first application applies for a VSYNC signal, it is necessary to determine whether the first application is in the background state.
[0113] In some embodiments, the electronic device may determine the status of the first application by reading a node. Specifically, the electronic device may read the file system of the first application, which is provided by the Linux kernel and includes: information about the process of the first application. The parameter oom_score_adj in the file system is used to indicate the priority of the Linux process memory resources, which may reflect the status of the first application. The range of oom_score_adj is -1000 to +1000, and the smaller the value, the higher the priority of the process memory resources of the first application. In some embodiments, the value of oom_score_adj is less than or equal to 0, which may indicate that the first application is in the foreground state, and the value of oom_score_adj is greater than 0, which may indicate that the first application is in the background state.
[0114] It should be noted that the electronic device can read oom_score_adj along the path / proc / self / oom_score_adj.
[0115] In other embodiments, the electronic device can read oom_adj of the system_server process for the first application, and determine the state of the first application by the value of oom_adj. Oom_adj has basically the same function as the parameter oom_score_adj in the file system, and can also reflect the state of the first application.
[0116] The range of oom_adj of the system_server process is: -1 to 20. In some embodiments, the value of oom_adj of the system_server process is less than or equal to 6, which may indicate that the first application is in the foreground state; the value of oom_adj of the system_server process is greater than 6, which may indicate that the first application is in the background state.
[0117] In other embodiments, the electronic device may also read a variable in the first application process, which is usually referred to as ActivityThread.java#mLastProcessState. This variable is completely synchronized with the oom_adj of the system_server process, has the same value, and has a range of -1 to 20. In some embodiments, the value of ActivityThread.java#mLastProcessState is less than or equal to 6, which may indicate that the first application is in the foreground state; the value of ActivityThread.java#mLastProcessState is greater than 6, which may indicate that the first application is in the background state.
[0118] The electronic device determines the state of the first application using the variable ActivityThread.java#mLastProcessState of the first application, and can determine the state of the first application only in the process of the first application.
[0119] It should be noted that the electronic device maintains the variable ActivityThread.java#mLastProcessState of the first application program by using the function updateProcessState(), that is, to implement operations such as modifying the value of the variable.
[0120] Therefore, the electronic device can determine whether the variable ActivityThread.java#mLastProcessState of the first application has changed by calling the function updateProcessState(), and when the variable changes, the electronic device reads the value of the variable to determine the state change of the first application in real time by reading the value of the variable. In addition, the electronic device can also determine that the state change of the first application has occurred when it is determined that the state of the first application has changed, that is, by Figure 4 and Figure 5 The process is used to determine whether the first application is switched to the foreground state or the background state, and then the variable of the first application is read to determine the state of the first application through the value of the variable.
[0121] However, when the electronic device uses the methods provided in the above three embodiments to determine that the first application of the electronic device is in the background state and prohibits the first application from requesting the VSYNC signal, the problem of third-party applications being unable to start may occur during actual execution.
[0122] The inventors have found that during the startup of the electronic device, the third-party application will be initialized and all belong to the background state. Of course, the parameters oom_score_adj in the file system, oom_adj in the system_server process, and the variables in the third-party application process proposed in the above three embodiments will all indicate that the third-party application is in the background state. Therefore, if the electronic device prohibits the first application from requesting the VSYNC signal, it will cause the third-party application to be activated by the user to switch from the background state to the foreground state. Since the VSYNC signal is prohibited from being requested, the third-party application cannot complete the drawing operation, that is, it cannot start and run normally.
[0123] Therefore, the electronic device will configure the flag boolean isVisible mentioned above for the third-party application, and the flag is initially set to true. During the initialization phase of the third-party application, the electronic device can read the flag boolean isVisible configured by the third-party application. Since it is set to true, the electronic device determines that the third-party application is in the foreground state and does not prohibit it from requesting the VSYNC signal, thus avoiding the problem of failure to start normally.
[0124] See also Figure 6 , during the initialization phase of the third-party application, the flag boolean isVisible is set to true. Based on the flag boolean isVisible set to true, the electronic device can determine that the third-party application is in the foreground state. Based on this, the electronic device will not detect background drawing, that is, the result of detecting background drawing is false. When the third-party application is initialized and started in the foreground state, the flag boolean isVisible will remain set to true, and because the flag boolean isVisible is true, the electronic device will not detect background drawing, that is, the result of detecting background drawing is false.
[0125] It should be noted that when a third-party application switches to the background state for background drawing, the electronic device will delay for a period of time to set the flag boolean isVisible to false, such as Figure 6 Therefore, when the third-party application has switched to the background state, the flag boolean isVisible will remain set to true, and the electronic device will not detect the background drawing, that is, the detection result of the background drawing is false.
[0126] After the electronic device sets the flag boolean isVisible to false, the electronic device starts to detect background drawing, and after a period of time, the background drawing can be detected, that is, the detection result of the background drawing is true.
[0127] Figure 7 A method for executing a drawing operation provided by an embodiment of the present application is shown. Figure 7 As shown, the method for executing the drawing operation provided in this embodiment includes the following steps:
[0128] S701. A first application of an electronic device requests a VSYNC signal.
[0129] The first application is any one of a plurality of third-party applications configured by the electronic device as described above. Of course, the first application may also be a system application configured by the electronic device. In this embodiment, the first application is taken as an example of a third-party application.
[0130] The first-party application is launched by the user. When the first application needs to refresh the interface or view, Choreographer requests a VSYNC signal from Surface Flinger.
[0131] Therefore, the first application requesting the VSYNC signal mentioned in this step can be understood as when the first application needs to refresh the interface or view, the Choreographer of the first application requests the VSYNC signal from Surface Flinger, that is, the electronic device executes the Choreographer#scheduleVsyncLocked() method.
[0132] S702: The electronic device determines whether the first application is in the background state.
[0133] As mentioned above, the first application is configured with a flag bit boolean isVisible. The electronic device can read the flag bit boolean isVisible and determine whether the first application is in the background state through the flag bit boolean isVisible.
[0134] In some embodiments, the flag boolean isVisible is true, and the electronic device determines that the first application is in the foreground state, that is, not in the background state; the flag boolean isVisible is false, and the electronic device determines that the first application is in the background state.
[0135] The electronic device may also read the file system of the first application and determine whether the first application is in the background state through the parameter oom_score_adj in the file system. In some embodiments, the value of oom_score_adj is less than or equal to 0, which may indicate that the first application is in the foreground state, that is, not in the background state, and the value of oom_score_adj is greater than 0, which may indicate that the first application is in the background state.
[0136] The electronic device may also read the oom_adj of the system_server process for the first application, and determine the state of the first application by the value of oom_adj. In some embodiments, the value of oom_adj of the system_server process is less than or equal to 6, which may indicate that the first application is in the foreground state, that is, not in the background state; the value of oom_adj of the system_server process is greater than 6, which may indicate that the first application is in the background state.
[0137] The electronic device may also read the ActivityThread.java#mLastProcessState variable in the first application process, and determine whether the first application is in the background state by the ActivityThread.java#mLastProcessState variable. In some embodiments, the value of ActivityThread.java#mLastProcessState is less than or equal to 6, which may indicate that the first application is in the foreground state, that is, not in the background state; the value of ActivityThread.java#mLastProcessState is greater than 6, which may indicate that the first application is in the background state.
[0138] It should be noted that the electronic device may also determine whether the first application is in the background state by combining the flag boolean isVisible, the parameter oom_score_adj in the file system, the oom_adj of the system_server process for the first application, and at least one of the ActivityThread.java#mLastProcessState variable in the first application process.
[0139] The electronic device determines that the flag boolean isVisible is false, and at least one of the parameters oom_score_adj in the file system, the oom_adj of the system_server process for the first application, and the ActivityThread.java#mLastProcessState variable in the first application process meets the requirements of the background state, and the electronic device determines that the first application is in the background state. Otherwise, the electronic device determines that the first application is in the foreground state.
[0140] Exemplarily, the electronic device determines whether the first application is in the background state by combining the flag boolean isVisible and the ActivityThread.java#mLastProcessState variable in the first application process.
[0141] The electronic device determines that the flag bit boolean isVisible is false, and the ActivityThread.java#mLastProcessState variable in the first application process is greater than 6, then the electronic device determines that the first application is in the background state.
[0142] In the embodiment of the present application, if the electronic device determines that the first application is in the background state, the following step S703 is executed; if the electronic device determines that the first application is not in the background state, the following step S710 is executed.
[0143] S703: The electronic device determines whether the first application is a third-party application.
[0144] In some embodiments, the electronic device may determine whether the process of the first application includes a parameter, and the parameter is used to indicate that the first application is a third-party application. If the process of the first application includes a parameter, the electronic device determines that the first application is a third-party application.
[0145] In some other embodiments, the electronic device may also determine whether the first application is a third-party application by determining that the first application is not a system service isSystem, nor a system application isSystemApp. Of course, if the electronic device determines that the first application is a system service or a system application, it may determine that the first application is not a third-party application.
[0146] It should be noted that the electronic device may determine whether the process of the first application includes a parameter, which may be flag: ApplicationInfo.FLAG_SYSTEM. If the process of the first application includes the parameter flag: ApplicationInfo.FLAG_SYSTEM, the electronic device determines that the first application is a system application.
[0147] The parameter flag: ApplicationInfo.FLAG_SYSTEM is assigned during the system application installation scanning phase, and is packaged and transmitted to the system application process during the bindApplication phase when the system application is started.
[0148] It should also be noted that the system service is also pre-configured with variables, and the electronic device can determine whether the first application is a system service by whether the first application is configured with variables for indicating that it is a system service.
[0149] In the embodiment of the present application, if the electronic device determines that the first application is a third-party application, the following step S704 is executed; if the electronic device determines that the first application is not a third-party application, the following step S710 is executed.
[0150] It should also be noted that Figure 7 The execution order of step S702 and step S703 is shown. Of course, the execution order of step S702 and step S703 is not limited to Figure 7 In some embodiments, step S702 and step S703 may be performed in parallel, or the electronic device may first perform step S703 and then perform step S702.
[0151] S704: The electronic device determines whether it is in a shielding area.
[0152] The electronic device is configured with a shielding interval for prohibiting the request for the VSYNC signal, and the shielding interval can be turned on and off. After the shielding interval is turned on, the request for the VSYNC signal by the third-party application program occurring in the shielding interval will be prohibited.
[0153] The masking interval can be understood as a time period during which a third-party application is prohibited from requesting a VSYNC signal. In some embodiments, the masking interval can be set to 2 seconds. Of course, it is not limited to being set to only 2 seconds.
[0154] The electronic device determines whether it is in the shielding interval, which can be understood as whether the electronic device has opened the shielding interval when the first application program applies for the VSYNC signal.
[0155] Of course, there are conditions for the electronic device to open the shielding interval. In some embodiments, the electronic device determines that the first application meets the feature recognition of background drawing, and then opens the shielding interval. Among them, the way in which the electronic device determines that the first application meets the feature recognition of background drawing can be referred to the content of step S707 below, and no further explanation is given here.
[0156] It should be noted that the electronic device sets a shielding interval. After the electronic device opens the shielding interval, the first application's request for a VSYNC signal is prohibited. In this way, it can be ensured that when the first application is a third-party application and is in the background state, and the request for the VSYNC signal is for background drawing, the first application can prohibit multiple requests for the VSYNC signal for background drawing within the shielding interval.
[0157] Typically, the first application may request a VSYNC signal for background drawing multiple times. Basically, each UI component of the first application will request a VSYNC signal, and the first application may include multiple UI components. Therefore, by setting a shielding interval, each UI component can be prohibited from requesting a VSYNC signal.
[0158] In the embodiment of the present application, if the electronic device determines that it is in the shielding interval, the following step S708 is executed; if the electronic device determines that it is not in the shielding interval, the following step S705 is executed.
[0159] Of course, step S704 may also be a selectively executed step. In some embodiments, after the electronic device determines that the first application is a third-party application, it may not execute step S704 and directly execute step S705.
[0160] S705: The electronic device determines whether it is outside the background delay interval.
[0161] As mentioned above, the first application of the electronic device is configured with a flag bit boolean isVisible. When the first application is switched to the background state, the electronic device sets the flag bit boolean isVisible to false after a delay; or, the electronic device sets the flag bit boolean isVisible to false, but the flag bit boolean isVisible set to false will take effect after a delay. This delay period can be called the background delay interval.
[0162] The electronic device determines whether it is outside the background delay interval, which can be understood as the electronic device determining whether the moment when the first application requests the VSYNC signal is outside the background delay interval. Exemplarily, the background delay interval is set to 1 second, and the electronic device determines whether the moment when the first application requests the VSYNC signal is 1 second after the electronic device sets the flag bit boolean isVisible to false; or the moment after the electronic device sets the flag bit boolean isVisible to false after a delay of 1 second.
[0163] In the embodiment of the present application, if the electronic device determines that it is outside the background delay interval, the following step S706 is executed; if the electronic device determines that it is not outside the background delay interval, the following step S709 is executed.
[0164] Of course, step S705 may also be a selectively executed step. In some embodiments, after the electronic device determines that the first application is a third-party application and is not in the shielding interval, the electronic device may not execute step S705 and the following step S709, and directly execute step S706. In other embodiments, after the electronic device determines that the first application is a third-party application, it may not execute step S704, step S705, and the following step S709, and directly execute step S706.
[0165] S706: The electronic device determines whether the first application meets the feature recognition requirements for background drawing.
[0166] The background drawing performed by the first application may include invalid background drawing and valid background drawing. Invalid background drawing can be understood as the drawn interface is not visible to the user. Valid background drawing includes background pop-ups, etc., and the drawn interface will be visible to the user. Therefore, the electronic device determines whether the first application meets the feature recognition of background drawing, which means determining whether the first application meets the feature recognition of invalid background drawing.
[0167] If the first application is in the background state and continues to refresh frames within a certain period of time, it can be determined that the first application is performing invalid background drawing, rather than valid background drawing such as background pop-up windows. Based on this, the electronic device determines that the first application has completed drawing for a certain period of time. If the number of times it reaches a threshold, it is determined that the first application meets the feature recognition of invalid background drawing. Exemplarily, the electronic device can set the number of times the drawing is completed in 3 seconds to 30 times (also known as refreshing 30 frames in 3 seconds) as the judgment standard for feature recognition of background drawing. Of course, other judgment criteria can also be set, such as the number of times the drawing is completed in 3 seconds reaches 15 times, etc., and there is no specific restriction.
[0168] The electronic device can use the accumulated results of the function isVsyncFilter() being called within a certain period of time to detect whether the first application meets the feature recognition of background drawing. It is understandable that the first application can call the function isVsyncFilter() once when refreshing the screen. And, the function isVsyncFilter() is called once, and the call result is increased by 1. Based on this, the electronic device determines that the number of times the drawing is completed in 3 seconds reaches 30 times, which can be understood as: judging whether the accumulated results of the function isVsyncFilter() being called are accumulated 30 times within 3 seconds.
[0169] In the embodiment of the present application, if the electronic device determines that the first application meets the feature recognition of background drawing, the following step S707 is executed; if the electronic device determines that the first application does not meet the feature recognition of background drawing, the following step S710 is executed.
[0170] Figure 8 A flowchart is shown in which an electronic device determines whether a first application meets feature recognition requirements for background drawing.
[0171] like Figure 8 As shown, the electronic device determines that it is outside the background delay interval, and can execute step S801 to determine whether it is within the characteristic time. Among them, the electronic device determines whether it is within the characteristic time, which can be understood as the electronic device determines whether the moment when the first application requests the VSYNC signal is within the characteristic time. Exemplarily, the characteristic time is 3 seconds.
[0172] When the electronic device determines that it is within the characteristic time, the electronic device executes step S802 to determine whether the characteristic frame number reaches a threshold. In some embodiments, the electronic device determines whether the characteristic frame number reaches a threshold, which can be understood as the electronic device determining whether the number of times the first application refreshes the screen reaches a threshold, and illustratively, the threshold is 30 times.
[0173] If the electronic device determines that the characteristic frame number reaches the threshold, it means that the first application program has refreshed the characteristic frame number within the characteristic time and reaches the threshold, which means that the first application program is performing invalid background drawing. Therefore, the electronic device determines that the first application program meets the characteristic recognition of background drawing and can execute Figure 7 Step S707 in .
[0174] If the electronic device determines that it is not within the characteristic time and that the characteristic frame number does not reach the threshold, the electronic device executes step S803 to reset the characteristic frame number count and the characteristic time count. Of course, the electronic device may also determine that the first application does not meet the characteristic recognition requirements of the background drawing and execute Figure 7 Step S710 in .
[0175] Resetting the characteristic frame count and the characteristic time timing can be understood as the electronic device updating the characteristic frame count and the characteristic time timing.
[0176] The electronic device updates the characteristic frame count by adding 1 to the characteristic frame count for the drawing behavior of the first application program requesting the VSYNC signal, that is, adding 1 to the number of times the first application program refreshes the screen reflected by the last characteristic frame count.
[0177] Updating the characteristic time timing by the electronic device means that: the electronic device extends the characteristic time timing in response to the drawing behavior of the first application's request for the VSYNC signal this time, that is, based on the accumulated time of the first application refreshing the screen reflected by the last characteristic timing, the time interval between the time when the first application currently requests the VSYNC signal and the time when the first application last requested the VSYNC signal is delayed.
[0178] It should be noted that step S801 and step S802 are not limited to Figure 8 The execution order shown may also be executed in parallel, or step S802 may be executed first and then step S801.
[0179] It should also be noted that Figure 8 The method for detecting whether the first application is performing background drawing can also be performed after the electronic device detects that the first application is in the background state. That is, when the electronic device detects that the first application is in the background state, steps S801 to S803 are performed.
[0180] S707, the electronic device prohibits the first application from requesting the VSYNC signal and opens a shielding interval for 2 seconds. The first application in the shielding interval is prohibited from requesting the VSYNC signal.
[0181] If the electronic device determines that the first application meets the feature recognition of background drawing, it means that the first application is performing background drawing, which is invalid and wastes the system resources of the electronic device, and increases the heat generation and power consumption of the electronic device. Therefore, the electronic device prohibits the first application from requesting the VSYNC signal and opens the shielding interval for 2 seconds. Of course, as mentioned above, after the shielding interval is opened, the behavior of the first application requesting the VSYNC signal in the shielding interval is prohibited.
[0182] Furthermore, the 2-second activation of the shielding interval by the electronic device is an exemplary description, and the electronic device is not limited to being able to activate the shielding interval for only 2 seconds, and other time periods may be possible.
[0183] S708: The electronic device prohibits the first application from requesting a VSYNC signal.
[0184] Among them, the electronic device prohibiting the first application from requesting the VSYNC signal can be understood as: the electronic device prohibiting the first application from sending an instruction to Surface Flinger to request the VSYNC signal; or, the electronic device discards the instruction generated by the first application to request the VSYNC signal.
[0185] S709, the electronic device switches to the background with a delay of 1 second.
[0186] The electronic device determines that the first application is in the background state and is not outside the background delay interval, indicating that the first application has just been switched to the background state, so a delay of one second is required. The electronic device switching to the background delay interval of 1 second can be understood as the first application switching to the background state. After a delay of 1 second, the electronic device determines that the first application has switched to the background state.
[0187] It should be noted that step S710 can be executed during the 1-second background delay interval of the electronic device. Because within the 1-second delay interval, the first application can normally request the VSYNC signal. In this way, as mentioned above, it can be avoided that the electronic device determines that the first application is in the background state due to the flag boolean isVisible being set to false, and the drawing operation of the first application is controlled by prohibiting the request for the VSYNC signal, resulting in the inability to display the window of the first application.
[0188] The 1 second delay interval for the electronic device to switch to the background can be understood as an exemplary description. The electronic device is not limited to being able to switch to the background with a delay interval of 1 second, and can be other time periods.
[0189] S710: The electronic device controls the first application to normally request a VSYNC signal.
[0190] The electronic device controls the first application to normally request the VSYNC signal, which can be understood as: the electronic device controls the first application to send an instruction to request the VSYNC signal to Surface Flinger. Of course, Surface Flinger will return the VSYNC signal to the first application according to the screen refresh rate.
[0191] It should also be noted that when the first application requests the VSYNC signal for drawing, the mFrameScheduled flag is used to ensure that the VSYNC signal request matches the doFrame, and a VSYNC signal request must correspond to a doFrame. From the literal meaning, mFrameScheduled can be understood as the video frame has been requested, that is, it is used to indicate that the VSYNC signal has been requested, and do not request the VSYNC signal again.
[0192] When the first application switches to the background and the electronic device determines that it meets the conditions for feature identification of background drawing, it means that the first application has successfully applied for the VSYNC signal (because the requirement for feature identification of background drawing is that the first application continues to refresh frames in the background state), so the mFrameScheduled flag will be set to true.
[0193] If the mFrameScheduled flag is set to true, the electronic device determines that the first application has already requested the VSYNC signal and no longer needs to apply for the VSYNC signal. Therefore, when the first application switches to the foreground state, if the mFrameScheduled flag is not set to false, the screen displayed by the first application on the electronic device screen will be fixed after the first application switches to the foreground state.
[0194] Based on this, in the embodiment of the present application, after the electronic device executes step S709, it needs to set the mFrameScheduled flag to false. That is, the electronic device sets the mFrameScheduled flag to reflect that the first application has not successfully applied for the VSYNC signal, so as to allow the first application to apply for the VSYNC signal again.
[0195] It should also be noted that when the first application executes multiple processes, it may involve applying for and requesting a VSYNC signal. If the first application is in the background state, and the first application applies for and requests a VSYNC signal from the scheduleTraversals process executed by the first application (the scheduleTraversals process can be understood as a drawing request process), the problem that has always existed with SyncBarrier will appear. The SyncBarrier problem will cause the MSG_DISPATCH_APP_VISIBILITY synchronization message in the scheduleTraversals process to be blocked and unable to execute when the first application switches back to the foreground state from the background state, and then the first application cannot apply for a VSYNC signal, causing the screen displayed by the first application on the electronic device to become frozen.
[0196] Among them, SyncBarrier can be understood as Handler synchronization barrier, which means that the electronic device blocks the synchronous message queue and processes the asynchronous message first, so that the asynchronous message does not have to wait in line for processing. After the asynchronous message is processed, the electronic device continues to process the synchronous message.
[0197] Based on this, the method for executing a drawing operation provided in the embodiment of the present application can also be applied to the electronic device's process of executing a drawing request for a third-party application.
[0198] Fig. 9 A method for executing a drawing operation provided by an embodiment of the present application is shown. Fig. 9 As shown, the method for executing the drawing operation provided in this embodiment includes the following steps:
[0199] S901: A first application of an electronic device applies for drawing.
[0200] The first application is any one of a plurality of third-party applications configured in the electronic device as described above. Similarly, it is not limited to a third-party application, and may also be a system application.
[0201] The first-party application is started by the user. When the first application needs to refresh the interface or view, the first application will request drawing, that is, the first application needs to execute the ViewRootImpl#scheduleTraversals() method.
[0202] S902: The electronic device determines whether the first application is in the background state.
[0203] The specific implementation of step S902 may refer to the content of step S702 in the aforementioned embodiment, which will not be repeated here.
[0204] In the embodiment of the present application, if the electronic device determines that the first application is in the background state, the following step S903 is executed; if the electronic device determines that the first application is not in the background state, the following step S910 is executed.
[0205] S903: The electronic device determines whether the first application is a third-party application.
[0206] The specific implementation of step S903 may refer to the content of step S703 in the aforementioned embodiment, which will not be repeated here.
[0207] In the embodiment of the present application, if the electronic device determines that the first application is a third-party application, the following step S904 is executed; if the electronic device determines that the first application is not a third-party application, the following step S910 is executed.
[0208] It should also be noted that Fig. 9 The execution order of step S902 and step S903 is shown. Of course, the execution order of step S902 and step S903 is not limited to Fig. 9In some embodiments, step S902 and step S903 may be performed in parallel, or the electronic device first performs step S903 and then performs step S902.
[0209] S904: The electronic device determines whether it is in a shielding area.
[0210] The specific implementation of step S904 may refer to the content of step S704 in the aforementioned embodiment, which will not be repeated here.
[0211] S905: The electronic device determines whether it is outside the background delay interval.
[0212] The specific implementation of step S905 may refer to the content of step S705 in the aforementioned embodiment, which will not be repeated here.
[0213] S906: The electronic device determines whether the first application meets feature recognition requirements for background drawing.
[0214] The specific implementation of step S906 may refer to the content of step S706 in the aforementioned embodiment, which will not be repeated here.
[0215] It should be noted that electronic devices can also be used Figure 8 The method for detecting whether an application performs background drawing is shown to determine whether the first application meets the feature recognition of background drawing.
[0216] S907, the electronic device prohibits the first application from requesting the VSYNC signal and opens a shielding interval for 2 seconds. The first application in the shielding interval is prohibited from requesting the VSYNC signal.
[0217] The specific implementation of step S907 may refer to the content of step S707 in the aforementioned embodiment, which will not be repeated here.
[0218] S908: The electronic device prohibits the first application from requesting a VSYNC signal.
[0219] The specific implementation of step S908 may refer to the content of step S708 in the aforementioned embodiment, which will not be repeated here.
[0220] S909, the electronic device switches to the background with a delay of 1 second.
[0221] The specific implementation of step S909 may refer to the content of step S709 in the aforementioned embodiment, which will not be repeated here.
[0222] S910: The electronic device controls the first application to normally request a VSYNC signal.
[0223] The specific implementation of step S910 may refer to the content of step S610 in the aforementioned embodiment, which will not be repeated here.
[0224] It should be noted that, as mentioned above Figure 7 In the corresponding embodiment, after the electronic device executes step S908, it is also necessary to set the mFrameScheduled flag to false to allow the first application to request the VSYNC signal again.
[0225] Combined with the above correspondence Figure 7 The corresponding embodiment content, and Fig. 9 From the corresponding embodiment content, it can be seen that: an application of an electronic device has two entries for executing a method of performing a drawing operation.
[0226] See also Fig.10 When the application executes the ViewRootImpl#scheduleTraversals() method and the Choreographer#scheduleVsyncLocked() method, the electronic device can start the execution method of the drawing operation, that is, Fig.10 Displays isVsyncFilter.
[0227] For an application in an electronic device to execute the Choreographer#scheduleVsyncLocked() method or the ViewRootImpl#scheduleTraversals() method and apply for a VSYNC signal request, the electronic device needs to determine whether the application meets the following three conditions. Fig.10 Display: The electronic device determines that the application is not a system service, that is, !isSystem(); determines that the application is not a system application, that is, !isSystemApp(); determines that the application is not visible, that is, !isVisible.
[0228] For example Fig.10 As shown, when the above three conditions are met, the electronic device then detects the background refresh feature to determine whether the application is performing invalid background drawing.
[0229] Further integration Fig.11 , Fig.11 The flowchart of the execution method of the electronic device performing the drawing operation is shown. From the analysis of the principle of the execution method of the electronic device performing the drawing operation, it can be seen that the execution method of the drawing operation performed by the electronic device is as follows: Fig.11 As shown, the following steps may be included:
[0230] S1101 . An application of an electronic device requests a VSYNC signal or requests drawing.
[0231] Among them, the application of the electronic device applies for a VSYNC signal, which can be understood as when the application needs to refresh the interface or view, the Choreographer of the application requests a VSYNC signal from Surface Flinger, that is, the electronic device needs to execute the Choreographer#scheduleVsyncLocked() method.
[0232] When an application of an electronic device is started by a user and the application needs to refresh the interface or view, the application will request drawing, that is, the application needs to execute the ViewRootImpl#scheduleTraversals() method.
[0233] S1102: The electronic device determines whether the application is in the background state.
[0234] The specific implementation of step S1102 may refer to the content of step S702 in the aforementioned embodiment, which will not be repeated here.
[0235] S1103: The electronic device determines whether the application is a third-party application.
[0236] The specific implementation of step S1103 may refer to the content of step S703 in the aforementioned embodiment, which will not be repeated here.
[0237] It should be noted that in the embodiment of the present application, the electronic device should control the third-party application to not perform invalid background drawing when it is in the background state. Therefore, it is necessary to determine whether the application is a third-party application.
[0238] Of course, the electronic device may also control all applications of the electronic device not to perform invalid background drawing. Based on this, step S1103 may also be a selectively executed step.
[0239] S1104: The electronic device determines whether the application program performs invalid background drawing.
[0240] The electronic device determines whether the application performs invalid background drawing, which may refer to the electronic device determining whether the application meets the feature recognition of background drawing. The implementation process may be as shown in step S706, which will not be repeated here.
[0241] If the electronic device determines that the application is in the background state through step S1102, determines that the application is a third-party application through step S1103, and determines that the application performs invalid background drawing through step S1104, the electronic device may execute step S1105. When the electronic device executes steps S1102, S1103, and S1104, if the judgment result of any one of the three judgment conditions of steps S1102, S1103, and S1104 is no, the electronic device may execute step S1106.
[0242] Fig.11 The execution order of step S1102, step S1103 and step S1104 is shown. Of course, step S1102, step S1103 and step S1104 are not limited to Fig.11 Step S1102, step S1103 and step S1104 may be executed in parallel or in another execution order.
[0243] S1105. The electronic device prohibits the application from requesting a VSYNC signal.
[0244] The specific implementation of step S1105 may refer to the content of step S708 in the aforementioned embodiment, which will not be repeated here.
[0245] S1106 , the electronic device control application normally requests the VSYNC signal.
[0246] The specific implementation of step S1106 may refer to the content of step S710 in the aforementioned embodiment, which will not be repeated here.
[0247] In the method for executing drawing operations provided in the embodiment of the present application, when the electronic device determines that an application is requesting drawing or requesting a VSYNC signal, it determines whether the application should be prohibited from requesting a VSYNC signal by determining whether the application is in the background state and whether the application is performing invalid background drawing. When the application is in the background state and performing invalid background drawing, the electronic device prohibits the application from requesting a VSYNC signal to avoid the application from performing a drawing operation to refresh the interface, which wastes the system resources of the electronic device and increases the heating and power consumption of the electronic device.
[0248] Another embodiment of the present application further provides a computer-readable storage medium, which stores instructions, and when the computer-readable storage medium is executed on a computer or a processor, the computer or the processor executes one or more steps in any of the above methods.
[0249] The computer-readable storage medium may be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium may be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
[0250] Another embodiment of the present application further provides a computer program product including instructions. When the computer program product is run on a computer or a processor, the computer or the processor executes one or more steps in any of the above methods.
Claims
1. A method for executing a drawing operation, characterized in that: Applied to an electronic device, the electronic device is configured with an application program, and the method for executing the drawing operation includes: The electronic device determines that an application program requests a vertical synchronization VSYNC signal, wherein the VSYNC signal is used to trigger the application program to perform a drawing operation; The electronic device determines that the application is in a background state, determines that the shielding interval is not opened when the application applies for a VSYNC signal, and determines that the application is performing invalid background drawing; wherein, when the shielding interval is opened, the electronic device prohibits the application from sending an instruction to request a VSYNC signal within a time period indicated by the shielding interval, or the electronic device discards the instruction to request a VSYNC signal generated by the application within the time period indicated by the shielding interval; The electronic device prohibits the application from sending an instruction for requesting a VSYNC signal, or discards the instruction for requesting a VSYNC signal generated by the application.
2. The method for executing a drawing operation according to claim 1, characterized in that: After the electronic device prohibits the application from sending an instruction to request a VSYNC signal, or discards the instruction to request a VSYNC signal generated by the application, the electronic device further includes: the electronic device turning on the shielding interval.
3. The method for executing a drawing operation according to claim 1 or 2, characterized in that: Before the electronic device prohibits the application from sending an instruction for requesting a VSYNC signal, or discards an instruction for requesting a VSYNC signal generated by the application, the electronic device further includes: The electronic device determines that the application is a third-party application, and the third-party application does not belong to an application that comes with the electronic device system.
4. The method for executing a drawing operation according to claim 1 or 2, characterized in that: The electronic device determines that the application is in the background state in the following manner: The electronic device obtains a flag bit configured by the application program, wherein the flag bit configured by the application program is synchronized with a state of the application program; The electronic device determines whether the application is in the background state by using the flag bit configured by the application; wherein, the flag bit configured by the application is a first value, and the electronic device determines that the application is in the background state.
5. The method for executing a drawing operation according to claim 3, characterized in that: The electronic device determines that the application is in the background state in the following manner: The electronic device obtains a flag bit configured by the application program, wherein the flag bit configured by the application program is synchronized with a state of the application program; The electronic device determines whether the application is in the background state by using the flag bit configured by the application; wherein, the flag bit configured by the application is a first value, and the electronic device determines that the application is in the background state.
6. The method for executing a drawing operation according to claim 1 or 2, characterized in that: The electronic device determines that the application is in the background state in the following manner: The electronic device determines whether the application is in the background state by using the parameter in the file system of the application; wherein if the parameter in the file system of the application is greater than a first value, the electronic device determines that the application is in the background state; The electronic device determines whether the application is in the background state by using the parameter of the application program in the system process of the electronic device; wherein if the parameter of the application program in the system process of the electronic device is greater than a second value, the electronic device determines that the application program is in the background state; Alternatively, the electronic device uses a variable in the application process to determine whether the application is in the background state; wherein, if the variable in the application process is greater than a second value, the electronic device determines that the application is in the background state.
7. The method for executing a drawing operation according to claim 1 or 2, characterized in that: The electronic device determines that the application is in the background state in the following manner: The electronic device obtains a flag bit configured by the application, and at least one of a parameter in a file system of the application, a parameter of a system process of the electronic device for the application, and a variable in the application process, wherein the flag bit configured by the application is synchronized with a state of the application; The electronic device determines whether the application is in the background state by using a flag bit configured by the application, a parameter in a file system of the application, a parameter of a system process of the electronic device for the application, and at least one of a variable in the application process; Among them, the flag bit configured by the application is a first value, the parameters in the file system of the application, the parameters of the system process of the electronic device for the application and at least one of the variables in the application process meet the requirement that the application is in the background state, and the electronic device determines that the application is in the background state.
8. The method for executing a drawing operation according to claim 1 or 2, characterized in that: The electronic device determines that the application is performing invalid background drawing in a manner including: The electronic device determines whether the number of times the application completes drawing within a predetermined time period reaches a threshold; wherein, if the electronic device determines that the number of times the application completes drawing within a preset time period reaches a threshold, the electronic device determines that the application is performing invalid background drawing.
9. The method for executing a drawing operation according to claim 3, characterized in that: The electronic device determines that the application is performing invalid background drawing in a manner including: The electronic device determines whether the number of times the application completes drawing within a predetermined time period reaches a threshold; wherein, if the electronic device determines that the number of times the application completes drawing within a preset time period reaches a threshold, the electronic device determines that the application is performing invalid background drawing.
10. The method for executing a drawing operation according to claim 1 or 2, characterized in that: After the electronic device determines that the application program requests a vertical synchronization VSYNC signal, the electronic device further includes: When the electronic device determines that the application is in the background state and the shielding interval is in the open state, the application is prohibited from requesting a VSYNC signal.
11. The method for executing a drawing operation according to claim 3, characterized in that: After the electronic device determines that the application program requests a vertical synchronization VSYNC signal, the electronic device further includes: When the electronic device determines that the application is in the background state and the shielding interval is in the open state, the application is prohibited from requesting a VSYNC signal.
12. The method for executing a drawing operation according to claim 1 or 2, characterized in that: Before the electronic device prohibits the application from sending an instruction for requesting a VSYNC signal, or discards an instruction for requesting a VSYNC signal generated by the application, the electronic device further includes: The electronic device determines that the moment when the application program applies for requesting the VSYNC signal is outside the background delay interval.
13. The method for executing a drawing operation according to claim 3, characterized in that: Before the electronic device prohibits the application from sending an instruction for requesting a VSYNC signal, or discards an instruction for requesting a VSYNC signal generated by the application, the electronic device further includes: The electronic device determines that the moment when the application program applies for requesting the VSYNC signal is outside the background delay interval.
14. The method for executing a drawing operation according to claim 1 or 2, characterized in that: After the electronic device determines that the application program requests a vertical synchronization VSYNC signal, the electronic device further includes: The electronic device determines that the application is in the background state, and determines that the moment when the application applies for a VSYNC signal is not outside the background delay interval, and the electronic device switches to the background delay interval for a preset time, wherein within the preset time of the background delay interval, the electronic device allows the application to request a VSYNC signal.
15. The method for executing a drawing operation according to claim 3, characterized in that: After the electronic device determines that the application program requests a vertical synchronization VSYNC signal, the electronic device further includes: The electronic device determines that the application is in the background state, and determines that the moment when the application applies for a VSYNC signal is not outside the background delay interval, and the electronic device switches to the background delay interval for a preset time, wherein within the preset time of the background delay interval, the electronic device allows the application to request a VSYNC signal.
16. The method for executing a drawing operation according to claim 1 or 2, characterized in that: Also includes: The electronic device determines that an application program requests drawing; If the electronic device determines that the application is in the background state and is performing invalid background drawing, the electronic device prohibits the application from sending an instruction requesting a VSYNC signal, or discards the instruction requesting a VSYNC signal generated by the application.
17. The method for executing a drawing operation according to claim 3, characterized in that: Also includes: The electronic device determines that an application program requests drawing; If the electronic device determines that the application is in the background state and is performing invalid background drawing, the electronic device prohibits the application from sending an instruction requesting a VSYNC signal, or discards the instruction requesting a VSYNC signal generated by the application.
18. An electronic device, characterized in that: include: one or more processors, memory, and display screens; The memory and the display screen are coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method for executing the drawing operation as described in any one of claims 1 to 17.
19. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed, is specifically used to implement the method for executing the drawing operation as described in any one of claims 1 to 17.
Citation Information
Patent Citations
Method for executing drawing operation by application and electronic equipment
CN113553130A