Communication method and electronic equipment

By detecting the energy consumption difference between Wi-Fi and Modem networks, automatically switch to Modem network with lower energy consumption for heartbeat packet transmission, solving the problems of high energy consumption and instability under Wi-Fi networks and achieving lower energy consumption communication.

CN120378976APending Publication Date: 2025-07-25HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410073177.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-17
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

Sending heartbeat packets under Wi-Fi networks results in higher energy consumption of user equipment, and poor stability of Wi-Fi networks, and frequent disconnection increases additional energy consumption.

Method used

By detecting the energy consumption difference between Wi-Fi and Modem networks, we automatically switch to the Modem network with lower energy consumption for heartbeat packets to establish a long connection to the Modem network.

Benefits of technology

It reduces the energy consumption of user equipment when sending heartbeat packets, reduces the additional energy consumption caused by network instability, and improves the battery efficiency of the equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120378976A_ABST
    Figure CN120378976A_ABST
Patent Text Reader

Abstract

The invention discloses a communication method and electronic equipment, and the method comprises the steps: disconnecting a first long connection and building a second long connection corresponding to a second network under the conditions that a first network supports the building of the long connection, a second network supports the building of the long connection, the building of the first long connection corresponding to the first network, and the first energy consumption is higher than the second energy consumption; the first energy consumption is the energy consumption of sending a heartbeat data packet based on a long connection corresponding to the first network within the first duration, and the second energy consumption is the energy consumption of sending a heartbeat data packet based on a long connection corresponding to the second network within the first duration; and sending the heartbeat data packet based on the second long connection. By implementing the application, the heartbeat data packet can be sent on the long connection corresponding to the network with lower energy consumption, so that the energy consumption of the equipment is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of terminals, and in particular, to a communication method and an electronic device. Background Art

[0002] Compared with short connections, long connections can support the transceiver at both ends to send multiple data packets, and can avoid waste of resources caused by frequent connection establishment. Currently, a user equipment can communicate based on a long connection established with a server, and keep the long connection alive by periodically sending heartbeat data packets. When the user equipment supports both wireless fidelity (Wi-Fi) network function and mobile network function (also known as cellular network function or modem network function, etc.) at the same time, if there is a connectable Wi-Fi network at the location where the user equipment is located, the user equipment will default to giving priority to using the Wi-Fi network for communication. Correspondingly, the user equipment establishes a long connection with the server based on the Wi-Fi network, and sends heartbeat data packets under the Wi-Fi network.

[0003] However, sending heartbeat data packets under the Wi-Fi network will cause relatively high energy consumption of the user equipment. Summary of the Invention

[0004] The present application provides a communication method and an electronic device, which can reduce the energy consumption of the device when sending heartbeat data packets.

[0005] In a first aspect, an embodiment of the present application provides a communication method, and the method includes:

[0006] When a first network supports establishing a long connection, a second network supports establishing a long connection, a first long connection corresponding to the first network is established, and the first energy consumption is higher than the second energy consumption, disconnect the first long connection and establish a second long connection corresponding to the second network; the first energy consumption is the energy consumption of sending heartbeat data packets based on the long connection corresponding to the first network within a first time period, and the second energy consumption is the energy consumption of sending heartbeat data packets based on the long connection corresponding to the second network within the first time period; send heartbeat data packets based on the second long connection.

[0007] When implementing the method described in the first aspect, if it is determined that the energy consumption of sending a heartbeat data packet based on the second network is smaller than that of sending a heartbeat data packet based on the first network when sending a heartbeat data packet based on the first network, the device can automatically switch from the first network to the second network, and then send the heartbeat data packet based on the long connection corresponding to the second network. Through this automatic switching method, the energy consumption of the device can be reduced when sending a heartbeat data packet. For example, in a scenario where Wi-Fi network communication is used by default to send a heartbeat data packet, if it is determined that the energy consumption of sending a heartbeat data packet based on the Modem network is smaller, the device automatically switches from the Wi-Fi network to the Modem network, and then sends the heartbeat data packet based on the long connection corresponding to the Modem network.

[0008] In a possible implementation manner, the method of disconnecting the first long connection and establishing a second long connection corresponding to the second network specifically includes: disconnecting the first long connection and releasing the first socket corresponding to the first long connection; creating a second socket; binding the second socket to the address and port number corresponding to the second network; and establishing a second long connection based on the bound second socket.

[0009] It can be seen that a second long connection corresponding to the second network can be established by creating a new socket and binding the new socket to the address and port number corresponding to the second network.

[0010] In a possible implementation manner, the first duration is M days, where M is a positive integer greater than or equal to 1; before disconnecting the first long connection and establishing a second long connection corresponding to the second network, the method further includes: detecting the first effective power-off data corresponding to each day within M days in the standby mode where the first network is in the on state, the second network is in the off state, and the long connection corresponding to the first network is established; detecting the second effective power-off data corresponding to each day within M days in the standby mode where the first network is in the off state, the second network is in the on state, and the long connection corresponding to the second network is established; determining the standby current of the first network based on the first effective power-off data corresponding to each day within M days; determining the standby current of the second network based on the second effective power-off data corresponding to each day within M days; and if the standby current of the first network is higher than the standby current of the second network, determining that the first energy consumption is higher than the second energy consumption.

[0011] It can be seen that, first of all, the standby mode can ensure that most applications and loads are turned off, and ensure that the network in the on state is used to send heartbeat data packets without sending other data packets except the heartbeat data packets. Therefore, by ensuring that one network is turned off and the other network is turned on in the standby mode respectively, the detected effective power-off data can be approximately equal to the effective power-off data corresponding to sending heartbeat data packets in the network in the on state. In addition, by detecting the effective power-off data for multiple days and obtaining the standby current based on the effective power-off data for multiple days, the value of the obtained standby current can be made more reliable and can more accurately reflect the energy consumption of sending heartbeat data packets under different networks.

[0012] In a possible implementation manner, the standby duration corresponding to the first effective power-off data is greater than or equal to a preset threshold, and the standby duration corresponding to the second effective power-off data is greater than or equal to a preset threshold.

[0013] It can be seen that when the standby duration corresponding to the power-off data of any day is greater than or equal to the preset threshold, the power-off data of this day is used as the effective power-off data; on the contrary, when the standby duration corresponding to the power-off data of any day is less than the preset threshold, the power-off data of this day is not used as the effective power-off data. This can ensure that the standby duration corresponding to the effective data of any day under the two networks is long enough to more accurately reflect the energy consumption of sending heartbeat data packets under different networks.

[0014] In a possible implementation manner, the detection positions corresponding to the first effective power-off data for each day within M days are the same, the detection positions corresponding to the second effective power-off data for each day within M days are the same, and the detection position corresponding to the first effective power-off data for any day is the same as the detection position corresponding to the second effective data for any day.

[0015] It can be seen that by ensuring that the detection positions corresponding to the effective power-off data under the two networks are the same, it is possible to avoid the situation where the detected effective power-off data is invalid when the signal changes for the connection under the same network due to the user being occasionally not in a fixed position. For example, in order to detect the energy consumption difference between the Wi-Fi network and the Modem network when the user is at home, it is necessary to detect the effective power-off data when the user is at home and connected to the Wi-Fi network and the Modem network respectively; if the user is away on a business trip, the effective power-off data when the user is connected to the Wi-Fi network and the Modem network during the business trip is not used to measure the energy consumption of the Wi-Fi network and the Modem network when the user is at home.

