WO2021017935A1 - Wakelock management method and electronic device - Google Patents

Wakelock management method and electronic device Download PDF

Info

Publication number
WO2021017935A1
WO2021017935A1 PCT/CN2020/103128 CN2020103128W WO2021017935A1 WO 2021017935 A1 WO2021017935 A1 WO 2021017935A1 CN 2020103128 W CN2020103128 W CN 2020103128W WO 2021017935 A1 WO2021017935 A1 WO 2021017935A1
Authority
WO
WIPO (PCT)
Prior art keywords
wakelock
target process
electronic device
identifier
wake
Prior art date
Application number
PCT/CN2020/103128
Other languages
French (fr)
Chinese (zh)
Inventor
钱华君
张贵文
赵凡凡
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021017935A1 publication Critical patent/WO2021017935A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M1/00Substation equipment, e.g. for use by subscribers
    • H04M1/72Mobile telephones; Cordless telephones, i.e. devices for establishing wireless links to base stations without route selection
    • H04M1/724User interfaces specially adapted for cordless or mobile telephones
    • H04M1/72448User interfaces specially adapted for cordless or mobile telephones with means for adapting the functionality of the device according to specific conditions
    • H04M1/72454User interfaces specially adapted for cordless or mobile telephones with means for adapting the functionality of the device according to specific conditions according to context-related or environment-related conditions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W52/00Power management, e.g. TPC [Transmission Power Control], power saving or power classes
    • H04W52/02Power saving arrangements
    • H04W52/0209Power saving arrangements in terminal devices
    • H04W52/0261Power saving arrangements in terminal devices managing power supply demand, e.g. depending on battery level
    • H04W52/0274Power saving arrangements in terminal devices managing power supply demand, e.g. depending on battery level by switching on or off the equipment or parts thereof
    • H04W52/028Power saving arrangements in terminal devices managing power supply demand, e.g. depending on battery level by switching on or off the equipment or parts thereof switching on or off only a part of the equipment circuit blocks
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Definitions

  • This application relates to the field of electronic equipment, and in particular to a management method and electronic equipment of a wake-up lock.
  • an application program application, APP, hereinafter referred to as an application
  • the functions of the mobile phone can be improved to provide users with a richer experience.
  • Wakelock is a locking mechanism. As long as the application applies for this lock (or as long as the lock is held), the processor (central processing unit, CPU) of the mobile phone will always be in working state, and the system cannot enter the sleep state. , In order to ensure the normal operation of the corresponding business of the application. For example, the process used to implement the function of the application can create a wakelock, so that when the mobile phone screen is turned off, the mobile phone screen can still be woken up to display the prompt message of the application.
  • the embodiments of the present application provide a wake lock management method and an electronic device, which solves the problem that the system cannot sleep for a long time due to the abnormal application of the lock, and the device consumes fast power, thereby prolonging the battery life of the device.
  • an embodiment of the present application provides a wakelock management method, which may include: a process of an electronic device creates a wakelock, the process includes a target process, and the target process may include one or more of the following processes: Create a wakelock process by writing file nodes, and create a wakelock process by invoking the corresponding interface of the kernel kernel layer of the electronic device; the electronic device associates the identifier of the target process with the wakelock created by the target process; the target process exits abnormally when it is determined When it is time, the wakelock corresponding to the identifier of the target process is obtained; when it is determined that the state of the wakelock corresponding to the identifier of the target process is active, the wakelock is released.
  • the process identifier is recorded at the kernel layer to bind it to the process resource of.
  • the wakelock applied for by the process can be automatically released when the process exit processing is performed, avoiding abnormal application locks, ensuring that the system sleeps in time, and extending the battery life of the electronic device.
  • the solution provided by this embodiment does not cause large system overhead and has universal applicability.
  • the target process of the electronic device creates a wakelock by writing a file node, which may include: the target process writes the name of the wakelock that the target process needs to create into the corresponding file node; the electronic device writes the target
  • the process ID and the wakelock created by the target process are stored associative storage, which can include: the kernel layer obtains the target process ID, and creates a wake_source node at the kernel layer.
  • the wake_source node includes the target process ID and the wakelock lock that the target process needs to create. name.
  • the identifier of the process to which the wake_source node belongs is written into the wake_source node, so as to realize the association between the wakelock created by the process and the process identifier.
  • the target process of the electronic device creates a wakelock by calling the corresponding interface of the kernel layer, which may include: the target process calls the corresponding interface of the kernel layer, and inputting the name of the wakelock that the target process needs to create;
  • the electronic device stores the identifier of the target process in association with the wakelock created by the target process, which may include: obtaining the identifier of the target process at the kernel layer and creating a wake_source node at the kernel layer.
  • the wake_source node includes the identifier of the target process and the wakelock created by the target process.
  • the lock name may include: the target process calls the corresponding interface of the kernel layer, and inputting the name of the wakelock that the target process needs to create;
  • the electronic device stores the identifier of the target process in association with the wakelock created by the target process, which may include: obtaining the identifier of the target process at the kernel layer and creating a wake_source node at the kernel layer.
  • the wake_source node includes the identifier of the
  • the identifier of the process to which the wake_source node belongs is written into the wake_source node, so that the wakelock created by the process is associated with the process identifier.
  • acquiring the wakelock corresponding to the identifier of the target process may include: when the target process exits abnormally, the kernel layer obtains the wake_source containing the identifier of the target process. Node; when the electronic device determines that the state of the wakelock corresponding to the target process's identifier is the active state, releasing the wakelock may include: the kernel layer deactivates the wake_source node when the state of the wake_source node containing the target process's identifier is determined to be the active state . In this way, after the process exits abnormally, the wakelock as a process management resource can be automatically released when the process exit processing is performed at the kernel layer.
  • the aforementioned target process may be an application process, a local native process or a kernel process.
  • an embodiment of the present application provides an electronic device.
  • the electronic device may include a processor and a memory; the processor and the memory are coupled, and the memory is used to store computer program codes.
  • the computer program codes include computer instructions.
  • the electronic device is executed, the electronic device is caused to perform the following operations: the process creates a wakelock wakelock, the process includes the target process, and the target process includes one or more of the following processes: the process of creating the wakelock by writing to the file node, and calling the electronic device
  • the kernel kernel layer of the kernel layer corresponds to the interface to create the wakelock process; the target process identifier and the wakelock created by the target process are associated and stored; when the target process is determined to exit abnormally, the wakelock corresponding to the target process identifier is obtained; When the state of the wakelock corresponding to the mark is activated, the wakelock is released.
  • the target process creates a wakelock by writing a file node, including: the target process writes the lock name of the wakelock that the target process needs to create into the corresponding file node; and the target process identifier and the target process
  • the created wakelock associated storage includes: the kernel layer obtains the identifier of the target process, and the wake_source node is created at the kernel layer.
  • the wake_source node includes the identifier of the target process and the name of the wakelock that the target process needs to create.
  • the target process creates wakelock by calling the corresponding interface of the kernel layer, including: the target process calls the corresponding interface of the kernel layer, and enters the lock name of the wakelock that the target process needs to create;
  • the identifier and wakelock associated storage created by the target process include: the kernel layer obtains the identifier of the target process and creates a wake_source node at the kernel layer.
  • the wake_source node includes the identifier of the target process and the name of the wakelock that the target process needs to create.
  • obtaining the wakelock corresponding to the target process identifier includes: when the target process exits abnormally, the kernel layer obtains the wake_source node containing the target process identifier;
  • releasing the wakelock includes: when the kernel layer determines that the state of the wake_source node containing the identifier of the target process is the active state, deactivating the wake_source node.
  • the target process may be an application process, a local native process or a kernel process.
  • embodiments of the present application provide a computer storage medium, the computer storage medium includes computer instructions, when the computer instructions run on an electronic device, the electronic device executes the first aspect or a possible implementation of the first aspect The wake lock management method described in any of the methods.
  • the embodiments of the present application provide a computer program product, which when the computer program product runs on a computer, causes the computer to execute the wake-up as described in the first aspect or any one of the possible implementations of the first aspect Lock management method.
  • an embodiment of the present application provides a device that has a function of implementing the behavior of an electronic device in the method of the first aspect.
  • the function can be realized by hardware, or by hardware executing corresponding software.
  • the hardware or software includes one or more modules corresponding to the aforementioned functions, for example, a creation unit or module, an acquisition unit or module, and a release unit or module.
  • Figure 1 is a schematic diagram of a network architecture applied to an APT scenario provided by the prior art
  • FIG. 2 is a simplified schematic diagram of a system architecture provided by an embodiment of the application.
  • FIG. 3 is a schematic flowchart of a wake lock management method provided by an embodiment of the application.
  • FIG. 4 is a schematic diagram of the composition of a wake lock management device provided by an embodiment of the application.
  • the electronic device For an application in an electronic device, the electronic device usually creates multiple processes for it to execute different services to implement corresponding functions. Among these services, the execution of some services (such as the display of prompt messages) requires the system to be in a working state all the time and cannot sleep. Android (Android) provides a lock mechanism, wakelock, as long as the lock system cannot enter sleep. Therefore, the process used to implement the function of the application can create a wakelock to ensure that the system will not sleep during the execution of the corresponding service.
  • Android Android
  • the processes in the Android system can be divided into three categories: application processes, native processes and kernel processes.
  • the application process may refer to the process created by the application.
  • the native process may refer to a process created in the native layer of the Android system of the electronic device to provide local services or system library functions.
  • the process created in the kernel mode can be called a kernel process, such as a kernel driver process.
  • the native process and the kernel process are generally resident, that is, they have been created when the system starts, and when an application needs to implement the corresponding function, it can provide the corresponding service.
  • the function of the application can be realized by one or more of the above three types of processes.
  • the wakelock created by the process for implementing the function of the application can be regarded as the wakelock of the application, or a lock held by the application.
  • the application can hold one or more wakelocks.
  • Method 1 Create/release wakelock by invoking the corresponding interface of PowerManagerService. For example, the wakelock is created by calling the acquire interface of PowerManagerService, and the wakelock is released by calling the release interface of PowerManagerService.
  • Method 2 Create wakelock by calling acquire_wake_lock interface, and release wakelock by calling release_wake_lock interface.
  • Method 3 Create/release a wakelock by directly writing to the file node, such as writing the lock name of the wakelock to be created to the corresponding file node. For example, create wakelock by writing file /sys/power/wake_lock, and release wakelock by writing file /sys/power/wake_unlock.
  • Method 4 Create/release wakelock by calling the corresponding interface of the kernel layer. For example, create wakelock by calling wake_lock/wake_lock_timeout, and release wakelock by calling wake_unlock/wake_lock_active.
  • the application process generally creates/releases wakelock through method 1.
  • the native process can create/release wakelock by way 2 or way 3.
  • the kernel process uses method 4 to create/release wakelock.
  • the above method of releasing wakelock only takes effect when the process exits normally.
  • the process exits abnormally such as the process exits abnormally when it cross-bounds access
  • the above-mentioned method of releasing wakelock cannot take effect.
  • the wakelock created by it cannot be released normally, or the release will be missed, which will cause the system to fail to sleep and cause high power consumption.
  • the situation in which the process used to implement the function of the application exits but the wakelock applied for is not released is called abnormal application lock holding.
  • the Power Manager Service (PMS) of the electronic device can detect the lock-holding application state through the binder mechanism.
  • PMS Power Manager Service
  • the electronic device can detect that the application is not responding through the binder mechanism. At this time, the electronic device will actively release the wakelock held by the application. But the binder mechanism can only release the wakelock created by the above method 1 or method 2, and it cannot take effect for the wakelock created by the above method 3 and method 4.
  • Mechanism 1 The lock-holding application detects whether there is an abnormal lock-holding situation in the application according to the end of the service. If the application's business has ended, but the wakelock requested by the process executing the business is not released, it is determined that the application is holding the lock abnormally. At this time, the corresponding wakelock can be released.
  • Mechanism 2. The system monitors all lock-holding applications in a manner similar to a watchdog. If an application does not respond within a period of time, it is considered that the application is abnormal, or it is determined that the application is abnormally locked. At this point, the wakelock held by the application can be released.
  • the application cannot accurately identify the end of the service, that is, a misjudgment may occur. For example, the service has ended, but the application does not recognize it.
  • the detection mechanism will also fail. In this way, there will still be situations where the application locks abnormally.
  • the system needs to poll and monitor all lock-holding applications, which will bring greater system overhead.
  • this monitoring mechanism needs to modify the implementation of the application so that it can register watchdogs, which is not universal. That is to say, for the wakelock created by the above method 3 or method 4, the current mechanism cannot well solve the problem of the system cannot sleep and the device consumes high power due to the abnormal lock holding of the application.
  • the embodiment of the present application provides a method for managing wake locks. For a wakelock created by the above method 3 or method 4, after the corresponding process exits abnormally, the wakelock applied for by the process can be automatically released to avoid the application of abnormal lock holding situations. Ensure that the system sleeps in time, extending the battery life of electronic devices. In addition, the solution provided by this embodiment does not cause large system overhead and has universal applicability.
  • the electronic devices described in the embodiments of this application may be mobile phones, tablet computers, desktop computers, laptops, handheld computers, notebook computers, ultra-mobile personal computers (UMPC), netbooks, As well as cellular phones, personal digital assistants (PDA), augmented reality (AR) ⁇ virtual reality (VR) devices, wearable devices (such as smart watches), media players, etc.
  • PDA personal digital assistants
  • AR augmented reality
  • VR virtual reality
  • wearable devices such as smart watches
  • media players etc.
  • the application embodiment does not impose special restrictions on the specific form of the device.
  • FIG. 1 is a schematic structural diagram of an electronic device provided by an embodiment of this application.
  • 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, and a battery 142, Antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, earphone interface 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, A display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
  • SIM subscriber identification module
  • the sensor module 180 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
  • the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device.
  • the electronic device may include more or fewer components than shown, or combine certain components, or split certain components, or arrange different components.
  • the illustrated components can be implemented in hardware, software, or a combination of software and hardware.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural-network processing unit (NPU) Wait.
  • AP application processor
  • modem processor modem processor
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller memory
  • video codec digital signal processor
  • DSP digital signal processor
  • NPU neural-network processing unit
  • the different processing units may be independent devices or integrated in one or more processors.
  • the controller can be the nerve center and command center of the electronic device.
  • the controller can generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching and executing instructions.
  • a memory may also be provided in the processor 110 to store instructions and data.
  • the memory in the processor 110 is a cache memory.
  • the memory can store instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. Repeated accesses are avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved.
  • the processor 110 may include one or more interfaces.
  • the interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, and a universal asynchronous transmitter (universal asynchronous transmitter) interface.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous transmitter
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM interface SIM interface
  • USB interface universal asynchronous transmitter
  • the charging management module 140 is used to receive charging input from the charger.
  • the charger can be a wireless charger or a wired charger. While the charging management module 140 charges the battery 142, it can also supply power to the electronic device through the power management module 141.
  • the power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110.
  • the power management module 141 receives input from the battery 142 and/or the charge management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160.
  • the power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle times, and battery health status (leakage, impedance).
  • the power management module 141 may also be provided in the processor 110.
  • the power management module 141 and the charging management module 140 may also be provided in the same device.
  • the wireless communication function of the electronic device can be realized by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor.
  • the antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals.
  • the mobile communication module 150 can provide wireless communication solutions including 2G/3G/4G/5G and the like applied to electronic devices.
  • the mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc.
  • the mobile communication module 150 can receive electromagnetic waves by the antenna 1, and perform processing such as filtering, amplifying and transmitting the received electromagnetic waves to the modem processor for demodulation.
  • the mobile communication module 150 can also amplify the signal modulated by the modem processor, and convert it into electromagnetic waves for radiation via the antenna 1.
  • the wireless communication module 160 can provide applications in electronic devices including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), and global navigation satellite systems. (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR) and other wireless communication solutions.
  • WLAN wireless local area networks
  • BT Bluetooth
  • GNSS global navigation satellite system
  • frequency modulation frequency modulation, FM
  • NFC near field communication technology
  • infrared technology infrared, IR
  • the wireless communication module 160 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110.
  • the wireless communication module 160 can also receive the signal to be sent from the processor 110, perform frequency modulation, amplify it, and convert it into electromagnetic wave radiation via the antenna 2.
  • the antenna 1 of the electronic device is coupled with the mobile communication module 150, and the antenna 2 is coupled with the wireless communication module 160, so that the electronic device can communicate with the network and other devices through wireless communication technology.
  • the wireless communication technologies may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code division multiple access (wideband code division multiple access, WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc.
  • the GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (quasi -zenith satellite system, QZSS) and/or satellite-based augmentation systems (SBAS).
  • GPS global positioning system
  • GLONASS global navigation satellite system
  • BDS Beidou navigation satellite system
  • QZSS quasi-zenith satellite system
  • SBAS satellite-based augmentation systems
  • the electronic device realizes the display function through GPU, display screen 194, and application processor.
  • the GPU is a microprocessor for image processing, connected to the display 194 and the application processor.
  • the GPU is used to perform mathematical and geometric calculations for graphics rendering.
  • the processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
  • the display screen 194 is used to display images, videos, etc.
  • the display screen 194 includes a display panel.
  • the display panel can adopt liquid crystal display (LCD), organic light-emitting diode (OLED), active-matrix organic light-emitting diode or active-matrix organic light-emitting diode (active-matrix organic light-emitting diode).
  • LCD liquid crystal display
  • OLED organic light-emitting diode
  • active-matrix organic light-emitting diode active-matrix organic light-emitting diode
  • emitting diode AMOLED, flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, quantum dot light-emitting diode (QLED), etc.
  • the electronic device may include 1 or N display screens 194, and N is a positive integer greater than 1.
  • Electronic equipment can realize shooting functions through ISP, camera 193, video codec, GPU, display 194, and application processor.
  • the ISP is used to process the data fed back from the camera 193.
  • ISP can also optimize the image noise, brightness, and skin color.
  • ISP can also optimize the exposure, color temperature and other parameters of the shooting scene.
  • the ISP may be provided in the camera 193.
  • the camera 193 is used to capture still images or videos.
  • the electronic device may include 1 or N cameras 193, and N is a positive integer greater than 1.
  • Digital signal processors are used to process digital signals.
  • Video codecs are used to compress or decompress digital video.
  • the electronic device can support one or more video codecs.
  • NPU is a neural-network (NN) computing processor.
  • NN neural-network
  • NPU can realize the intelligent cognition of electronic devices and other applications, such as: image recognition, face recognition, voice recognition, text understanding, etc.
  • the external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device.
  • the external memory card communicates with the processor 110 through the external memory interface 120 to realize the data storage function. For example, save music, video and other files in an external memory card.
  • the internal memory 121 may be used to store computer executable program code, where the executable program code includes instructions.
  • the processor 110 executes various functional applications and data processing of the electronic device by running instructions stored in the internal memory 121. For example, in the embodiment of the present application, the processor 110 may automatically release the wakelock applied for by the process after the process exits abnormally by executing the instructions stored in the internal memory 121.
  • the internal memory 121 may include a storage program area and a storage data area. Among them, the storage program area can store an operating system, at least one application program (such as a sound playback function, an image playback function, etc.) required by at least one function.
  • the data storage area can store data (such as audio data, phone book, etc.) created during the use of the electronic device.
  • the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash storage (UFS), etc.
  • the electronic device can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor. For example, music playback, recording, etc.
  • the audio module 170 is used to convert digital audio information into an analog audio signal for output, and is also used to convert an analog audio input into a digital audio signal.
  • the audio module 170 can also be used to encode and decode audio signals.
  • the audio module 170 may be provided in the processor 110, or part of the functional modules of the audio module 170 may be provided in the processor 110.
  • the speaker 170A also called a “speaker” is used to convert audio electrical signals into sound signals.
  • the electronic device can listen to music through the speaker 170A, or listen to a hands-free call.
  • the receiver 170B also called “earpiece” is used to convert audio electrical signals into sound signals.
  • the electronic device answers a call or voice message, it can receive the voice by bringing the receiver 170B close to the human ear.
  • the microphone 170C also called “microphone”, “microphone”, is used to convert sound signals into electrical signals.
  • the user can approach the microphone 170C through the mouth to make a sound, and input the sound signal to the microphone 170C.
  • the electronic device may be provided with at least one microphone 170C.
  • the earphone interface 170D is used to connect wired earphones.
  • the earphone interface 170D may be a USB interface 130, or a 3.5mm open mobile terminal platform (OMTP) standard interface, or a cellular telecommunications industry association (cellular telecommunications industry association of the USA, CTIA) standard interface.
  • OMTP open mobile terminal platform
  • CTIA cellular telecommunications industry association
  • the pressure sensor is used to sense the pressure signal and can convert the pressure signal into an electrical signal.
  • the pressure sensor may be provided on the display screen 194.
  • pressure sensors such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc.
  • the gyroscope sensor can be used to determine the movement posture of the electronic device.
  • the angular velocity of the electronic device around three axes ie, x, y, and z axes
  • the gyroscope sensor can be used for shooting anti-shake.
  • the gyroscope sensor can also be used for navigation and somatosensory game scenes.
  • the air pressure sensor is used to measure air pressure.
  • the electronic device calculates the altitude based on the air pressure value measured by the air pressure sensor to assist positioning and navigation.
  • the magnetic sensor includes a Hall sensor.
  • the electronic device can use a magnetic sensor to detect the opening and closing of the flip holster.
  • the acceleration sensor can detect the magnitude of the acceleration of the electronic device in all directions (usually three-axis). The magnitude and direction of gravity can be detected when the electronic device is stationary. It can also be used to identify the posture of electronic devices, and used in applications such as horizontal and vertical screen switching, pedometers and so on.
  • Distance sensor used to measure distance.
  • the proximity light sensor may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode.
  • the electronic device emits infrared light through the light-emitting diode.
  • Electronic equipment uses photodiodes to detect infrared reflected light from nearby objects to determine whether there are objects near the electronic equipment.
  • the ambient light sensor is used to sense the brightness of the ambient light.
  • the electronic device can adaptively adjust the brightness of the display screen 194 according to the perceived brightness of the ambient light.
  • the ambient light sensor can also be used to automatically adjust the white balance when taking pictures.
  • the ambient light sensor can also cooperate with the proximity light sensor to detect whether the electronic device is in the pocket to prevent accidental touch.
  • the fingerprint sensor is used to collect fingerprints. Electronic devices can use the collected fingerprint characteristics to unlock fingerprints, access application locks, take photos with fingerprints, and answer calls with fingerprints.
  • the temperature sensor is used to detect temperature.
  • the electronic device uses the temperature detected by the temperature sensor to execute the temperature processing strategy.
  • the touch sensor also called “touch panel”.
  • the touch sensor may be provided on the display screen 194, and the touch screen is composed of the touch sensor and the display screen 194, which is also called a “touch screen”.
  • the touch sensor is used to detect touch operations acting on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • the visual output related to the touch operation can be provided through the display screen 194.
  • the touch sensor may also be disposed on the surface of the electronic device, which is different from the position of the display screen 194.
  • Bone conduction sensors can acquire vibration signals.
  • the bone conduction sensor can obtain the vibration signal of the vibrating bone mass of the human voice.
  • the bone conduction sensor can also contact the human pulse and receive the blood pressure pulse signal.
  • the bone conduction sensor may also be provided in the earphone.
  • the button 190 includes a power button, a volume button, and so on.
  • the button 190 may be a mechanical button. It can also be a touch button.
  • the electronic device can receive key input and generate key signal input related to user settings and function control of the electronic device.
  • the motor 191 can generate vibration prompts.
  • the motor 191 can be used for incoming call vibration notification, and can also be used for touch vibration feedback.
  • the indicator 192 may be an indicator light, which may be used to indicate the charging status, power change, or to indicate messages, missed calls, notifications, and so on.
  • the SIM card interface 195 is used to connect to the SIM card.
  • the SIM card can be inserted into the SIM card interface 195 or pulled out from the SIM card interface 195 to achieve contact and separation with the electronic device.
  • the electronic device can support 1 or N SIM card interfaces, and N is a positive integer greater than 1.
  • the SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc.
  • the electronic device interacts with the network through the SIM card to realize functions such as call and data communication.
  • the electronic device adopts eSIM, that is, an embedded SIM card.
  • the eSIM card can be embedded in the electronic device and cannot be separated from the electronic device.
  • the software system of the electronic device can adopt a layered architecture, event-driven architecture, micro-core architecture, micro-service architecture, or cloud architecture.
  • the embodiment of the present application takes an Android system with a layered architecture as an example to illustrate the software structure of an electronic device.
  • FIG. 2 is a schematic diagram of the software structure of an electronic device provided by an embodiment of the application.
  • the layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Communication between layers through software interface.
  • the Android system is divided into four layers, from top to bottom, the application layer, the application framework layer (framework), the native layer, and the kernel layer.
  • the application layer may include a series of application packages.
  • the application package may include applications such as WeChat, Amazon, calendar, call, map, music player, video player, short message, etc.
  • the application framework layer provides application programming interfaces (application programming interface, API) and programming frameworks for applications in the application layer to provide support for the operation of applications in the application layer.
  • API application programming interface
  • the native layer is used to provide system services, location services, touch services, display services, etc. for applications in the application layer.
  • the kernel layer is the layer between hardware and software.
  • the kernel layer contains at least display driver, camera driver, audio driver, sensor driver, location driver (such as GPS driver) and so on.
  • the electronic device when the system is started, the electronic device creates a native process and/or a kernel process for providing corresponding services.
  • a corresponding application process is created. In this way, by using one or more of these processes, the corresponding functions of the application can be realized.
  • the electronic device when the system is started, the electronic device creates a native process 1 and a kernel process 1 for providing location services. Then, native process 1 and kernel process 1 can provide corresponding location services to implement applications such as Amazon's location function.
  • FIG. 3 is a schematic flowchart of a wake lock management method provided by an embodiment of the application. As shown in Figure 3, the method may include:
  • the electronic device creates multiple processes for it to execute corresponding services to realize the functions of the application.
  • the business performed by some processes requires the system to be in a working state and cannot sleep. These processes can create wakelocks to ensure that the system does not sleep during the execution of the corresponding services.
  • the operating system of the electronic device is the Android system as an example.
  • the processes in the Android system can be divided into three categories: application processes, native processes and kernel processes.
  • the function of the application can be realized through one or more of these three types of processes.
  • the wakelock created by the process for implementing the function of the application can be regarded as the wakelock of the application, or a lock held by the application.
  • the application can hold one or more wakelocks.
  • the current process can create/release wakelock in the following four ways:
  • Method 1 Create/release wakelock by calling the corresponding interface of PowerManagerService.
  • Method 2 Create wakelock by calling acquire_wake_lock interface, and release wakelock by calling release_wake_lock interface.
  • Method 3 Create/release a wakelock by directly writing to the file node, for example, by writing the lock name of the wakelock that the process needs to create to the corresponding file node.
  • Method 4 Create/release wakelock by calling the corresponding interface of the kernel layer.
  • the wakelock can be created/released through the above method 1.
  • the native process can create/release wakelock by way 2 or way 3.
  • the kernel process can create/release wakelock through method 4.
  • a wakelock created in any way will eventually create a wake_source node in the kernel layer.
  • process A can use the power saving management service (PowerMangerService) provided by the application framework layer to call the acquire interface of PowerManagerService to create a wakelock.
  • PowerMangerService the power saving management service
  • the wakelock created by process A is called wakelock_A.
  • process A calls the acquire interface of PowerManagerService and enters the lock name of wakelock_A that process A needs to create.
  • the native layer can obtain the identity of process A according to the call, such as PID_A, and call the acquire_wake_lock interface to write the identity of process A in the corresponding file node, such as /sys/power/wake_lock, that is, the locks of PID_A and wakelock_A name. After that, the wakelock_A of process A is created.
  • Process B can create a wakelock by calling the corresponding interface, such as acquire_wake_lock, when the business it is executing requires that the system does not sleep.
  • the wakelock created by process B is called wakelock_B.
  • process B inputs the lock name of wakelock_B that process B needs to create by calling the interface acquire_wake_lock.
  • the native layer can obtain the identity of process B according to the call, such as PID_B, and write the identity of process B in the corresponding file node, such as /sys/power/wake_lock, that is, the lock names of PID_B and wakelock_B. After that, the wakelock_B of process B is created.
  • Process C can create a wakelock by writing a file node when the business it is executing requires that the system does not sleep.
  • the wakelock created by process C is called wakelock_C.
  • the process C can directly write the lock name of the wakelock_C that the process C needs to create in the corresponding file node, such as /sys/power/wake_lock. After that, the wakelock_C of process C is created.
  • process D can call the corresponding interface of the kernel layer, such as wake_lock/wake_lock_timeout, and enter the name of the wakelock that process D needs to create.
  • the wakelock created by process D is called wakelock_D. After that, the wakelock_D of process D is created.
  • the electronic device stores the identifier of the target process in association with the wakelock created by the target process.
  • the target process includes one or more of the following processes: a process that creates a wakelock by writing a file node, and calls a corresponding interface at the kernel layer. Way to create a wakelock process.
  • wakelock can also be used as a resource managed by the process to achieve the purpose of automatically releasing the wakelock created by the process when it exits.
  • the wakelock created by it can be released through the binder mechanism. Since this mechanism is not applicable to processes that create wakelocks using the above methods 3 and 4, in this embodiment, only the processes that create wakelocks using the above methods 3 and 4 can be used as process management. A resource.
  • the kernel layer can create a wakelock and a wakelock created by the target process.
  • the identification of the target process is stored in association.
  • the kernel layer stores the wake_source node created in the kernel layer in association with the PID of the process to which the wake_source node belongs. In this way, the wakelock created by it can be used as a resource for process management to facilitate subsequent management.
  • process C creates wakelock by writing file nodes.
  • process C writes the lock name of wakelock_C that needs to be created into the corresponding file node
  • the kernel layer can obtain the identity of the process C, namely PID_C, and create the wake_source node of process C in the kernel layer.
  • PID_C the identity of the process C
  • the PID of process C that is, PID_C and the lock name of wakelock_C to be created by process C, can be written into the wake_source node C, so that the created wake_source node C and the process to which wake_source node C belongs The PID is associated.
  • process D creates wakelock by calling the corresponding interface of the kernel layer.
  • process D by calling the corresponding interface of the kernel layer, enter the lock name of wakelock_D that process D needs to create, and after completing the creation of wakelock_D, the kernel layer can obtain the identity of process D, namely PID_D, and in the kernel layer.
  • the PID of process D namely PID_D and the lock name of wakelock_D to be created by process D
  • the PID of process D can be written into the wake_source node D, so as to create wake_source node D It is associated with the PID of the process to which the wake_source node D belongs.
  • a wake_source node is created at the kernel layer, and the wake_source node may include the lock name of the wakelock that the corresponding process needs to create.
  • the kernel layer creates wake_source node A for process A in the kernel layer, and the wake_source node A includes the lock name of wakelock_A that process A needs to create.
  • the kernel layer creates a wake_source node B for process B in the kernel layer, and the wake_source node B includes the lock name of wakelock_B that process B needs to create.
  • the electronic device When determining that the target process exits abnormally, acquires a wakelock corresponding to the identifier of the target process.
  • the electronic device releases the wakelock when determining that the state of the wakelock corresponding to the identifier of the target process is the active state.
  • the PMS of the electronic device can detect the abnormal hold of the application through the binder mechanism. In the lock situation, it is detected that process A or process B has exited, but the wakelock created by it has not been released. At this time, the electronic device will actively release the wakelock created by the process. For processes that create wakelocks using the above methods 3 and 4, such as process C and process D in the example of S301, when they exit abnormally, the above binder mechanism does not apply.
  • the electronic device can trigger the process exit processing at the kernel layer when determining the target process, such as process C or process D, which exits abnormally.
  • the kernel layer can clean up the file handle, occupied memory, socket and other resources of the target process.
  • the kernel layer can also execute the above S303-S304 to release the wakelock created by the target process. Specifically, the kernel layer may obtain the wakelock corresponding to the identifier of the target process. Then, when it is determined that the state of the wakelock corresponding to the identifier of the target process is the active state, the wakelock is released.
  • the kernel layer of the electronic device can obtain the wake_source node containing the C's identity of the process. For example, the kernel layer determines that the wake_source node C contains the C's identity of the process. At this time, when the kernel layer determines that the state of the wake_source node C is the active state, it means that the wakelock created by the process C has not been released, and the kernel layer can release the wake_source node C.
  • the kernel layer of the electronic device can obtain the wake_source node containing the ID of the process D, for example, the kernel layer determines that the wake_source node D contains the ID of the process D.
  • the kernel layer determines that the state of the wake_source node D is the active state, it means that the wakelock created by the process D has not been released, and the kernel layer can release the wake_source node D. This can avoid the application of abnormal lock holding situations.
  • the specific processing of releasing the corresponding wake_source node may be to deactivate the wake_source node to ensure that the system can sleep in time.
  • the process identifier is recorded at the kernel layer to bind it to the process resource of.
  • the wakelock applied for by the process can be automatically released when the process exit processing is performed, avoiding abnormal application locks, ensuring that the system sleeps in time, and extending the battery life of the electronic device.
  • the solution provided by this embodiment does not cause large system overhead and has universal applicability.
  • the computer storage medium may include computer instructions.
  • the computer instructions run on an electronic device, the electronic device executes the execution of the electronic device in the embodiment shown in FIG. 3. The various steps.
  • FIG. 3 Another embodiments of the present application also provide a computer program product, which when the computer program product runs on a computer, causes the computer to execute each step performed by the electronic device in the embodiment shown in FIG. 3.
  • FIG. 3 Other embodiments of the present application also provide a chip system, which can be applied to electronic devices; the chip system can include one or more interface circuits and one or more processors; the interface circuits and the processors are interconnected by wires; The interface circuit is used to receive signals from the memory of the electronic device and send signals to the processor.
  • the signals include computer instructions stored in the memory; when the processor executes the computer instructions, the electronic device executes the method in the corresponding embodiment of FIG. 3.
  • the electronic device may include a processor and a memory; the processor and the memory are coupled, and the memory is used to store computer program codes.
  • the computer program codes include computer instructions. When the device is executed, the electronic device is caused to execute the method in the corresponding embodiment in FIG. 3.
  • a wake lock management device which has the function of realizing the behavior of the electronic device in the corresponding embodiment in FIG. 3 above.
  • the function can be realized by hardware, or by hardware executing corresponding software.
  • the hardware or software includes one or more modules corresponding to the above functions, for example, a creation unit or module, an acquisition unit or module, a release unit or module, and so on.
  • the device may include a creation unit 401, an acquisition unit 402, and a release unit 403.
  • the creation unit 401 is used for a process to create a wakelock wakelock.
  • the process may include a target process, and the target process may include one or more of the following processes: a process for creating a wakelock by writing a file node, and calling the corresponding interface of the kernel layer Create a wakelock process in a way; associate the target process identifier with the wakelock created by the target process.
  • the acquiring unit 402 is configured to acquire the wakelock corresponding to the identifier of the target process when it is determined that the target process exits abnormally.
  • the releasing unit 403 is configured to release the wakelock when it is determined that the state of the wakelock corresponding to the identifier of the target process is the active state.
  • the creation unit 401 is specifically used for the target process to write the lock name of the wakelock that the target process needs to create into the corresponding file node, obtain the identifier of the target process, and create a wake_source node in the kernel layer, and the wake_source node includes the target process The identifier and the lock name of the wakelock that the target process needs to create.
  • the creation unit 401 is specifically used for the target process to call the corresponding interface of the kernel layer, to input the lock name of the wakelock that the target process needs to create; to obtain the identifier of the target process, to create a wake_source node in the kernel layer, and the wake_source node includes the target process The identifier and the lock name of the wakelock that the target process needs to create.
  • the obtaining unit 402 is specifically configured to obtain the wake_source node containing the identifier of the target process when the target process exits abnormally.
  • the releasing unit 403 is specifically configured to deactivate the wake_source node when it is determined that the state of the wake_source node containing the identifier of the target process is the active state.
  • the aforementioned target process may be an application process, a local native process or a kernel process.
  • the computer storage medium, computer program product, electronic device, wake lock management device, and chip system provided in the embodiment of the application are used to execute the method in the corresponding embodiment of FIG. 3 above, so the same effect can be achieved, and will not be omitted here. Repeat.
  • the disclosed device and method may be implemented in other ways.
  • the device embodiments described above are merely illustrative.
  • the division of the modules or units is only a logical function division.
  • there may be other division methods for example, multiple units or components may be It can be combined or integrated into another device, or some features can be omitted or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
  • the units described as separate parts may or may not be physically separate.
  • the parts displayed as units may be one physical unit or multiple physical units, that is, they may be located in one place, or they may be distributed to multiple different places. . Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • each unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
  • the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium.
  • the technical solutions of the embodiments of the present application are essentially or the part that contributes to the prior art, or all or part of the technical solutions can be embodied in the form of software products, which are stored in a storage medium.
  • a device which may be a single-chip microcomputer, a chip, etc.
  • a processor processor
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Environmental & Geological Engineering (AREA)
  • Human Computer Interaction (AREA)
  • Telephone Function (AREA)

Abstract

Provided are a wakelock management method and an electronic device, wherein same relate to the field of electronic devices. The problems of a system failing to sleep for a long time and of the high power consumption of a device due to abnormal lock holding of an application are solved, and the service life of the device is prolonged. The method comprises: a process creating a wakelock, wherein the process comprises a target process, and the target process comprises one or more of the following processes: a process of creating a wakelock by using a file node writing mode, and a process of creating a wakelock by using a mode of calling an interface corresponding to a kernel layer; storing an identifier of the target process in association with the wakelock created by the target process; when it is determined that the target process is exited abnormally, acquiring a wakelock corresponding to the identifier of the target process; and when it is determined that the wakelock corresponding to the identifier of the target process is in an activated state, releasing the wakelock.

Description

一种唤醒锁的管理方法及电子设备Management method and electronic equipment of wake lock
本申请要求于2019年07月26日提交国家知识产权局、申请号为201910687713.2、申请名称为“一种唤醒锁的管理方法及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the State Intellectual Property Office on July 26, 2019, the application number is 201910687713.2, and the application name is "a wake-lock management method and electronic equipment", the entire content of which is incorporated by reference In this application.
技术领域Technical field
本申请涉及电子设备领域,尤其涉及一种唤醒锁的管理方法及电子设备。This application relates to the field of electronic equipment, and in particular to a management method and electronic equipment of a wake-up lock.
背景技术Background technique
如今,手机等电子设备已成为人们日常生活和工作中必不可少的通讯工具。通过在手机中安装应用程序(application,APP,以下简称为应用),可以完善手机功能,为用户提供更丰富的使用体验。对于手机中安装的应用,可以通过申请唤醒锁(wakelock)来确保某些业务的正常运行。Nowadays, electronic devices such as mobile phones have become indispensable communication tools in people's daily life and work. By installing an application program (application, APP, hereinafter referred to as an application) in a mobile phone, the functions of the mobile phone can be improved to provide users with a richer experience. For applications installed in mobile phones, you can apply for a wakelock to ensure the normal operation of certain services.
唤醒锁(wakelock)是一种锁的机制,只要应用申请了这个锁(或说只要持锁),手机的处理器(central processing unit,CPU)便会一直处于工作状态,系统就无法进入休眠状态,以此来确保该应用对应业务的正常运行。例如,用于实现应用的功能的进程可通过创建wakelock,使得手机屏幕在关闭的情况下,依然可唤醒手机屏幕显示该应用的提示消息。Wakelock (wakelock) is a locking mechanism. As long as the application applies for this lock (or as long as the lock is held), the processor (central processing unit, CPU) of the mobile phone will always be in working state, and the system cannot enter the sleep state. , In order to ensure the normal operation of the corresponding business of the application. For example, the process used to implement the function of the application can create a wakelock, so that when the mobile phone screen is turned off, the mobile phone screen can still be woken up to display the prompt message of the application.
但是,如果应用出现异常持锁的情况,则会导致系统无法休眠,带来高耗电的问题,大大缩短了手机的续航时间。However, if the application is locked abnormally, the system will not be able to sleep, which will cause high power consumption and greatly shorten the battery life of the mobile phone.
发明内容Summary of the invention
本申请实施例提供一种唤醒锁的管理方法及电子设备,解决了由于应用异常持锁,导致的系统长时间无法休眠,设备电量消耗快的问题,延长了设备的续航时间。The embodiments of the present application provide a wake lock management method and an electronic device, which solves the problem that the system cannot sleep for a long time due to the abnormal application of the lock, and the device consumes fast power, thereby prolonging the battery life of the device.
为达到上述目的,本申请实施例采用如下技术方案:In order to achieve the foregoing objectives, the following technical solutions are adopted in the embodiments of this application:
第一方面,本申请实施例提供一种唤醒锁的管理方法,该方法可以包括:电子设备的进程创建wakelock,该进程包括目标进程,该目标进程可以包括以下进程中的一个或多个:采用写文件节点的方式创建wakelock的进程,采用调用电子设备的内核kernel层对应接口的方式创建wakelock的进程;电子设备将上述目标进程的标识和目标进程创建的wakelock关联存储;在确定目标进程异常退出时,获取与该目标进程的标识对应的wakelock;在确定与目标进程的标识对应的wakelock的状态为激活态时,释放wakelock。In the first aspect, an embodiment of the present application provides a wakelock management method, which may include: a process of an electronic device creates a wakelock, the process includes a target process, and the target process may include one or more of the following processes: Create a wakelock process by writing file nodes, and create a wakelock process by invoking the corresponding interface of the kernel kernel layer of the electronic device; the electronic device associates the identifier of the target process with the wakelock created by the target process; the target process exits abnormally when it is determined When it is time, the wakelock corresponding to the identifier of the target process is obtained; when it is determined that the state of the wakelock corresponding to the identifier of the target process is active, the wakelock is released.
本申请实施例提供的唤醒锁的管理方法,对于通过写文件节点或调用内核层对应接口的方式创建的wakelock,通过在内核层记录其所属进程的标识,以将其作为一种与进程绑定的资源。这样,在对应进程异常退出后,在进行进程退出处理时,便能够自动释放该进程申请的wakelock,避免应用异常持锁的情况出现,保证系统及时休眠,延长了电子设备的续航时间。另外,本实施例提供的方案不会带来大的系统开销,且具备普适性。In the wakelock management method provided by the embodiments of the present application, for a wakelock created by writing a file node or calling the corresponding interface of the kernel layer, the process identifier is recorded at the kernel layer to bind it to the process resource of. In this way, after the corresponding process exits abnormally, the wakelock applied for by the process can be automatically released when the process exit processing is performed, avoiding abnormal application locks, ensuring that the system sleeps in time, and extending the battery life of the electronic device. In addition, the solution provided by this embodiment does not cause large system overhead and has universal applicability.
在一种可能的实现方式中,电子设备的目标进程采用写文件节点的方式创建 wakelock,可以包括:目标进程将目标进程所需创建的wakelock的锁名称写入对应的文件节点;电子设备将目标进程的标识和目标进程创建的wakelock关联存储,可以包括:内核层获取目标进程的标识,在内核层创建唤醒源wake_source节点,wake_source节点中包括目标进程的标识和目标进程所需创建的wakelock的锁名称。这样,对于采用写文件节点的方式创建wakelock的进程,通过在内核层创建wake_source节点时,将该wake_source节点所属进程的标识写入wake_source节点,实现了进程所创建wakelock与进程的标识的关联。In a possible implementation, the target process of the electronic device creates a wakelock by writing a file node, which may include: the target process writes the name of the wakelock that the target process needs to create into the corresponding file node; the electronic device writes the target The process ID and the wakelock created by the target process are stored associative storage, which can include: the kernel layer obtains the target process ID, and creates a wake_source node at the kernel layer. The wake_source node includes the target process ID and the wakelock lock that the target process needs to create. name. In this way, for a process that creates a wakelock by writing a file node, when the wake_source node is created in the kernel layer, the identifier of the process to which the wake_source node belongs is written into the wake_source node, so as to realize the association between the wakelock created by the process and the process identifier.
在另一种可能的实现方式中,电子设备的目标进程采用调用内核层对应接口的方式创建wakelock,可以包括:目标进程调用内核层的对应接口,输入目标进程所需创建的wakelock的锁名称;电子设备将目标进程的标识和目标进程创建的wakelock关联存储,可以包括:内核层获取目标进程的标识,在内核层创建wake_source节点,wake_source节点包括目标进程的标识和目标进程所需创建的wakelock的锁名称。这样,对于采用调用内核层对应接口的方式创建wakelock的进程,通过在内核层创建wake_source节点时,将该wake_source节点所属进程的标识写入wake_source节点,实现了进程所创建wakelock与进程的标识的关联。In another possible implementation, the target process of the electronic device creates a wakelock by calling the corresponding interface of the kernel layer, which may include: the target process calls the corresponding interface of the kernel layer, and inputting the name of the wakelock that the target process needs to create; The electronic device stores the identifier of the target process in association with the wakelock created by the target process, which may include: obtaining the identifier of the target process at the kernel layer and creating a wake_source node at the kernel layer. The wake_source node includes the identifier of the target process and the wakelock created by the target process. The lock name. In this way, for a process that creates a wakelock by calling the corresponding interface of the kernel layer, when the wake_source node is created in the kernel layer, the identifier of the process to which the wake_source node belongs is written into the wake_source node, so that the wakelock created by the process is associated with the process identifier. .
在另一种可能的实现方式中,电子设备在确定目标进程异常退出时,获取与目标进程的标识对应的wakelock,可以包括:在目标进程异常退出时,内核层获取包含目标进程的标识的wake_source节点;电子设备在确定与目标进程的标识对应的wakelock的状态为激活态时,释放wakelock,可以包括:内核层在确定包含目标进程的标识的wake_source节点的状态为激活态时,去激活wake_source节点。这样,在进程异常退出后,在内核层进行进程退出处理时,能够将作为进程管理资源的wakelock自动释放。In another possible implementation manner, when the electronic device determines that the target process exits abnormally, acquiring the wakelock corresponding to the identifier of the target process may include: when the target process exits abnormally, the kernel layer obtains the wake_source containing the identifier of the target process. Node; when the electronic device determines that the state of the wakelock corresponding to the target process's identifier is the active state, releasing the wakelock may include: the kernel layer deactivates the wake_source node when the state of the wake_source node containing the target process's identifier is determined to be the active state . In this way, after the process exits abnormally, the wakelock as a process management resource can be automatically released when the process exit processing is performed at the kernel layer.
在另一种可能的实现方式中,上述目标进程可以为应用进程,本地native进程或kernel进程。In another possible implementation manner, the aforementioned target process may be an application process, a local native process or a kernel process.
第二方面,本申请实施例提供一种电子设备,该电子设备可以包括:处理器和存储器;处理器和存储器耦合,存储器用于存储计算机程序代码,计算机程序代码包括计算机指令,当计算机指令被电子设备执行时,使得电子设备执行如下操作:进程创建唤醒锁wakelock,进程包括目标进程,目标进程包括以下进程中的一个或多个:采用写文件节点的方式创建wakelock的进程,采用调用电子设备的内核kernel层对应接口的方式创建wakelock的进程;将目标进程的标识和目标进程创建的wakelock关联存储;在确定目标进程异常退出时,获取与目标进程的标识对应的wakelock;在确定与目标进程的标识对应的wakelock的状态为激活态时,释放wakelock。In the second aspect, an embodiment of the present application provides an electronic device. The electronic device may include a processor and a memory; the processor and the memory are coupled, and the memory is used to store computer program codes. The computer program codes include computer instructions. When the electronic device is executed, the electronic device is caused to perform the following operations: the process creates a wakelock wakelock, the process includes the target process, and the target process includes one or more of the following processes: the process of creating the wakelock by writing to the file node, and calling the electronic device The kernel kernel layer of the kernel layer corresponds to the interface to create the wakelock process; the target process identifier and the wakelock created by the target process are associated and stored; when the target process is determined to exit abnormally, the wakelock corresponding to the target process identifier is obtained; When the state of the wakelock corresponding to the mark is activated, the wakelock is released.
在一种可能的实现方式中,目标进程采用写文件节点的方式创建wakelock,包括:目标进程将目标进程所需创建的wakelock的锁名称写入对应的文件节点;将目标进程的标识和目标进程创建的wakelock关联存储,包括:内核层获取目标进程的标识,在内核层创建唤醒源wake_source节点,wake_source节点中包括目标进程的标识和目标进程所需创建的wakelock的锁名称。In a possible implementation, the target process creates a wakelock by writing a file node, including: the target process writes the lock name of the wakelock that the target process needs to create into the corresponding file node; and the target process identifier and the target process The created wakelock associated storage includes: the kernel layer obtains the identifier of the target process, and the wake_source node is created at the kernel layer. The wake_source node includes the identifier of the target process and the name of the wakelock that the target process needs to create.
在另一种可能的实现方式中,目标进程采用调用内核层对应接口的方式创建wakelock,包括:目标进程调用内核层的对应接口,输入目标进程所需创建的wakelock 的锁名称;将目标进程的标识和目标进程创建的wakelock关联存储,包括:内核层获取目标进程的标识,在内核层创建wake_source节点,wake_source节点包括目标进程的标识和目标进程所需创建的wakelock的锁名称。In another possible implementation, the target process creates wakelock by calling the corresponding interface of the kernel layer, including: the target process calls the corresponding interface of the kernel layer, and enters the lock name of the wakelock that the target process needs to create; The identifier and wakelock associated storage created by the target process include: the kernel layer obtains the identifier of the target process and creates a wake_source node at the kernel layer. The wake_source node includes the identifier of the target process and the name of the wakelock that the target process needs to create.
在另一种可能的实现方式中,在确定目标进程异常退出时,获取与目标进程的标识对应的wakelock,包括:在目标进程异常退出时,内核层获取包含目标进程的标识的wake_source节点;在确定与目标进程的标识对应的wakelock的状态为激活态时,释放wakelock,包括:内核层在确定包含目标进程的标识的wake_source节点的状态为激活态时,去激活wake_source节点。In another possible implementation manner, when it is determined that the target process exits abnormally, obtaining the wakelock corresponding to the target process identifier includes: when the target process exits abnormally, the kernel layer obtains the wake_source node containing the target process identifier; When determining that the state of the wakelock corresponding to the identifier of the target process is the active state, releasing the wakelock includes: when the kernel layer determines that the state of the wake_source node containing the identifier of the target process is the active state, deactivating the wake_source node.
在另一种可能的实现方式中,目标进程可以为应用进程,本地native进程或kernel进程。In another possible implementation, the target process may be an application process, a local native process or a kernel process.
第三方面,本申请实施例提供一种计算机存储介质,该计算机存储介质包括计算机指令,当该计算机指令在电子设备上运行时,使得电子设备执行如第一方面或第一方面的可能的实现方式中任一项所述的唤醒锁的管理方法。In a third aspect, embodiments of the present application provide a computer storage medium, the computer storage medium includes computer instructions, when the computer instructions run on an electronic device, the electronic device executes the first aspect or a possible implementation of the first aspect The wake lock management method described in any of the methods.
第四方面,本申请实施例提供一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行如第一方面或第一方面的可能的实现方式中任一项所述的唤醒锁的管理方法。In a fourth aspect, the embodiments of the present application provide a computer program product, which when the computer program product runs on a computer, causes the computer to execute the wake-up as described in the first aspect or any one of the possible implementations of the first aspect Lock management method.
第五方面,本申请实施例提供一种装置,该装置具有实现上述第一方面的方法中电子设备行为的功能。功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括一个或多个与上述功能相对应的模块,例如,创建单元或模块,获取单元或模块,释放单元或模块等。In a fifth aspect, an embodiment of the present application provides a device that has a function of implementing the behavior of an electronic device in the method of the first aspect. The function can be realized by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the aforementioned functions, for example, a creation unit or module, an acquisition unit or module, and a release unit or module.
应当理解的是,本申请中对技术特征、技术方案、有益效果或类似语言的描述并不是暗示在任意的单个实施例中可以实现所有的特点和优点。相反,可以理解的是对于特征或有益效果的描述意味着在至少一个实施例中包括特定的技术特征、技术方案或有益效果。因此,本说明书中对于技术特征、技术方案或有益效果的描述并不一定是指相同的实施例。进而,还可以任何适当的方式组合本实施例中所描述的技术特征、技术方案和有益效果。本领域技术人员将会理解,无需特定实施例的一个或多个特定的技术特征、技术方案或有益效果即可实现实施例。在其他实施例中,还可在没有体现所有实施例的特定实施例中识别出额外的技术特征和有益效果。It should be understood that the description of technical features, technical solutions, beneficial effects or similar language in this application does not imply that all the features and advantages can be realized in any single embodiment. On the contrary, it can be understood that the description of the features or beneficial effects means that a specific technical feature, technical solution or beneficial effect is included in at least one embodiment. Therefore, the descriptions of technical features, technical solutions, or beneficial effects in this specification do not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions, and beneficial effects described in this embodiment can also be combined in any appropriate manner. Those skilled in the art will understand that the embodiments can be implemented without one or more specific technical features, technical solutions, or beneficial effects of the specific embodiments. In other embodiments, additional technical features and beneficial effects may also be identified in specific embodiments that do not reflect all the embodiments.
附图说明Description of the drawings
图1为现有技术提供的一种应用于APT场景的网络架构示意图;Figure 1 is a schematic diagram of a network architecture applied to an APT scenario provided by the prior art;
图2为本申请实施例提供的一种系统架构的简化示意图;FIG. 2 is a simplified schematic diagram of a system architecture provided by an embodiment of the application;
图3为本申请实施例提供的一种唤醒锁的管理方法的流程示意图;FIG. 3 is a schematic flowchart of a wake lock management method provided by an embodiment of the application;
图4为本申请实施例提供的一种唤醒锁的管理装置的组成示意图。FIG. 4 is a schematic diagram of the composition of a wake lock management device provided by an embodiment of the application.
具体实施方式Detailed ways
对于电子设备中的应用,电子设备通常会为其创建多个进程(process),用于执行不同的业务,以实现对应功能。在这些业务中,有些业务(如提示消息的显示)的执行需要系统一直处于工作状态,不能休眠。安卓(Android)提供一种锁的机制,即wakelock,只要持锁系统就无法进入休眠。因此,用于实现应用的功能的进程可通过创建wakelock,确保在执行对应业务的过程中系统不会休眠。For an application in an electronic device, the electronic device usually creates multiple processes for it to execute different services to implement corresponding functions. Among these services, the execution of some services (such as the display of prompt messages) requires the system to be in a working state all the time and cannot sleep. Android (Android) provides a lock mechanism, wakelock, as long as the lock system cannot enter sleep. Therefore, the process used to implement the function of the application can create a wakelock to ensure that the system will not sleep during the execution of the corresponding service.
一般来说,Android系统中的进程可分为三类:应用进程、本地(native)进程和内核(kernel)进程。其中,应用进程可以是指应用创建的进程。Native进程可以是指在电子设备Android系统的native层创建的进程,用于提供本地服务或者系统库的功能。内核态创建的进程可称为kernel进程,如内核驱动进程。另外,native进程和kernel进程一般是常驻的,也就是说在系统启动时便已创建好,当有应用需要实现对应功能时,其便可提供相应的服务。Generally speaking, the processes in the Android system can be divided into three categories: application processes, native processes and kernel processes. The application process may refer to the process created by the application. The native process may refer to a process created in the native layer of the Android system of the electronic device to provide local services or system library functions. The process created in the kernel mode can be called a kernel process, such as a kernel driver process. In addition, the native process and the kernel process are generally resident, that is, they have been created when the system starts, and when an application needs to implement the corresponding function, it can provide the corresponding service.
应用的功能可通过上述三类进程中的一个或多个配合来实现。在本实施例中,用于实现应用的功能的进程创建的wakelock都可以认为是该应用的wakelock,或者说是该应用持有的锁。应用可持有一个或多个wakelock。另外,在进程退出时,也需要释放其创建的wakelock。需要说明的是,在电子设备中,只要有一个进程申请了wakelock,或者说只要有一个应用持锁,电子设备的CPU便不会休眠,一直处于工作状态。The function of the application can be realized by one or more of the above three types of processes. In this embodiment, the wakelock created by the process for implementing the function of the application can be regarded as the wakelock of the application, or a lock held by the application. The application can hold one or more wakelocks. In addition, when the process exits, it also needs to release the wakelock it created. It should be noted that, in an electronic device, as long as a process applies for a wakelock, or as long as an application holds a lock, the CPU of the electronic device will not sleep and is always working.
目前,进程可通过以下方式创建/释放wakelock:Currently, processes can create/release wakelocks in the following ways:
方式1、通过调用节电管理服务(PowerManagerService)的对应接口来创建/释放wakelock。如,通过调用PowerManagerService的acquire接口创建wakelock,通过调用PowerManagerService的release接口释放wakelock。Method 1. Create/release wakelock by invoking the corresponding interface of PowerManagerService. For example, the wakelock is created by calling the acquire interface of PowerManagerService, and the wakelock is released by calling the release interface of PowerManagerService.
方式2、通过调用acquire_wake_lock接口创建wakelock,通过调用release_wake_lock接口释放wakelock。Method 2. Create wakelock by calling acquire_wake_lock interface, and release wakelock by calling release_wake_lock interface.
方式3、通过直接写文件节点的方式,如通过向对应文件节点写入所需创建的wakelock的锁名称来创建/释放wakelock。如,通过写文件/sys/power/wake_lock创建wakelock,通过写文件/sys/power/wake_unlock释放wakelock。Method 3. Create/release a wakelock by directly writing to the file node, such as writing the lock name of the wakelock to be created to the corresponding file node. For example, create wakelock by writing file /sys/power/wake_lock, and release wakelock by writing file /sys/power/wake_unlock.
方式4、通过调用内核层对应接口来创建/释放wakelock。如,通过调用wake_lock/wake_lock_timeout创建wakelock,通过调用wake_unlock/wake_lock_active释放wakelock。Method 4. Create/release wakelock by calling the corresponding interface of the kernel layer. For example, create wakelock by calling wake_lock/wake_lock_timeout, and release wakelock by calling wake_unlock/wake_lock_active.
其中,应用进程一般通过方式1来创建/释放wakelock。native进程可通过方式2或方式3来创建/释放wakelock。kernel进程通过方式4来创建/释放wakelock。Among them, the application process generally creates/releases wakelock through method 1. The native process can create/release wakelock by way 2 or way 3. The kernel process uses method 4 to create/release wakelock.
但,上述释放wakelock的方式仅在进程正常退出的情况下才可生效。在进程异常退出,如进程越界访问时会异常退出的情况下,上述释放wakelock的方式是无法生效的。也就是说,在进程异常退出时,其创建的wakelock没办法正常释放,或会出现遗漏释放的情况,这时会导致统无法休眠,带来高耗电的问题。其中,可将用于实现应用的功能的进程退出但其申请的wakelock没有释放的情况称为应用异常持锁。However, the above method of releasing wakelock only takes effect when the process exits normally. In the case where the process exits abnormally, such as the process exits abnormally when it cross-bounds access, the above-mentioned method of releasing wakelock cannot take effect. In other words, when the process exits abnormally, the wakelock created by it cannot be released normally, or the release will be missed, which will cause the system to fail to sleep and cause high power consumption. Among them, the situation in which the process used to implement the function of the application exits but the wakelock applied for is not released is called abnormal application lock holding.
在现有技术中,为了避免应用异常持锁的情况出现,电子设备的节电管理服务(Power Manager Service,PMS)可通过binder机制对持锁的应用状态进行检测。在应用出现异常时,通过binder机制电子设备可检测出该应用没有响应。此时,电子设备会主动释放应用所持有的wakelock。但binder机制只能释放掉通过上述方式1或方式2创建的wakelock,对于通过上述方式3及方式4创建的wakelock无法生效。In the prior art, in order to avoid the occurrence of abnormal lock-holding of applications, the Power Manager Service (PMS) of the electronic device can detect the lock-holding application state through the binder mechanism. When the application is abnormal, the electronic device can detect that the application is not responding through the binder mechanism. At this time, the electronic device will actively release the wakelock held by the application. But the binder mechanism can only release the wakelock created by the above method 1 or method 2, and it cannot take effect for the wakelock created by the above method 3 and method 4.
对于通过上述方式3或方式4创建的wakelock,可利用以下两种检测机制来进行应用异常持锁的检测。机制1、由持锁的应用根据业务的结束情况,来检测该应用是否存在异常持锁情况。如果应用的业务已结束,但执行该业务的进程申请的wakelock 却没有释放,则确定存在应用异常持锁的情况。此时,可释放对应wakelock。机制2、由系统采用类似监视器(watchdog)的方式,监控所有持锁的应用。如果某个应用一段时间内没有响应,则认为该应用异常,或者说确定该应用存在异常持锁的情况。此时,可释放该应用所持有的wakelock。For the wakelock created by the above method 3 or method 4, the following two detection mechanisms can be used to detect the application of abnormal holding lock. Mechanism 1. The lock-holding application detects whether there is an abnormal lock-holding situation in the application according to the end of the service. If the application's business has ended, but the wakelock requested by the process executing the business is not released, it is determined that the application is holding the lock abnormally. At this time, the corresponding wakelock can be released. Mechanism 2. The system monitors all lock-holding applications in a manner similar to a watchdog. If an application does not respond within a period of time, it is considered that the application is abnormal, or it is determined that the application is abnormally locked. At this point, the wakelock held by the application can be released.
但是,在上述机制1中,应用是无法精确识别业务的结束情况的,即可能出现误判,如业务已结束,但应用却没有识别出。另,当应用异常时,该检测机制也会失效。这样,依然会出现应用异常持锁的情况。在上述机制2中,需系统对所有持锁的应用进行轮询监控,这会带来较大的系统开销。另,这种监测机制需要修改应用的实现,使其可注册watchdog,不具备普适性。也就是说,对于通过上述方式3或方式4创建的wakelock,目前的机制并不能很好的解决应用异常持锁导致的系统无法休眠,设备耗电量高的问题。However, in the above mechanism 1, the application cannot accurately identify the end of the service, that is, a misjudgment may occur. For example, the service has ended, but the application does not recognize it. In addition, when the application is abnormal, the detection mechanism will also fail. In this way, there will still be situations where the application locks abnormally. In the above mechanism 2, the system needs to poll and monitor all lock-holding applications, which will bring greater system overhead. In addition, this monitoring mechanism needs to modify the implementation of the application so that it can register watchdogs, which is not universal. That is to say, for the wakelock created by the above method 3 or method 4, the current mechanism cannot well solve the problem of the system cannot sleep and the device consumes high power due to the abnormal lock holding of the application.
本申请实施例提供一种唤醒锁的管理方法,对于通过上述方式3或方式4创建的wakelock,在对应进程异常退出后,能够自动释放该进程申请的wakelock,避免应用异常持锁的情况出现,保证系统及时休眠,延长了电子设备的续航时间。另外,本实施例提供的方案不会带来大的系统开销,且具备普适性。The embodiment of the present application provides a method for managing wake locks. For a wakelock created by the above method 3 or method 4, after the corresponding process exits abnormally, the wakelock applied for by the process can be automatically released to avoid the application of abnormal lock holding situations. Ensure that the system sleeps in time, extending the battery life of electronic devices. In addition, the solution provided by this embodiment does not cause large system overhead and has universal applicability.
示例性的,本申请实施例中所述的电子设备可以是手机、平板电脑、桌面型、膝上型、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本,以及蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)\虚拟现实(virtual reality,VR)设备、可穿戴设备(如智能手表)、媒体播放器等设备,本申请实施例对该设备的具体形态不作特殊限制。Exemplarily, the electronic devices described in the embodiments of this application may be mobile phones, tablet computers, desktop computers, laptops, handheld computers, notebook computers, ultra-mobile personal computers (UMPC), netbooks, As well as cellular phones, personal digital assistants (PDA), augmented reality (AR)\virtual reality (VR) devices, wearable devices (such as smart watches), media players, etc. The application embodiment does not impose special restrictions on the specific form of the device.
下面将结合附图对本申请实施例的实施方式进行详细描述。The implementation of the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.
请参考图1,为本申请实施例提供的一种电子设备的结构示意图。如图1所示,电子设备可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriber identification module,SIM)卡接口195等。Please refer to FIG. 1, which is a schematic structural diagram of an electronic device provided by an embodiment of this application. As shown in FIG. 1, 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, and a battery 142, Antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, earphone interface 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, A display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
其中,传感器模块180可以包括压力传感器,陀螺仪传感器,气压传感器,磁传感器,加速度传感器,距离传感器,接近光传感器,指纹传感器,温度传感器,触摸传感器,环境光传感器,骨传导传感器等。The sensor module 180 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
可以理解的是,本实施例示意的结构并不构成对电子设备的具体限定。在另一些实施例中,电子设备可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device. In other embodiments, the electronic device may include more or fewer components than shown, or combine certain components, or split certain components, or arrange different components. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,存储器, 视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural-network processing unit (NPU) Wait. Among them, the different processing units may be independent devices or integrated in one or more processors.
控制器可以是电子设备的神经中枢和指挥中心。控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。The controller can be the nerve center and command center of the electronic device. The controller can generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching and executing instructions.
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。A memory may also be provided in the processor 110 to store instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can store instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. Repeated accesses are avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved.
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,SIM接口,和/或USB接口等。In some embodiments, the processor 110 may include one or more interfaces. The interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, and a universal asynchronous transmitter (universal asynchronous transmitter) interface. receiver/transmitter, UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, SIM interface, and/or USB interface, etc.
充电管理模块140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。充电管理模块140为电池142充电的同时,还可以通过电源管理模块141为电子设备供电。The charging management module 140 is used to receive charging input from the charger. Among them, the charger can be a wireless charger or a wired charger. While the charging management module 140 charges the battery 142, it can also supply power to the electronic device through the power management module 141.
电源管理模块141用于连接电池142,充电管理模块140与处理器110。电源管理模块141接收电池142和/或充电管理模块140的输入,为处理器110,内部存储器121,外部存储器,显示屏194,摄像头193,和无线通信模块160等供电。电源管理模块141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块141也可以设置于处理器110中。在另一些实施例中,电源管理模块141和充电管理模块140也可以设置于同一个器件中。The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle times, and battery health status (leakage, impedance). In some other embodiments, the power management module 141 may also be provided in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may also be provided in the same device.
电子设备的无线通信功能可以通过天线1,天线2,移动通信模块150,无线通信模块160,调制解调处理器以及基带处理器等实现。The wireless communication function of the electronic device can be realized by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor.
天线1和天线2用于发射和接收电磁波信号。The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals.
移动通信模块150可以提供应用在电子设备上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块150可以由天线1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块150还可以对经调制解调处理器调制后的信号放大,经天线1转为电磁波辐射出去。The mobile communication module 150 can provide wireless communication solutions including 2G/3G/4G/5G and the like applied to electronic devices. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves by the antenna 1, and perform processing such as filtering, amplifying and transmitting the received electromagnetic waves to the modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor, and convert it into electromagnetic waves for radiation via the antenna 1.
无线通信模块160可以提供应用在电子设备上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块160经由天线2接收电 磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器110。无线通信模块160还可以从处理器110接收待发送的信号,对其进行调频,放大,经天线2转为电磁波辐射出去。The wireless communication module 160 can provide applications in electronic devices including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), and global navigation satellite systems. (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR) and other wireless communication solutions. The wireless communication module 160 may be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, perform frequency modulation, amplify it, and convert it into electromagnetic wave radiation via the antenna 2.
在一些实施例中,电子设备的天线1和移动通信模块150耦合,天线2和无线通信模块160耦合,使得电子设备可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。In some embodiments, the antenna 1 of the electronic device is coupled with the mobile communication module 150, and the antenna 2 is coupled with the wireless communication module 160, so that the electronic device can communicate with the network and other devices through wireless communication technology. The wireless communication technologies may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code division multiple access (wideband code division multiple access, WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc. The GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (quasi -zenith satellite system, QZSS) and/or satellite-based augmentation systems (SBAS).
电子设备通过GPU,显示屏194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。The electronic device realizes the display function through GPU, display screen 194, and application processor. The GPU is a microprocessor for image processing, connected to the display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
显示屏194用于显示图像,视频等。显示屏194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备可以包括1个或N个显示屏194,N为大于1的正整数。The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can adopt liquid crystal display (LCD), organic light-emitting diode (OLED), active-matrix organic light-emitting diode or active-matrix organic light-emitting diode (active-matrix organic light-emitting diode). emitting diode, AMOLED, flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device may include 1 or N display screens 194, and N is a positive integer greater than 1.
电子设备可以通过ISP,摄像头193,视频编解码器,GPU,显示屏194以及应用处理器等实现拍摄功能。Electronic equipment can realize shooting functions through ISP, camera 193, video codec, GPU, display 194, and application processor.
ISP用于处理摄像头193反馈的数据。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头193中。The ISP is used to process the data fed back from the camera 193. ISP can also optimize the image noise, brightness, and skin color. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP may be provided in the camera 193.
摄像头193用于捕获静态图像或视频。在一些实施例中,电子设备可以包括1个或N个摄像头193,N为大于1的正整数。The camera 193 is used to capture still images or videos. In some embodiments, the electronic device may include 1 or N cameras 193, and N is a positive integer greater than 1.
数字信号处理器用于处理数字信号。视频编解码器用于对数字视频压缩或解压缩。电子设备可以支持一种或多种视频编解码器。Digital signal processors are used to process digital signals. Video codecs are used to compress or decompress digital video. The electronic device can support one or more video codecs.
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。NPU is a neural-network (NN) computing processor. By drawing on the structure of biological neural networks, for example, the transfer mode between human brain neurons, it can quickly process input information and can continuously learn by itself. NPU can realize the intelligent cognition of electronic devices and other applications, such as: image recognition, face recognition, voice recognition, text understanding, etc.
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor 110 through the external memory interface 120 to realize the data storage function. For example, save music, video and other files in an external memory card.
内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。处理器110通过运行存储在内部存储器121的指令,从而执行电子设备的各种功能应用以及数据处理。例如,在本申请实施例中,处理器110可以通过执行存储在内部存储器121中的指令,在进程异常退出后,自动释放该进程申请的wakelock。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。The internal memory 121 may be used to store computer executable program code, where the executable program code includes instructions. The processor 110 executes various functional applications and data processing of the electronic device by running instructions stored in the internal memory 121. For example, in the embodiment of the present application, the processor 110 may automatically release the wakelock applied for by the process after the process exits abnormally by executing the instructions stored in the internal memory 121. The internal memory 121 may include a storage program area and a storage data area. Among them, the storage program area can store an operating system, at least one application program (such as a sound playback function, an image playback function, etc.) required by at least one function. The data storage area can store data (such as audio data, phone book, etc.) created during the use of the electronic device. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash storage (UFS), etc.
电子设备可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。The electronic device can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor. For example, music playback, recording, etc.
音频模块170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块170还可以用于对音频信号编码和解码。在一些实施例中,音频模块170可以设置于处理器110中,或将音频模块170的部分功能模块设置于处理器110中。The audio module 170 is used to convert digital audio information into an analog audio signal for output, and is also used to convert an analog audio input into a digital audio signal. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 may be provided in the processor 110, or part of the functional modules of the audio module 170 may be provided in the processor 110.
扬声器170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备可以通过扬声器170A收听音乐,或收听免提通话。The speaker 170A, also called a "speaker", is used to convert audio electrical signals into sound signals. The electronic device can listen to music through the speaker 170A, or listen to a hands-free call.
受话器170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备接听电话或语音信息时,可以通过将受话器170B靠近人耳接听语音。The receiver 170B, also called "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device answers a call or voice message, it can receive the voice by bringing the receiver 170B close to the human ear.
麦克风170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风170C发声,将声音信号输入到麦克风170C。电子设备可以设置至少一个麦克风170C。The microphone 170C, also called "microphone", "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can approach the microphone 170C through the mouth to make a sound, and input the sound signal to the microphone 170C. The electronic device may be provided with at least one microphone 170C.
耳机接口170D用于连接有线耳机。耳机接口170D可以是USB接口130,也可以是3.5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。The earphone interface 170D is used to connect wired earphones. The earphone interface 170D may be a USB interface 130, or a 3.5mm open mobile terminal platform (OMTP) standard interface, or a cellular telecommunications industry association (cellular telecommunications industry association of the USA, CTIA) standard interface.
压力传感器用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器可以设置于显示屏194。压力传感器的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。The pressure sensor is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor may be provided on the display screen 194. There are many types of pressure sensors, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc.
陀螺仪传感器可以用于确定电子设备的运动姿态。在一些实施例中,可以通过陀螺仪传感器确定电子设备围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器可以用于拍摄防抖。陀螺仪传感器还可以用于导航,体感游戏场景。The gyroscope sensor can be used to determine the movement posture of the electronic device. In some embodiments, the angular velocity of the electronic device around three axes (ie, x, y, and z axes) can be determined by a gyroscope sensor. The gyroscope sensor can be used for shooting anti-shake. The gyroscope sensor can also be used for navigation and somatosensory game scenes.
气压传感器用于测量气压。在一些实施例中,电子设备通过气压传感器测得的气压值计算海拔高度,辅助定位和导航。磁传感器包括霍尔传感器。电子设备可以利用磁传感器检测翻盖皮套的开合。加速度传感器可检测电子设备在各个方向上(一般为 三轴)加速度的大小。当电子设备静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。距离传感器,用于测量距离。The air pressure sensor is used to measure air pressure. In some embodiments, the electronic device calculates the altitude based on the air pressure value measured by the air pressure sensor to assist positioning and navigation. The magnetic sensor includes a Hall sensor. The electronic device can use a magnetic sensor to detect the opening and closing of the flip holster. The acceleration sensor can detect the magnitude of the acceleration of the electronic device in all directions (usually three-axis). The magnitude and direction of gravity can be detected when the electronic device is stationary. It can also be used to identify the posture of electronic devices, and used in applications such as horizontal and vertical screen switching, pedometers and so on. Distance sensor, used to measure distance.
接近光传感器可以包括例如发光二极管(LED)和光检测器,例如光电二极管。电子设备通过发光二极管向外发射红外光。电子设备使用光电二极管检测来自附近物体的红外反射光,以确定电子设备附近是否有物体。The proximity light sensor may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The electronic device emits infrared light through the light-emitting diode. Electronic equipment uses photodiodes to detect infrared reflected light from nearby objects to determine whether there are objects near the electronic equipment.
环境光传感器用于感知环境光亮度。电子设备可以根据感知的环境光亮度自适应调节显示屏194亮度。环境光传感器也可用于拍照时自动调节白平衡。环境光传感器还可以与接近光传感器配合,检测电子设备是否在口袋里,以防误触。The ambient light sensor is used to sense the brightness of the ambient light. The electronic device can adaptively adjust the brightness of the display screen 194 according to the perceived brightness of the ambient light. The ambient light sensor can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor can also cooperate with the proximity light sensor to detect whether the electronic device is in the pocket to prevent accidental touch.
指纹传感器用于采集指纹。电子设备可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。The fingerprint sensor is used to collect fingerprints. Electronic devices can use the collected fingerprint characteristics to unlock fingerprints, access application locks, take photos with fingerprints, and answer calls with fingerprints.
温度传感器用于检测温度。在一些实施例中,电子设备利用温度传感器检测的温度,执行温度处理策略。The temperature sensor is used to detect temperature. In some embodiments, the electronic device uses the temperature detected by the temperature sensor to execute the temperature processing strategy.
触摸传感器,也称“触控面板”。触摸传感器可以设置于显示屏194,由触摸传感器与显示屏194组成触摸屏,也称“触控屏”。触摸传感器用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器也可以设置于电子设备的表面,与显示屏194所处的位置不同。Touch sensor, also called "touch panel". The touch sensor may be provided on the display screen 194, and the touch screen is composed of the touch sensor and the display screen 194, which is also called a “touch screen”. The touch sensor is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. The visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor may also be disposed on the surface of the electronic device, which is different from the position of the display screen 194.
骨传导传感器可以获取振动信号。在一些实施例中,骨传导传感器可以获取人体声部振动骨块的振动信号。骨传导传感器也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器也可以设置于耳机中。Bone conduction sensors can acquire vibration signals. In some embodiments, the bone conduction sensor can obtain the vibration signal of the vibrating bone mass of the human voice. The bone conduction sensor can also contact the human pulse and receive the blood pressure pulse signal. In some embodiments, the bone conduction sensor may also be provided in the earphone.
按键190包括开机键,音量键等。按键190可以是机械按键。也可以是触摸式按键。电子设备可以接收按键输入,产生与电子设备的用户设置以及功能控制有关的键信号输入。马达191可以产生振动提示。马达191可以用于来电振动提示,也可以用于触摸振动反馈。指示器192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。The button 190 includes a power button, a volume button, and so on. The button 190 may be a mechanical button. It can also be a touch button. The electronic device can receive key input and generate key signal input related to user settings and function control of the electronic device. The motor 191 can generate vibration prompts. The motor 191 can be used for incoming call vibration notification, and can also be used for touch vibration feedback. The indicator 192 may be an indicator light, which may be used to indicate the charging status, power change, or to indicate messages, missed calls, notifications, and so on.
SIM卡接口195用于连接SIM卡。SIM卡可以通过插入SIM卡接口195,或从SIM卡接口195拔出,实现和电子设备的接触和分离。电子设备可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。电子设备通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备中,不能和电子设备分离。The SIM card interface 195 is used to connect to the SIM card. The SIM card can be inserted into the SIM card interface 195 or pulled out from the SIM card interface 195 to achieve contact and separation with the electronic device. The electronic device can support 1 or N SIM card interfaces, and N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. The electronic device interacts with the network through the SIM card to realize functions such as call and data communication. In some embodiments, the electronic device adopts eSIM, that is, an embedded SIM card. The eSIM card can be embedded in the electronic device and cannot be separated from the electronic device.
电子设备的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的Android系统为例,示例性说明电子设备的软件结构。The software system of the electronic device can adopt a layered architecture, event-driven architecture, micro-core architecture, micro-service architecture, or cloud architecture. The embodiment of the present application takes an Android system with a layered architecture as an example to illustrate the software structure of an electronic device.
图2为本申请实施例提供的一种电子设备的软件结构示意图。分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。如图2所示,在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层(framework),native层,以及内核层。FIG. 2 is a schematic diagram of the software structure of an electronic device provided by an embodiment of the application. The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Communication between layers through software interface. As shown in FIG. 2, in some embodiments, the Android system is divided into four layers, from top to bottom, the application layer, the application framework layer (framework), the native layer, and the kernel layer.
其中,应用程序层可以包括一系列应用程序包。例如,应用程序包可以包括微信, 亚马逊,日历,通话,地图,音乐播放器,视频播放器,短信息等应用程序。Among them, the application layer may include a series of application packages. For example, the application package may include applications such as WeChat, Amazon, calendar, call, map, music player, video player, short message, etc.
应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架,以为应用程序层中应用的运行提供支撑。The application framework layer provides application programming interfaces (application programming interface, API) and programming frameworks for applications in the application layer to provide support for the operation of applications in the application layer.
native层用于为应用程序层中的应用提供系统服务,位置服务,触摸服务,显示服务等。The native layer is used to provide system services, location services, touch services, display services, etc. for applications in the application layer.
内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动,位置驱动(如GPS驱动)等。The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, sensor driver, location driver (such as GPS driver) and so on.
在本实施例中,在系统启动时,电子设备会创建用于提供对应服务的native进程和/或kernel进程。另外,电子设备的应用程序层的应用启动时,会创建对应的应用进程。这样,利用这些进程中的一个或多个配合,可实现应用对应的功能。例如,在系统启动时,电子设备创建了用于提供位置服务的native进程1和kernel进程1。那么,native进程1和kernel进程1便可提供相应的位置服务,以实现应用,如亚马逊的定位功能。In this embodiment, when the system is started, the electronic device creates a native process and/or a kernel process for providing corresponding services. In addition, when the application of the application layer of the electronic device is started, a corresponding application process is created. In this way, by using one or more of these processes, the corresponding functions of the application can be realized. For example, when the system is started, the electronic device creates a native process 1 and a kernel process 1 for providing location services. Then, native process 1 and kernel process 1 can provide corresponding location services to implement applications such as Amazon's location function.
示例性的,以下实施例中所涉及的技术方案均可以在具有上述硬件架构和软件架构的电子设备中实现。以下结合附图和应用场景对本申请实施例提供的控制方法进行详细介绍。Exemplarily, the technical solutions involved in the following embodiments can all be implemented in an electronic device having the foregoing hardware architecture and software architecture. The control method provided by the embodiment of the present application will be described in detail below with reference to the drawings and application scenarios.
图3为本申请实施例提供的一种唤醒锁的管理方法的流程示意图。如图3所示,该方法可以包括:FIG. 3 is a schematic flowchart of a wake lock management method provided by an embodiment of the application. As shown in Figure 3, the method may include:
S301、电子设备的进程创建wakelock。S301. The process of the electronic device creates a wakelock.
对于电子设备中的应用,电子设备会为其创建多个进程,用于执行对应业务,以实现应用的功能。在创建的进程中,有些进程执行的业务需要系统一直处于工作状态,不能休眠。这些进程可通过创建唤醒锁(wakelock),来确保在执行对应业务的过程中系统不会休眠。For an application in an electronic device, the electronic device creates multiple processes for it to execute corresponding services to realize the functions of the application. In the created process, the business performed by some processes requires the system to be in a working state and cannot sleep. These processes can create wakelocks to ensure that the system does not sleep during the execution of the corresponding services.
一般的,以电子设备的操作系统为Android系统为例。参考图2,Android系统中的进程可分为三类:应用进程、native进程和kernel进程。应用的功能可通过这三类进程中的一个或多个配合来实现。在本实施例中,用于实现应用的功能的进程创建的wakelock都可以认为是该应用的wakelock,或者说是该应用持有的锁。应用可持有一个或多个wakelock。Generally, the operating system of the electronic device is the Android system as an example. Referring to Figure 2, the processes in the Android system can be divided into three categories: application processes, native processes and kernel processes. The function of the application can be realized through one or more of these three types of processes. In this embodiment, the wakelock created by the process for implementing the function of the application can be regarded as the wakelock of the application, or a lock held by the application. The application can hold one or more wakelocks.
目前进程可通过以下四种方式创建/释放wakelock:The current process can create/release wakelock in the following four ways:
方式1、通过调用PowerManagerService的对应接口来创建/释放wakelock。Method 1. Create/release wakelock by calling the corresponding interface of PowerManagerService.
方式2、通过调用acquire_wake_lock接口创建wakelock,通过调用release_wake_lock接口释放wakelock。Method 2. Create wakelock by calling acquire_wake_lock interface, and release wakelock by calling release_wake_lock interface.
方式3、通过直接写文件节点的方式,如通过向对应文件节点写入进程所需创建的wakelock的锁名称来创建/释放wakelock。Method 3. Create/release a wakelock by directly writing to the file node, for example, by writing the lock name of the wakelock that the process needs to create to the corresponding file node.
方式4、通过调用内核层对应接口来创建/释放wakelock。Method 4. Create/release wakelock by calling the corresponding interface of the kernel layer.
示例性的,对于应用进程一般可通过上述方式1来创建/释放wakelock。native进程可通过方式2或方式3来创建/释放wakelock。kernel进程可通过方式4来创建/释放wakelock。另外,以任何方式创建的wakelock,最终会在内核层创建一个wake_source节点。Exemplarily, for the application process, the wakelock can be created/released through the above method 1. The native process can create/release wakelock by way 2 or way 3. The kernel process can create/release wakelock through method 4. In addition, a wakelock created in any way will eventually create a wake_source node in the kernel layer.
例如,以应用进程(如称为进程A)采用方式1创建wakelock为例。进程A在其执行的业务需要系统不休眠时,进程A可通过应用程序框架层提供的节电管理服务(PowerMangerService),调用PowerManagerService的acquire接口来创建wakelock。如,将进程A创建的wakelock称为wakelock_A。具体的,进程A通过调用PowerManagerService的acquire接口,输入进程A所需创建的wakelock_A的锁名称。native层根据调用可获取到进程A的标识,如PID_A,并通过调用acquire_wake_lock接口,以在对应的文件节点,如/sys/power/wake_lock中写入该进程A的标识,即PID_A和wakelock_A的锁名称。之后,进程A的wakelock_A创建完成。For example, take the application process (such as process A) using method 1 to create a wakelock as an example. When process A needs the system not to sleep during the business it is executing, process A can use the power saving management service (PowerMangerService) provided by the application framework layer to call the acquire interface of PowerManagerService to create a wakelock. For example, the wakelock created by process A is called wakelock_A. Specifically, process A calls the acquire interface of PowerManagerService and enters the lock name of wakelock_A that process A needs to create. The native layer can obtain the identity of process A according to the call, such as PID_A, and call the acquire_wake_lock interface to write the identity of process A in the corresponding file node, such as /sys/power/wake_lock, that is, the locks of PID_A and wakelock_A name. After that, the wakelock_A of process A is created.
又例如,以native进程(如称为进程B)采用方式2创建wakelock为例。进程B在其执行的业务需要系统不休眠时,进程B可通过调用对应接口,如acquire_wake_lock来创建wakelock。如,将进程B创建的wakelock称为wakelock_B。具体的,进程B通过调用接口acquire_wake_lock,输入进程B所需创建的wakelock_B的锁名称。native层根据调用可获取到进程B的标识,如PID_B,并在对应的文件节点,如/sys/power/wake_lock中写入该进程B的标识,即PID_B和wakelock_B的锁名称。之后,进程B的wakelock_B创建完成。For another example, take a native process (such as process B) using method 2 to create a wakelock as an example. Process B can create a wakelock by calling the corresponding interface, such as acquire_wake_lock, when the business it is executing requires that the system does not sleep. For example, the wakelock created by process B is called wakelock_B. Specifically, process B inputs the lock name of wakelock_B that process B needs to create by calling the interface acquire_wake_lock. The native layer can obtain the identity of process B according to the call, such as PID_B, and write the identity of process B in the corresponding file node, such as /sys/power/wake_lock, that is, the lock names of PID_B and wakelock_B. After that, the wakelock_B of process B is created.
再例如,以native进程(如称为进程C)采用方式3创建wakelock为例。进程C在其执行的业务需要系统不休眠时,进程C可通过写文件节点的方式来创建wakelock。如,将进程C创建的wakelock称为wakelock_C。具体的,进程C可直接在对应的文件节点,如/sys/power/wake_lock中写入该进程C所需创建的wakelock_C的锁名称。之后,进程C的wakelock_C创建完成。For another example, take a native process (such as process C) using method 3 to create a wakelock as an example. Process C can create a wakelock by writing a file node when the business it is executing requires that the system does not sleep. For example, the wakelock created by process C is called wakelock_C. Specifically, the process C can directly write the lock name of the wakelock_C that the process C needs to create in the corresponding file node, such as /sys/power/wake_lock. After that, the wakelock_C of process C is created.
再例如,以kernel进程(如称为进程D)采用方式4创建wakelock为例。进程D在其执行的业务需要系统不休眠时,进程D可通过调用内核层对应接口,如wake_lock/wake_lock_timeout,输入进程D所需创建的wakelock的锁名称。如,将进程D创建的wakelock称为wakelock_D。之后,进程D的wakelock_D创建完成。For another example, take the kernel process (such as process D) using method 4 to create a wakelock as an example. When process D needs the system not to sleep during the business it is executing, process D can call the corresponding interface of the kernel layer, such as wake_lock/wake_lock_timeout, and enter the name of the wakelock that process D needs to create. For example, the wakelock created by process D is called wakelock_D. After that, the wakelock_D of process D is created.
S302、电子设备将目标进程的标识和该目标进程创建的wakelock关联存储,该目标进程包括以下进程中的一个或多个:采用写文件节点的方式创建wakelock的进程,采用调用内核层对应接口的方式创建wakelock的进程。S302. The electronic device stores the identifier of the target process in association with the wakelock created by the target process. The target process includes one or more of the following processes: a process that creates a wakelock by writing a file node, and calls a corresponding interface at the kernel layer. Way to create a wakelock process.
目前,对于进程的文件句柄、占用的内存、套接字(socket)等资源,是作为进程管理的资源,在进程退出时自动进行释放的。在本实施例中,也可以将wakelock作为进程管理的一种资源,以达到进程退出时自动释放其创建的wakelock的目的。其中,对于采用上述方式1及方式2创建wakelock的进程,在其异常退出时,可通过binder机制来释放其创建的wakelock。由于该机制并不适用采用上述方式3及方式4创建wakelock的进程,因此,在本实施例中,可仅针对采用上述方式3及方式4创建wakelock的进程,将其创建的wakelock作为进程管理的一种资源。Currently, resources such as file handles, occupied memory, and sockets of a process are used as resources managed by the process, and are automatically released when the process exits. In this embodiment, wakelock can also be used as a resource managed by the process to achieve the purpose of automatically releasing the wakelock created by the process when it exits. Among them, for a process that uses the above method 1 and method 2 to create a wakelock, when it exits abnormally, the wakelock created by it can be released through the binder mechanism. Since this mechanism is not applicable to processes that create wakelocks using the above methods 3 and 4, in this embodiment, only the processes that create wakelocks using the above methods 3 and 4 can be used as process management. A resource.
具体的,对于采用写文件节点的方式及采用调用内核层对应接口的方式创建wakelock的进程,如称为目标进程,在内核层创建对应wake_source节点时,内核层可将该目标进程创建的wakelock和该目标进程的标识关联存储起来。如,内核层将在内核层中创建的wake_source节点与该wake_source节点所属进程的PID关联存储。这样,便可将其创建的wakelock作为进程管理的资源,方便后续进行管理。Specifically, for a process that creates a wakelock by writing a file node and by calling the corresponding interface of the kernel layer, such as a target process, when a corresponding wake_source node is created at the kernel layer, the kernel layer can create a wakelock and a wakelock created by the target process. The identification of the target process is stored in association. For example, the kernel layer stores the wake_source node created in the kernel layer in association with the PID of the process to which the wake_source node belongs. In this way, the wakelock created by it can be used as a resource for process management to facilitate subsequent management.
例如,结合S301中的示例,进程C是通过写文件节点的方式来创建wakelock的。在进程C将所需创建的wakelock_C的锁名称写入对应的文件节点,完成wakelock_C的创建后,内核层可获取到该进程C的标识,即PID_C,并在内核层创建进程C的wake_source节点,如称为wake_source节点C时,可将进程C的PID,即PID_C和进程C所需创建的wakelock_C的锁名称写入该wake_source节点C中,以将创建的wake_source节点C与该wake_source节点C所属进程的PID关联起来。For example, in combination with the example in S301, process C creates wakelock by writing file nodes. After process C writes the lock name of wakelock_C that needs to be created into the corresponding file node, after completing the creation of wakelock_C, the kernel layer can obtain the identity of the process C, namely PID_C, and create the wake_source node of process C in the kernel layer. For example, when it is called wake_source node C, the PID of process C, that is, PID_C and the lock name of wakelock_C to be created by process C, can be written into the wake_source node C, so that the created wake_source node C and the process to which wake_source node C belongs The PID is associated.
又例如,结合S301中的示例,进程D是通过调用内核层对应接口的方式来创建wakelock的。在进程D通过调用内核层的对应接口,输入进程D所需创建的wakelock_D的锁名称,完成wakelock_D的创建后,内核层根据调用,可获取到该进程D的标识,即PID_D,并在内核层创建进程D的wake_source节点,如称为wake_source节点D时,可将进程D的PID,即PID_D和进程D所需创建的wakelock_D的锁名称写入该wake_source节点D中,以将创建的wake_source节点D与该wake_source节点D所属进程的PID关联起来。For another example, in combination with the example in S301, process D creates wakelock by calling the corresponding interface of the kernel layer. In process D, by calling the corresponding interface of the kernel layer, enter the lock name of wakelock_D that process D needs to create, and after completing the creation of wakelock_D, the kernel layer can obtain the identity of process D, namely PID_D, and in the kernel layer. Create the wake_source node of process D, for example, when it is called wake_source node D, the PID of process D, namely PID_D and the lock name of wakelock_D to be created by process D, can be written into the wake_source node D, so as to create wake_source node D It is associated with the PID of the process to which the wake_source node D belongs.
当然,对于采用方式1创建wakelock的进程,如结合S301的示例中的进程A,及采用方式2创建wakelock的进程,如进程B,在进程A和进程B完成wakelock的创建后,内核层也会对应的在内核层创建一wake_source节点,该wake_source节点中可包括对应进程所需创建的wakelock的锁名称。如,内核层在内核层为进程A创建wake_source节点A,该wake_source节点A包括进程A所需创建的wakelock_A的锁名称。又如,内核层在内核层为进程B创建wake_source节点B,该wake_source节点B包括进程B所需创建的wakelock_B的锁名称。Of course, for a process that uses method 1 to create a wakelock, such as process A in the example of S301, and a process that uses method 2 to create a wakelock, such as process B, after process A and process B complete the creation of wakelock, the kernel layer will also Correspondingly, a wake_source node is created at the kernel layer, and the wake_source node may include the lock name of the wakelock that the corresponding process needs to create. For example, the kernel layer creates wake_source node A for process A in the kernel layer, and the wake_source node A includes the lock name of wakelock_A that process A needs to create. For another example, the kernel layer creates a wake_source node B for process B in the kernel layer, and the wake_source node B includes the lock name of wakelock_B that process B needs to create.
S303、电子设备在确定目标进程异常退出时,获取与该目标进程的标识对应的wakelock。S303. When determining that the target process exits abnormally, the electronic device acquires a wakelock corresponding to the identifier of the target process.
S304、电子设备在确定与该目标进程的标识对应的wakelock的状态为激活态时,释放该wakelock。S304. The electronic device releases the wakelock when determining that the state of the wakelock corresponding to the identifier of the target process is the active state.
如果用于实现应用的功能的进程退出但其申请的wakelock没有释放,则可认为出现了应用异常持锁的情况。为了避免该情况出现,对于采用上述方式1及方式2创建wakelock的进程,如S301的示例中进程A和进程B,在其异常退出时,电子设备的PMS可通过binder机制检测到应用存在异常持锁的情况,即检测到进程A或进程B已退出,但其创建的wakelock并未释放,此时电子设备会主动释放该进程所创建的wakelock。而对于采用上述方式3及方式4创建wakelock的进程,如S301的示例中进程C和进程D,在其异常退出时,上述binder机制并不能适用。If the process used to implement the function of the application exits but the wakelock it applied for is not released, it can be considered that the application is holding the lock abnormally. In order to avoid this situation, for processes that create wakelock using the above methods 1 and 2, such as process A and process B in the example of S301, when they exit abnormally, the PMS of the electronic device can detect the abnormal hold of the application through the binder mechanism. In the lock situation, it is detected that process A or process B has exited, but the wakelock created by it has not been released. At this time, the electronic device will actively release the wakelock created by the process. For processes that create wakelocks using the above methods 3 and 4, such as process C and process D in the example of S301, when they exit abnormally, the above binder mechanism does not apply.
在本实施例中,电子设备可在确定目标进程,如进程C或进程D异常退出时,在内核层触发进程退出处理过程。如,内核层可清理该目标进程的文件句柄、占用的内存、socket等资源。另外,内核层还可执行上述S303-S304,以便释放该目标进程创建的wakelock。具体的,内核层可获取与该目标进程的标识对应的wakelock。然后在确定与该目标进程的标识对应的wakelock的状态为激活态时,释放该wakelock。In this embodiment, the electronic device can trigger the process exit processing at the kernel layer when determining the target process, such as process C or process D, which exits abnormally. For example, the kernel layer can clean up the file handle, occupied memory, socket and other resources of the target process. In addition, the kernel layer can also execute the above S303-S304 to release the wakelock created by the target process. Specifically, the kernel layer may obtain the wakelock corresponding to the identifier of the target process. Then, when it is determined that the state of the wakelock corresponding to the identifier of the target process is the active state, the wakelock is released.
如,在进程C异常退出时,电子设备的内核层可获取包含该进程的C的标识的wake_source节点,如内核层确定出wake_source节点C包含进程的C的标识。此时,在内核层确定该wake_source节点C的状态为激活态时,说明进程C创建的wakelock 并未释放,内核层可释放该wake_source节点C。又如,在进程D异常退出时,电子设备的内核层可获取包含该进程的D的标识的wake_source节点,如内核层确定出wake_source节点D包含进程的D的标识。此时,在内核层确定该wake_source节点D的状态为激活态时,说明进程D创建的wakelock并未释放,内核层可释放该wake_source节点D。这样可避免应用异常持锁的情况出现。其中,释放对应的wake_source节点的具体处理可以是去激活该wake_source节点,以保证系统能够及时休眠。For example, when the process C exits abnormally, the kernel layer of the electronic device can obtain the wake_source node containing the C's identity of the process. For example, the kernel layer determines that the wake_source node C contains the C's identity of the process. At this time, when the kernel layer determines that the state of the wake_source node C is the active state, it means that the wakelock created by the process C has not been released, and the kernel layer can release the wake_source node C. For another example, when the process D exits abnormally, the kernel layer of the electronic device can obtain the wake_source node containing the ID of the process D, for example, the kernel layer determines that the wake_source node D contains the ID of the process D. At this time, when the kernel layer determines that the state of the wake_source node D is the active state, it means that the wakelock created by the process D has not been released, and the kernel layer can release the wake_source node D. This can avoid the application of abnormal lock holding situations. Among them, the specific processing of releasing the corresponding wake_source node may be to deactivate the wake_source node to ensure that the system can sleep in time.
本申请实施例提供的唤醒锁的管理方法,对于通过写文件节点或调用内核层对应接口的方式创建的wakelock,通过在内核层记录其所属进程的标识,以将其作为一种与进程绑定的资源。这样,在对应进程异常退出后,在进行进程退出处理时,便能够自动释放该进程申请的wakelock,避免应用异常持锁的情况出现,保证系统及时休眠,延长了电子设备的续航时间。另外,本实施例提供的方案不会带来大的系统开销,且具备普适性。In the wakelock management method provided by the embodiments of the present application, for a wakelock created by writing a file node or calling the corresponding interface of the kernel layer, the process identifier is recorded at the kernel layer to bind it to the process resource of. In this way, after the corresponding process exits abnormally, the wakelock applied for by the process can be automatically released when the process exit processing is performed, avoiding abnormal application locks, ensuring that the system sleeps in time, and extending the battery life of the electronic device. In addition, the solution provided by this embodiment does not cause large system overhead and has universal applicability.
本申请另一些实施例还提供一种计算机存储介质,该计算机存储介质可包括计算机指令,当该计算机指令在电子设备上运行时,使得该电子设备执行如图3所示实施例中电子设备执行的各个步骤。Other embodiments of the present application also provide a computer storage medium. The computer storage medium may include computer instructions. When the computer instructions run on an electronic device, the electronic device executes the execution of the electronic device in the embodiment shown in FIG. 3. The various steps.
本申请另一些实施例还提供一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得该计算机执行如图3所示实施例中电子设备执行的各个步骤。Other embodiments of the present application also provide a computer program product, which when the computer program product runs on a computer, causes the computer to execute each step performed by the electronic device in the embodiment shown in FIG. 3.
本申请另一些实施例还提供一种芯片系统,该芯片系统可应用于电子设备;该芯片系统可以包括一个或多个接口电路和一个或多个处理器;接口电路和处理器通过线路互联;接口电路用于从电子设备的存储器接收信号,并向处理器发送信号,信号包括存储器中存储的计算机指令;当处理器执行计算机指令时,电子设备执行如图3相应实施例中的方法。Other embodiments of the present application also provide a chip system, which can be applied to electronic devices; the chip system can include one or more interface circuits and one or more processors; the interface circuits and the processors are interconnected by wires; The interface circuit is used to receive signals from the memory of the electronic device and send signals to the processor. The signals include computer instructions stored in the memory; when the processor executes the computer instructions, the electronic device executes the method in the corresponding embodiment of FIG. 3.
本申请另一些实施例还提供一种电子设备,该电子设备可以包括:处理器和存储器;处理器和存储器耦合,存储器用于存储计算机程序代码,计算机程序代码包括计算机指令,当计算机指令被电子设备执行时,使得电子设备执行图3相应实施例中的方法。Other embodiments of the present application also provide an electronic device. The electronic device may include a processor and a memory; the processor and the memory are coupled, and the memory is used to store computer program codes. The computer program codes include computer instructions. When the device is executed, the electronic device is caused to execute the method in the corresponding embodiment in FIG. 3.
本申请另一些实施例还提供一种唤醒锁的管理装置,该装置具有实现上述图3相应实施例中电子设备行为的功能。所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。所述硬件或软件包括一个或多个与上述功能相对应的模块,例如,创建单元或模块,获取单元或模块,释放单元或模块等。Other embodiments of the present application also provide a wake lock management device, which has the function of realizing the behavior of the electronic device in the corresponding embodiment in FIG. 3 above. The function can be realized by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, for example, a creation unit or module, an acquisition unit or module, a release unit or module, and so on.
如图4所示,该装置可以包括创建单元401,获取单元402和释放单元403。As shown in FIG. 4, the device may include a creation unit 401, an acquisition unit 402, and a release unit 403.
创建单元401,用于进程创建唤醒锁wakelock,该进程可以包括目标进程,该目标进程可以包括以下进程中的一个或多个:采用写文件节点的方式创建wakelock的进程,采用调用kernel层对应接口的方式创建wakelock的进程;将目标进程的标识和目标进程创建的wakelock关联存储。The creation unit 401 is used for a process to create a wakelock wakelock. The process may include a target process, and the target process may include one or more of the following processes: a process for creating a wakelock by writing a file node, and calling the corresponding interface of the kernel layer Create a wakelock process in a way; associate the target process identifier with the wakelock created by the target process.
获取单元402,用于在确定目标进程异常退出时,获取与目标进程的标识对应的wakelock。The acquiring unit 402 is configured to acquire the wakelock corresponding to the identifier of the target process when it is determined that the target process exits abnormally.
释放单元403,用于在确定与目标进程的标识对应的wakelock的状态为激活态时, 释放wakelock。The releasing unit 403 is configured to release the wakelock when it is determined that the state of the wakelock corresponding to the identifier of the target process is the active state.
进一步的,创建单元401,具体用于目标进程将目标进程所需创建的wakelock的锁名称写入对应的文件节点,获取目标进程的标识,在内核层创建wake_source节点,该wake_source节点中包括目标进程的标识和目标进程所需创建的wakelock的锁名称。Further, the creation unit 401 is specifically used for the target process to write the lock name of the wakelock that the target process needs to create into the corresponding file node, obtain the identifier of the target process, and create a wake_source node in the kernel layer, and the wake_source node includes the target process The identifier and the lock name of the wakelock that the target process needs to create.
进一步的,创建单元401,具体用于目标进程调用内核层的对应接口,输入目标进程所需创建的wakelock的锁名称;获取目标进程的标识,在内核层创建wake_source节点,该wake_source节点包括目标进程的标识和目标进程所需创建的wakelock的锁名称。Further, the creation unit 401 is specifically used for the target process to call the corresponding interface of the kernel layer, to input the lock name of the wakelock that the target process needs to create; to obtain the identifier of the target process, to create a wake_source node in the kernel layer, and the wake_source node includes the target process The identifier and the lock name of the wakelock that the target process needs to create.
进一步的,获取单元402,具体用于在目标进程异常退出时,获取包含目标进程的标识的wake_source节点。Further, the obtaining unit 402 is specifically configured to obtain the wake_source node containing the identifier of the target process when the target process exits abnormally.
释放单元403,具体用于在确定包含目标进程的标识的wake_source节点的状态为激活态时,去激活wake_source节点。The releasing unit 403 is specifically configured to deactivate the wake_source node when it is determined that the state of the wake_source node containing the identifier of the target process is the active state.
进一步的,上述目标进程可以为应用进程,本地native进程或kernel进程。Further, the aforementioned target process may be an application process, a local native process or a kernel process.
本申请实施例提供的计算机存储介质,计算机程序产品,电子设备,唤醒锁的管理装置及芯片系统,用于执行上述图3相应实施例中的方法,因此可以达到相同的效果,此处不再赘述。The computer storage medium, computer program product, electronic device, wake lock management device, and chip system provided in the embodiment of the application are used to execute the method in the corresponding embodiment of FIG. 3 above, so the same effect can be achieved, and will not be omitted here. Repeat.
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。Through the description of the above embodiments, those skilled in the art can clearly understand that for the convenience and brevity of the description, only the division of the above-mentioned functional modules is used as an example for illustration. In practical applications, the above-mentioned functions can be allocated as needed. It is completed by different functional modules, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed device and method may be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, for example, multiple units or components may be It can be combined or integrated into another device, or some features can be omitted or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是一个物理单元或多个物理单元,即可以位于一个地方,或者也可以分布到多个不同地方。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate parts may or may not be physically separate. The parts displayed as units may be one physical unit or multiple physical units, that is, they may be located in one place, or they may be distributed to multiple different places. . Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, the functional units in each embodiment of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only  Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application are essentially or the part that contributes to the prior art, or all or part of the technical solutions can be embodied in the form of software products, which are stored in a storage medium There are several instructions to make a device (which may be a single-chip microcomputer, a chip, etc.) or a processor (processor) execute all or part of the steps of the method described in each embodiment of the application. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above are only specific implementations of this application, but the protection scope of this application is not limited to this. Any change or replacement within the technical scope disclosed in this application shall be covered by the protection scope of this application . Therefore, the protection scope of this application should be subject to the protection scope of the claims.

Claims (12)

  1. 一种唤醒锁的管理方法,其特征在于,所述方法包括:A management method of wake lock, characterized in that the method includes:
    电子设备的进程创建唤醒锁wakelock,所述进程包括目标进程,所述目标进程包括以下进程中的一个或多个:采用写文件节点的方式创建wakelock的进程,采用调用所述电子设备的内核kernel层对应接口的方式创建wakelock的进程;A process of the electronic device creates a wakelock wakelock, the process includes a target process, and the target process includes one or more of the following processes: a process that creates a wakelock by writing a file node, and uses a kernel kernel that calls the electronic device The wakelock process is created in the way that the layer corresponds to the interface;
    所述电子设备将所述目标进程的标识和所述目标进程创建的wakelock关联存储;The electronic device associates and stores the identifier of the target process and the wakelock created by the target process;
    所述电子设备在确定所述目标进程异常退出时,获取与所述目标进程的标识对应的wakelock;When determining that the target process exits abnormally, the electronic device acquires a wakelock corresponding to the identifier of the target process;
    所述电子设备在确定与所述目标进程的标识对应的wakelock的状态为激活态时,释放所述wakelock。The electronic device releases the wakelock when determining that the state of the wakelock corresponding to the identifier of the target process is the active state.
  2. 根据权利要求1所述的方法,其特征在于,The method according to claim 1, wherein:
    所述电子设备的所述目标进程采用写文件节点的方式创建wakelock,包括:The target process of the electronic device creates a wakelock in a way of writing a file node, including:
    所述目标进程将所述目标进程所需创建的wakelock的锁名称写入对应的文件节点;The target process writes the lock name of the wakelock that the target process needs to create into the corresponding file node;
    所述电子设备将所述目标进程的标识和所述目标进程创建的wakelock关联存储,包括:The electronic device associates and stores the identifier of the target process and the wakelock created by the target process, including:
    所述内核层获取所述目标进程的标识,在所述内核层创建唤醒源wake_source节点,所述wake_source节点中包括所述目标进程的标识和所述目标进程所需创建的wakelock的锁名称。The kernel layer obtains the identifier of the target process, and creates a wake_source node in the kernel layer. The wake_source node includes the identifier of the target process and the lock name of the wakelock to be created by the target process.
  3. 根据权利要求1所述的方法,其特征在于,The method according to claim 1, wherein:
    所述电子设备的所述目标进程采用调用内核层对应接口的方式创建wakelock,包括:The target process of the electronic device creates a wakelock by calling the corresponding interface of the kernel layer, including:
    所述目标进程调用所述内核层的对应接口,输入所述目标进程所需创建的wakelock的锁名称;The target process calls the corresponding interface of the kernel layer, and enters the lock name of the wakelock that the target process needs to create;
    所述电子设备将所述目标进程的标识和所述目标进程创建的wakelock关联存储,包括:The electronic device associates and stores the identifier of the target process and the wakelock created by the target process, including:
    所述内核层获取所述目标进程的标识,在所述内核层创建wake_source节点,所述wake_source节点包括所述目标进程的标识和所述目标进程所需创建的wakelock的锁名称。The kernel layer obtains the identifier of the target process, and creates a wake_source node in the kernel layer. The wake_source node includes the identifier of the target process and the lock name of the wakelock that the target process needs to create.
  4. 根据权利要求2或3所述的方法,其特征在于,The method according to claim 2 or 3, wherein:
    所述电子设备在确定所述目标进程异常退出时,获取与所述目标进程的标识对应的wakelock,包括:When the electronic device determines that the target process exits abnormally, acquiring the wakelock corresponding to the identifier of the target process includes:
    在所述目标进程异常退出时,所述内核层获取包含所述目标进程的标识的wake_source节点;When the target process exits abnormally, the kernel layer obtains the wake_source node containing the identifier of the target process;
    所述电子设备在确定与所述目标进程的标识对应的wakelock的状态为激活态时,释放所述wakelock,包括:When the electronic device determines that the state of the wakelock corresponding to the identifier of the target process is the active state, releasing the wakelock includes:
    所述内核层在确定包含所述目标进程的标识的wake_source节点的状态为激活态时,去激活所述wake_source节点。The kernel layer deactivates the wake_source node when determining that the state of the wake_source node containing the identifier of the target process is the active state.
  5. 根据权利要求1-4中任一项所述的方法,其特征在于,所述目标进程为应用进 程,本地native进程或kernel进程。The method according to any one of claims 1-4, wherein the target process is an application process, a local native process or a kernel process.
  6. 一种电子设备,其特征在于,所述电子设备包括:处理器和存储器;所述处理器和所述存储器耦合,所述存储器用于存储计算机程序代码,所述计算机程序代码包括计算机指令,当所述计算机指令被所述电子设备执行时,使得所述电子设备执行如下操作:An electronic device, characterized in that the electronic device comprises: a processor and a memory; the processor is coupled to the memory, and the memory is used to store computer program code, and the computer program code includes computer instructions. When the computer instruction is executed by the electronic device, the electronic device is caused to perform the following operations:
    进程创建唤醒锁wakelock,所述进程包括目标进程,所述目标进程包括以下进程中的一个或多个:采用写文件节点的方式创建wakelock的进程,采用调用所述电子设备的内核kernel层对应接口的方式创建wakelock的进程;The process creates a wakelock wakelock, the process includes a target process, and the target process includes one or more of the following processes: a process that creates a wakelock by writing a file node, and uses a corresponding interface that calls the kernel kernel layer of the electronic device The way to create a wakelock process;
    将所述目标进程的标识和所述目标进程创建的wakelock关联存储;Store the identifier of the target process in association with the wakelock created by the target process;
    在确定所述目标进程异常退出时,获取与所述目标进程的标识对应的wakelock;When it is determined that the target process exits abnormally, obtaining a wakelock corresponding to the identifier of the target process;
    在确定与所述目标进程的标识对应的wakelock的状态为激活态时,释放所述wakelock。When it is determined that the state of the wakelock corresponding to the identifier of the target process is the active state, the wakelock is released.
  7. 根据权利要求6所述的电子设备,其特征在于,所述目标进程采用写文件节点的方式创建wakelock,包括:7. The electronic device according to claim 6, wherein the target process uses a file node writing method to create a wakelock, comprising:
    所述目标进程将所述目标进程所需创建的wakelock的锁名称写入对应的文件节点;The target process writes the lock name of the wakelock that the target process needs to create into the corresponding file node;
    所述将所述目标进程的标识和所述目标进程创建的wakelock关联存储,包括:The associating and storing the identifier of the target process and the wakelock created by the target process includes:
    所述内核层获取所述目标进程的标识,在所述内核层创建唤醒源wake_source节点,所述wake_source节点中包括所述目标进程的标识和所述目标进程所需创建的wakelock的锁名称。The kernel layer obtains the identifier of the target process, and creates a wake_source node in the kernel layer. The wake_source node includes the identifier of the target process and the lock name of the wakelock to be created by the target process.
  8. 根据权利要求6所述的电子设备,其特征在于,所述目标进程采用调用内核层对应接口的方式创建wakelock,包括:The electronic device according to claim 6, wherein the target process uses the kernel layer corresponding interface to create the wakelock, comprising:
    所述目标进程调用所述内核层的对应接口,输入所述目标进程所需创建的wakelock的锁名称;The target process calls the corresponding interface of the kernel layer, and enters the lock name of the wakelock that the target process needs to create;
    所述将所述目标进程的标识和所述目标进程创建的wakelock关联存储,包括:The associating and storing the identifier of the target process and the wakelock created by the target process includes:
    所述内核层获取所述目标进程的标识,在所述内核层创建wake_source节点,所述wake_source节点包括所述目标进程的标识和所述目标进程所需创建的wakelock的锁名称。The kernel layer obtains the identifier of the target process, and creates a wake_source node in the kernel layer. The wake_source node includes the identifier of the target process and the lock name of the wakelock that the target process needs to create.
  9. 根据权利要求7或8所述的电子设备,其特征在于,所述在确定所述目标进程异常退出时,获取与所述目标进程的标识对应的wakelock,包括:The electronic device according to claim 7 or 8, wherein when it is determined that the target process exits abnormally, obtaining a wakelock corresponding to the identifier of the target process comprises:
    在所述目标进程异常退出时,所述内核层获取包含所述目标进程的标识的wake_source节点;When the target process exits abnormally, the kernel layer obtains the wake_source node containing the identifier of the target process;
    所述在确定与所述目标进程的标识对应的wakelock的状态为激活态时,释放所述wakelock,包括:When it is determined that the state of the wakelock corresponding to the identifier of the target process is the active state, releasing the wakelock includes:
    所述内核层在确定包含所述目标进程的标识的wake_source节点的状态为激活态时,去激活所述wake_source节点。The kernel layer deactivates the wake_source node when determining that the state of the wake_source node containing the identifier of the target process is the active state.
  10. 根据权利要求6-9中任一项所述的电子设备,其特征在于,所述目标进程为应用进程,本地native进程或kernel进程。The electronic device according to any one of claims 6-9, wherein the target process is an application process, a local native process or a kernel process.
  11. 一种计算机存储介质,其特征在于,所述计算机存储介质包括计算机指令, 当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求1-5中任一项所述的唤醒锁的管理方法。A computer storage medium, characterized in that the computer storage medium includes computer instructions, and when the computer instructions run on an electronic device, the electronic device is caused to execute the electronic device according to any one of claims 1-5 The management method of wake lock.
  12. 一种计算机程序产品,其特征在于,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如权利要求1-5中任一项所述的唤醒锁的管理方法。A computer program product, characterized in that when the computer program product runs on a computer, the computer is caused to execute the wake lock management method according to any one of claims 1-5.
PCT/CN2020/103128 2019-07-26 2020-07-20 Wakelock management method and electronic device WO2021017935A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910687713.2A CN110572866B (en) 2019-07-26 2019-07-26 Management method of wake-up lock and electronic equipment
CN201910687713.2 2019-07-26

Publications (1)

Publication Number Publication Date
WO2021017935A1 true WO2021017935A1 (en) 2021-02-04

Family

ID=68773587

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/103128 WO2021017935A1 (en) 2019-07-26 2020-07-20 Wakelock management method and electronic device

Country Status (2)

Country Link
CN (1) CN110572866B (en)
WO (1) WO2021017935A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110572866B (en) * 2019-07-26 2021-03-30 华为技术有限公司 Management method of wake-up lock and electronic equipment
CN113747552B (en) * 2021-06-18 2024-03-19 荣耀终端有限公司 Power consumption optimization method and electronic equipment
CN116723384B (en) * 2022-02-28 2024-04-19 荣耀终端有限公司 Process control method, electronic device and readable storage medium
CN116701134B (en) * 2022-10-14 2024-05-17 荣耀终端有限公司 Data processing method and electronic equipment
CN117131497B (en) * 2023-02-28 2024-06-14 荣耀终端有限公司 Software detection method and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130268257A1 (en) * 2012-04-09 2013-10-10 Purdue Research Foundation System and method for energy usage accounting in software applications
CN105867581A (en) * 2015-12-16 2016-08-17 乐视移动智能信息技术(北京)有限公司 Power optimization method and device and mobile terminal
CN106125891A (en) * 2016-06-24 2016-11-16 北京奇虎科技有限公司 Terminal power optimization method, device and terminal
CN107608724A (en) * 2017-09-26 2018-01-19 深圳市金立通信设备有限公司 A kind of method, terminal and computer-readable recording medium for managing application program
US10244479B1 (en) * 2014-01-22 2019-03-26 Seven Networks, Llc Method for power saving in mobile devices by optimizing wakelocks
CN110572866A (en) * 2019-07-26 2019-12-13 华为技术有限公司 Management method of wake-up lock and electronic equipment

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103885565B (en) * 2012-12-21 2018-01-23 希姆通信息技术(上海)有限公司 The dormancy method and system of smart machine
CN104023147B (en) * 2014-06-27 2016-05-11 广东欧珀移动通信有限公司 A kind of method and system that make mobile terminal stablize dormancy
CN105183137B (en) * 2015-09-09 2018-06-01 厦门美图移动科技有限公司 A kind of mobile terminal and its wake-up lock control method and control system
JP6639665B2 (en) * 2015-10-29 2020-02-05 華為技術有限公司Huawei Technologies Co.,Ltd. Method, apparatus and terminal for terminal-based wakelock control
CN105807894B (en) * 2016-03-22 2019-06-25 北京小米移动软件有限公司 Using the treating method and apparatus for holding lock
CN106502687A (en) * 2016-10-24 2017-03-15 深圳市金立通信设备有限公司 A kind of method and terminal for entering resting state
CN108268116B (en) * 2017-01-03 2022-06-07 中兴通讯股份有限公司 Method and device for solving abnormal power consumption of mobile terminal and mobile terminal

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130268257A1 (en) * 2012-04-09 2013-10-10 Purdue Research Foundation System and method for energy usage accounting in software applications
US10244479B1 (en) * 2014-01-22 2019-03-26 Seven Networks, Llc Method for power saving in mobile devices by optimizing wakelocks
CN105867581A (en) * 2015-12-16 2016-08-17 乐视移动智能信息技术(北京)有限公司 Power optimization method and device and mobile terminal
CN106125891A (en) * 2016-06-24 2016-11-16 北京奇虎科技有限公司 Terminal power optimization method, device and terminal
CN107608724A (en) * 2017-09-26 2018-01-19 深圳市金立通信设备有限公司 A kind of method, terminal and computer-readable recording medium for managing application program
CN110572866A (en) * 2019-07-26 2019-12-13 华为技术有限公司 Management method of wake-up lock and electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
WANG, YONGCHAO: "Research on the Energy Efficiency and Power Optimization Strategy for Mobile Devices", ELECTRONIC TECHNOLOGY & INFORMATION SCIENCE, CHINA MASTER’S THESES FULL-TEXT DATABASE, no. 04, 15 April 2017 (2017-04-15), XP55777564, DOI: 20200826132609X *

Also Published As

Publication number Publication date
CN110572866B (en) 2021-03-30
CN110572866A (en) 2019-12-13

Similar Documents

Publication Publication Date Title
WO2021052263A1 (en) Voice assistant display method and device
WO2021017935A1 (en) Wakelock management method and electronic device
WO2021000807A1 (en) Processing method and apparatus for waiting scenario in application
EP4084486B1 (en) Cross-device content projection method, and electronic device
WO2021043046A1 (en) Resource management and control method and device
WO2021147396A1 (en) Icon management method and smart terminal
WO2021190344A1 (en) Multi-screen display electronic device, and multi-screen display method for electronic device
WO2021052410A1 (en) Application management method and apparatus
WO2020073288A1 (en) Method for triggering electronic device to execute function and electronic device
EP4231147A1 (en) Drawing command processing method and related device therefor
WO2021052200A1 (en) Device capability scheduling method and electronic device
WO2022033320A1 (en) Bluetooth communication method, terminal device, and computer-readable storage medium
WO2021253975A1 (en) Permission management method and apparatus for application, and electronic device
WO2021218429A1 (en) Method for managing application window, and terminal device and computer-readable storage medium
WO2021258795A1 (en) Atomic ability invoking method and terminal device
WO2021223539A1 (en) Radio frequency resource allocation method and apparatus
WO2022017474A1 (en) Task processing method and related apparatus
WO2020056778A1 (en) Method for shielding touch event, and electronic device
WO2021073183A1 (en) Always on display method and mobile device
CN114189846B (en) Method, system, electronic device and storage medium for avoiding missed call
WO2022170856A1 (en) Method for establishing connection, and electronic device
WO2022078105A1 (en) Memory management method, electronic device, and computer-readable storage medium
WO2023005282A9 (en) Message pushing method and apparatus
WO2021238387A1 (en) Application execution method and apparatus
WO2021042991A1 (en) Non-intrusive interaction method and electronic device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20846149

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20846149

Country of ref document: EP

Kind code of ref document: A1