Application processing method and related apparatus
By setting a threshold in electronic devices to monitor the number of layers and stopping applications that consume too many layers, the display anomaly when running multiple applications was resolved, the risk of insufficient memory was reduced, and the user experience was improved.
Patent Information
- Application Number
- CN202311855290.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2043-12-28
AI Technical Summary
Electronic devices are prone to display problems when running multiple applications, such as screen flickering, screen glitches, restarts, or lag, mainly due to insufficient memory caused by an excessive number of layers.
By setting a threshold to monitor the number of layers, when the threshold is reached or exceeded, applications that consume a lot of layers will stop running to free up memory and reduce the probability of layer leakage.
It effectively reduces the probability of display errors, reduces the risk of insufficient memory, and improves the user experience.
Smart Images

Figure CN120276622B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal technology, and in particular to an application processing method and related apparatus. Background Technology
[0002] With the development of terminal technology, electronic devices can support an increasing number of applications. Currently, when running multiple applications, electronic devices may experience display problems. For example, screen flickering, screen glitches, restarts, or lag may occur. Summary of the Invention
[0003] This application provides an application processing method and related apparatus, which are applied in the field of terminal technology and help reduce the probability of display abnormalities.
[0004] In a first aspect, embodiments of this application provide an application processing method applicable to electronic devices. The method includes: at a first moment, a first application running in the foreground of the electronic device, and a second and third application running in the background of the electronic device, wherein the number of layers in the electronic device is a first quantity, which is less than or equal to a first threshold; at a second moment, the first application running in the foreground of the electronic device, and the number of layers in the electronic device is a second quantity, which is greater than the first threshold, stopping the second application from running in the background, and maintaining the third application running in the background, wherein the number of layers occupied by the third application in the layers of the electronic device is less than the number of layers occupied by the second application in the layers of the electronic device; wherein the second moment is later than the first moment, and between the first and second moments, the first application continues to run in the foreground, and the second and third applications continue to run in the background.
[0005] The first application, the second application, and the third application can be three different applications deployed in an electronic device. In some implementations, the first application can be a video application, the second application can be a chat application, and the third application can be a gallery application. In other implementations, the first application can be a calendar application, the second application can be a video application, and the third application can be a chat application. This application does not limit the first, second, and third applications.
[0006] The first threshold is used to represent the critical value. When the number of layers is greater than the first threshold, it means that the number of layers needs to be controlled. When the number of layers is less than or equal to the first threshold, it means that the number of layers has not reached the condition that needs to be controlled.
[0007] At the first moment, the number of layers on the electronic device is the first quantity, which is less than or equal to the first threshold, indicating that the number of layers has not reached the condition requiring control. At the second moment, the number of layers on the electronic device is the second quantity, which is greater than the first threshold, indicating that the number of layers needs to be controlled. Therefore, the electronic device can stop using applications with a large number of layers. It's understandable that the second quantity is greater than the first threshold at the second moment because the first application is running in the foreground and can continuously create layers, causing the number of layers on the electronic device to exceed the first threshold, thus reaching the condition requiring control.
[0008] In this embodiment, when the number of layers in the electronic device exceeds a first threshold, it can be termed a layer leak. The first threshold can be referenced... Figure 5 M in the example. In one example, M can be 3500.
[0009] The first application runs in the foreground; stopping it would affect the user experience. Among the background applications, the third application occupies fewer layers on the electronic device than the second application. This indicates that the second application occupies more layers, so the electronic device stops running the second application in the background.
[0010] Understandably, at the second moment, if there are other applications running in the background of the electronic device besides the second and third applications, and some of these other applications occupy more or less layers in the electronic device's layers than the second application, the electronic device can also stop running these applications.
[0011] In this case, if the number of layers in the electronic device exceeds the first threshold, the second application will occupy a large number of layers in the electronic device's layers. The probability of the second application abnormally adding layers or failing to release layers normally is relatively high. Stopping the second application can release the memory occupied by the second application, which helps reduce the probability of insufficient memory and thus helps reduce the probability of display abnormalities.
[0012] In one possible implementation, the number of layers occupied by the second application in the electronic device's layers is greater than a second threshold, and the number of layers occupied by the third application in the electronic device's layers is less than the second threshold, with the second threshold being less than the first threshold.
[0013] The second threshold represents a critical value. When the number of layers occupied by an application on an electronic device exceeds the second threshold, it indicates that the application occupies too many layers and needs to be stopped. When the number of layers occupied by an application on an electronic device is less than or equal to the second threshold, it indicates that the application occupies too few layers and does not need to be stopped.
[0014] In this embodiment of the application, the second threshold can be referenced Figure 5 In the case of i, in one example, i can be 50.
[0015] If the second application occupies more layers in the electronic device's layers than the second threshold, and the third application occupies less layers in the electronic device's layers than the second threshold, then the electronic device can stop the second application from running in the background while maintaining the third application running in the background. This facilitates the identification of the applications that need to be stopped.
[0016] In one possible implementation, the number of layers occupied by the first application in the layers of the electronic device is greater than or equal to the number of layers occupied by the second application in the layers of the electronic device; the method further includes: stopping the first application when it is switched to the background.
[0017] If the number of layers occupied by the first application on the electronic device is greater than or equal to the number of layers occupied by the second application, then the first application should also be stopped. To avoid affecting the user experience, the first application can be stopped when it is switched to the background. This reduces the probability of display errors and minimizes the impact on the user experience.
[0018] In one possible implementation, the electronic device includes a first layer, and the method further includes: determining whether the number of first layers in the electronic device is greater than a third threshold, wherein the third threshold is less than or equal to the first threshold; if the number of first layers in the electronic device is greater than the third threshold, obtaining a fourth application, wherein the number of first layers occupied by the fourth application in the first layer of the electronic device is greater than the fourth threshold, wherein the fourth threshold is less than the third threshold; determining whether the fourth application is running in the background; and stopping the fourth application if it is running in the background.
[0019] The first layer is used to represent the layer that occupies more memory than the threshold. For example, the first layer can be one or more of the following: BufferLayer, PictureLayer, and TextureLayer.
[0020] The third threshold is used to represent the critical value. When the number of first layers is greater than the third threshold, it means that the number of first layers needs to be controlled. When the number of first layers is less than or equal to the third threshold, it means that the number of first layers has not reached the condition that needs to be controlled.
[0021] The fourth threshold represents a critical value. When the number of applications occupying the first layer of the electronic device exceeds the fourth threshold, it indicates that the number of applications occupying the first layer of the electronic device is too large, and the application needs to be stopped. When the number of applications occupying the first layer of the electronic device is less than or equal to the fourth threshold, it indicates that the number of applications occupying the first layer of the electronic device is too small, and the application does not need to be stopped.
[0022] In this embodiment of the application, the third threshold can be referenced Figure 5 In the context of N, the fourth threshold can be referenced. Figure 5 For the fourth application, refer to application B.
[0023] The fourth application may include one application or multiple applications; this application embodiment does not limit this. The fourth application may run in the foreground or in the background; this application embodiment does not limit this.
[0024] If the number of first layers in the electronic device is greater than the third threshold, and the number of first layers occupied by the fourth application in the first layer of the electronic device is greater than the fourth threshold, and the fourth application is running in the background, then the fourth application shall be stopped.
[0025] Thus, if the number of first layers in an electronic device exceeds the third threshold, the fourth application occupies a large number of first layers in the electronic device's layers. The fourth application is more likely to abnormally add first layers or fail to release first layers normally. Stopping the fourth application can release the memory occupied by the fourth application, which helps reduce the probability of insufficient memory and thus helps reduce the probability of display abnormalities.
[0026] In one possible implementation, the method further includes stopping the fourth application when it is switched to the background if it is not running in the background. The fact that the fourth application is in the background indicates that it does not have a visible window. Therefore, stopping the fourth application when it is switched to the background reduces the probability of display errors and also helps to minimize the impact on user experience.
[0027] In one possible implementation, determining whether the number of first layers in the electronic device is greater than a third threshold includes: if the number of layers in the electronic device is less than or equal to the first threshold, determining whether the number of first layers in the electronic device is greater than the third threshold.
[0028] In this application embodiment, the example can be referred to Figure 6 The number of layers can be referenced to the total number of layers. The first threshold can be referenced to M. The number of the first layer can be referenced to the number of buffer layers. The third threshold can be referenced to N.
[0029] In this way, determining the number of layers based on the number of layers does not require control. Instead, the number of the first layer is determined to decide whether to control its quantity. This multi-level judgment helps to better control the number of layers, thereby reducing the probability of layers consuming excessive memory.
[0030] In one possible implementation, the method further includes: determining whether the number of windows in the electronic device is greater than a fifth threshold; if the number of windows in the electronic device is greater than the fifth threshold, obtaining a fifth application, wherein the number of windows occupied by the fifth application in the electronic device is greater than a sixth threshold and the sixth threshold is less than the fifth threshold; determining whether the fifth application is running in the background; and if the fifth application is running in the background, stopping the fifth application from running.
[0031] The fifth threshold represents a critical value. When the number of windows on an electronic device exceeds the fifth threshold, it indicates that the number of windows needs to be controlled. Conversely, when the number of windows is less than or equal to the fifth threshold, it indicates that the number of windows has not met the criteria for control. It's important to note that windows are a step before layers are created. If the number of windows needs to be controlled, it implies that the number of layers also needs to be controlled. Conversely, if the number of windows does not need to be controlled, it implies that the number of layers does not need to be controlled.
[0032] The sixth threshold represents a critical value. When the number of windows occupied by an application on an electronic device exceeds the sixth threshold, it indicates that the application is occupying too many windows and should be stopped. When the number of windows occupied by an application is less than or equal to the sixth threshold, it indicates that the application is occupying too few windows and should not be stopped.
[0033] In this embodiment of the application, the fifth threshold can be referenced Figure 5 The sixth threshold in O can be referenced. Figure 5 For the fifth application of k, please refer to application C.
[0034] The fifth application may include one application or multiple applications; this application embodiment does not limit this. The fifth application may run in the foreground or in the background; this application embodiment does not limit this.
[0035] If the number of windows in the electronic device exceeds the fifth threshold, the number of windows occupied by the fifth application in the electronic device exceeds the sixth threshold, and the fifth application is running in the background, then stop running the fifth application.
[0036] Thus, when the number of windows on an electronic device exceeds the fifth threshold, the fifth application occupies a large number of windows on the electronic device, and the probability of the fifth application malfunctioning is relatively high. Stopping the fifth application can release the memory it occupies, which helps reduce the probability of insufficient memory and, consequently, the probability of display malfunctions.
[0037] In one possible implementation, the method further includes stopping the fifth application when it is switched to the background, provided the fifth application is not running in the background. This way, stopping the fifth application when it is switched to the background reduces the probability of display errors and also helps to minimize the impact on user experience.
[0038] In one possible implementation, the electronic device includes a first layer. Determining whether the number of windows in the electronic device is greater than a fifth threshold includes: if the number of layers in the electronic device is less than or equal to the first threshold, and the number of the first layer in the electronic device is less than or equal to a third threshold, determining whether the number of windows in the electronic device is greater than the fifth threshold, where the third threshold is less than or equal to the first threshold.
[0039] In this application embodiment, the example can be referred to Figure 6 The number of layers can be referenced to the total number of layers. The first threshold can be referenced to M. The number of first layers can be referenced to the number of buffer layers. The third threshold can be referenced to N. The number of windows can be referenced to the number of application windows. The fifth threshold can be referenced to O.
[0040] In this way, determining the number of layers based on the number of layers does not require control, determining the number of layers based on the number of the first layer does not require control, and determining the number of windows to determine whether to control the number of windows, multi-level judgment is conducive to better control of the number of windows, thereby achieving control over the number of layers and reducing the probability of layers occupying too much memory.
[0041] In one possible implementation, the method further includes: determining whether the number of surfaces in the electronic device is greater than a seventh threshold; if the number of surfaces in the electronic device is greater than the seventh threshold, obtaining a sixth application, wherein the number of surfaces occupied by the sixth application in the electronic device is greater than an eighth threshold and the eighth threshold is less than the seventh threshold; determining whether the sixth application is running in the background; and if the sixth application is running in the background, stopping the sixth application from running.
[0042] The seventh threshold represents a critical value. When the number of surfaces in an electronic device exceeds the seventh threshold, it indicates that the number of surfaces needs to be controlled. Conversely, when the number of surfaces is less than or equal to the seventh threshold, it indicates that the number of surfaces has not met the criteria for control. It's important to note that surfaces are a step before creating layers. If the number of surfaces needs to be controlled, it implies that the number of layers also needs to be controlled. Conversely, if the number of surfaces does not need to be controlled, it implies that the number of surfaces does not need to be controlled.
[0043] The eighth threshold represents a critical value. When the number of times an application occupies space on the surface of an electronic device exceeds the eighth threshold, it indicates that the application is occupying too much space and should be stopped. When the number of times an application occupies space on the surface of an electronic device is less than or equal to the eighth threshold, it indicates that the application is occupying too little space and should not be stopped.
[0044] In this embodiment of the application, the seventh threshold can be referenced Figure 5 The eighth threshold, P, can be referenced. Figure 5 For m in the context, the sixth application can refer to application D.
[0045] The sixth application may include one application or multiple applications; this application embodiment does not limit this. The sixth application may run in the foreground or in the background; this application embodiment does not limit this.
[0046] If the number of surfaces in the electronic device exceeds the seventh threshold, and the number of surfaces occupied by the sixth application in the electronic device exceeds the eighth threshold, and the sixth application is running in the background, then the sixth application shall be stopped.
[0047] Thus, when the number of surfaces in an electronic device exceeds the seventh threshold, the sixth application occupies a large number of surfaces, increasing the probability of it malfunctioning. Stopping the sixth application can release the memory it occupies, reducing the probability of insufficient memory and consequently reducing the probability of display malfunctions.
[0048] In one possible implementation, the method further includes stopping the sixth application when it is switched to the background, provided the sixth application is not running in the background. This way, stopping the sixth application when it is switched to the background reduces the probability of display errors and also helps to minimize the impact on user experience.
[0049] In one possible implementation, the electronic device includes a first layer. Determining whether the number of surfaces in the electronic device is greater than a seventh threshold includes: if the number of layers in the electronic device is less than or equal to the first threshold, and the number of the first layer in the electronic device is less than or equal to a third threshold, determining whether the number of surfaces in the electronic device is greater than the seventh threshold, and the third threshold is less than or equal to the first threshold.
[0050] In this application embodiment, the example can be referred to Figure 6 The number of layers can be referenced to the total number of layers. The first threshold can be referenced to M. The number of first layers can be referenced to the number of buffer layers. The third threshold can be referenced to N. The number of surfaces can be referenced to the number of interfaces. The seventh threshold can be referenced to m.
[0051] In this way, determining the number of layers based on the number of layers does not require control, determining the number of layers based on the number of the first layer does not require control, and determining the number of surfaces to determine whether to control the number of surfaces, multi-level judgment is conducive to better control of the number of surfaces, thereby achieving control over the number of layers and reducing the probability of layers occupying too much memory.
[0052] In one possible implementation, before the second quantity exceeds the first threshold, the method further includes: determining whether the number of layers in the electronic device is greater than a ninth threshold, wherein the ninth threshold is less than or equal to the first threshold; and if the number of layers in the electronic device exceeds the ninth threshold, outputting an alarm message to indicate an abnormal number of layers.
[0053] The ninth threshold represents a critical value. When the number of layers exceeds the ninth threshold, it indicates that the condition for an abnormal number of layers has been met. When the number of layers is less than or equal to the ninth threshold, it indicates that the condition for an abnormal number of layers has not been met.
[0054] If the first threshold and the ninth threshold are the same, for example, both are 3500, then the number of layers can be controlled simultaneously with the alarm. This is simple to implement. If the first threshold and the ninth threshold are different, for example, the first threshold is 3000 and the second threshold is 3500, then layer monitoring can continue after the alarm, and the number of layers can be controlled when the control conditions are met. This provides greater flexibility.
[0055] In this way, when the number of layers exceeds the ninth threshold, it indicates that there may be an anomaly in the layer, and an alarm message can be output to facilitate the monitoring and control of the layer.
[0056] In one possible implementation, determining whether the number of layers in the electronic device is greater than the ninth threshold includes: periodically polling to determine whether the number of layers in the electronic device is greater than the ninth threshold, or, if the number of layers in the electronic device is greater than the tenth threshold, determining whether the number of layers in the electronic device is greater than the ninth threshold, and the tenth threshold is less than the ninth threshold.
[0057] The timeout period can be 3 minutes, 5 minutes, or 6 minutes, etc., and this application embodiment does not limit this. In some implementations, the electronic device can determine every 3 minutes whether the number of layers in the electronic device is greater than the ninth threshold.
[0058] In this embodiment, the method of periodically determining whether the number of layers in the electronic device exceeds the ninth threshold can be referred to... Figure 4 The system periodically polls to check if the layer is leaking data. This periodic check, compared to real-time checks, helps save power.
[0059] The tenth threshold represents a critical value. When the number of layers exceeds the tenth threshold, the condition for monitoring the number of layers has been met. When the number of layers is less than or equal to the tenth threshold, the condition for monitoring the number of layers has not been met.
[0060] If the number of layers in an electronic device exceeds a tenth threshold, the electronic device can determine in real time whether the number of layers exceeds a ninth threshold. In this embodiment, the tenth threshold can be referenced to X, and when the number of layers exceeds X, layer leakage is detected.
[0061] In this way, real-time judgment is made when the number of layers in the electronic device exceeds the tenth threshold, which is more efficient than real-time judgment under no conditions.
[0062] In one possible implementation, the electronic device includes a first layer. Before the second quantity is greater than a first threshold, the method further includes: determining whether the quantity of the first layer in the electronic device is greater than an eleventh threshold, wherein the eleventh threshold is less than or equal to the first threshold; if the quantity of the first layer in the electronic device is greater than the eleventh threshold, outputting an alarm message, the alarm message being used to indicate an abnormal number of layers.
[0063] The eleventh threshold is used to represent a critical value. When the number of layers in the first layer is greater than the eleventh threshold, it indicates that the condition of an abnormal number of layers has been met. When the number of layers in the first layer is less than or equal to the eleventh threshold, it indicates that the condition of an abnormal number of layers has not been met.
[0064] In this way, when the number of layers in the first layer exceeds the eleventh threshold, it indicates that there may be an anomaly in the layer, and an alarm message can be output to facilitate the monitoring and control of the layer.
[0065] In one possible implementation, determining whether the number of first layers in the electronic device exceeds the eleventh threshold includes: periodically polling to determine whether the number of first layers in the electronic device exceeds the eleventh threshold; or, if the number of layers in the electronic device exceeds the tenth threshold, determining whether the number of first layers in the electronic device exceeds the eleventh threshold. This helps save power consumption.
[0066] Secondly, embodiments of this application provide an application processing apparatus, which may be an electronic device, a chip or chip system within an electronic device. The application processing apparatus may include a processing unit. When the application processing apparatus is an electronic device, the processing unit may be a processor. The application processing apparatus may further include a storage unit, which may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit to cause the electronic device to implement an application processing method described in the first aspect or any possible implementation of the first aspect. When the application processing apparatus is a chip or chip system within an electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit to cause the electronic device to implement an application processing method described in the first aspect or any possible implementation of the first aspect. The storage unit may be a storage unit within the chip (e.g., a register, cache, etc.), or a storage unit located outside the chip within the electronic device (e.g., a read-only memory, random access memory, etc.).
[0067] For example, the processing unit is configured to: at a first moment, run a first application in the foreground of the application processing device, and run a second and a third application in the background of the application processing device, wherein the number of layers in the application processing device is a first number less than or equal to a first threshold; at a second moment, run the first application in the foreground of the application processing device, and run a second application in the background, wherein the number of layers occupied by the third application in the layers of the application processing device is less than the number of layers occupied by the second application in the layers of the application processing device; wherein the second moment is later than the first moment, and between the first and second moments, the first application continues to run in the foreground, and the second and third applications continue to run in the background.
[0068] In one possible implementation, the number of layers occupied by the second application in the electronic device's layers is greater than a second threshold, and the number of layers occupied by the third application in the electronic device's layers is less than the second threshold, with the second threshold being less than the first threshold.
[0069] In one possible implementation, the number of layers occupied by the first application in the layers of the electronic device is greater than or equal to the number of layers occupied by the second application in the layers of the electronic device; the processing unit is further configured to: stop running the first application when the first application is switched to background operation.
[0070] In one possible implementation, the electronic device includes a first layer, and the processing unit is further configured to: determine whether the number of first layers in the electronic device is greater than a third threshold, wherein the third threshold is less than or equal to the first threshold; if the number of first layers in the electronic device is greater than the third threshold, obtain a fourth application, wherein the number of first layers occupied by the fourth application in the first layer of the electronic device is greater than the fourth threshold, wherein the fourth threshold is less than the third threshold; determine whether the fourth application is running in the background; and if the fourth application is running in the background, stop running the fourth application.
[0071] In one possible implementation, the processing unit is further configured to: stop running the fourth application when the fourth application is switched to running in the background, provided that the fourth application is not running in the background.
[0072] In one possible implementation, the processing unit is further configured to: determine whether the number of the first layer in the electronic device is greater than a third threshold if the number of layers in the electronic device is less than or equal to a first threshold.
[0073] In one possible implementation, the processing unit is further configured to: determine whether the number of windows in the electronic device is greater than a fifth threshold; if the number of windows in the electronic device is greater than the fifth threshold, obtain a fifth application, wherein the number of windows occupied by the fifth application in the electronic device is greater than a sixth threshold and the sixth threshold is less than the fifth threshold; determine whether the fifth application is running in the background; and if the fifth application is running in the background, stop running the fifth application.
[0074] In one possible implementation, the processing unit is also configured to: stop running the fifth application when the fifth application is switched to running in the background if the fifth application is not running in the background.
[0075] In one possible implementation, the electronic device includes a first layer, and the processing unit is further configured to: determine whether the number of windows in the electronic device is greater than a fifth threshold, wherein the third threshold is less than or equal to the first threshold, when the number of layers in the electronic device is less than or equal to a first threshold and the number of first layers in the electronic device is less than or equal to a third threshold.
[0076] In one possible implementation, the processing unit is further configured to: determine whether the number of surfaces in the electronic device is greater than a seventh threshold; if the number of surfaces in the electronic device is greater than the seventh threshold, obtain a sixth application, wherein the number of surfaces occupied by the sixth application in the electronic device is greater than an eighth threshold and the eighth threshold is less than the seventh threshold; determine whether the sixth application is running in the background; and if the sixth application is running in the background, stop running the sixth application.
[0077] In one possible implementation, the processing unit is also configured to: stop running the sixth application when the sixth application switches to running in the background if the sixth application is not running in the background.
[0078] In one possible implementation, the electronic device includes a first layer, and the processing unit is further configured to: determine whether the number of surfaces in the electronic device is greater than a seventh threshold, and the third threshold is less than or equal to the first threshold, when the number of layers in the electronic device is less than or equal to a first threshold and the number of first layers in the electronic device is less than or equal to a third threshold.
[0079] In one possible implementation, before the second quantity is greater than the first threshold, the processing unit is further configured to: determine whether the number of layers in the electronic device is greater than the ninth threshold, wherein the ninth threshold is less than or equal to the first threshold; and if the number of layers in the electronic device is greater than the ninth threshold, output alarm information, wherein the alarm information is used to indicate that the number of layers is abnormal.
[0080] In one possible implementation, the processing unit is further configured to: periodically poll to determine whether the number of layers in the electronic device is greater than the ninth threshold, or, if the number of layers in the electronic device is greater than the tenth threshold, determine whether the number of layers in the electronic device is greater than the ninth threshold and the tenth threshold is less than the ninth threshold.
[0081] In one possible implementation, the electronic device includes a first layer. Before the second quantity is greater than the first threshold, the processing unit is further configured to: determine whether the quantity of the first layer in the electronic device is greater than the eleventh threshold, wherein the eleventh threshold is less than or equal to the first threshold; and output alarm information if the quantity of the first layer in the electronic device is greater than the eleventh threshold, wherein the alarm information is used to indicate that the number of layers is abnormal.
[0082] In one possible implementation, the processing unit is further configured to: periodically poll to determine whether the number of the first layer in the electronic device is greater than the eleventh threshold, or, if the number of layers in the electronic device is greater than the tenth threshold, determine whether the number of the first layer in the electronic device is greater than the eleventh threshold.
[0083] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, the memory for storing code instructions, and the processor for running the code instructions to perform the methods described in the first aspect or any possible implementation of the first aspect.
[0084] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program or instructions that, when executed on a computer, cause the computer to perform the methods described in the first aspect or any possible implementation thereof.
[0085] Fifthly, embodiments of this application provide a computer program product including a computer program, which, when run on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation thereof.
[0086] Sixthly, this application provides a chip or chip system including at least one processor and a communication interface. The communication interface and the at least one processor are interconnected via a circuit. The at least one processor is used to run computer programs or instructions to perform the methods described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip can be an input / output interface, pins, or circuits, etc.
[0087] In one possible implementation, the chip or chip system described above in this application further includes at least one memory storing instructions. The memory can be an internal storage unit of the chip, such as a register or cache, or it can be a storage unit of the chip itself (e.g., read-only memory, random access memory, etc.).
[0088] It should be understood that the second to sixth aspects of this application correspond to the technical solutions of the first aspect of this application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation are similar, and will not be repeated here. Attached Figure Description
[0089] Figure 1 This is a diagram illustrating the relationship between an app, WMS, and SurfaceFlinger.
[0090] Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0091] Figure 3 A schematic diagram of the software architecture of an electronic device provided in an embodiment of this application;
[0092] Figure 4A schematic flowchart illustrating an application processing method provided in an embodiment of this application;
[0093] Figure 5 A schematic diagram illustrating how a WMS (Web Application Management System) can control applications, as provided in this application embodiment.
[0094] Figure 6 A schematic diagram illustrating another application requiring management via a WMS, provided as an embodiment of this application;
[0095] Figure 7 This is a schematic diagram illustrating a processing method for applications in a control processing list, provided as an embodiment of this application.
[0096] Figure 8 A schematic flowchart illustrating another application processing method provided in an embodiment of this application;
[0097] Figure 9 This is a schematic diagram of the structure of a chip provided in an embodiment of this application. Detailed Implementation
[0098] To facilitate a clear description of the technical solutions in the embodiments of this application, the following explanation is provided first:
[0099] In the embodiments of this application, terms such as "first" and "second" are used to distinguish identical or similar items with substantially the same function and effect. For example, "first application" and "second application" are merely used to distinguish different chips and do not limit their order. Those skilled in the art will understand that terms such as "first" and "second" do not limit the quantity or execution order, and that "first" and "second" do not necessarily imply that they are different.
[0100] It should be noted that, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design scheme described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0101] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, and c can be single or multiple.
[0102] Currently, electronic devices may experience display problems when running multiple applications. For example, electronic devices may experience screen flickering, screen distortion, restarting, or lag.
[0103] When electronic devices run multiple applications, they inevitably need to composite numerous interfaces. Layers are the basic units for compositing interfaces, and each application's interface corresponds to a layer, resulting in a large number of layers. Since each layer occupies memory, especially buffer layers which carry graphics buffers and consume a significant amount of memory (around 10 megabytes), when the number of layers reaches a certain limit, memory consumption becomes excessive, leading to insufficient memory on the electronic device. This results in various display abnormalities, such as screen flickering, lag, and even restarts if the limit is reached.
[0104] Under normal circumstances, if a Layer is created or released normally, it is unlikely to reach its limit. For example, when an electronic device displays an interface, a Layer is created. When the interface is running in the background, the electronic device releases the Layer after a period of time, or when the interface stops running, the electronic device releases the Layer.
[0105] In some scenarios, such as when electronic devices add or create layers abnormally, or when layers are not properly released, the number of layers can be large, consuming a lot of memory, leading to insufficient memory and layer leaks.
[0106] For example, in some scenarios, applications in electronic devices may frequently add and create many layers due to design flaws or abnormal code logic, resulting in layer leakage.
[0107] In another scenario, an electronic device malfunctions and fails to release the layer properly, causing the layer to occupy the inner layer for an extended period, resulting in a layer leak.
[0108] For example, when an electronic device displays an interface, it creates a Layer. When the interface is running in the background, the electronic device does not release the Layer after a certain period of time, or when the interface stops running, the electronic device does not release the Layer.
[0109] The more interfaces and layers an electronic device has, the easier it is for the number of layers to reach the limit if layer leakage occurs. This can lead to insufficient memory and various abnormalities in the electronic device, such as screen flickering, screen distortion, restarting, lag, and other problems that prevent it from functioning properly.
[0110] For example, the default maximum number of layers on an electronic device can be 4096, which can be represented as `static const size_t MAX_LAYERS = 4096`. If the electronic device detects that the number of layers exceeds 4096, it will return `ErrorCode = -12`, indicating an exception. For instance, if the electronic device detects that the number of layers equals 4096, and is still creating layers, it will return `ErrorCode = -12` and restart.
[0111] To better understand the relationship between the interface and layers, the following explanation will cover this relationship.
[0112] An electronic device's display interface can be jointly created by an application (App), a window management service (WMS), a surface-flinger (SurfaceFlinger), a display driver, and the display screen. The App is responsible for displaying the window content, the WMS manages the window's state, size, and transparency, and the SurfaceFlinger allocates the graphics buffer required by the application and composes the entire graphics window on the electronic device, creating a layer. This layer can include Z-order, which refers to the order of the displayed interface on the electronic device. SurfaceFlinger can then draw or update the graphics window content onto the display screen through the display driver.
[0113] Figure 1 This illustrates the relationship between the App, WMS, and SurfaceFlinger. (For example...) Figure 1 As shown, an electronic device may include multiple apps, namely App1, App2, and App3. Each app may include multiple interfaces. Figure 1As shown, App1 includes activity1, activity2, view1, and view2. Figure 2 App2 includes Activity 1, Activity 2, and video. Figure 1 and vision Figure 2 App3 includes Activity 1, Activity 2, and video. Figure 1 and vision Figure 2 Different apps may contain different activities and views. An activity represents the interface displayed on the screen of an electronic device, and each activity can have an associated window to display the interface content. A view is the basic building block of the interface, used to represent the visible elements on the screen, such as buttons, text boxes, and images.
[0114] WMS is used to manage windows. Figure 1 In WMS, window states 1, 2, 3, 4, 5, and 6 can be managed.
[0115] SurfaceControl can manage the user interface. For example... Figure 1 As shown, the interface control can manage surface1, surface2, and surface3.
[0116] SurfaceFlinger can composite layers. For example... Figure 1 As shown, SurfaceFlinger can composite layers 1, 2, 3, 4, 5, and 6.
[0117] like Figure 1 As shown, there is a corresponding relationship between Activity 2, Window State 2, Surface 3, and Layer 3 in App1. App1 can be responsible for displaying window content, WMS can manage Window State 2, and WMS can also call Surface 3 to make SurfaceFlinger composite the layer. SurfaceFlinger is responsible for allocating the graphics buffer required by App1 and combining the entire graphics window in the electronic device to composite Layer 3.
[0118] As can be seen from the above, there is a certain correspondence between the interface, window, and layers. In the case of layer leakage, if the number of layers is not limited, the number of layers will increase, the memory occupied will increase, and the memory space will be insufficient.
[0119] In view of this, embodiments of this application provide an application processing method and related apparatus, which sets a threshold. When the number of layers reaches the threshold, applications that occupy a large number of layers are identified, and the operation of those applications is stopped to release the layers. This reduces the probability of layers consuming excessive memory, which helps to reduce the probability of display abnormalities. It is understood that this threshold can be less than the upper limit of the number of layers.
[0120] The method provided in this application can be applied to electronic devices. The electronic devices involved in this application may include handheld devices with display functions, vehicle-mounted devices, etc. For example, some electronic devices include: mobile phones, tablets, PDAs, laptops, mobile internet devices (MIDs), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminals in industrial control, wireless terminals in self-driving vehicles, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, cellular phones, cordless phones, session initiation protocol (SIP) phones, wireless local loop (WLL) stations, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices or other processing devices connected to wireless modems, in-vehicle devices, wearable devices, terminal devices in 5G networks, or future evolution of public land mobile communication networks. Terminal devices in a network (PLMN), etc., are not limited to this in the embodiments of this application.
[0121] By way of example and not limitation, in this embodiment, the electronic device can also be a wearable device. Wearable devices, also known as wearable smart devices, are a general term for devices that utilize wearable technology to intelligently design and develop everyday wearables, such as glasses, gloves, watches, clothing, and shoes. Wearable devices are portable devices that are worn directly on the body or integrated into the user's clothing or accessories. Wearable devices are not merely hardware devices, but also achieve powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable smart devices include those that are feature-rich, large in size, and can achieve complete or partial functions without relying on a smartphone, such as smartwatches or smart glasses, as well as those that focus on a specific type of application function and require the use of other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.
[0122] The electronic devices in the embodiments of this application may also be referred to as: terminal equipment, user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent, or user device, etc.
[0123] For ease of understanding, the hardware structure of the electronic device in the embodiments of this application will be described below.
[0124] For example, Figure 2 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Figure 2 As shown, the electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, and a display screen 194, etc.
[0125] Optionally, the aforementioned sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0126] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device. In other embodiments of this application, the electronic device may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0127] The processor 110 and the display screen 194 can be used to implement the display functions involved in the embodiments of this application.
[0128] The software system of an electronic device can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. A layered architecture can use the Android system, the Apple iOS system, or other operating systems; this application embodiment does not limit this. The following uses a layered Android system as an example to exemplify the software architecture of the electronic device provided in this application embodiment.
[0129] Figure 3 This is a schematic diagram of the software architecture of an electronic device provided in an embodiment of this application. Figure 3 As shown, a layered architecture divides the software system of an electronic device into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system can be divided into five layers, from top to bottom: applications, application framework, hardware abstraction layer (HAL), kernel, and hardware layer. The application layer can include a series of application packages, and it runs applications by calling the application programming interface (API) provided by the application framework layer. Figure 3 As shown, the application package can include applications such as chat, calendar, gallery, and video.
[0130] The application framework layer provides APIs and a programming framework for applications within the application layer. The application framework layer includes predefined functions. For example... Figure 3As shown, the application framework layer can include SurfaceFlinger, WMS, and ActivityManagerService (AMS). SurfaceFlinger detects the number of created layers; if it exceeds an alarm threshold, it sends an alarm to WMS. Upon receiving the alarm, WMS stores applications occupying a large number of layers in a management list. AMS stops the application from running if it exists in the management list, thus releasing the layers it occupies.
[0131] The purpose of the HAL layer is to abstract hardware, providing a unified interface for upper-layer applications to query hardware devices, or to provide data storage services for upper-layer applications. For example... Figure 3 As shown, the HAL layer may include a display driver module and a sensor hardware abstraction (sensor hidl). The display driver module can be used to transfer display-related content from the application framework layer to the display driver in the kernel layer.
[0132] The kernel layer is the layer between hardware and software. For example... Figure 3 As shown, the kernel layer may include one or more of the following: sensor drivers and display drivers, etc. In this embodiment, the display driver can drive the display screen to display display-related content from the application framework layer.
[0133] The hardware layer can include hardware such as microphones, cameras, and displays. The display is used to show the application's interface.
[0134] It should be understood that in some embodiments, layers that perform the same function may be called by other names, or layers that can perform the functions of multiple layers may be considered as one layer, or layers that can perform the functions of multiple layers may be divided into multiple layers. This application does not impose any limitations on this.
[0135] The above combination Figure 2 and Figure 3 The electronic devices described in the embodiments of this application have been introduced. The methods provided in the embodiments of this application will be described below.
[0136] Figure 4 A schematic flowchart illustrating an application processing method provided in an embodiment of this application is shown. This method can be executed by an electronic device, and the software architecture of the electronic device can be as described above. Figure 3 As shown. Electronic devices may include SurfaceFlinger, WMS, and AMS.
[0137] like Figure 4 As shown, the method may include the following steps:
[0138] S401, SurfaceFlinger periodically polls for layer leaks, or, when the number of layers is greater than X, checks for layer leaks.
[0139] When creating layers, electronic devices can save the process ID of newly created Layer objects and count the number of Layer objects. Layers can include: ContainerLayer, BufferLayer, PictureLayer, TextureLayer, etc.
[0140] For example, when an electronic device creates a layer, it can add the process identifier of the newly created layer to the mCurrentState array through the addClientLayer function, and count the number of Layer objects, represented by mNumLayers.
[0141] In some implementations, SurfaceFlinger can periodically poll whether layers are leaking. To save power on electronic devices, SurfaceFlinger can initiate a periodic polling mechanism when the screen is on to monitor for layer leaks.
[0142] For example, SurfaceFlinger can detect whether layers are leaked every 3 minutes after the electronic device screen is turned on.
[0143] In some implementations, SurfaceFlinger can detect layer leakage when the number of layers is greater than X. The value of X can be set differently according to different needs, and this application embodiment does not limit it.
[0144] For example, SurfaceFlinger can detect whether layers are leaking when the number of layers mNumLayers is greater than 1000.
[0145] Whether a layer is leaking can be determined by whether the total number of layers exceeds a threshold. SurfaceFlinger detects layer leakage by checking if the total number of layers exceeds a threshold Y. This threshold Y can be set to different values according to different needs, and this embodiment does not limit it.
[0146] In some implementations, layer leakage can be defined as the total number of layers exceeding 3200; no layer leakage can be defined as the total number of layers not exceeding 3200. Alternatively, layer leakage can be defined as the total number of layers exceeding 3000; no layer leakage can be defined as the total number of layers not exceeding 3000.
[0147] Since buffer layers consume a significant amount of memory, in some implementations, whether a layer leaks is determined by whether the total number of BufferLayers in the layers exceeds a threshold Z. This threshold Z can be set to different values according to different needs, and this application embodiment does not limit it. Buffer layers can include Layers of types such as BufferStateLayer and BufferQueueLayer, and this application embodiment does not limit it.
[0148] In some implementations, layer leakage is defined as the total number of BufferLayers exceeding 80; no layer leakage is defined as the total number of layers not exceeding 80. Alternatively, layer leakage is defined as the total number of layers exceeding 90; no layer leakage is defined as the total number of layers not exceeding 90.
[0149] S402. In the event of layer leakage, SurfaceFlinger transmits layer abnormality alarm information to WMS.
[0150] In some examples, in the event of a layer leak, SurfaceFlinger can transmit a layer exception warning event (Transaction LayerLeak Event) to WMS via the notifyLayerLeakWarning function.
[0151] After receiving an alarm event for an abnormal layer, S403 and WMS will store the applications that need to be managed in the management and control processing list.
[0152] For example, after receiving a layer anomaly alarm event, WMS can use the `handleLayerLeak` function to obtain the applications that need to be managed and store them in the management processing list. In some implementations, WMS can trigger the `handleLayerLeak` function via an asynchronous message to obtain the applications that need to be managed and store them in the management processing list.
[0153] It should be noted that storing the applications that need to be managed in the management processing list is just an example. WMS can also store the applications that need to be managed in the form of arrays or matrices. This application embodiment does not limit this.
[0154] Figure 5 This diagram illustrates how a WMS (Web Management System) can manage applications that require control. Figure 5As shown, after receiving a layer anomaly alarm event, WMS can determine whether the total number of layers is greater than M. If the total number of layers is greater than M, it indicates a layer leak. WMS can then perform three steps: 1) Obtain and save layer-related information; 2) Perform fault logging; 3) Obtain application A with more than i layers occupied and store application A in the management and control processing list.
[0155] Wherein, M can be the same as or different from Y, and this application embodiment does not limit this. If M is the same as Y, then after the WMS receives the layer abnormality alarm information event, it can directly execute the above 3 steps. This is beneficial for handling layer leakage as quickly as possible.
[0156] If M and Y are different, and M can be greater than Y, then after receiving a layer anomaly alarm event, WMS can monitor the total number of layers. If the total number of layers is greater than M, then the above three steps are executed. In this way, WMS can execute independently of the applications that need to be managed and the layer anomaly alarm events, thus increasing flexibility.
[0157] For step 1) above, the layer-related information may include the total number of layers, the application and application status corresponding to each layer in the total layers, the number of BufferLayers in the total layers, and the application and application status corresponding to each BufferLayer. The application status may include not running, inactive, active, background, and suspended. Not running indicates that the application has been terminated or has not yet started. Inactive indicates that the application is in the foreground but no longer receives events; for example, the user has locked the device while the application is active. Active indicates that the application is in use, or in other words, the application is in the foreground. Background indicates that the application is not displayed on the screen but is still executing code related to that application. Suspended indicates that the application resides in memory but is not executing application-related code. WMS can store layer-related information in a list, workbook, or database; this embodiment does not limit this.
[0158] For example, WMS can save layer-related information in the layerleak.txt file.
[0159] Regarding step 2) above, layer leakage can be understood as a malfunction of the electronic device. WMS can use layer-related information as fault information so that layer leakage can be included when calling fault information later.
[0160] In some implementations, WMS can also report layer-related information to a server or the cloud to facilitate subsequent analysis of electronic device malfunctions.
[0161] Regarding step 3) above, WMS can count the number of layers occupied by each application, obtain application A which occupies more than i layers, and store application A in the management list. Application A may include one or more applications, but this embodiment does not limit this.
[0162] If an application occupies more than i layers, it indicates that the application has a large number of layers and requires management. WMS can store these applications in a management processing list. It is understood that i is less than or equal to M. In some examples, M can be 3500, 3200, or 3300, etc., and i can be 50 or 45, etc., but this application embodiment does not limit this.
[0163] The above three steps can be executed sequentially or in parallel, and this application embodiment does not limit this.
[0164] For example, steps 1) and 2) above can be executed in parallel, and step 3) is executed serially with the first two steps. M can be 3500. If the total number of layers is greater than 3500, WMS triggers the dumpsys event. The dumpsys event includes steps 1) and 2). After triggering the dumpsys event, step 3 is executed.
[0165] like Figure 5 As shown, after receiving a layer anomaly alarm event, WMS can determine whether the number of buffered layers is greater than N. If the number of buffered layers is greater than N, it indicates a layer leak. WMS can then determine that application B occupies more than j buffered layers and store application B in the management and control processing list.
[0166] Application B may include one or more applications, and this application embodiment does not limit this. If there are applications that occupy more than j buffer layers, it indicates that the number of buffer layers corresponding to that application is large and needs to be managed. WMS can store these applications in the management processing list. It is understood that j is less than or equal to N, and N is a value less than or equal to M. In some examples, N can be 100, 80, or 90, etc., and j can be 25 or 30, etc., and this application embodiment does not limit this.
[0167] like Figure 5 As shown, after receiving the layer abnormality alarm information event, WMS can also determine whether the number of application windows is greater than 0. If the number of application windows is greater than 0, it indicates that the layer is leaked. WMS can then obtain the application C that occupies more than k application windows and store application C in the management and processing list.
[0168] Application C may include one or more applications, and this embodiment of the application does not limit this. If there are applications with more than k application windows, it indicates that the number of application windows corresponding to that application is large and needs to be managed. WMS can store these applications in a management and processing list. It is understood that k is less than or equal to 0. In some examples, 0 can be 3500, 3000, 150 or 3200, and k can be 60, 50 or 55, etc., and this embodiment of the application does not limit this.
[0169] like Figure 5 As shown, after receiving the layer abnormality alarm information event, WMS can also determine whether the number of surfaces is greater than P. If the number of interfaces is greater than P, it indicates that the layer is leaked. WMS can then obtain the application D with more than m interfaces and store the application D in the management and processing list.
[0170] Application D may include one or more applications, and this embodiment of the application does not limit this. If there are applications with more than m interfaces, it indicates that the number of interfaces corresponding to the application is large and needs to be managed. WMS can store these applications in the management and processing list. It is understood that m is less than or equal to P. In some examples, P can be 3500, 3000, 150 or 3200, etc., and m can be 40, 30 or 35, etc., and this embodiment of the application does not limit this.
[0171] exist Figure 5 In this context, M, O, and P can be the same or different, and this application embodiment does not limit this. I, j, k, and m can also be the same or different, and this application embodiment does not limit this. In some examples, since the memory occupied by the interface is greater than the memory occupied by the application window, m can be less than k, so as to facilitate reasonable management of the application.
[0172] exist Figure 5 In the method shown, WMS can determine one or multiple layers; this embodiment does not limit this. Determining multiple layers is more beneficial for controlling the number of layers and reducing the probability of layer leakage.
[0173] The above Figure 5 This is just one example; in another example, Figure 5 The decision-making process shown may not be parallel.
[0174] Figure 6 This illustrates another scenario where a WMS provides control over an application that requires management. For example... Figure 6As shown, after receiving a layer abnormality alarm event, WMS can determine whether the total number of layers is greater than M. If the total number of layers is greater than M, WMS can perform three steps: 1) obtain and save layer-related information; 2) perform fault marking; 3) obtain application A with more than i layers occupied, and store application A in the management and control processing list.
[0175] If the total number of layers is less than or equal to M, WMS can determine whether the number of buffered layers is greater than N. If the number of buffered layers is greater than N, it indicates a layer leak. WMS can then obtain application B, which occupies more than j buffered layers, and store application B in the management and processing list.
[0176] If the number of buffer layers is less than or equal to N, WMS can determine whether the number of application windows is greater than O and whether the number of interfaces is greater than P. If the number of application windows is greater than O, it indicates a layer leak, and WMS can identify application C with more than k application windows and store application C in the management and processing list. If the number of interfaces is greater than P, it indicates a layer leak, and WMS can identify application D with more than m interface windows and store application D in the management and processing list.
[0177] In this way, making judgments in sequence is beneficial for obtaining the necessary control applications under different circumstances.
[0178] S404. When the number of applications in the control and processing list is greater than 1, AMS processes the applications in the control and processing list.
[0179] AMS processes applications in the control list to control layers and reduce the probability of layer leaks.
[0180] Figure 7 This diagram illustrates a method for processing applications in a controlled processing list. For example... Figure 7 As shown, when the number of applications detected in the management and control list is greater than 1, AMS can determine whether each application in the management and control list is in the background. For applications in the background, AMS can stop running the application and release the leaked layer.
[0181] For applications not in the background of the management list, AMS can determine whether the application has a visible window. For applications that are not in the background and do not have a visible window, AMS can stop the application from running, thereby releasing the leaked layer.
[0182] If an application is not in the background but has a visible window, it means that the application is running in the foreground. For applications that are not in the background but have a visible window, AMS can monitor the status of these applications. When such applications are switched to the background, AMS can stop running these applications, thereby releasing leaked layers.
[0183] For example, for applications that are not in the background but have a visible window, AMS can start or invoke a monitoring function for the application, and stop the application from running when it is switched to the background.
[0184] In some implementations, AMS can stop the application from running by calling the forceStopPackage function.
[0185] The application processing method provided in this application embodiment allows SurfaceFlinger to detect layer leakage, WMS to identify applications requiring management in the event of layer leakage, and AMS to process these applications, thereby controlling the number of layers. This reduces the probability of layers consuming excessive memory, thus helping to lower the probability of display anomalies.
[0186] Optionally, for applications that are not running in the background but have a visible window, AMS can initiate a periodic monitoring of the application. If, when the timer expires, the application is still not running in the background and has a visible window, then the application process will be terminated. This forces the application to be processed, reducing the probability of display errors.
[0187] For example, for applications that are not in the background but have a visible window, AMS can start a monitoring function that monitors the application for 5 minutes at a time. If the application is still not in the background and has a visible window when the timer expires, the application process of such an application can be terminated by killing process.
[0188] From the above Figure 4 The method shown indicates that when an application is running on an electronic device and layer leakage occurs, the application experiencing layer leakage is identified, and it is addressed at an appropriate time to release the memory occupied by its layers, reducing the probability of layer resources being occupied for extended periods without release. Applications experiencing layer leakage can include one or more of the following: application A (occupying more than i layers), application B (occupying more than j buffered layers), application C (occupying more than k application windows), or application D (occupying more than m surface elements). It's understood that if these applications can release layers normally, the probability of exceeding the set threshold is relatively high. If the threshold is exceeded, it indicates a higher probability of an anomaly. Stopping these applications from running in the background can also improve the user experience.
[0189] The above description uses the internal implementation of an electronic device as an example. The following description uses an electronic device as the execution subject to explain the method provided in the embodiments of this application.
[0190] For example, Figure 8 A schematic flowchart illustrating an application processing method provided in an embodiment of this application is shown. This method can be applied to electronic devices. Figure 8 As shown, the method may include the following steps:
[0191] S801. At the first moment, the first application runs in the foreground of the electronic device, and the second and third applications run in the background of the electronic device. The number of layers in the electronic device is the first quantity, which is less than or equal to the first threshold.
[0192] S802, at the second moment, the first application is running in the foreground of the electronic device, and the number of layers in the electronic device is the second number. The second number is greater than the first threshold, so the second application stops running in the background, and the third application continues to run in the background. The number of layers occupied by the third application in the layers of the electronic device is less than the number of layers occupied by the second application in the layers of the electronic device. The second moment is later than the first moment. Between the first moment and the second moment, the first application continues to run in the foreground, and the second application and the third application continue to run in the background.
[0193] In this case, if the number of layers in the electronic device exceeds the first threshold, the second application will occupy a large number of layers in the electronic device's layers. The probability of the second application abnormally adding layers or failing to release layers normally is relatively high. Stopping the second application can release the memory occupied by the second application, which helps reduce the probability of insufficient memory and thus helps reduce the probability of display abnormalities.
[0194] Optionally, the second application occupies more layers than the second threshold in the electronic device's layers, while the third application occupies less layers than the second threshold, and the second threshold is less than the first threshold. This facilitates the identification of applications that need to be stopped.
[0195] Optionally, the number of layers occupied by the first application in the electronic device's layers is greater than or equal to the number of layers occupied by the second application in the electronic device's layers; the method further includes: stopping the first application when it is switched to the background. This reduces the probability of display anomalies and also helps to reduce the probability of impacting user experience.
[0196] Optionally, the electronic device includes a first layer, and the method further includes: determining whether the number of first layers in the electronic device is greater than a third threshold, wherein the third threshold is less than or equal to the first threshold; if the number of first layers in the electronic device is greater than the third threshold, obtaining a fourth application, wherein the number of first layers occupied by the fourth application in the first layer of the electronic device is greater than the fourth threshold, wherein the fourth threshold is less than the third threshold; determining whether the fourth application is running in the background; and stopping the fourth application from running if the fourth application is running in the background.
[0197] Thus, if the number of first layers in an electronic device exceeds the third threshold, the fourth application occupies a large number of first layers in the electronic device's layers. The fourth application is more likely to abnormally add first layers or fail to release first layers normally. Stopping the fourth application can release the memory occupied by the fourth application, which helps reduce the probability of insufficient memory and thus helps reduce the probability of display abnormalities.
[0198] Optionally, the above method further includes: stopping the fourth application when it switches to the background if the fourth application is not running in the background. This way, stopping the fourth application when it switches to the background reduces the probability of display errors and also helps to reduce the probability of negatively impacting the user experience.
[0199] Optionally, determining whether the number of first layers in the electronic device is greater than a third threshold includes: if the number of layers in the electronic device is less than or equal to the first threshold, determining whether the number of first layers in the electronic device is greater than the third threshold.
[0200] In this way, determining the number of layers based on the number of layers does not require control. Instead, the number of the first layer is determined to decide whether to control its quantity. This multi-level judgment helps to better control the number of layers, thereby reducing the probability of layers consuming excessive memory.
[0201] Optionally, the above method further includes: determining whether the number of windows in the electronic device is greater than a fifth threshold; if the number of windows in the electronic device is greater than the fifth threshold, obtaining a fifth application, wherein the number of windows occupied by the fifth application in the electronic device is greater than a sixth threshold and the sixth threshold is less than the fifth threshold; determining whether the fifth application is running in the background; and if the fifth application is running in the background, stopping the fifth application from running.
[0202] Thus, when the number of windows on an electronic device exceeds the fifth threshold, the fifth application occupies a large number of windows on the electronic device, and the probability of the fifth application malfunctioning is relatively high. Stopping the fifth application can release the memory it occupies, which helps reduce the probability of insufficient memory and, consequently, the probability of display malfunctions.
[0203] Optionally, the method further includes: stopping the fifth application when it is switched to the background if the fifth application is not running in the background. This way, stopping the fifth application when it is switched to the background reduces the probability of display errors and also helps to reduce the probability of negatively impacting the user experience.
[0204] Optionally, the electronic device includes a first layer. Determining whether the number of windows in the electronic device is greater than a fifth threshold includes: if the number of layers in the electronic device is less than or equal to the first threshold, and the number of first layers in the electronic device is less than or equal to a third threshold, determining whether the number of windows in the electronic device is greater than a fifth threshold, where the third threshold is less than or equal to the first threshold.
[0205] In this way, determining the number of layers based on the number of layers does not require control, determining the number of layers based on the number of the first layer does not require control, and determining the number of windows to determine whether to control the number of windows, multi-level judgment is conducive to better control of the number of windows, thereby achieving control over the number of layers and reducing the probability of layers occupying too much memory.
[0206] Optionally, the above method further includes: determining whether the number of surfaces in the electronic device is greater than a seventh threshold; if the number of surfaces in the electronic device is greater than the seventh threshold, obtaining a sixth application, wherein the number of surfaces occupied by the sixth application in the electronic device is greater than an eighth threshold and the eighth threshold is less than the seventh threshold; determining whether the sixth application is running in the background; if the sixth application is running in the background, stopping the sixth application from running.
[0207] Thus, when the number of surfaces in an electronic device exceeds the seventh threshold, the sixth application occupies a large number of surfaces, increasing the probability of it malfunctioning. Stopping the sixth application can release the memory it occupies, reducing the probability of insufficient memory and consequently reducing the probability of display malfunctions.
[0208] Optionally, the method further includes: stopping the sixth application when it is switched to the background if the sixth application is not running in the background. This way, stopping the sixth application when it is switched to the background reduces the probability of display errors and also helps to reduce the probability of negatively impacting the user experience.
[0209] Optionally, the electronic device includes a first layer. Determining whether the number of surfaces in the electronic device is greater than a seventh threshold includes: if the number of layers in the electronic device is less than or equal to the first threshold, and the number of the first layer in the electronic device is less than or equal to a third threshold, determining whether the number of surfaces in the electronic device is greater than a seventh threshold, and the third threshold is less than or equal to the first threshold.
[0210] In this way, determining the number of layers based on the number of layers does not require control, determining the number of layers based on the number of the first layer does not require control, and determining the number of surfaces to determine whether to control the number of surfaces, multi-level judgment is conducive to better control of the number of surfaces, thereby achieving control over the number of layers and reducing the probability of layers occupying too much memory.
[0211] Optionally, before the second quantity is greater than the first threshold, the method further includes: determining whether the number of layers in the electronic device is greater than a ninth threshold, wherein the ninth threshold is less than or equal to the first threshold; and if the number of layers in the electronic device is greater than the ninth threshold, outputting an alarm message, wherein the alarm message is used to indicate that the number of layers is abnormal.
[0212] In this way, when the number of layers exceeds the ninth threshold, it indicates that there may be an anomaly in the layer, and an alarm message can be output to facilitate the monitoring and control of the layer.
[0213] Optionally, determining whether the number of layers in the electronic device is greater than the ninth threshold includes: periodically polling to determine whether the number of layers in the electronic device is greater than the ninth threshold, or, if the number of layers in the electronic device is greater than the tenth threshold, determining whether the number of layers in the electronic device is greater than the ninth threshold, and the tenth threshold is less than the ninth threshold. This helps to save power consumption.
[0214] Optionally, the electronic device includes a first layer. Before the second quantity is greater than the first threshold, the method further includes: determining whether the quantity of the first layer in the electronic device is greater than an eleventh threshold, wherein the eleventh threshold is less than or equal to the first threshold; if the quantity of the first layer in the electronic device is greater than the eleventh threshold, outputting an alarm message, wherein the alarm message is used to indicate that the number of layers is abnormal.
[0215] In this way, when the number of layers in the first layer exceeds the eleventh threshold, it indicates that there may be an anomaly in the layer, and an alarm message can be output to facilitate the monitoring and control of the layer.
[0216] Optionally, determining whether the number of first layers in the electronic device is greater than the eleventh threshold includes: periodically polling to determine whether the number of first layers in the electronic device is greater than the eleventh threshold, or, if the number of layers in the electronic device is greater than the tenth threshold, determining whether the number of first layers in the electronic device is greater than the eleventh threshold. This helps save power consumption.
[0217] It should be noted that the module names involved in the embodiments of this application can all be defined as other names, as long as they can achieve the function of each module, and no specific restrictions are placed on the module names.
[0218] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0219] The application processing method of the embodiments of this application has been described above. The apparatus for executing the above method provided in the embodiments of this application is described below. Those skilled in the art will understand that the methods and apparatus can be combined with and referenced by each other, and the related apparatus provided in the embodiments of this application can execute the steps in the above application processing method.
[0220] For example, Figure 9 This is a schematic diagram of a chip structure provided in an embodiment of this application. Figure 9 As shown, chip 90 includes one or more processors 901, communication lines 902, communication interfaces 903, and memory 904.
[0221] In some implementations, memory 904 stores elements such as executable modules or data structures, or subsets thereof, or extended sets thereof.
[0222] The methods for measuring physiological characteristics described in the embodiments of this application can be applied to or implemented by the processor 901. The processor 901 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the methods for measuring the physiological characteristics can be completed by integrated logic circuits in the hardware or by instructions in software within the processor 901. The processor 901 may be a general-purpose processor (e.g., a microprocessor or conventional processor), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates, transistor logic devices, or discrete hardware components. The processor 901 can implement or execute the various processing-related methods, steps, and logic block diagrams disclosed in the embodiments of this application.
[0223] The steps of the method for measuring physiological characteristics disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can be located in mature storage media in the art, such as random access memory, read-only memory, programmable read-only memory, or electrically erasable programmable read-only memory (EEPROM). This storage medium is located in memory 904, and processor 901 reads the information in memory 904 and, in conjunction with its hardware, completes the steps of the above method.
[0224] The processor 901, memory 904 and communication interface 903 can communicate with each other via communication line 902.
[0225] The application processing method provided in this application embodiment can be applied to electronic devices with communication functions. Electronic devices include terminal devices, and the specific device form of the terminal device can be referred to the above-mentioned descriptions, which will not be repeated here.
[0226] This application provides a terminal device, which includes a processor and a memory; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, causing the terminal device to perform the above-described method.
[0227] This application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, it implements the methods described above. The methods described in the above embodiments can be implemented wholly or partially by software, hardware, firmware, or any combination thereof. If implemented in software, the functionality can be stored as one or more instructions or code on or transmitted over the computer-readable medium. The computer-readable medium can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium accessible by a computer.
[0228] In one possible implementation, a computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage or other magnetic storage devices, or any other medium targeted to carry or to store the required program code in the form of instructions or data structures, and accessible by a computer. Furthermore, any connection is appropriately referred to as a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave, then coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. As used herein, disks and optical discs include optical discs, laser discs, optical discs, Digital Versatile Discs (DVDs), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs optically reproduce data using lasers. Combinations of the above should also be included within the scope of computer-readable media.
[0229] This application provides a computer program product, which includes a computer program that, when run, causes a computer to perform the above-described method.
[0230] This application describes embodiments of methods, apparatus (systems), and computer program products according to embodiments of this application with reference to flowchart illustrations and / or block diagrams. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing device, generate instructions for implementing the flowchart illustrations. Figure 1One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0231] The above specific embodiments further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.
Claims
1. An application processing method, characterized in that, Applied to electronic devices, including: At the first moment, the electronic device runs a first application in the foreground and a second and a third application in the background. The number of layers in the electronic device is a first number, which is less than or equal to a first threshold. At the second moment, the first application is running in the foreground of the electronic device, the number of layers in the electronic device is a second number, the second number is greater than the first threshold, the second application stops running in the background, and the third application is kept running in the background, the number of layers occupied by the third application in the layers of the electronic device is less than the number of layers occupied by the second application in the layers of the electronic device; Wherein, the second moment is later than the first moment, and between the first moment and the second moment, the first application continues to run in the foreground, and the second application and the third application continue to run in the background; The electronic device includes a first layer, and the method further includes: Determine whether the number of first layers in the electronic device is greater than a third threshold, wherein the third threshold is less than or equal to the first threshold; If the number of first layers in the electronic device is greater than the third threshold, a fourth application is obtained, wherein the number of first layers occupied by the fourth application in the first layer of the electronic device is greater than the fourth threshold, and the fourth threshold is less than the third threshold. Determine whether the fourth application is running in the background; If the fourth application is running in the background, stop running the fourth application.
2. The method according to claim 1, characterized in that, The second application occupies more than a second threshold in the number of layers in the electronic device's layers, while the third application occupies less than the second threshold in the number of layers in the electronic device's layers, and the second threshold is less than the first threshold.
3. The method according to claim 1 or 2, characterized in that, The number of layers occupied by the first application in the layers of the electronic device is greater than or equal to the number of layers occupied by the second application in the layers of the electronic device; The method further includes: When the first application is switched to run in the background, the first application stops running.
4. The method according to claim 1, characterized in that, The method further includes: If the fourth application is not running in the background, when the fourth application is switched to run in the background, the fourth application will stop running.
5. The method according to claim 1 or 4, characterized in that, The step of determining whether the number of first layers in the electronic device is greater than the third threshold includes: If the number of layers in the electronic device is less than or equal to the first threshold, it is determined whether the number of the first layer in the electronic device is greater than the third threshold.
6. The method according to any one of claims 1 to 2, characterized in that, The method further includes: Determine whether the number of windows in the electronic device is greater than a fifth threshold; If the number of windows in the electronic device is greater than the fifth threshold, a fifth application is obtained, wherein the number of windows occupied by the fifth application in the electronic device is greater than a sixth threshold, and the sixth threshold is less than the fifth threshold. Determine whether the fifth application is running in the background; If the fifth application is running in the background, stop running the fifth application.
7. The method according to claim 6, characterized in that, The method further includes: If the fifth application is not running in the background, it will stop running when it is switched to the background.
8. The method according to claim 6, characterized in that, The electronic device includes a first layer, and determining whether the number of windows in the electronic device is greater than a fifth threshold includes: If the number of layers in the electronic device is less than or equal to the first threshold, and the number of first layers in the electronic device is less than or equal to the third threshold, then it is determined whether the number of windows in the electronic device is greater than the fifth threshold, wherein the third threshold is less than or equal to the first threshold.
9. The method according to any one of claims 1 to 2, characterized in that, The method further includes: Determine whether the number of surfaces in the electronic device is greater than the seventh threshold; If the number of surfaces in the electronic device is greater than the seventh threshold, a sixth application is obtained, wherein the number of surfaces occupied by the sixth application in the electronic device is greater than an eighth threshold, and the eighth threshold is less than the seventh threshold. Determine whether the sixth application is running in the background; If the sixth application is running in the background, stop running the sixth application.
10. The method according to claim 9, characterized in that, The method further includes: If the sixth application is not running in the background, it will stop running when it is switched to the background.
11. The method according to claim 9, characterized in that, The electronic device includes a first layer, and determining whether the number of surfaces in the electronic device is greater than a seventh threshold includes: If the number of layers in the electronic device is less than or equal to the first threshold, and the number of first layers in the electronic device is less than or equal to the third threshold, it is determined whether the number of surfaces in the electronic device is greater than the seventh threshold, wherein the third threshold is less than or equal to the first threshold.
12. The method according to any one of claims 1 to 2, characterized in that, Before the second quantity exceeds the first threshold, the method further includes: Determine whether the number of layers in the electronic device is greater than a ninth threshold, wherein the ninth threshold is less than or equal to the first threshold; If the number of layers in the electronic device exceeds the ninth threshold, an alarm message is output, which indicates an abnormal number of layers.
13. The method according to claim 12, characterized in that, The step of determining whether the number of layers in the electronic device is greater than the ninth threshold includes: The system periodically polls to determine whether the number of layers in the electronic device exceeds the ninth threshold, or... If the number of layers in the electronic device is greater than the tenth threshold, it is determined whether the number of layers in the electronic device is greater than the ninth threshold, wherein the tenth threshold is less than the ninth threshold.
14. The method according to any one of claims 1 to 2, characterized in that, The electronic device includes a first layer, and before the second quantity exceeds the first threshold, the method further includes: Determine whether the number of the first layer in the electronic device is greater than the eleventh threshold, wherein the eleventh threshold is less than the first threshold; If the number of first layers in the electronic device exceeds the eleventh threshold, an alarm message is output, which indicates an abnormal number of layers.
15. The method according to claim 14, characterized in that, The step of determining whether the number of first layers in the electronic device is greater than the eleventh threshold includes: The system periodically polls to determine whether the number of first layers in the electronic device is greater than the eleventh threshold, or... If the number of layers in the electronic device is greater than the tenth threshold, determine whether the number of the first layer in the electronic device is greater than the eleventh threshold.
16. An electronic device, characterized in that, include: Processor and memory; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the electronic device to perform the method as described in any one of claims 1-15.
17. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-15.
18. A chip system, characterized in that, It includes at least one processor and a communication interface, the communication interface and the at least one processor being interconnected via a line, the at least one processor being configured to run a computer program or instructions to perform the method as described in any one of claims 1-15.
19. A computer program product, characterized in that, Includes a computer program that, when run, causes a computer to perform the method as described in any one of claims 1-15.
Citation Information
Patent Citations
Memory processing method and related device
CN115794413A
Layer processing method, electronic equipment and readable storage medium
CN116048679A