[0016] In a possible implementation, before disconnecting the first long connection and establishing the second long connection corresponding to the second network, the method further includes: detecting first single-power-off data of sending a heartbeat data packet based on the long connection corresponding to the first network; detecting second single-power-off data of sending a heartbeat data packet based on the long connection corresponding to the second network; detecting a first period of sending a heartbeat data packet based on the long connection of the first network; detecting a second period of sending a heartbeat data packet based on the long connection of the second network; determining a first energy consumption based on the first single-power-off data, the first period, and a first duration; and determining a second energy consumption based on the second single-power-off data, the second period, and the first duration.

[0017] It can be seen that by directly detecting the power-off data of sending a heartbeat data packet once under different networks and the periods of sending a heartbeat data packet under different networks, the energy consumption of sending a heartbeat data packet within the first duration under different networks can be directly measured. This method can be detected in real time based on the chip, without requiring the device to be in the standby mode, etc., and can obtain the energy consumption under different networks more efficiently.

[0018] In a possible implementation, the method for determining the first energy consumption based on the first single-power-off data, the first period, and the first duration specifically includes: determining a first number of times of sending a heartbeat data packet based on the long connection of the first network within the first duration based on the first period and the first duration; and determining the product of the first number of times and the first single-power-off data as the first energy consumption. The method for determining the second energy consumption based on the second single-power-off data, the second period, and the first duration specifically includes: determining a second number of times of sending a heartbeat data packet based on the long connection of the second network within the first duration based on the second period and the first duration; and determining the product of the second number of times and the second single-power-off data as the second energy consumption.

[0019] In a second aspect, the present application provides an electronic device, including one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are configured to store computer program code. The computer program code includes computer instructions. When the one or more processors execute the computer instructions, the electronic device is caused to execute the communication method in the first aspect and any possible implementation manner thereof.

[0020] In a third aspect, the present application provides a communication device, which includes functions / units for executing the communication method in the first aspect and any possible implementation manner thereof.

[0021] Fourthly, the present application provides a chip system. The chip system is applied to an electronic device and includes at least one processor and an interface. The interface is configured to receive computer instructions and transmit them to at least one processor; the at least one processor runs the computer instructions to cause the electronic device to execute the communication method in the first aspect and any possible implementation manner thereof as described above.

[0022] Fifthly, the present application provides a computer-readable storage medium. Computer instructions are stored in the computer-readable storage medium. When the computer instructions run on an electronic device, the electronic device is caused to execute the communication method in the first aspect and any possible implementation manner thereof as described above.

[0023] Sixthly, the present application provides a computer program product. When the computer program product runs on a computer, the computer is caused to execute the communication method in the first aspect and any possible implementation manner thereof as described above.

[0024] It can be understood that for the beneficial effects that can be achieved by the above-provided electronic device, communication device, chip system, computer-readable storage medium, and computer program product, reference can be made to the beneficial effects in the first aspect and any possible implementation manner thereof, which will not be elaborated herein. Description of the Drawings

[0025] Figure 1 is a schematic diagram of a status bar and a drop-down notification interface provided by an embodiment of the present application;

[0026] Figure 2 is a schematic diagram of the NAT keep-alive duration under a Modem network provided by an embodiment of the present application;

[0027] Figure 3 is a schematic diagram of the NAT keep-alive duration under a Wi-Fi network provided by an embodiment of the present application;

[0028] Figure 4 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application;

[0029] Figure 5 is a schematic diagram of the software structure of an electronic device provided by an embodiment of the present application;

[0030] Figure 6 is a schematic diagram of the process of a communication method based on the software structure provided by an embodiment of the present application;

[0031] Figure 7 is a schematic diagram of the process of a communication method provided by an embodiment of the present application;

[0032] Figure 8 is a schematic diagram of the interaction of a power-saving application provided by an embodiment of the present application;

[0033] Figure 9 It is an interaction schematic diagram of another power-saving application provided by an embodiment of the present application;

[0034] Figure 10 It is a structural schematic diagram of a chip system provided by an embodiment of the present application. Specific embodiments

[0035] Hereinafter, the technical solutions in the embodiments of the present application will be clearly and elaborately described with reference to the accompanying drawings. Among them, in the description of the embodiments of the present application, unless otherwise specified, " / " means "or". For example, A / B may mean A or B; "and / or" in the text is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B may mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of the present application, "a plurality" means two or more than two.

[0036] Hereinafter, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as implying or suggesting relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the embodiments of the present application, unless otherwise specified, the meaning of "a plurality" is two or more than two.

[0037] The term "user interface (UI)" in the following embodiments of the present application is a media interface for interaction and information exchange between an application program or an operating system and a user, and it realizes the conversion between the internal form of information and the form acceptable to the user. The user interface is source code written in specific computer languages such as Java and Extensible Markup Language (XML). The interface source code is parsed and rendered on an electronic device and finally presented as content recognizable by the user. The common manifestation form of the user interface is the graphical user interface (GUI), which refers to the user interface related to computer operations displayed in a graphical manner. It can be visual interface elements such as time, date, text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, and Widgets displayed on the display screen of an electronic device.

[0038] To facilitate the understanding of the embodiments of the present application, the scenarios and related technologies of the embodiments of the present application will be introduced first:

[0039] Figure 1The figure shows a schematic diagram of the status bar and the pull-down notification interface of an electronic device in the scenario of an embodiment of the present application. Among them, the electronic device refers to a device that can support multiple network functions to access the Internet. For example, Figure 1 the electronic device in [reference] supports accessing the Internet using WLAN and mobile data. The way of accessing the Internet using WLAN means that the electronic device accesses the Internet by searching for and connecting to the signal of a Wi-Fi network. The way of accessing the Internet using mobile data means that the electronic device accesses the Internet by searching for and connecting to the signal of a cellular network (or called a Modem network). The cellular network includes, but is not limited to, Global System of Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), Time-Division WCDMA (TD-WCDMA), Time-Division LTE (TD-LTE), 5th Generation New Radio (5G NR), etc.

[0040] As Figure 1 shown, the pull-down notification interface of the electronic device displays the following partial controls, including "WLAN" control, "Bluetooth" control, "Flashlight" control, "Ringer" control, "Auto Rotation" control, "Instant Share" control, "NFC" control, "Mobile Data" control, "Location" control, "Screenshot" control, and "Brightness Adjustment" control. The status bar of the electronic device includes the time status and the network status of the electronic device. Among them, Figure 1 the shown "WLAN" control and "Mobile Data" control are both in the enabled state (shown in gray), which is equivalent to the electronic device enabling both the Wi-Fi network function and the Modem network function at the same time. The electronic device can search for the signals of the Wi-Fi network and the Modem network.

[0041] In Figure 1In the scenario shown, if the location where the electronic device is located can simultaneously detect the signals of both the Wi-Fi network and the Modem network, and the quality of the Wi-Fi network signal meets the quality requirements for connecting to the Wi-Fi network, and the quality of the Modem network signal meets the quality requirements for connecting to the Modem network, then the electronic device will default to preferentially connecting to the Wi-Fi network according to the detected Wi-Fi network signal (as Figure 1 shown by "WLAN connected").

