File sharing method and terminal device
Embodiments of this application provide a file sharing method and a terminal device. The method includes: After receiving a file sharing request of a transmitter device, if a receiver device is currently connected to a 2.4 GHz Wi-Fi network and does not support dual band dual concurrent DBDC, the receiver device establishes a peer-to-peer P2P connection in a target frequency band with the transmitter device, where the target frequency band includes frequency bands of 5 GHz and above; and the receiver device receives, by using the P2P connection, a file sent by the transmitter device. In this way, the transmitter device establishes the P2P connection in a higher wireless frequency band with the receiver device, to prevent another wireless signal in a frequency band of less than 5 GHz from causing interference to the P2P connection between the transmitter device and the receiver device.
1 . A file sharing method, applied to a receiver device, wherein the method comprises:
receiving a first broadcast message sent by a transmitter device, wherein the first broadcast message comprises a file sharing request;
sending a second broadcast message to the transmitter device in response to the first broadcast message, wherein the second broadcast message comprises receiver device information;
receiving a P2P connection request of the transmitter device, wherein the P2P connection request is generated by the transmitter device based on the receiver device information;
when the receiver device is currently connected to a 2.4 GHz Wi-Fi network and does not support dual band dual concurrent (DBDC), starting a network preferential selection procedure in response to the P2P connection request, wherein the network preferential selection procedure is used for the receiver device to switch from the 2.4 GHz Wi-Fi network to a Wi-Fi network in a target frequency band, wherein the target frequency band comprises frequency bands of 5 GHz and above, wherein the network preferential selection procedure comprises
determining whether the receiver device is currently connected to a Wi-Fi hotspot in the target frequency band,
when the receiver device is not currently connected to the Wi-Fi hotspot in the target frequency band, selecting a target hotspot from surrounding Wi-Fi hotspots in the target frequency band based on a signal strength and/or a protocol standard of the Wi-Fi hotspot,
when the target hotspot is selected, determining whether a condition for connecting to the target hotspot is met, and
when the condition for connecting to the target hotspot is met, connecting to the target hotspot;
establishing a Wi-Fi P2P connection in the target frequency band with the transmitter device; and
receiving a file sent by the transmitter device by using the Wi-Fi P2P connection.
2 . The method according to claim 1 , wherein the selecting the target hotspot from surrounding Wi-Fi hotspots in the target frequency band based on a signal strength and/or a protocol standard of the Wi-Fi hotspot comprises:
selecting, from the Wi-Fi hotspots in the target frequency band, a Wi-Fi hotspot that belongs to a same access point device as a Wi-Fi hotspot to which the receiver device is currently connected and that has a received signal strength indicator RSSI value greater than a first preset threshold as the target hotspot; and/or
selecting, from the Wi-Fi hotspots in the target frequency band, a Wi-Fi hotspot that has a largest quantity of signal bars as the target hotspot; and/or
selecting, from the Wi-Fi hotspots in the target frequency band, a Wi-Fi hotspot that has a highest protocol standard as the target hotspot.
3 . The method according to claim 1 , wherein the determining whether the condition for connecting to the target hotspot is met further comprises: determining, based on a score and/or a signal strength of the target hotspot, whether the condition for connecting to the target hotspot is met, wherein the score of the target hotspot is determined based on at least one or more of the following information: a quantity of times of success of historical connections between the receiver device and the target hotspot, a historical transmission rate, a historical signal strength, and a quantity of times of historical freeze.
4 . The method according to claim 1 , wherein meeting the condition for connecting to the target hotspot comprises any one of the following:
a score of the target hotspot is greater than or equal to a second preset threshold, and an RSSI value of the target hotspot is greater than or equal to a third preset threshold;
the score of the target hotspot is greater than a sum of a score of a Wi-Fi hotspot to which the receiver device is currently connected and a preset compensation value, and the RSSI value of the target hotspot is greater than or equal to a fourth preset threshold; or
the target hotspot and the Wi-Fi hotspot to which the receiver device is currently connected belong to a same access point device, and designated bits in a media access control address MAC address are the same, and the RSSI value of the target hotspot is greater than or equal to a fifth preset threshold.
5 . The method according to claim 1 , further comprising:
ending the network preferential selection procedure when the receiver device is currently connected to the Wi-Fi hotspot in the target frequency band.
6 . The method according to claim 1 , further comprising: when the target hotspot is not selected, or when the condition for connecting to the target hotspot is not met, starting a network multiplex procedure.
7 . The method according to claim 6 , wherein the network multiplex procedure comprises:
sending a first indication message to the transmitter device, wherein the first indication message is used to indicate the transmitter device to create a personal hotspot in the target frequency band;
receiving connection information of the personal hotspot from the transmitter device; and
connecting to the personal hotspot based on the connection information.
8 . The method according to claim 6 , wherein the network multiplex procedure comprises:
sending a remote network configuration request to the transmitter device, wherein the remote network configuration request is used to indicate the transmitter device to configure a P2P agent server network in the target frequency band;
receiving a configuration result of the P2P agent server network from the transmitter device; and
configuring a local P2P agent client network based on the configuration result, to switch from the 2.4 GHz Wi-Fi network to the P2P agent server network.
9 . The method according to claim 1 , wherein the first broadcast message and the second broadcast message are Bluetooth low energy (BLE) broadcast messages, and the P2P connection request is sent by the transmitter device by using a BLE connection; and before the receiving, by the receiver device, the P2P connection request from the transmitter device, the method further comprises: establishing the BLE connection with the transmitter device.
10 . The method according to claim 1 , wherein before the establishing the Wi-Fi P2P connection in the target frequency band with the transmitter device, the method further comprises: disconnecting a Bluetooth low energy (BLE) connection from the transmitter device.
11 . A terminal device operating as a receiver device, comprising:
a processor;
a memory coupled to the processor and configured to store program instructions, wherein the processor is configured to execute the program instructions to cause the terminal device to:
receive a first broadcast message sent by a transmitter device, wherein the first broadcast message comprises a file sharing request;
send a second broadcast message to the transmitter device in response to the first broadcast message, wherein the second broadcast message comprises receiver device information;
receive a P2P connection request of the transmitter device, wherein the P2P connection request is generated by the transmitter device based on the receiver device information;
when the receiver device is currently connected to a 2.4 GHz Wi-Fi network and does not support dual band dual concurrent (DBDC), start a network preferential selection procedure in response to the P2P connection request, wherein the network preferential selection procedure is used for the receiver device to switch from the 2.4 GHz Wi-Fi network to a Wi-Fi network in a target frequency band, wherein the target frequency band comprises frequency bands of 5 GHz and above;
establish a Wi-Fi P2P connection in the target frequency band with the transmitter device;
receive a file sent by the transmitter device by using the Wi-Fi P2P connection;
when a target hotspot is not selected, or when a condition for connecting to the target hotspot is not met, start a network multiplex procedure, which when performed, is configured to:
send a first indication message to the transmitter device, wherein the first indication message is used to indicate the transmitter device to create a personal hotspot in the target frequency band;
receive connection information of the personal hotspot from the transmitter device; and
connect to the personal hotspot based on the connection information.
12 . The terminal device according to claim 11 , wherein the network preferential selection procedure comprises to:
determine whether the receiver device is currently connected to a Wi-Fi hotspot in the target frequency band;
when the receiver device is not currently connected to the Wi-Fi hotspot in the target frequency band, select a target hotspot from surrounding Wi-Fi hotspots in the target frequency band based on a signal strength and/or a protocol standard of the Wi-Fi hotspot;
when the target hotspot is selected, determine whether a condition for connecting to the target hotspot is met; and
when the condition for connecting to the target hotspot is met, connect to the target hotspot.
13 . The terminal device according to claim 12 , wherein to select the target hotspot from surrounding Wi-Fi hotspots in the target frequency band based on the signal strength and/or the protocol standard of the Wi-Fi hotspot comprises to:
select, from the Wi-Fi hotspots in the target frequency band, a Wi-Fi hotspot that belongs to a same access point device as a Wi-Fi hotspot to which the receiver device is currently connected and that has a received signal strength indicator RSSI value greater than a first preset threshold as the target hotspot; and/or
select, from the Wi-Fi hotspots in the target frequency band, a Wi-Fi hotspot that has a largest quantity of signal bars as the target hotspot; and/or
select, from the Wi-Fi hotspots in the target frequency band, a Wi-Fi hotspot that has a highest protocol standard as the target hotspot.
14 . The terminal device according to claim 12 , wherein to determine whether the condition for connecting to the target hotspot is met comprises to: determine, based on a score and/or a signal strength of the target hotspot, whether the condition for connecting to the target hotspot is met, wherein the score of the target hotspot is determined based on at least one or more of the following information: a quantity of times of success of historical connections between the receiver device and the target hotspot, a historical transmission rate, a historical signal strength, and a quantity of times of historical freeze.
15 . The terminal device according to claim 12 , wherein meeting the condition for connecting to the target hotspot comprises any one of the following:
a score of the target hotspot is greater than or equal to a second preset threshold, and an RSSI value of the target hotspot is greater than or equal to a third preset threshold;
the score of the target hotspot is greater than a sum of a score of a Wi-Fi hotspot to which the receiver device is currently connected and a preset compensation value, and the RSSI value of the target hotspot is greater than or equal to a fourth preset threshold; or
the target hotspot and the Wi-Fi hotspot to which the receiver device is currently connected belong to a same access point device, and designated bits in a media access control address MAC address are the same, and the RSSI value of the target hotspot is greater than or equal to a fifth preset threshold.
16 . The terminal device according to claim 12 , the program instructions further cause the terminal device to:
end the network preferential selection procedure when the receiver device is currently connected to the Wi-Fi hotspot in the target frequency band.
17 . The terminal device according to claim 12 , the program instructions further cause the terminal device to:
when the target hotspot is not selected, or when the condition for connecting to the target hotspot is not met, start a network multiplex procedure.
18 . The terminal device according to claim 17 , wherein the network multiplex procedure comprises to:
send a first indication message to the transmitter device, wherein the first indication message is used to indicate the transmitter device to create a personal hotspot in the target frequency band;
receive connection information of the personal hotspot from the transmitter device; and
connect to the personal hotspot based on the connection information.
19 . A non-transitory computer storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are run on a computer operating as a receiver device, the computer is enabled to:
receive a first broadcast message sent by a transmitter device, wherein the first broadcast message comprises a file sharing request;
send a second broadcast message to the transmitter device in response to the first broadcast message, wherein the second broadcast message comprises receiver device information;
receive a P2P connection request of the transmitter device, wherein the P2P connection request is generated by the transmitter device based on the receiver device information;
when the receiver device is currently connected to a 2.4 GHz Wi-Fi network and does not support dual band dual concurrent (DBDC), start a network preferential selection procedure in response to the P2P connection request, wherein the network preferential selection procedure is used for the receiver device to switch from the 2.4 GHz Wi-Fi network to a Wi-Fi network in a target frequency band, wherein the target frequency band comprises frequency bands of 5 GHz and above;
establish a Wi-Fi P2P connection in the target frequency band with the transmitter device;
receive a file sent by the transmitter device by using the Wi-Fi P2P connection; and
when a target hotspot is not selected, or when a condition for connecting to the target hotspot is not met, start a network multiplex procedure, which when performed, is configured to:
send a remote network configuration request to the transmitter device, wherein the remote network configuration request is used to indicate the transmitter device to configure a P2P agent server network in the target frequency band;
receive a configuration result of the P2P agent server network from the transmitter device; and
configure a local P2P agent client network based on the configuration result, to switch from the 2.4 GHz Wi-Fi network to the P2P agent server network.