Interface electric quantity determination method and device, electronic equipment and storage medium
By reading and saving the interface battery level from the target storage partition to shared memory during the electronic device's startup process, and using the kernel layer to determine the battery level to be displayed, the problem of interface battery level jumps is solved, achieving more efficient and secure battery level display.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-11
- Publication Date
- 2026-04-14
AI Technical Summary
In existing technologies, the battery level on the screen of electronic devices is prone to fluctuating when the device is turned off and then restarted, resulting in inconsistent display and causing inconvenience to users. Furthermore, the battery level meter is at risk of fluctuating when monitoring the battery level, which affects display efficiency and security.
During the resource preloading phase of the device startup process, the screen battery level at the time of the most recent shutdown is read from the target storage partition and saved to the shared memory. During the kernel startup phase, the screen battery level to be displayed is read from the shared memory through the kernel layer, avoiding direct interaction with user space, reducing read lag, and improving display efficiency and security.
It effectively avoids the battery level fluctuation on the screen when the device restarts, improves the accuracy and efficiency of the battery level display, enhances the security of the kernel layer, and is suitable for various electronic devices.
Smart Images

Figure CN119597376B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of battery technology, specifically to a method, apparatus, electronic device, and storage medium for determining interface charge. Background Technology
[0002] Currently, to better monitor the battery status of electronic devices, fuel gauges (such as fuel gauge chips installed outside the battery) are typically used to monitor the battery level. However, fuel gauges have a certain probability of fluctuating battery level readings during monitoring, especially when the electronic device is turned off and then restarted. If the battery level displayed on the electronic device matches the fuel gauge reading, a discrepancy will occur, causing confusion for the user. Therefore, preventing these fluctuations in the displayed battery level on electronic devices has become a pressing technical problem that needs to be solved. Summary of the Invention
[0003] This application discloses a method, apparatus, electronic device, and storage medium for determining the battery level on the screen. This method can prevent the battery level displayed on the screen from changing abruptly when the electronic device is started, thus avoiding inconvenience to the user and improving the efficiency of battery level display.
[0004] This application discloses a method for determining interface power, applied to electronic devices, the method comprising:
[0005] During the resource preloading phase of the device startup process, the battery level of the first interface is read from the target storage partition and written to the shared memory; the battery level of the first interface is the battery level displayed by the display device when the electronic device was last powered off; the shared memory is the memory space shared with the kernel layer during the resource preloading phase.
[0006] During the kernel startup phase, the battery level of the first interface is read from the shared memory through the kernel layer, and the battery level of the second interface to be displayed is determined based on the battery level of the first interface.
[0007] This application discloses a device for determining interface power, applied to an electronic device, the device comprising:
[0008] The power reading module is used to read the power level of the first interface from the target storage partition and write the power level of the first interface into shared memory during the resource preloading phase of the device startup process; the power level of the first interface is the power level of the interface displayed by the display device when the electronic device was last powered off; the shared memory is the memory space shared with the kernel layer during the resource preloading phase.
[0009] A battery level determination module is used to read the battery level of the first interface from the shared memory through the kernel layer during the kernel startup phase, and determine the battery level of the second interface to be displayed based on the battery level of the first interface.
[0010] This application discloses an electronic device, including a memory and a processor. The memory stores a computer program, and when the computer program is executed by the processor, the processor performs the method described above.
[0011] This application discloses a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the method described above.
[0012] The method, apparatus, electronic device, and storage medium for determining the battery level of the device disclosed in this application, during the resource preloading phase of the device startup process, read a first interface battery level from a target storage partition and write it to shared memory. This first interface battery level is the battery level displayed on the display device when the electronic device was last powered off. During the kernel startup phase, the kernel layer reads the first interface battery level from the shared memory and determines the second interface battery level to be displayed based on the first interface battery level. In this application embodiment, when the electronic device is powered off, the first interface battery level displayed on the display device can be saved to the target storage partition. When the device starts up, the first interface battery level is read from the target storage partition, and the second interface battery level to be displayed is determined using the first interface battery level. This avoids the situation where the displayed interface battery level jumps when the electronic device is powered off and then restarted, avoiding inconvenience to the user. Moreover, reading the first interface battery level stored in the target storage partition during the resource preloading phase of the device startup process and then passing it to the kernel layer through shared memory does not require waiting for the user space process to load, reducing the lag in reading the first interface battery level and improving the display efficiency of the interface battery level. In addition, the kernel layer does not interact directly with the target storage partition, which improves the security of the kernel layer. Attached Figure Description
[0013] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0014] Figure 1A This is an application scenario diagram of a method for determining the interface power level in one embodiment;
[0015] Figure 1B This is a system architecture diagram of an operating system in an electronic device in one embodiment;
[0016] Figure 2 This is a flowchart of a method for determining the interface power level in one embodiment;
[0017] Figure 3 A flowchart of a method for determining interface power in another embodiment;
[0018] Figure 4 This is a flowchart illustrating, in one embodiment, the determination of the battery level of the second interface to be displayed based on the battery level of the first interface;
[0019] Figure 5 This is a block diagram of a device for determining the interface power level in one embodiment;
[0020] Figure 6 This is a structural block diagram of an electronic device in one embodiment. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0022] It should be noted that the terms "comprising" and "having," and any variations thereof, in the embodiments and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0023] It is understood that the terms "first," "second," etc., used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another. For example, without departing from the scope of this application, the first interface charge may be referred to as the second interface charge, and similarly, the second interface charge may be referred to as the first interface charge. Both the first interface charge and the second interface charge are interface charges, but they do not indicate the same interface charge. The term "multiple" as used in this application refers to two or more. The term "and / or" as used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0024] Fuel gauges have a certain probability of fluctuating battery levels during monitoring, especially when charging is nearing completion or when electronic devices are turned off and then restarted. For example, the battery level might jump from 96% to 100%, or from 4% to 0%. There are several possible reasons for these fluctuations. For instance, the fuel gauge's internal algorithm might be causing the fluctuations during smoothing calculations. When the battery voltage is below a certain threshold, the algorithm speeds up the smoothing calculation. However, the processor polls the fuel gauge at fixed time intervals. If the fuel gauge smooths too quickly within a given time interval, it can cause the processor to read a fluctuating battery level. Other possibilities include calculation errors in the fuel gauge itself.
[0025] Therefore, the battery level displayed on the interface of electronic devices needs to be smoothed to ensure that the battery level changes continuously without jumps. In cases where an electronic device is powered off and then restarted, to avoid discrepancies between the battery level displayed after startup and the battery level displayed when the device was powered off, which could cause confusion for users, related technologies use kernel drivers to save the battery level from before power-off to the RTC (Real-Time Clock) register of the PMIC (Power Management IC). Upon power-on, the saved battery level is read from the RTC register and displayed, ensuring that the battery level displayed after startup is consistent with the battery level displayed when the device was powered off.
[0026] However, not all electronic devices' PMICs have RTC registers, which makes this solution less versatile. Furthermore, storing the interface power in the RTC register poses a risk if the PMIC chip loses power, as the data in the RTC register will be lost.
[0027] This application discloses a method, apparatus, electronic device, and storage medium for determining the battery level of an electronic device. This method can prevent the battery level displayed on the screen from changing abruptly when the electronic device is started, thus avoiding inconvenience to the user. It also improves the efficiency of displaying the battery level. This solution is highly versatile and can prevent data loss.
[0028] Figure 1A This is an application scenario diagram of a method for determining the battery level on the interface, as shown in one embodiment. Figure 1AAs shown, the method for determining the battery level of the interface can be applied to electronic device 10, which may include, but is not limited to, mobile phones, wearable devices, in-vehicle terminals, tablet computers, PCs (Personal Computers), PDAs (Personal Digital Assistants), etc. Electronic device 10 may include a display device, which may be a display screen, etc., and the display device can be used to display a UI (User Interface).
[0029] The display device of the electronic device 10 can display the interface battery level 110 on the interface. This interface battery level 110 can be used to indicate the remaining available battery power within the electronic device 10, thereby facilitating user access to the remaining battery power. In this embodiment, during the resource preloading phase of the device startup process, the electronic device 10 can read the first interface battery level from the target storage partition and write it to shared memory. This first interface battery level can be the interface battery level displayed by the display device during the most recent shutdown of the electronic device 10. The shared memory is a memory space shared with the kernel layer during the resource preloading phase. During the kernel startup phase, the electronic device 10 can read the first interface battery level from the shared memory through the kernel layer and determine the second interface battery level to be displayed based on the first interface battery level.
[0030] For example, Figure 1B This is a system architecture diagram of an operating system in an electronic device in one embodiment. For example... Figure 1B As shown, taking the Android system as an example, the operating system of an electronic device can include an application layer, an application framework layer, a system library, and a kernel layer.
[0031] The application layer can include a series of application packages, such as camera, calendar, map, music and other applications.
[0032] The application framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. This layer can include window managers, content providers, view systems, phone managers, resource managers, and notification managers. Window managers manage window programs, such as obtaining screen size, determining the presence of a status bar, locking the screen, and capturing the screen. Content providers store and retrieve data, making this data accessible to applications. View systems include visual controls, such as controls for displaying text and images. Phone managers provide communication functions for electronic devices, such as managing call status (including connection and disconnection). Resource managers provide various resources for applications, such as localized strings, icons, images, and video files. Notification managers allow applications to display notification information in the status bar, which can be used to convey informational messages.
[0033] The Android Runtime consists of core libraries and a virtual machine. The Android runtime is responsible for scheduling and managing the Android system, the core libraries provide the functionalities that Java needs to call, and Android's core libraries, while the application layer and application framework layer run in the virtual machine.
[0034] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0035] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.
[0036] Now combined Figure 1BThe system architecture diagram shown illustrates the embodiments of this application. The power module driver (or charging module driver) at the kernel layer determines the battery level of the interface to be displayed and reports it to the application layer (hereinafter referred to as the application layer). The application layer displays the battery level through the user interface. When the electronic device is powered off, the application layer can respond to the power-off command, obtain the battery level of the first interface currently displayed on the display device, and store the first interface battery level in the target storage partition. During the resource preloading phase of the device startup process, the first interface battery level can be read from the target storage partition and written to shared memory. During the kernel startup phase, the power module driver (or charging module driver) is initialized. The initialized power module driver (or charging module driver) can read the first interface battery level from the shared memory, determine the battery level of the second interface to be displayed based on the first interface battery level, and then report the second interface battery level to be displayed to the application layer, which displays the second interface battery level in the user interface of the application layer.
[0037] It should be noted that, Figure 1B The system architecture diagram shown is only for illustrating the embodiments of this application. The operating system of the electronic device may be other operating systems or other system architectures, and is not limited to them. Figure 1B The system architecture shown.
[0038] like Figure 2 As shown, in one embodiment, a method for determining interface power is provided, which can be applied to the above-mentioned electronic device. The method may include the following steps:
[0039] Step 210: During the resource preloading phase of the device startup process, read the first interface power level from the target storage partition and write the first interface power level to the shared memory.
[0040] The device startup process of an electronic device can refer to the startup of part or all of the electronic device's operating system. Optionally, the device startup process can be the startup of the entire operating system of the electronic device, such as the power-on process. Alternatively, it can be the startup of a portion of the operating system; for example, when charging an electronic device while it is powered off, a partial startup of the operating system is required to display the battery level. Furthermore, the device startup process must at least start the kernel layer of the operating system and the target process running in user space, which can be used to implement the battery level display on the user interface.
[0041] The device startup process can include a resource preloading phase, a kernel startup phase, and a user-space process startup phase. The resource preloading phase occurs before the kernel startup phase. During this phase, some hardware modules of the electronic device (such as input / output systems and power management ICs) are initialized, establishing the most basic operating environment. The kernel startup phase refers to the stage of starting the kernel layer, during which drivers within the kernel layer are loaded and initialized. The user-space process startup phase refers to the stage of starting user-space service processes.
[0042] In one specific implementation, when an electronic device is powered on, it enters the device startup process. First, a preload image file is loaded into SRAM (Static Random-Access Memory), entering the resource preloading stage. During this stage, DRAM (Dynamic Random Access Memory) can be initialized. Then, the kernel is loaded through the initialized DRAM, entering the kernel startup stage, where the kernel layer is started using the set kernel parameters. Here, "powering on the electronic device" refers to the power supply providing power to the electronic device, enabling it to run some or all of its functional modules. This power supply can be the internal battery of the electronic device or a connected charging device (such as an adapter).
[0043] During the resource preloading phase of the device startup process, the first interface battery level can be read from the target storage partition. This first interface battery level can be the battery level displayed on the display device when the electronic device was last powered off. Further, the last time the electronic device was powered off can refer to shutting down the entire operating system of the electronic device. The first interface battery level can be the battery level displayed on the display device when the power supply (including the battery and connected charging devices, etc.) stopped supplying power to the electronic device most recently before this power-on.
[0044] When an electronic device is powered off, the battery level displayed on the first screen can be stored in a target storage partition. This target storage partition can be a designated partition in non-volatile memory. The target storage partition can be used solely to store the displayed battery level, or it can store the displayed battery level along with other battery-related data, such as battery temperature, charging current, and charging voltage, but is not limited to these. Storing the battery level in the target storage partition eliminates the risk of data loss due to chip power failure, thus preventing data loss. Furthermore, since almost all electronic devices are equipped with non-volatile memory, the entire solution is more versatile and the overall function is more stable.
[0045] Optionally, during the resource preloading stage, data stored in the target storage partition in the non-volatile memory can be directly read to obtain the first interface power level, and the first interface power level can be written to the shared memory.
[0046] Shared memory can be a memory space shared between the resource preloading stage and the kernel layer. Both the resource preloading stage and the kernel layer can access this shared memory, which can be used to implement data transmission between the resource preloading stage and the kernel layer. In some embodiments, the memory address of the shared memory can be pre-configured. During the resource preloading stage of the device startup process, after the memory is initialized, the shared memory can be accessed according to this memory address, and the first interface power level can be written into the shared memory.
[0047] Step 220: During the kernel startup phase, the battery level of the first interface is read from the shared memory through the kernel layer, and the battery level of the second interface to be displayed is determined based on the battery level of the first interface.
[0048] After entering the kernel boot phase of the device startup process, the kernel layer can read the battery level of the first interface from shared memory and determine the battery level of the second interface to be displayed based on the battery level of the first interface. As a specific implementation, the power module driver (or charging module driver) can be initialized during the kernel boot phase. The power module driver (or charging module driver) may include a battery level update submodule, which can be used to detect the actual battery level and update or adjust the displayed battery level. During the initialization of the power module driver (or charging module driver), if the battery level update submodule is running, the battery level of the first interface can be read from shared memory, and the battery level of the second interface to be displayed can be determined based on the battery level of the first interface.
[0049] The battery level displayed on the second screen can be the same as or different from the battery level on the first screen. In some embodiments, a battery display rule can be preset, and the battery level on the second screen to be displayed can be determined according to the battery display rule. Optionally, the battery display rule may include, but is not limited to, one or more of the following:
[0050] (1) Directly determine the battery level of the first interface as the battery level of the second interface to be displayed.
[0051] (2) Compare the battery level on the first screen with the actual battery level. If the difference between the two is significant, the battery level on the first screen is inaccurate. In this case, the actual battery level can be used as the battery level on the second screen to improve the accuracy of the displayed battery level. If the difference between the battery level on the first screen and the actual battery level is small, the battery level on the first screen is relatively accurate. To avoid the battery level on the first screen from changing during startup, the battery level on the first screen can be used as the battery level on the second screen.
[0052] (3) Determine the time elapsed between the current device startup process and the most recent shutdown. If this time is long, it indicates that the battery level on the first screen is inaccurate. In this case, the actual battery level can be determined as the battery level on the second screen to improve the accuracy of the displayed battery level. If this time is short, the battery level on the first screen can be determined as the battery level on the second screen to ensure that the battery level displayed during the most recent shutdown and the current device startup is consistent, thus avoiding confusion for the user.
[0053] In some embodiments, the kernel layer can report the determined battery level of the second interface to be displayed to the application layer, and the application layer's user interface can then display the battery level of the second interface. Alternatively, after the target process in user space starts, the kernel layer can pass the battery level of the second interface to the target process, which can then control the user interface to display that battery level.
[0054] In related technologies, the user-space service process typically reads the battery level of the first interface from a specific storage partition and then passes it to the kernel layer. The kernel layer determines the battery level of the interface to be displayed and then reports it to the application layer for display. However, the user-space service process starts relatively late during device startup, so the determination of the interface battery level can only be done after the user-space service process has finished starting. In this embodiment, the first interface battery level is read during the resource preloading phase of the device startup process and passed to the kernel layer via shared memory. During the kernel startup phase, the second interface battery level to be displayed can be determined by the kernel layer, without waiting for the user-space service process to finish starting and then reading the first interface battery level and passing it to the kernel layer. This reduces the lag in reading the first interface battery level and improves the efficiency of determining and displaying the interface battery level.
[0055] In this embodiment, when the electronic device is powered off, the battery level of the first screen displayed on the device can be saved to a target storage partition. Upon device startup, the battery level of the first screen is read from the target storage partition, and this battery level is used to determine the battery level of the second screen to be displayed. This avoids the situation where the displayed battery level jumps when the electronic device is powered off and then powered on again, preventing inconvenience to the user. Furthermore, by reading the battery level of the first screen stored in the target storage partition during the resource preloading phase of the device startup process and then passing it to the kernel layer via shared memory, it is not necessary to wait for the user space process to load, reducing the lag in reading the battery level of the first screen and improving the display efficiency of the battery level. In addition, the kernel layer does not directly interact with the target storage partition, improving the security of the kernel layer.
[0056] like Figure 3 As shown, in another embodiment, a method for determining interface power is provided, which can be applied to the above-mentioned electronic device. The method may include the following steps:
[0057] Step 302: In response to the power-off command, obtain the battery level of the first interface currently displayed on the display device.
[0058] When an electronic device detects that it needs to be shut down, it can generate a shutdown command. This shutdown command can be used to control the shutdown of the entire operating system of the electronic device. It should be noted that shutting down an electronic device can mean that there is no power supply to the electronic device and no function module in the electronic device is supported.
[0059] In some embodiments, the electronic device may generate a power-off command when a power-off operation is detected. The power-off operation may include, but is not limited to, a user touching a key button, detecting a user's voice instruction to power off, or detecting a power-off gesture. Optionally, the power-off operation may also include an operation such as disconnecting the electronic device from the charging device (e.g., unplugging the charging device) when the electronic device is charging while powered off.
[0060] In some embodiments, the electronic device may also automatically generate a shutdown command according to a set shutdown rule. For example, when the actual battery power is detected to be less than a power threshold (such as 2% or 3% power), a shutdown command may be automatically generated; or, when a set shutdown time period (such as 2 a.m. to 5 a.m.) is reached, a shutdown command may be automatically generated.
[0061] Electronic devices can respond to a shutdown command and shut down. In one specific implementation, when an electronic device shuts down, the application layer first executes the shutdown process. Before shutting down, the application layer can obtain the battery level of the first interface currently displayed on the display device and store it in a target storage partition. Optionally, a target process running in user space can obtain the latest reported battery level from the kernel layer as the first interface battery level currently displayed on the display device and write it to the target storage partition.
[0062] Step 304: Store the battery level of the first interface to the target storage partition according to the defined first data structure.
[0063] The first data structure can be a predefined data structure used to update the interface power stored in the target storage partition. This first data structure may include at least one or more power display parameters, each of which can be used to characterize a variable attribute related to the interface power. For example, the first data structure may be as follows:
[0064]
[0065] Where Xxx represents other target parameters, Uisoc_tag is used to indicate the validity of the stored interface power, for example, when the value of Uisoc_tag is "uisoc", it means that the stored interface power is valid; Uisoc_value is used to indicate the specific interface power.
[0066] In some embodiments, the first data structure may further define the arrangement order of each power display parameter. The data stored in the target storage area may be arranged according to a certain byte order. The arrangement order of each power display parameter defined in the first data structure may match the arrangement order of the corresponding stored data of the power display parameter in the target storage area. The number of bytes occupied by the stored data corresponding to each power display parameter may be the same or different.
[0067] As an optional implementation, the first data currently stored in the target storage partition can be read from the target storage partition, the first data can be parsed according to the defined first data structure to obtain the power display parameters, the value of the power display parameters can be updated according to the power of the first interface to obtain the second data, and the second data can be written to the target storage partition.
[0068] The target storage partition can be used to store data corresponding to multiple target parameters related to the battery. Each target parameter can represent a battery-related variable attribute. These multiple target parameters may include at least the aforementioned power display parameters, and may also include other parameters, such as battery temperature parameters, charging voltage parameters during battery charging, charging current parameters, etc. The target storage partition can store data corresponding to each target parameter separately. Optionally, the first data structure may include these multiple target parameters. The data types of the multiple target parameters included in the first data structure can correspond one-to-one with the data stored in the target storage partition, and different target parameters can correspond to different data types. Further, the first data structure can define the arrangement order of the target parameters. The arrangement order of the target parameters defined in the first data structure matches (i.e., is the same) the arrangement order of the corresponding stored data in the target storage partition.
[0069] Since the target storage partition stores data corresponding to multiple target parameters, different data structures can be used to map the target storage partition when it is necessary to read or update data for different target parameters. As a specific implementation, the target process in user space can access the target storage partition through the corresponding access API (Application Programming Interface) and read the first data currently stored in the target storage partition. This first data can be all data stored in the target storage partition, or it can be all battery-related data stored in the target storage partition. The target process can parse the first data according to the first data structure, find the battery display parameters contained in the first data, further find the values corresponding to each battery display parameter in the first data, and update the values of the battery display parameters according to the battery level on the first screen to obtain the second data.
[0070] Taking the first data structure in the above example as an example, the first data can be parsed according to the first data structure, and the value corresponding to Uisoc_value in the first data can be updated to the battery level of the first interface. The value of Uisoc_tag in the first data can be updated to "uisoc", while the values of other target parameters remain unchanged, thus obtaining the second data. In other words, the second data is relative to the first data, only the value corresponding to the battery display parameter is updated.
[0071] After obtaining the second data, it can be rewritten to the target storage partition according to the first data structure. Since the arrangement order of the target parameters defined in the first data structure matches the arrangement order of the corresponding stored data in the target storage partition, writing the second data to the target storage partition according to the first data structure ensures that only the data corresponding to the power display parameters stored in the target storage partition is updated, thus improving the accuracy of data storage.
[0072] After the target process saves the battery level of the first screen to the target storage partition, the application layer completes the shutdown process, and then the kernel layer performs the shutdown. After the kernel layer completes the shutdown process, the electronic device is truly shut down.
[0073] Step 306: During the resource preloading phase of the device startup process, the first interface power is read from the target storage partition according to the first data structure, and the first interface power is written to the shared memory according to the defined second data structure.
[0074] In some embodiments, during the resource preloading phase of the device startup process, second data stored in the target storage partition can be read from the target storage partition, and the second data can be parsed according to the first data structure to obtain the power display parameters. The first data structure can be used to parse the read second data, find the value in the second data corresponding to the power display parameters, and determine the power level of the first interface based on the parsed power display parameter value.
[0075] Taking the first data structure in the above example as an example, during the resource preloading phase of the device startup process, the partition read function of the resource preloading phase can be used to read the second data from the target storage partition. The second data can be parsed according to the first data structure to obtain the values of Uisoc_value and Uisoc_tag. First, it can be determined whether the value of Uisoc_tag is "uisoc" to verify the validity of the value of Uisoc_value. If the value of Uisoc_value is determined to be valid, it can be used as the battery level of the first screen. Through the defined first data structure, the battery level of the first screen can be accurately read from the target storage partition, ensuring the accuracy of data reading.
[0076] After obtaining the first interface power level, the first interface power level can be written to shared memory according to the defined second data structure. The second data structure can be a predefined data structure used to transmit the interface power level saved during the most recent shutdown. This second data structure can include at least one or more interface power level parameters, where each parameter can characterize a variable attribute related to the interface power level. Optionally, the second data structure can also include other parameters passed between the resource preloading stage and the kernel layer. For example, the second data structure can be as follows:
[0077]
[0078] Here, Xxx represents other parameters passed between the resource preloading stage and the kernel layer, and share_uisoc is used to indicate the specific interface power consumption.
[0079] In some embodiments, the second data structure may also define the arrangement order of the various other parameters and the various interface power parameters mentioned above, which can be matched with the arrangement order of the corresponding stored data of the various other parameters and the various interface power parameters in the shared memory.
[0080] Shared memory can be used to store data that needs to be shared or transferred between the resource preloading stage and the kernel layer. This data can include at least the values of the aforementioned interface power parameters, and may also include the values of other parameters transferred between the resource preloading stage and the kernel layer. During the resource preloading stage, the fourth data currently stored in the shared memory can be read, and parsed according to the second data structure to obtain the interface power parameters. The second data structure can be used to parse the read fourth data, find the interface power parameters contained within it, further find the values in the fourth data corresponding to the interface power parameters, and update the values of the interface power parameters according to the first interface power level to obtain the third data.
[0081] Taking the second data structure in the example above as an example, the fourth data can be parsed based on the second data structure, and the value corresponding to share_uisoc in the fourth data can be updated to the battery level of the first screen, while the values of other parameters remain unchanged, thus obtaining the third data. Optionally, it can be determined whether the battery level of the first screen read from the target storage partition is valid. If it is valid, the value corresponding to share_uisoc can be updated to the battery level of the first screen. If it is invalid, the value corresponding to share_uisoc can be updated to a preset value, such as setting the value corresponding to share_uisoc to 1, etc., but it is not limited to this.
[0082] After obtaining the third data, it can be rewritten into the shared memory according to the second data structure. Since the second data structure defines the arrangement order of the other parameters and the interface power parameters mentioned above, which matches the arrangement order of the corresponding stored data in the shared memory, writing the third data into the shared memory according to the second data structure ensures that only the data corresponding to the interface power parameters stored in the shared memory is updated. This ensures that the data can be accurately transmitted to the kernel layer, improving the accuracy of data transmission.
[0083] Step 308: During the kernel startup phase, the kernel layer reads the battery level of the first interface from the shared memory according to the second data structure, and determines the battery level of the second interface to be displayed based on the battery level of the first interface.
[0084] During the kernel startup phase, the kernel layer can read third data stored in shared memory from shared memory and parse the third data according to the second data structure to obtain the first interface battery level. The kernel layer can use the second data structure to parse the read third data, find the value in the third data that corresponds to the interface battery parameter, and determine the first interface battery level based on the parsed value of the interface battery parameter.
[0085] Taking the second data structure in the example above as an example, after the kernel layer reads the third data from shared memory, it can parse the third data according to the second data structure to obtain the value of `share_uisoc` in the third data as the battery level of the first interface. Through the defined second data structure, the kernel layer can accurately read the battery level of the first interface from shared memory, ensuring the accuracy of data reading.
[0086] It should be noted that the first data structure and the second data structure described above are only examples to illustrate the embodiments of this application and are not intended to limit specific data structures. The first data structure and the second data structure can be adjusted and set according to actual needs, and the embodiments of this application do not limit them in this regard.
[0087] In some embodiments, before the kernel layer determines the battery level of the second interface to be displayed based on the battery level of the first interface, it can first determine whether the battery level of the first interface is correct data, that is, determine the rationality of the battery level of the first interface. For example, it can determine whether the battery level of the first interface is within the range of 0 to 100%. Since the displayed battery level must be within the range of 0 to 100%, if the battery level of the first interface read by the kernel layer is not within the range of 0 to 100%, it means that the battery level of the first interface is incorrect data. In this case, the battery level of the first interface can be discarded, the actual battery level value can be obtained directly, and the actual battery level value can be used as the battery level of the second interface to be displayed, thereby ensuring the accuracy of the battery level display.
[0088] In some embodiments, such as Figure 4 As shown, the step of determining the battery level of the second interface to be displayed based on the battery level of the first interface may include steps 402 to 410.
[0089] Step 402: Obtain the actual battery charge value detected by the fuel gauge.
[0090] Electronic devices may be equipped with a fuel gauge, which can detect the actual battery level in real time or at certain time intervals. The power module driver (or charging module driver) in the kernel layer can run a power update submodule to obtain the actual battery level detected by the fuel gauge each time.
[0091] Step 404: Determine the difference between the battery level on the first screen and the actual battery level.
[0092] Step 406: Determine whether the power difference is less than or equal to the difference threshold. If yes, proceed to step 408; otherwise, proceed to step 410.
[0093] Step 408: Determine the battery level on the first screen as the battery level on the second screen to be displayed.
[0094] Step 410: Determine the actual battery level as the battery level to be displayed on the second screen.
[0095] The kernel layer can calculate the difference between the battery level on the first screen and the latest detected battery level from the fuel gauge, and determine whether this difference is less than or equal to a threshold. If the difference is less than or equal to the threshold, the battery level on the first screen is considered relatively accurate, and it can be directly used as the battery level for the second screen. If the difference is greater than the threshold, the battery level on the first screen is considered inaccurate, and the actual battery level can be used as the battery level for the second screen.
[0096] The difference threshold can be set according to actual needs. For example, the power difference can be an absolute value, and the difference threshold can be 20%, 25%, 18%, etc. Optionally, the difference threshold can be a pre-configured fixed value or a dynamically adjusted value.
[0097] As one implementation method, the difference threshold can be determined based on the power range in which the actual power value is located. Multiple power ranges can be preset, and each power range can correspond one-to-one with a different difference threshold. The difference thresholds corresponding to different power ranges may be the same or different. Furthermore, the difference threshold corresponding to the smallest power range can be greater than or equal to the difference thresholds corresponding to other power ranges. The smallest power range refers to the power range with the smallest lower limit value. For example, the power range of 0-20% is the smallest power range, or the power range of 0-10% is the smallest power range, etc.
[0098] When the battery's actual charge level is in its lowest range, it indicates that the electronic device is in a low-battery state. Displaying the actual charge level directly could cause user anxiety about battery life. Therefore, a larger threshold can be set. The actual charge level should only be displayed when there is a significant difference between the initial charge level and the actual charge level. Otherwise, the initial charge level should be displayed to reduce user anxiety and improve user experience. Optionally, when the battery's actual charge level is in its lowest range and the initial charge level is used as the second charge level, the kernel layer can increase the update frequency of the charge level display. Following this increased update frequency, the displayed charge level will gradually decrease from the initial charge level to the actual charge level. This allows users to visually understand the battery's decline and charge the electronic device as soon as possible to avoid it shutting down due to low battery.
[0099] In some embodiments, if the difference between the battery level on the first screen and the actual battery level is greater than a threshold, the average value of the battery level on the first screen and the actual battery level can be calculated and used as the battery level on the second screen to be displayed. This can avoid the confusion caused by a large difference between the battery level displayed when the electronic device is turned on and the battery level displayed when it was last turned off, and it can also avoid the problem of inaccurate battery level display caused by a large difference between the displayed battery level and the actual battery level. At the same time, it takes into account the accuracy of the displayed battery level and the problem of jumps, thereby improving the user experience.
[0100] In some embodiments, when an electronic device is powered off, the first interface battery level displayed on the display device at the time of power-off and the first moment corresponding to the first interface battery level can be written to a target storage partition. The first moment corresponding to the first interface battery level can be the moment the first interface battery level is stored in the target storage partition (i.e., the moment of responding to a power-off command), or the first moment can be the interface update moment corresponding to the first interface battery level (i.e., the moment the interface battery level on the display device is updated to the first interface battery level). During the resource preloading phase of the device startup process, the first interface battery level and the first moment can be read from the target storage partition and written to shared memory. During the kernel startup phase, the first interface battery level and the first moment can be read from shared memory through the kernel layer, and the time difference between the current second moment and the first moment can be determined. Based on this time difference and the first interface battery level, the second interface battery level to be displayed can be determined.
[0101] In one implementation, when the electronic device is powered off, the target process in user space can write the battery level of the first interface and the corresponding first moment to the target storage partition according to a first data structure. During the resource preloading phase of the device startup process, the battery level of the first interface and the first moment can be read from the target storage partition according to the first data structure, and then written to shared memory according to a second data structure. During the kernel startup phase, the kernel layer can read the battery level of the first interface and the first moment from shared memory according to the second data structure.
[0102] In some embodiments, the battery level of the second interface to be displayed is determined based on the time difference and the battery level of the first interface, which may include, but is not limited to, the following methods:
[0103] (1) The kernel layer can determine whether the time difference is greater than the time threshold. If it is greater than the time threshold, the actual battery level can be determined as the battery level of the second interface to be displayed. If the time difference between the current second moment and the first moment is greater than the time threshold, it means that the time difference between the current device startup and the most recent shutdown is too long. The battery level of the first interface saved at the most recent shutdown is likely to be inaccurate (the battery of the electronic device will also consume a small current during the shutdown process, resulting in a decrease in battery level). Therefore, the actual battery level detected by the battery meter can be obtained and the actual battery level can be determined as the battery level of the second interface to be displayed, thereby improving the accuracy of the displayed battery level.
[0104] If the time difference is not greater than a time threshold, the battery level on the first screen can be determined as the battery level on the second screen to be displayed. If the time difference between the current second moment and the first moment is not greater than the time threshold, it indicates that the time difference between the current device startup and the most recent shutdown is short. Therefore, the battery level on the first screen saved during the most recent shutdown is relatively accurate, and it can be directly displayed. This avoids jumps in the displayed battery level during device startup, preventing confusion for the user.
[0105] (2) The kernel layer can obtain the battery's aging parameters, which can be used to characterize the degree of battery aging. These aging parameters may include, but are not limited to, the ratio of the battery's actual capacity to its standard capacity, the battery's internal resistance, and battery health. The power loss can be calculated based on the battery's aging parameters and the time difference, and the power loss on the first interface can be subtracted to obtain the power loss on the second interface to be displayed. The higher the degree of battery aging indicated by the aging parameters, the greater the corresponding loss coefficient. The corresponding loss coefficient can be determined based on the battery's aging parameters, and the loss coefficient, the time difference, and the power loss per unit time can be multiplied to obtain the power loss. The power loss per unit time can be the theoretical power loss per unit time of the battery in the off state, which can be determined through multiple experiments. Calculating the power loss of the electronic device between the current device startup and the most recent shutdown based on the battery's aging degree, and determining the power loss on the second interface to be displayed, can improve the accuracy of the displayed interface power loss.
[0106] In this embodiment of the application, the battery level of the first interface can be written to the target storage partition and read from the target storage partition according to the defined first data structure, and the battery level of the first interface can be written to the shared memory and read from the shared memory according to the defined second data structure, thus ensuring the accurate writing and reading of the battery level of the first interface.
[0107] like Figure 5 As shown, in one embodiment, an interface power determination device 500 is provided, which can be applied to the above-mentioned electronic device. The interface power determination device 500 may include a power reading module 510 and a power determination module 520.
[0108] The power reading module 510 is used to read the power of the first interface from the target storage partition and write the power of the first interface into the shared memory during the resource preloading phase of the device startup process; the power of the first interface is the power displayed by the display device when the electronic device was last turned off; the shared memory is the memory space shared with the kernel layer during the resource preloading phase.
[0109] The battery level determination module 520 is used to read the battery level of the first interface from the shared memory through the kernel layer during the kernel startup phase, and determine the battery level of the second interface to be displayed based on the battery level of the first interface.
[0110] In this embodiment, when the electronic device is powered off, the battery level of the first screen displayed on the device can be saved to a target storage partition. Upon device startup, the battery level of the first screen is read from the target storage partition, and this battery level is used to determine the battery level of the second screen to be displayed. This avoids the situation where the displayed battery level jumps when the electronic device is powered off and then powered on again, preventing inconvenience to the user. Furthermore, by reading the battery level of the first screen stored in the target storage partition during the resource preloading phase of the device startup process and then passing it to the kernel layer via shared memory, it is not necessary to wait for the user space process to load, reducing the lag in reading the battery level of the first screen and improving the display efficiency of the battery level. In addition, the kernel layer does not directly interact with the target storage partition, improving the security of the kernel layer.
[0111] In one embodiment, the interface power determination device 500 further includes a storage module.
[0112] The storage module is used to respond to a power-off command, obtain the current battery level of the first interface displayed on the display device, and store the battery level of the first interface into a target storage partition according to a defined first data structure.
[0113] In one embodiment, the storage module is further configured to read first data currently stored in the target storage partition from the target storage partition; parse the first data according to a defined first data structure to obtain power display parameters; update the value of the power display parameters according to the power level on the first interface to obtain second data, and write the second data into the target storage partition.
[0114] In one embodiment, the power reading module 510 is further configured to read second data stored in the target storage partition from the target storage partition; parse the second data according to the first data structure to obtain power display parameters, and determine the power level of the first interface according to the value of the parsed power display parameters.
[0115] In one embodiment, the power reading module 510 is further configured to write the power of the first interface into shared memory according to a defined second data structure.
[0116] The power determination module 520 is also used to read the third data stored in the shared memory from the shared memory through the kernel layer, and parse the third data according to the second data structure to obtain the power of the first interface.
[0117] In one embodiment, the power determination module 520 is further configured to acquire the actual power value of the battery detected by the power meter; determine the power difference between the power value on the first interface and the actual power value; if the power difference is less than or equal to a difference threshold, then the power value on the first interface is determined as the power value on the second interface to be displayed; if the power difference is greater than the difference threshold, then the actual power value is determined as the power value on the second interface to be displayed.
[0118] In one embodiment, the power reading module 510 is further configured to read the power level of the first interface and the first moment from the target storage partition, and write the power level of the first interface and the first moment into the shared memory; the first moment is the moment when the power level of the first interface is stored in the target storage partition, or the first moment is the interface update moment corresponding to the power level of the first interface.
[0119] The battery level determination module 520 is also used to read the battery level and the first moment of the first interface from the shared memory through the kernel layer; determine the time difference between the current second moment and the first moment; and determine the battery level of the second interface to be displayed based on the time difference and the battery level of the first interface.
[0120] In this embodiment of the application, the battery level of the first interface can be written to the target storage partition and read from the target storage partition according to the defined first data structure, and the battery level of the first interface can be written to the shared memory and read from the shared memory according to the defined second data structure, thus ensuring the accurate writing and reading of the battery level of the first interface.
[0121] Figure 6 This is a structural block diagram of an electronic device in one embodiment. For example... Figure 6 As shown, the electronic device 600 may include one or more of the following components: a processor 610 and a memory 620 coupled to the processor 610, wherein the memory 620 may store one or more computer programs, which may be configured to implement the methods described in the above embodiments when executed by one or more processors 610.
[0122] Processor 610 may include one or more processing cores. Processor 610 connects to various parts within the electronic device 600 using various interfaces and lines, and performs various functions and processes data of the electronic device 600 by running or executing instructions, programs, code sets, or instruction sets stored in memory 620, and by calling data stored in memory 620. Optionally, processor 610 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 610 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 610 and may be implemented separately using a communication chip.
[0123] The memory 620 may include random access memory (RAM) or read-only memory (ROM). The memory 620 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 620 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described above. The data storage area may also store data created by the electronic device 600 during use.
[0124] Understandably, electronic device 600 may include more or fewer structural elements than those shown in the above block diagram, such as power modules, physical buttons, WiFi (Wireless Fidelity) modules, speakers, Bluetooth modules, sensors, etc., and may not be limited herein.
[0125] This application discloses a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the methods described in the above embodiments.
[0126] This application discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program can be executed by a processor to implement the methods described in the above embodiments.
[0127] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, ROM, etc.
[0128] Any references to memory, storage, databases, or other media used herein may include non-volatile and / or volatile memory. Suitable non-volatile memory may include ROM, Programmable ROM (PROM), Erasable PROM (EPROM), Electrically Erasable PROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which is used as an external cache. By way of illustration and not limitation, RAM may take many forms, such as Static RAM (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchlink DRAM (SLDRAM), Rambus DRAM (RDRAM), and Direct Rambus DRAM (DRDRAM).
[0129] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Those skilled in the art should also recognize that the embodiments described in the specification are optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0130] In the various embodiments of this application, it should be understood that the sequence number of each process does not necessarily imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0131] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; they can be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0132] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0133] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0134] The foregoing has provided a detailed description of a method, apparatus, electronic device, and storage medium for determining interface power according to embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for determining interface charge, characterized in that, Applied to electronic devices, the method includes: During the resource preloading phase of the device startup process, the battery level of the first interface is read from the target storage partition and written to the shared memory; the battery level of the first interface is the battery level displayed by the display device when the electronic device was last powered off; the shared memory is the memory space shared with the kernel layer during the resource preloading phase. During the kernel startup phase, the battery level of the first interface is read from the shared memory through the kernel layer, and the battery level of the second interface to be displayed is determined based on the battery level of the first interface; the resource preloading phase occurs before the kernel startup phase. After the target process in user space starts, the battery level of the second interface is transmitted to the target process through the kernel layer, and the target process controls the user interface to display the battery level of the second interface.
2. The method according to claim 1, characterized in that, Before reading the first interface power level from the target storage partition during the resource preloading phase of the device startup process, the method further includes: In response to a power-off command, obtain the battery level currently displayed on the first screen of the display device; According to the defined first data structure, the battery level of the first interface is stored in the target storage partition.
3. The method according to claim 2, characterized in that, The step of storing the battery level of the first interface to the target storage partition according to the defined first data structure includes: Read the first data currently stored in the target storage partition; The first data is parsed according to the defined first data structure to obtain the power display parameters; The battery level display parameter is updated based on the battery level on the first interface to obtain second data, and the second data is written to the target storage partition.
4. The method according to claim 3, characterized in that, The step of reading the battery level of the first interface from the target storage partition includes: Read the second data stored in the target storage partition; The second data is parsed according to the first data structure to obtain the power display parameters, and the power level of the first interface is determined according to the value of the parsed power display parameters.
5. The method according to claim 1, characterized in that, The step of writing the power level of the first interface into shared memory includes: According to the defined second data structure, the power level of the first interface is written into the shared memory; The step of reading the battery level of the first interface from the shared memory through the kernel layer includes: The kernel layer reads the third data stored in the shared memory from the shared memory and parses the third data according to the second data structure to obtain the first interface power level.
6. The method according to any one of claims 1 to 5, characterized in that, The step of determining the battery level of the second interface to be displayed based on the battery level of the first interface includes: Obtain the actual battery charge value detected by the fuel gauge; Determine the difference between the battery level on the first screen and the actual battery level; If the power difference is less than or equal to the difference threshold, then the power level of the first interface is determined as the power level of the second interface to be displayed. If the power difference is greater than the difference threshold, then the actual power value is determined as the power value to be displayed on the second interface.
7. The method according to any one of claims 1 to 5, characterized in that, The step of reading the battery level of the first interface from the target storage partition and writing the battery level of the first interface into the shared memory includes: Read the battery level and first time of the first interface from the target storage partition, and write the battery level and first time of the first interface into the shared memory; the first time is the time when the battery level of the first interface is stored in the target storage partition, or the first time is the time when the interface corresponding to the battery level of the first interface is updated. The step of reading the battery level of the first interface from the shared memory through the kernel layer and determining the battery level of the second interface to be displayed based on the battery level of the first interface includes: The kernel layer reads the battery level of the first interface and the first time from the shared memory. Determine the time difference between the current second moment and the first moment; Based on the time difference and the battery level of the first interface, the battery level of the second interface to be displayed is determined.
8. A device for determining interface charge, characterized in that, Applied to electronic devices, the device includes: The power reading module is used to read the power level of the first interface from the target storage partition and write the power level of the first interface into shared memory during the resource preloading phase of the device startup process; the power level of the first interface is the power level of the interface displayed by the display device when the electronic device was last powered off; the shared memory is the memory space shared with the kernel layer during the resource preloading phase. A power determination module is used to read the power level of the first interface from the shared memory through the kernel layer during the kernel startup phase, and determine the power level of the second interface to be displayed based on the power level of the first interface; the resource preloading phase is performed before the kernel startup phase; and it is used to pass the power level of the second interface to the target process through the kernel layer after the target process in user space starts, and control the user interface to display the power level of the second interface through the target process.
9. An electronic device, characterized in that, The method includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor causes the processor to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Interface power determination method, device, storage medium, and mobile terminal
CN109040467A
Boot method, electronic device, readable storage medium and computer program product
WO2022170904A1