[0042] Alternatively, if the location where the electronic device is located can simultaneously detect the signals of both the Wi-Fi network and the Modem network, and within a certain period of time, the quality of the Wi-Fi network signal meets the quality requirements for connecting to the Wi-Fi network, while the quality of the Modem network signal does not meet the quality requirements for connecting to the Modem network, then the electronic device will connect to the Wi-Fi network according to the detected Wi-Fi network signal (as Figure 1 shown by "WLAN connected"). After connecting to the Wi-Fi network for a period of time, if the quality of both the Wi-Fi network signal and the Modem network signal meet the quality requirements for connection, then the electronic device will still maintain the default connection to the Wi-Fi network.

[0043] This application refers to the above scenarios as the scenarios where the electronic device defaults to connecting to the Wi-Fi network.

[0044] The following introduces the related technologies of the embodiments of this application:

[0045] I. Long connection

[0046] A long connection means that on a connection, the sending and receiving ends can continuously send multiple data packets; to maintain the long connection effectively, heartbeat data packets can be sent for keep-alive. For example, a long connection can be a Transmission Control Protocol (TCP) connection. After the client and the server establish a TCP connection through three-way handshake, the client and the server can send service data packets multiple times based on this TCP connection; at the same time, when there are no service data packets to send, the client can periodically send heartbeat data packets to the server to ensure that this TCP connection is always valid.

[0047] II. Push service

[0048] A push service means that when the server sends push information to the client, the client can display a notification prompt of the push information in the status bar and / or the lock screen notification. After seeing such a notification prompt, the user can trigger the client to display the corresponding page by clicking on the notification prompt. For example, the push service includes, but is not limited to, Push push service and / or instant messaging (IM) push service. The push information includes, but is not limited to, information of third-party applications (such as information of chat software, news information and personalized recommendation information of news software, etc.) and some system information (such as schedule reminder information set by the user, logistics update information and system update information, etc.).

[0049] The server sending push information to the client can be achieved based on the long connection established between the server and the client. For example, the server is a push server, and a long connection is established between the push server and the client. When the push server has push information to send and the long connection is in an effective state, the push server sends it to the client based on this long connection.

[0050] According to the above scenarios and related technologies, there are the following problems with the long connection under Wi-Fi network:

[0051] On the one hand, the energy consumption of sending heartbeat data packets under the long connection corresponding to the Wi-Fi network is higher than that under the long connection corresponding to the Modem network:

[0052] When the client is connected to the Wi-Fi network, the long connection between the server and the client is the long connection corresponding to the Wi-Fi network. When the client is connected to the Modem network, the long connection between the server and the client is the long connection corresponding to the Modem network. Generally speaking, the client periodically sends heartbeat data packets to the server to keep alive the long connection corresponding to the Wi-Fi network / Modem network. However, the period of the client sending heartbeat data packets to the server is different under different networks. Generally, the period of the client sending heartbeat data packets to the server under the Wi-Fi network / Modem network is less than or equal to the keep-alive duration of network address translation (NAT) under the Wi-Fi network / Modem network.

[0053] Figure 2 Shows a schematic diagram of the NAT keep-alive duration under the Modem network: As Figure 2 shown, the proportion of the NAT keep-alive duration being about 15 minutes under the Modem network reaches 99.38%, which means that under the Modem network, it is very likely that the client sends a heartbeat data packet to the server every 15 minutes.

[0054] Figure 3Shows a schematic diagram of the NAT keep-alive duration under the Wi-Fi network: As Figure 3 shown, the proportion of the NAT keep-alive duration less than or equal to 5 minutes under the Wi-Fi network reaches 40.77%, and the proportion of the NAT keep-alive duration equal to 15 minutes reaches 49.19%. According to Figure 3 the data, under the Wi-Fi network, the client may send a heartbeat data packet to the server every 15 minutes, or may send a heartbeat data packet to the server less than every 5 minutes. When the signal quality of the Wi-Fi network deteriorates, the client may even send a heartbeat data packet to the server every 3 minutes.

[0055] From the above Figure 2 and Figure 3 it can be seen that when the period of the client sending a heartbeat data packet to the server under the Wi-Fi network is much smaller than the period of the client sending a heartbeat data packet to the server under the Modem network, within the same time, the number of times the client sends a heartbeat data packet to the server under the Wi-Fi network is much higher than the frequency of the client sending a heartbeat data packet to the server under the Modem network. Assuming that the energy consumption of the client sending a heartbeat data packet under the Wi-Fi network and the Modem network is equal, then within the same time, the energy consumption of the client based on the Wi-Fi network will be much higher than the energy consumption of the client under the Modem network. Therefore, when the client is default-connected to the Wi-Fi network, it may cause excessive energy consumption of the client.

[0056] On the other hand: Due to factors such as distance, obstacles, and / or signal coverage, the stability of the Wi-Fi network is worse than that of the Modem network. When the Wi-Fi network has an abnormality, the long connection of the Wi-Fi network will be frequently disconnected. For example, the number of disconnections of the long connection of the Wi-Fi network may reach about 26 times in a day. In the case where the long connection of the Wi-Fi network is disconnected, the client sending a heartbeat data packet to the server will not receive the corresponding reply data packet, which will trigger the client and the server to establish a new long connection again. This process will increase the interaction between the client and the server, thus also increasing the energy consumption of the client.

[0057] According to the above two aspects, sending heartbeat data packets under a Wi-Fi network will result in relatively high power consumption of the client. To reduce the power consumption of the client when sending heartbeat data packets (including reducing the power consumption of sending and reducing the power consumption of triggering the reconstruction of a long connection), this application proposes a communication method and an electronic device. This communication method pre-detects the power consumption of sending heartbeat data packets under different networks, and then decides which network to switch to according to the detection results, and sends heartbeat data packets based on the connected network. Since this method takes into account the power consumption of the electronic device, even when the electronic device is default-connected to a Wi-Fi network, it can also perform network switching according to this method and communicate using a network with lower power consumption.

[0058] Among them, the electronic device is a user device that supports multiple Internet access methods, such as a smart phone, a tablet computer, a laptop computer, a desktop computer, an intelligent vehicle, etc., but is not limited thereto. The embodiments of this application do not limit the type of the electronic device. Exemplarily, the electronic device may be the electronic device 400.

[0059] The following introduces the hardware structure of the electronic device 400: Figure 4 The schematic diagram of the hardware structure of the electronic device 400 is shown. It should be understood that the electronic device 400 may have more or fewer components than those shown in the figure, may combine two or more components, or may have different component configurations. The various components shown in the figure may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0060] As Figure 4 shown, the electronic device 400 may include: a processor 110, a memory 120, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, and a display screen 194.

[0061] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modulation and demodulation processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.

[0062] Among them, the controller can be the nerve center and command center of the electronic device 400. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0063] A memory 120 can also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store the instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can directly call it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0064] In some embodiments, the processor 110 may include one or more interfaces. The interfaces can include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0065] The display screen 194 is used to display images, videos, etc. For example, in this application, the display screen 194 can be used to display prompts for push messages. The display screen 194 includes a display panel. The display panel can adopt a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 400 may include one or N display screens 194, where N is a positive integer greater than 1.

[0066] Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization rate of the antennas. For example: Antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0067] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc. applied to terminal 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 through Antenna 1, filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor and convert it into electromagnetic waves through Antenna 1 for radiation. In some embodiments, at least some functional modules of the mobile communication module 150 can be disposed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 can be disposed in the same device.

[0068] A modulation and demodulation processor (Modem processor) may include a modulator and a demodulator. Among them, the modulator is used to modulate a low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. Subsequently, the demodulator transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs a sound signal through an audio device, or displays an image or video. In some embodiments, the modulation and demodulation processor may be an independent device. In other embodiments, the modulation and demodulation processor may be independent of the processor 110 and be provided in the same device as the mobile communication module 150 or other functional modules.

[0069] The wireless communication module 160 may provide solutions for wireless communications applied to terminal devices, including wireless local area networks (WLANs) (such as Wi-Fi networks), Bluetooth (BT), BLE broadcasts, global navigation satellite systems (GNSSs), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc. 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, performs frequency modulation and filtering processing on the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive signals to be transmitted from the processor 110, perform frequency modulation and amplification on them, and convert them into electromagnetic waves through the antenna 2 for radiation.

[0070] In some embodiments, the antenna 1 of the terminal device is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 400 can communicate with the network and other devices through wireless communication technologies. For example, in the embodiments of the present application, the electronic device 400 is connected to the cellular network based on the antenna 1 and the mobile communication module 150, and is connected to the Wi-Fi network based on the antenna 2 and the wireless communication module 160.

[0071] For example, wireless communication technologies may include 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, and / or IR technologies, etc. The GNSS may include Global Positioning System (GPS), Global Navigation Satellite System (GLONASS), Beidou Navigation Satellite System (BDS), Quasi-Zenith Satellite System (QZSS), and / or Satellite Based Augmentation Systems (SBAS).

[0072] The software structure of the electronic device 400 will be introduced below:

[0073] Figure 5 The software architecture diagram of the electronic device 400 provided by the embodiment of the present application is shown. Among them, the software structure adopts a layered architecture. The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. As Figure 5 shown, taking the Android system running on the AP as an example, in some embodiments, the Android system is divided into three layers, from top to bottom are the application layer, the application framework layer (framework), and the kernel layer (kernel).

[0074] ①. The application layer may include a series of application packages. Such as Figure 5As shown, the application package includes, but is not limited to, push applications and power-saving applications, etc. Among them, a push application refers to an application with the function of receiving push messages. For example, the push application can be a system application and a third-party application, etc. The system application is used to receive push information from the system, such as including logistics update information and system update information, etc. The third-party application is used to receive push information from third-party applications, such as including chat information and news information, etc.

[0075] In this application, the push application can call the socket service in the application framework layer to create / release sockets, establish / disconnect long connections based on the sockets, and receive and send data packets (including heartbeat data packets and push information data packets) based on the long connections.

[0076] The power-saving application is used to manage the energy consumption of the push application. For example, in this application, the power-saving application can include an energy consumption identification module and an energy consumption optimization module. The energy consumption identification module is used to identify the energy consumption comparison result involved in sending heartbeat data packets by the push application under different networks according to the relevant data reported by the battery service in the application framework layer; the energy consumption optimization module is used to decide whether to perform energy consumption optimization according to the energy consumption comparison result. If energy consumption optimization is required, a network switching strategy (this strategy can follow some existing strategies, such as the night standby strategy, etc.) can be generated, and the switching instruction related to this strategy is sent to the network connection service in the application framework layer, so that the network connection service switches the network connected by the electronic device to a network with lower energy consumption according to the switching instruction.

[0077] ②. The application framework layer provides an application programming interface (API) framework, various services and management tools for application developers to access core functions, including functions such as interface management, data access, message passing at the application layer, application package management, telephone management, location management, etc. The application framework layer includes some predefined functions and algorithms. As Figure 5 shown, the application framework layer can include a battery service, a socket service, and a network connection service.

[0078] In this application, the battery service can detect the energy consumption involved in sending heartbeat data packets under different networks (for example, it can detect the power consumption data within a preset time, etc.), and report it to the energy consumption identification module in the application layer. Optionally, the power consumption data detected by the battery service can be the power consumption data of the entire system, or the battery service can be dedicated to detecting the power consumption data of sending heartbeat data packets. This application does not make a limitation on this.

[0079] The Connectivity Service can, in response to a switching instruction from an energy consumption optimization module in the application layer, determine which network the socket needs to be bound to. For example, the Connectivity Service can generate a network binding instruction and send the network binding instruction to the Socket Service.

[0080] The Socket Service can, in response to an instruction to push an application, create / release a socket. For a created socket, the Socket Service can also, in response to a network binding instruction sent by the Connectivity Service, bind the created socket to a network with lower energy consumption. Then, the Socket Service can call the network driver in the kernel layer to establish a long connection between the socket bound to the network and the server corresponding to the pushed application. It can be understood that after the long connection is established, the Socket Service can call the network driver in the kernel layer to send heartbeat data packets and push information data packets based on the socket bound to the network and with the long connection established.

[0081] ③. The kernel layer is the layer between hardware and software, including network drivers. As Figure 5 shown, the network drivers include Wi-Fi drivers and Modem drivers.

[0082] Among them, the Wi-Fi driver is used to establish a long connection with the server corresponding to the pushed application based on the Wi-Fi network, and send heartbeat data packets and push information data packets.

[0083] The Modem driver is used to establish a long connection with the server corresponding to the pushed application based on the Modem network, and send heartbeat data packets and push information data packets.

[0084] Based on the above software architecture, the embodiment of the present application provides a schematic flowchart of a communication method based on the software structure for the above scenario of default connection to the Wi-Fi network. As Figure 6 shown, the communication method includes the following steps 601 to step 606.

[0085] Wherein:

[0086] Step 601: When the Wi-Fi network supports establishing a long connection, the pushed application establishes a long connection corresponding to the Wi-Fi network based on the socket corresponding to the Wi-Fi network, and sends a heartbeat data packet based on the long connection corresponding to the Wi-Fi network.

[0087] In the embodiment of the present application, the electronic device supports communication through the Wi-Fi network or the Modem network. The user can turn on the Wi-Fi network and the Modem network at the same time to search for the signals of the Wi-Fi network and the Modem network. Exemplarily, as Figure 1 shown, if the user pre-turns on the "WLAN" control and the "Mobile Data" control.

[0088] If the signal quality of the Wi-Fi network and the signal quality of the Modem network searched by the electronic device both meet the connection quality requirements, it indicates that the Wi-Fi network supports establishing a long connection and the Modem network supports establishing a long connection. According to related technologies, the electronic device will default to connecting to the Wi-Fi network, establish a long connection corresponding to the Wi-Fi network, and send heartbeat data packets based on the long connection corresponding to the Wi-Fi network.

[0089] If the signal quality of the Wi-Fi network searched by the electronic device meets the connection quality requirements, and the signal quality of the Modem network does not meet the connection quality requirements, it indicates that the Wi-Fi network supports establishing a long connection and the Modem network does not support establishing a long connection. Therefore, the electronic device will connect to the Wi-Fi network, establish a long connection corresponding to the Wi-Fi network, and send heartbeat data packets based on the long connection corresponding to the Wi-Fi network.

[0090] Specifically, the push application in the electronic device can first call the socket service to create a socket, and then the push application calls the network connection service to bind the created socket to the Wi-Fi network. The bound socket is called the socket corresponding to the Wi-Fi network. Then, the socket service can call the Wi-Fi driver in the kernel layer to establish a long connection corresponding to the Wi-Fi network based on the socket corresponding to the Wi-Fi network. After the long connection corresponding to the Wi-Fi network is successfully established, the push application can periodically send heartbeat data packets to the server corresponding to the push application based on the long connection corresponding to the Wi-Fi network.

[0091] Step 602, the battery service reports the energy consumption corresponding to the Wi-Fi network and the energy consumption corresponding to the Modem network to the power-saving application.

[0092] In the embodiment of the present application, the battery service can detect the energy consumption corresponding to the Wi-Fi network and the energy consumption corresponding to the Modem network. Among them, the energy consumption corresponding to the Wi-Fi network is the energy consumption of sending heartbeat data packets based on the long connection corresponding to the Wi-Fi network within a preset duration, and the energy consumption corresponding to the Modem network is the energy consumption of sending heartbeat data packets based on the long connection corresponding to the Modem network within a preset duration. For example, the preset duration can be a preset number of days, hours, or minutes, etc. The energy consumption corresponding to the Wi-Fi network / Modem network can be detected according to connecting to the Wi-Fi network / Modem network in a historical period. The representation form of the energy consumption can be the power or current corresponding to sending heartbeat data packets, and the present application does not limit this.

[0093] Accordingly, after the power-saving application receives the energy consumption corresponding to the Wi-Fi network and the energy consumption corresponding to the Modem network, it can decide whether to perform energy consumption optimization. For example, Figure 6 In Figure 6 , Case 1 is the steps involved in performing energy consumption optimization, including subsequent steps 603 to 605; Case 2 is the steps involved in not performing energy consumption optimization, including subsequent step 606.

[0094] Step 603: When the energy consumption corresponding to the Wi-Fi network is higher than the energy consumption corresponding to the Modem network, the power-saving application sends a switching instruction to switch to the Modem network to the network connection service.

[0095] Step 604: When the Modem network supports establishing a long connection, the network connection service sends a network binding instruction to bind to the Modem network to the socket service.

[0096] Among them, when the network connection service receives the switching instruction to switch to the Modem network, it can first determine whether the Modem network supports establishing a long connection. For example, at step 601, if the Modem network supports establishing a long connection, it can determine whether the Modem network still supports establishing a long connection when receiving the switching instruction; or, at step 601, if the Modem network does not support establishing a long connection, it can determine whether the current Modem network supports establishing a long connection when receiving the switching instruction. Furthermore, when the Modem network supports establishing a long connection, it sends a network binding instruction to bind to the Modem network to the socket service.

[0097] Step 605: In response to the network binding instruction, the socket service calls the kernel layer to establish a long connection corresponding to the Modem network based on the socket corresponding to the Modem network, and sends a heartbeat data packet based on the long connection corresponding to the Modem network.

[0098] In this application, the socket service can first release the socket corresponding to the Wi-Fi network in step 601 and disconnect the long connection corresponding to the Wi-Fi network. Then, the socket service creates a new socket for the Modem network and establishes a long connection corresponding to the Modem network by binding the newly created socket to the Modem network. After the long connection corresponding to the Modem network is successfully established, the push application can periodically send heartbeat data packets to the server corresponding to the push application based on the long connection corresponding to the Modem network.

[0099] It can be understood that after switching to the long connection corresponding to the Modem network, the power-saving application can still continue to receive the energy consumption corresponding to the Wi-Fi network and the energy consumption corresponding to the Modem network reported by the battery service, so as to decide whether to perform another switch.

[0100] Step 606: When the energy consumption corresponding to the Wi-Fi network is lower than or equal to the energy consumption corresponding to the Modem network, call the kernel layer to continue sending heartbeat data packets based on the long connection corresponding to the Wi-Fi network.

[0101] If the energy consumption of sending heartbeat data packets over the Wi-Fi network is lower than or equal to that over the Modem network, the power-saving application does not need to generate a network switching instruction, and the long connection corresponding to the Wi-Fi network can still be maintained. Accordingly, the push application continues to send heartbeat data packets based on the long connection corresponding to the Wi-Fi network.

[0102] Based on Figure 6 In the illustrated embodiment, when the electronic device is default-connected to the Wi-Fi network, it can determine whether the energy consumption of sending heartbeat data packets over the Wi-Fi network is higher than that over the Modem network. If it is higher, it switches to the long connection over the Modem network to send heartbeat data packets; if not, it continues to send heartbeat data packets based on the long connection over the Wi-Fi network. In this way, the electronic device can select a network with lower energy consumption to establish a long connection and send heartbeat data packets, thereby effectively reducing the energy consumption of the device.

[0103] It should be added that if the electronic device is initially connected to the Modem network (for example, at the beginning, the signal quality of the Wi-Fi network does not meet the connection quality requirements, and the signal quality of the Modem network meets the connection quality requirements), and sends heartbeat data packets based on the long connection corresponding to the Modem network. Then, when the electronic device determines that the signal quality of the Wi-Fi network can meet the connection quality requirements, the electronic device will directly default to switch to the Wi-Fi network and send heartbeat data packets based on the long connection corresponding to the Wi-Fi network according to the relevant technology. Further, after the electronic device switches to the Wi-Fi network, it can decide whether to switch back to the Modem network or remain on the Wi-Fi network according to the Figure 6 process shown above.

[0104] Next, the implementation method for the case of switching from the Wi-Fi network to the Modem network (i.e., the above-mentioned Case 1) will be specifically described. As Figure 7 shown, this method includes the following steps 701 to 702. Figure 7 The execution subject of the method shown can be the above-mentioned electronic device. Or, Figure 7 The execution subject of the method shown can be the chip in the electronic device, which is not limited in the embodiments of the present application.

[0105] Step 701: When the first network supports establishing a long connection, the second network supports establishing a long connection, the first long connection corresponding to the first network is established, and the first energy consumption is higher than the second energy consumption, the electronic device disconnects the first long connection and establishes a second long connection corresponding to the second network.

[0106] In the embodiments of the present application, the first network may be a Wi-Fi network, and the second network may be a Modem network. That the first network supports establishing a long connection means that the signal quality of the Wi-Fi network searched by the electronic device meets the connection quality requirements, and that the second network supports establishing a long connection means that the signal quality of the Modem network searched by the electronic device meets the connection quality requirements.

[0107] The first long connection is a long connection established in advance through the Wi-Fi network. When the electronic device establishes the first long connection in advance, the Modem network may or may not support establishing a long connection, and the present application does not limit this.

[0108] Exemplarily, the electronic device simultaneously searches for the signals of the Wi-Fi network and the Modem network, and the signal qualities of both networks meet the connection quality requirements. Then, according to the related technology, the electronic device defaults to connecting to the Wi-Fi network and establishes the first long connection.

[0109] Alternatively, the electronic device searches for the signal of the Wi-Fi network and the signal meets the connection quality requirements, but the electronic device cannot search for the signal of the Modem network or searches for the signal of the Modem network but it does not meet the connection quality requirements. Then, the electronic device connects to the Wi-Fi network and establishes the first long connection.

[0110] Among them, the electronic device may establish the first socket in advance and bind the first socket to the Wi-Fi network to implement establishing the first long connection in advance. This process can specifically refer to the description in Step 601 above.

[0111] Furthermore, after the electronic device establishes the first long connection, it may first send heartbeat data packets and push information data packets based on the first long connection. When the electronic device determines that the Modem network supports establishing a long connection and the first energy consumption is higher than the second energy consumption, it means that the electronic device can switch from the Wi-Fi network to the Modem network. Therefore, the electronic device can disconnect the first long connection and establish a second long connection corresponding to the Modem network.

[0112] In a possible implementation, the manner in which the electronic device disconnects the first long connection and establishes a second long connection corresponding to the second network specifically includes: disconnecting the first long connection and releasing the first socket corresponding to the first long connection; creating a second socket; binding the second socket to the address and port number corresponding to the second network; and when the signal quality of the second network meets the connection requirement, establishing a second long connection based on the bound second socket.

[0113] Specifically, the electronic device can first disconnect the first long connection and release the first socket, then create a second socket and bind the second socket to the address and port number corresponding to the Modem network, and finally, based on the connection establishment process, establish a second long connection based on the second socket. By way of example, establishing a second long connection based on the second socket can refer to the TCP three-way handshake process in the related art, and the present application does not make any limitations thereto.

[0114] Step 702: The electronic device sends a heartbeat data packet based on the second long connection.

[0115] After the second long connection is successfully established, the electronic device can send a heartbeat data packet and a push information data packet based on the second long connection. The electronic device sending a heartbeat data packet based on the second long connection is also sending a heartbeat data packet based on the long connection corresponding to the Modem network.

[0116] Implementation Figure 7 In the illustrated embodiment, on the one hand, the energy consumption of sending a heartbeat data packet under the Modem network is less than that of sending a heartbeat data packet under the Wi-Fi network. This method can reduce the device energy consumption by switching from the Wi-Fi network to the Modem network. On the other hand, since the Modem network is more stable than the Wi-Fi network, after the switch, the long connection corresponding to the Modem network is not easily disconnected, and sending a heartbeat data packet over the Modem network is not likely to trigger the reconstruction of the long connection corresponding to the Modem network, which can also reduce the device energy consumption.

[0117] It should be noted that the method proposed in the present application can be applicable to the standby mode (especially the night standby mode), automatically switching the connection to different networks according to the energy consumption, and thus sending heartbeat data packets based on the long connections of different networks. If in the actual scenario of automatic network switching during specific implementation, there are also other data packets involved (such as push information data packets), then when obtaining the energy consumption, the energy consumption corresponding to the other data packets and the heartbeat data packet can also be obtained, so as to achieve automatic network switching after comparison.

[0118] Optionally, the electronic device can also perform network binding at any time according to the above embodiments. When performing network binding, if the electronic device is already connected to the network, it can switch or not switch from the currently connected network; when the network is not bound, the network binding of the electronic device is directly connected to a network with lower energy consumption.

[0119] The following introduces the methods for obtaining the above first energy consumption and second energy consumption:

[0120] Among them, the first energy consumption is the energy consumption of sending heartbeat data packets based on the long connection corresponding to the first network within the first time period, and the second energy consumption is the energy consumption of sending heartbeat data packets based on the long connection corresponding to the second network within the first time period.

[0121] Method 1: Evaluate the first energy consumption and the second energy consumption through standby detection.

[0122] In Method 1, the first time period is M days, where M is a positive integer greater than or equal to 1. Before the above electronic device disconnects the first long connection and establishes the second long connection corresponding to the second network, the method further includes: when the first network supports establishing a long connection, the second network does not support establishing a long connection, and in the standby mode where the long connection corresponding to the first network is established, detecting the first effective power-off data corresponding to each day within M days; when the first network does not support establishing a long connection, the second network supports establishing a long connection, and in the standby mode where the long connection corresponding to the second network is established, detecting the second effective power-off data corresponding to each day within M days; determining the standby current of the first network based on the first effective power-off data corresponding to each day within M days; determining the standby current of the second network based on the second effective power-off data corresponding to each day within M days; if the standby current of the first network is higher than the standby current of the second network, it is determined that the first energy consumption is higher than the second energy consumption.

[0123] Among them, the electronic device can respectively obtain the M-day effective power-off data detected through the standby mode under the Wi-Fi network or the Modem network. In this application, the standby mode means retaining the long connection heartbeat of the push application and closing the remaining applications and loads other than the push application. For example, the standby mode can be the mode that the mobile phone automatically enters after the user turns off the screen of the mobile phone at night and closes all processes and loads in the processes except the system processes. In such a standby mode, the mobile phone does not generate energy consumption due to the remaining processes or loads, and the energy consumption generated by the mobile phone is equivalent to the energy consumption of sending heartbeat data packets under the Wi-Fi network or the Modem network. Since this method is an approximate method, the M-day effective power-off data under the Wi-Fi network or the Modem network can be detected, and a more reliable evaluation of the first energy consumption or the second energy consumption can be performed based on the M-day effective power-off data.

[0124] Exemplarily, the first valid power-off data or the second valid power-off data of any day may include the standby duration (or standby time period) and the power-off amount of that day; alternatively, the first valid power-off data or the second valid power-off data of any day may include the average standby current of that day.

[0125] Based on the first valid power-off data corresponding to each day within M days, the electronic device can determine the standby current of the first network: Exemplarily, the electronic device first determines the average standby current of any day based on the standby duration and the power-off amount of that day, and then determines the average value of the average standby currents corresponding to each day within M days as the standby current of the first network / second network; alternatively, Exemplarily, the electronic device directly determines the average value of the average standby currents corresponding to each day within M days as the standby current of the first network / second network.

[0126] Optionally, the electronic device can standby for N days under the Wi-Fi network to obtain the first valid power-off data corresponding to each day within the above-mentioned M days, and standby for P days under the Modem network to obtain the second valid power-off data corresponding to each day within the above-mentioned M days. N is a positive integer greater than or equal to M, and P is a positive integer greater than or equal to M. In this optional method, when the electronic device stands by under the Wi-Fi network, the power-off data detected on a certain day of standby may be invalid power-off data. Therefore, the electronic device may need to standby for more than M days to obtain the first valid power-off data for M days. Similarly, when the electronic device stands by under the Modem network, it may need to standby for more than M days to obtain the second valid power-off data for M days.

[0127] Optionally, for any day during the N-day standby of the electronic device under the Wi-Fi network, if the standby duration corresponding to the power-off data detected on that day is greater than or equal to the preset threshold, the power-off data detected on that day is the first valid power-off data. Similarly, for any day during the P-day standby of the electronic device under the Modem network, if the standby duration corresponding to the power-off data detected on that day is greater than or equal to the preset threshold, the power-off data detected on that day is the second valid power-off data. Exemplarily, if the preset threshold is set to 5 hours, then when the electronic device is under the Wi-Fi network or the Modem network, the power-off data detected when the standby duration of one day is greater than or equal to 5 hours can be regarded as the first valid power-off data or the second valid power-off data.

[0128] Optionally, the detection positions corresponding to the first effective power-off data for each day within M days are the same, the detection positions corresponding to the second effective power-off data for each day within M days are the same, and the detection position corresponding to the first effective power-off data for any day is the same as the detection position corresponding to the second effective data for any day. By way of example, if the network switching solution in this application is for the switching between Wi-Fi network and Modem network when the user is at home, then it is necessary to detect the effective power-off data when the user is connected to the Wi-Fi network and the Modem network respectively at home; if the user is away on a business trip, the Wi-Fi network connected by the user at the business trip location cannot reflect the power consumption of the Wi-Fi network when the user is at home (different Wi-Fi signals), and the Modem network connected by the user at the business trip location cannot reflect the power consumption of the Modem network when the user is at home (different Modem signals). Therefore, the power-off data of the Wi-Fi network or the Modem network detected by the electronic device at the business trip location in the standby mode cannot be used as the first effective power-off data or the second effective power-off data. By ensuring the same detection position, the situation of signal change in the same network caused by the change of the detection position can be avoided.

[0129] Optionally, for any day during which the electronic device stands by for N days under the Wi-Fi network or for P days under the Modem network, if the network is interrupted during the time period corresponding to the standby duration of that day, the power-off data detected on that day is invalid power-off data.

[0130] The following shows a schematic table for collecting the first effective data provided by the embodiment of the present application, as shown in Table 1:

[0131] Table 1

[0132]

[0133] Among them, assuming that M takes a value of 5 hours, the standby duration corresponding to the effective power-off data for each day needs to be at least 5 hours. As shown in Table 1, the standby time period on the first day is 0:10 - 6:00 (equivalent to the standby duration on the first day being 5 hours and 50 minutes, which is greater than 5 hours). Therefore, the power-off data on the first day is effective, and the average standby current on the first day can be calculated based on the power-off data on the first day as 31 mA; the standby time period on the second day is 23:10 - 6:00 (equivalent to the standby duration on the second day being 6 hours and 50 minutes, which is greater than 5 hours). Therefore, the power-off data on the second day is effective, and the average standby current on the second day can be calculated based on the power-off data on the second day as 2527 mA; the standby time period on the third day is 3:10 - 5:00 (equivalent to the standby duration on the third day being 1 hour and 50 minutes, less than 5 hours). Therefore, the power-off data on the third day is invalid; the standby time period on the fourth day is 0:10 - 7:05 (equivalent to the standby duration on the fourth day being 6 hours and 55 minutes, which is greater than 5 hours). Therefore, the power-off data on the fourth day is effective, and the average standby current on the fourth day can be calculated based on the power-off data on the fourth day as 25 mA; the standby time period on the fifth day is 01:10 - 6:30. Although the standby duration on the fifth day is 5 hours and 20 minutes, which is greater than 5 hours, since the network was shut down midway, the power-off data on the fifth day is invalid; the standby time period on the sixth day is 22:10 - 6:20 (equivalent to the standby duration on the sixth day being 8 hours and 10 minutes, which is greater than 5 hours). Therefore, the power-off data on the sixth day is effective, and the average standby current on the sixth day can be calculated based on the power-off data on the first day as 26 mA; the standby time period on the seventh day is 01:10 - 6:30 (equivalent to the standby duration on the seventh day being 5 hours and 20 minutes, which is greater than 5 hours). Therefore, the power-off data on the seventh day is effective, and the average standby current on the seventh day can be calculated based on the power-off data on the first day as 38 mA.

[0134] Based on the above Table 1, the electronic device can standby for 7 days under the Wi-Fi network, thereby obtaining the average standby current for 5 days. Based on the average standby current for these 5 days, the standby current under the Wi-Fi network can be obtained as 29.4 mA.

[0135] It can be understood that the above method of obtaining the effective power-off data for M days in the standby mode is only an example. In specific implementation, it can be set to obtain the power-off data for a preset duration in the standby mode, such as obtaining a total of 30 hours of power-off data, and these 30 hours can be obtained on different days.

[0136] Optionally, when Method 1 is actually applied, the power-saving application in the electronic device can prompt the user in a timely manner. For example, the electronic device prompts the user to obtain the effective power consumption data during M days of Wi-Fi network standby, so that the user can turn off the "Mobile Data" control and turn on the "WLAN" control before the electronic device's screen goes off at night. At the same time, during the process of obtaining the effective power consumption data during M days of Wi-Fi network standby, the user is prompted about how many days of effective power consumption data during Wi-Fi network standby have been obtained, and how many more days of effective power consumption data during Wi-Fi network standby need to be obtained. Alternatively, the power-saving application can also store the relevant data of the above prompts, and the user can view it when clicking to enter the power-saving application.

[0137] Method 2: Directly detect the energy consumption of a single heartbeat data packet and the number of times of sending a single heartbeat data packet within the first duration.

[0138] In Method 1, before the above-mentioned electronic device disconnects the first long connection and establishes a second long connection corresponding to the second network, the method further includes: detecting the first single power consumption data of sending a single heartbeat data packet based on the long connection corresponding to the first network; detecting the second single power consumption data of sending a single heartbeat data packet based on the long connection corresponding to the second network; detecting the first period of sending heartbeat data packets based on the long connection of the first network; detecting the second period of sending heartbeat data packets based on the long connection of the second network; determining the first energy consumption based on the first single power consumption data, the first period, and the first duration; determining the second energy consumption based on the second single power consumption data, the second period, and the first duration.

[0139] Among them, the manner in which the electronic device determines the first energy consumption based on the first single power consumption data, the first period, and the first duration specifically includes: determining the first number of times of sending heartbeat data packets based on the long connection of the first network within the first duration based on the first period and the first duration; determining the product of the first number of times and the first single power consumption data as the first energy consumption; the manner in which the electronic device determines the second energy consumption based on the second single power consumption data, the second period, and the first duration specifically includes: determining the second number of times of sending heartbeat data packets based on the long connection of the second network within the first duration based on the second period and the first duration; determining the product of the second number of times and the second single power consumption data as the second energy consumption.

[0140] Exemplarily, the electronic device measures the energy consumption of sending a heartbeat data packet once under the Wi-Fi network as P1 (i.e., the first single power-off data), and measures the energy consumption of sending a heartbeat data packet once under the Modem network as P2 (i.e., the second single power-off data). At the same time, the electronic device detects that the NAT keep-alive duration under the Wi-Fi network is T1 (i.e., the first period), and the NAT keep-alive duration under the Modem network is T2 (i.e., the second period). If the first duration is T, the electronic device can determine that the first number is T / T1, and the second number is T / T2. If T / T1 * P1 (the calculation result is the first energy consumption) is greater than T / T2 * P2 (the calculation result is the second energy consumption), the electronic device can determine that the first energy consumption is greater than the second energy consumption; otherwise, the first energy consumption is less than or equal to the second energy consumption.

[0141] It can be seen that by directly detecting the power-off data of sending a heartbeat data packet once under different networks and the periods of sending heartbeat data packets under different networks, the energy consumption of sending heartbeat data packets by different networks within the first duration can be directly measured. This method can be detected in real time based on the chip, without requiring the electronic device to be in the standby mode, etc., and can obtain the energy consumption conditions under different networks more efficiently.

[0142] The following is a supplementary introduction to the specific implementation of the above two methods in step 603:

[0143] For Method 1, Figure 8 An interaction schematic diagram involved in step 603 is shown.

[0144] Among them, when the power-saving application determines whether to switch to the Modem network according to the first energy consumption and the second energy consumption, if it is the above Method 1, the energy consumption recognition module in the power-saving application can receive the standby duration and the power-off amount (including those corresponding to the Modem network and the Wi-Fi network respectively). Since Method 1 requires long-term standby, the energy consumption recognition module needs to perform energy consumption learning based on the standby duration and the power-off amount to identify the effectiveness of the standby duration and the power-off amount according to the energy consumption learning, and calculate the standby current, etc.; after obtaining the standby current through the energy consumption learning, the energy consumption recognition module performs energy consumption comparison based on the standby current and sends the energy consumption comparison result to the energy consumption optimization module. The energy consumption optimization module can decide whether to send a switching instruction according to the energy consumption comparison result. If not, it continues to connect to the Wi-Fi network. If a switching instruction to switch to the Modem network is sent, it switches to the Modem network to send heartbeat data packets based on the Modem network.

[0145] For Method 2, Figure 9 An interaction schematic diagram involved in step 603 is shown.

[0146] Among them, when the power-saving application determines whether to switch to the Modem network according to the first energy consumption and the second energy consumption, if it is the above-mentioned method 2, the energy consumption identification module in the power-saving application can receive the energy consumption and period of sending the heartbeat data packet once (including those corresponding to the Modem network and the Wi-Fi network respectively). Since method 2 does not require long-term standby and all data is valid, the energy consumption identification module compares the energy consumption based on the energy consumption and period of sending the heartbeat data packet once, and sends the energy consumption comparison result to the energy consumption optimization module. The energy consumption optimization module can decide whether to send a switching instruction according to the energy consumption comparison result. If not, it continues to connect to the Wi-Fi network. If it sends a switching instruction to switch to the Modem network, it switches to the Modem network to send the heartbeat data packet based on the Modem network.

[0147] An embodiment of the present application further provides an electronic device, which may include: one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code. The computer program code includes computer instructions. When the one or more processors execute the computer instructions, the electronic device performs each function or step executed by the electronic device in the above method embodiment.

[0148] An embodiment of the present application further provides an audio processing device, which includes a function / unit for executing the functions in the electronic device in the above embodiment.

[0149] An embodiment of the present application further provides a chip system, as Figure 10 shown, the chip system includes at least one processor 1001 and at least one interface circuit 1002. The processor 1001 and the interface circuit 1002 can be interconnected by lines. For example, the interface circuit 1002 can be used to receive signals from other devices (such as the memory of the electronic device). For another example, the interface circuit 1002 can be used to send signals to other devices (such as the processor 1001). Exemplarily, the interface circuit 1002 can read the instructions stored in the memory and send the instructions to the processor 1001. When the instructions are executed by the processor 1001, the electronic device can perform each step in the above embodiment. Of course, the chip system may also include other discrete devices, and the embodiments of the present application do not make specific limitations on this.

[0150] This embodiment further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions run on the electronic device, the electronic device performs each function or step executed in the above method embodiment.

[0151] This embodiment also provides a computer program product. When the computer program product runs on a computer, it causes the computer to execute each function or step performed by the electronic device in the above method embodiment.

[0152] In addition, an embodiment of the present application also provides a device, which may specifically be a chip, a component or a module. The device may include a processor and a memory connected to each other. Among them, the memory is used to store computer-executable instructions. When the device runs, the processor may execute the computer-executable instructions stored in the memory, so that the chip executes each function or step performed by the electronic device in the above method embodiment.

[0153] Among them, the electronic device, the audio processing device, the computer-readable storage medium, the computer program product or the chip provided in this embodiment are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be elaborated here.

[0154] Through the description of the above embodiments, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the above division of each functional module is used as an example. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.

[0155] In several embodiments provided in the present application, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the module or unit is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces. The indirect coupling or communication connection of the device or unit may be in an electrical, mechanical or other form.

[0156] The unit described as a separated component may or may not be physically separated. The component displayed as a unit may be a physical unit or multiple physical units, that is, it may be located in one place, or may be distributed to multiple different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0157] In addition, in each embodiment of the present application, each functional unit may be integrated into a processing unit, may exist physically alone for each unit, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.

[0158] 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 solution of the embodiments of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. The software product is stored in a storage medium and includes several instructions to enable a device (which may be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the methods of the various embodiments of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.

[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and not to limit them. Although the present application has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present application can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present application.

Claims

1. A communication method, characterized in that, The method includes: When the first network supports establishing a long connection, the second network supports establishing a long connection, the first long connection corresponding to the first network is established, and the first energy consumption is higher than the second energy consumption, disconnect the first long connection and establish a second long connection corresponding to the second network; the first energy consumption is the energy consumption of sending a heartbeat data packet based on the long connection corresponding to the first network within a first time period, and the second energy consumption is the energy consumption of sending a heartbeat data packet based on the long connection corresponding to the second network within the first time period; Send a heartbeat data packet based on the second long connection.

2. The method according to claim 1, characterized in that, The disconnecting the first long connection and establishing a second long connection corresponding to the second network includes: Disconnect the first long connection and release the first socket corresponding to the first long connection; Create a second socket; Bind the second socket to the address and port number corresponding to the second network; When the signal quality of the second network meets the connection requirement, establish the second long connection based on the bound second socket.

3. The method according to claim 1 or 2, characterized in that, The first time period is M days, and M is a positive integer greater than or equal to 1; Before disconnecting the first long connection and establishing a second long connection corresponding to the second network, the method further includes: When the first network supports establishing a long connection, the second network does not support establishing a long connection, and in the standby mode where the long connection corresponding to the first network is established, detect the first effective power-off data corresponding to each day within M days; When the first network does not support establishing a long connection, the second network supports establishing a long connection, and in the standby mode where the long connection corresponding to the second network is established, detect the second effective power-off data corresponding to each day within M days; Based on the first effective power-off data corresponding to each day within the M days, determine the standby current of the first network; Based on the second effective power-off data corresponding to each day within the M days, determine the standby current of the second network; If the standby current of the first network is higher than the standby current of the second network, determine that the first energy consumption is higher than the second energy consumption.

4. The method according to claim 3, characterized in that The standby duration corresponding to the first effective power-off data is greater than or equal to a preset threshold, and the standby duration corresponding to the second effective power-off data is greater than or equal to the preset threshold.

5. The method according to claim 3, characterized in that, The detection positions corresponding to the first effective power-off data corresponding to each day within the M days are the same, the detection positions corresponding to the second effective power-off data corresponding to each day within the M days are the same, and the detection position corresponding to the first effective power-off data corresponding to any day is the same as the detection position corresponding to the second effective data corresponding to any day.

6. The method according to claim 1 or 2, characterized in that, Before disconnecting the first long connection and establishing a second long connection corresponding to the second network, the method further includes: Detect the first single-time power-off data for sending a heartbeat data packet once based on the long connection corresponding to the first network; Detect the second single-time power-off data for sending a heartbeat data packet once based on the long connection corresponding to the second network; Detect the first period for sending a heartbeat data packet based on the long connection of the first network; Detect the second period for sending a heartbeat data packet based on the long connection of the second network; Determine the first energy consumption based on the first single power-off data, the first period, and the first duration; Determine the second energy consumption based on the second single power-off data, the second period, and the first duration.

7. The method according to claim 6, wherein The determining the first energy consumption based on the first single power-off data, the first period, and the first duration includes: Based on the first period and the first duration, determine the first number of times of sending heartbeat data packets based on the long connection of the first network within the first duration; Determine the product of the first number of times and the first single power-off data as the first energy consumption; The determining the second energy consumption based on the second single power-off data, the second period, and the first duration includes: Based on the second period and the first duration, determine the second number of times of sending heartbeat data packets based on the long connection of the second network within the first duration; Determine the product of the second number of times and the second single power-off data as the second energy consumption.

8. An electronic device, characterized in that, Includes: One or more processors, one or more memories; wherein, the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, and the computer program code includes computer instructions. When the one or more processors execute the computer instructions, the electronic device executes the method according to any one of claims 1-7.

9. A chip system is applied to an electronic device, characterized in that, The chip system includes at least one processor and an interface. The interface is used to receive computer instructions and transmit them to the at least one processor; the at least one processor runs the computer instructions to make the electronic device execute the method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, Computer instructions are stored in the computer-readable storage medium. When the computer instructions run on an electronic device, the electronic device executes the method according to any one of claims 1-7.