Wi-Fi P2P connection method, electronic device, program product, and medium
This application provides a Wi-Fi P2P connection method, an electronic device, a program product, and a readable storage medium. A first device and a second device access a network by using different channels in a same band. The first device determines a device with a weaker switching capability by using Wi-Fi module intra-band inter-channel switching capability values of the first device and the second device, and establishes a P2P connection by using a STA channel through which the device with the weaker switching capability accesses the network.
1 . A Wireless Fidelity (Wi-Fi) Peer-To-Peer (P2P) connection method, applied to a first device, wherein the first device and a second device access a network by using different channels in a same band, and the Wi-Fi P2P connection method comprises:
obtaining, by the first device, a first Wi-Fi module intra-band inter-channel switching capability of the first device, and establishing a connection channel with the second device;
receiving, by the first device, a second Wi-Fi module intra-band inter-channel switching capability of the second device and a station (STA) channel through which the second device accesses the network that are sent by the second device through the connection channel established with the first device;
determining, by the first device, which of the first device and the second device has a weaker switching capability according to the first Wi-Fi module intra-band inter-channel switching capability and the second Wi-Fi module intra-band inter-channel switching capability; and
establishing, by the first device, a Wi-Fi P2P connection with the second device according to the STA channel through which the second device accesses the network when it is determined that the second device has the weaker switching capability than the first device.
2 . The Wi-Fi P2P connection method according to claim 1 , wherein the first Wi-Fi module intra-band inter-channel switching capability comprises three values: a P2P channel working duration of the first device, a STA channel working duration of the first device, and a switching-consumed time of the first device; and
wherein the second Wi-Fi module intra-band inter-channel switching capability comprises three values: a P2P channel working duration of the second device, a STA channel working duration of the second device, and a switching-consumed time of the second device.
3 . The Wi-Fi P2P connection method according to claim 1 , wherein the first Wi-Fi module intra-band inter-channel switching capability comprises a first value, and the first value represents the Wi-Fi module intra-band inter-channel switching capability of the first device; and
wherein the second Wi-Fi module intra-band inter-channel switching capability comprises a second value, and the second value represents the Wi-Fi module intra-band inter-channel switching capability of the second device; and
wherein determining, by the first device, which of the first device and the second device has the weaker switching capability according to the first Wi-Fi module intra-band inter-channel switching capability and the second Wi-Fi module intra-band inter-channel switching capability comprises:
comparing, by the first device, the first value with the second value, and determining which of the first device and the second device has the weaker switching capability according to which of the first value and the second value is smaller.
4 . The Wi-Fi P2P connection method according to claim 2 , wherein determining, by the first device, which of the first device and the second device has the weaker switching capability according to the first Wi-Fi module intra-band inter-channel switching capability and the second Wi-Fi module intra-band inter-channel switching capability comprises:
separately comparing, by the first device, the P2P channel working duration of the first device with the P2P channel working duration of the second device, the STA channel working duration of the first device with the STA channel working duration of the second device, and the switching-consumed time of the first device with the switching-consumed time of the second device, to obtain three comparison results; and
determining, by the first device, which of the first device and the second device has the weaker switching capability according to the three comparison results.
5 . The Wi-Fi P2P connection method according to claim 1 , wherein receiving, by the first device, the second Wi-Fi module intra-band inter-channel switching capability of the second device and the STA channel through which the second device accesses the network that are sent by the second device through the connection channel established with the first device, comprises:
receiving, by the first device through a Bluetooth connection channel or a P2P connection channel, the second Wi-Fi module intra-band inter-channel switching capability of the second device and the STA channel through which the second device accesses the network that are sent by the second device, wherein the P2P connection channel is obtained by the first device and the second device by establishing a P2P connection through a common channel.
6 . The Wi-Fi P2P connection method according to claim 1 , further comprising:
when the first device determines that the second device has the weaker switching capability than the first device, and the STA channel through which the second device accesses the network is not supported by the first device, establishing, by the first device, a P2P connection between the first device and the second device by using a STA channel through which the first device accesses the network; or
when the first device determines that the first device has the weaker switching capability than the second device and the STA channel through which the first device accesses the network is not supported by the second device, establishing, by the first device, a P2P connection between the first device and the second device by using a STA channel through which the second device accesses the network.
7 . The Wi-Fi P2P connection method according to claim 6 , further comprising:
before establishing, by the first device, the P2P connection between the first device and the second device by using the STA channel through which the first device accesses the network, determining, by the first device, that the STA channel through which the first device accesses the network is a channel supported by the second device; or
before establishing, by the first device, the P2P connection between the first device and the second device by using the STA channel through which the second device accesses the network, determining, by the first device, that the STA channel through which the second device accesses the network is a channel supported by the first device.
8 . The Wi-Fi P2P connection method according to claim 7 , further comprising:
when the first device determines that the STA channel through which the first device accesses the network is not a channel supported by the second device, establishing, by the first device, a P2P connection between the first device and the second device by using a channel supported by both the first device and the second device; or
when the first device determines that the STA channel through which the second device accesses the network is not a channel supported by the first device, establishing, by the first device, a P2P connection between the first device and the second device by using a channel supported by both the first device and the second device.
9 . The Wi-Fi P2P connection method according to claim 1 , the method further comprising:
after establishing, by the first device, the P2P connection between the first device and the second device by using the STA channel through which the second device accesses the network when it is determined that the second device has the weaker switching capability than the first device, when the first device determines that the P2P connection between the first device and the second device is not successfully established, establishing, by the first device, a P2P connection between the first device and the second device by an STA channel through which the first device accesses the network.
10 . The Wi-Fi P2P connection method according to claim 9 , wherein after establishing, by the first device, the P2P connection between the first device and the second device by using the STA channel through which the first device accesses the network, the method further comprises:
when the first device determines that the P2P connection between the first device and the second device is not successfully established, establishing, by the first device, a P2P connection between the first device and the second device by using a channel supported by both the first device and the second device.
11 . An electronic device, configured to act as a first device, and the electronic device comprising:
one or more processors, a memory, and a wireless communications interface, wherein
the memory and the wireless communications interface are coupled to the one or more processors, the memory is configured to stores computer program code, the computer program code comprises computer instructions, and when the one or more processors execute the computer instructions, the electronic device performs the following:
obtaining a first Wireless Fidelity (Wi-Fi) module intra-band inter-channel switching capability of the first device, and establishing a connection channel with a second device;
receiving a second Wi-Fi module intra-band inter-channel switching capability of the second device and a station (STA) channel through which the second device accesses a network that are sent by the second device through the connection channel established with the first device;
determining which of the first device and the second device has a weaker switching capability according to the first Wi-Fi module intra-band inter-channel switching capability and the second Wi-Fi module intra-band inter-channel switching capability; and
establishing a Wi-Fi Peer-To-Peer (P2P) connection with the second device according to the STA channel through which the second device accesses the network when it is determined that the second device is the device has the weaker switching capability than the first device.
12 . The electronic device according to claim 11 , wherein the first Wi-Fi module intra-band inter-channel switching capability comprises three values: a P2P channel working duration of the first device, a STA channel working duration of the first device, and a switching-consumed time of the first device; and
wherein the second Wi-Fi module intra-band inter-channel switching capability comprises three values: a P2P channel working duration of the second device, STA channel working duration of the second device, and switching-consumed time of the second device.
13 . The electronic device according to claim 11 , wherein the first Wi-Fi module intra-band inter-channel switching capability comprises a first value, and the first value represents the Wi-Fi module intra-band inter-channel switching capability of the first device;
wherein the second Wi-Fi module intra-band inter-channel switching capability comprises a second value, and the second value represents the Wi-Fi module intra-band inter-channel switching capability of the second device; and
wherein determining which of the first device and the second device has the weaker switching capability by using the first Wi-Fi module intra-band inter-channel switching capability and the second Wi-Fi module intra-band inter-channel switching capability comprises:
comparing the first value with the second value, and determining which of the first device and the second device has the weaker switching capability according to which of the first value and the second value is smaller.
14 . The electronic device according to claim 12 , wherein determining, by the first device, the weaker switching capability which of the first device and the second device has the weaker switching capability according to the first Wi-Fi module intra-band inter-channel switching capability and the second Wi-Fi module intra-band inter-channel switching capability comprises:
separately comparing the P2P channel working duration of the first device with the P2P channel working duration of the second device, the STA channel working duration of the first device with the STA channel working duration of the second device, and the switching-consumed time of the first device with the switching-consumed time of the second device, to obtain three comparison results; and
determining which of the first device and the second device has the weaker switching capability according to the three comparison results.
15 . The electronic device according to claim 11 , wherein receiving the second Wi-Fi module intra-band inter-channel switching capability of the second device and the STA channel through which the second device accesses the network that are sent by the second device comprises:
receiving, through a Bluetooth connection channel or a peer to peer (P2P) connection channel, the second Wi-Fi module intra-band inter-channel switching capability of the second device and the STA channel through which the second device accesses the network that are sent by the second device, wherein the P2P connection channel is obtained by the first device and the second device by establishing a P2P connection through a common channel.
16 . The electronic device according to claim 15 , wherein when the one or more processors execute the computer instructions, the electronic device performs the following:
when the first device determines that the second device has the weaker switching capability than the first device, and the STA channel through which the second device accesses the network is not supported by the first device, establishing a P2P connection between the first device and the second device by using a STA channel through which the first device accesses the network; or
when the first device determines that the first device has the weaker switching capability than the second device and the STA channel through which the first device accesses the network is not supported by the second device, establishing a P2P connection between the first device and the second device by using a STA channel through which the second device accesses the network.
17 . The electronic device according to claim 16 , wherein when the one or more processors execute the computer instructions, the electronic device performs the following:
before establishing the P2P connection between the first device and the second device by using the STA channel through which the first device accesses the network, determining that the STA channel through which the first device accesses the network is a channel supported by the second device; or
before establishing the P2P connection between the first device and the second device by using the STA channel through which the second device accesses the network, determining that the STA channel through which the second device accesses the network is a channel supported by the first device.
18 . The electronic device according to claim 17 , wherein when the one or more processors execute the computer instructions, the electronic device performs the following:
when the first device determines that the STA channel through which the first device accesses the network is not a channel supported by the second device, establishing a P2P connection between the first device and the second device by using a channel supported by both the first device and the second device; or
when the first device determines that the STA channel through which the second device accesses the network is not a channel supported by the first device, establishing a P2P connection between the first device and the second device by using a channel supported by both the first device and the second device.
19 . The electronic device according to claim 11 , wherein when the one or more processors execute the computer instructions, the electronic device performs the following:
after establishing the P2P connection between the first device and the second device by using the STA channel through which the second device accesses the network when it is determined that the second device has the weaker switching capability than the first device, when the first device determines that the P2P connection between the first device and the second device is not successfully established, establishing a P2P connection between the first device and the second device by using an STA channel through which the first device accesses the network.
20 . The electronic device according to claim 19 , wherein when the one or more processors execute the computer instructions, the electronic device performs the following:
after establishing the P2P connection between the first device and the second device by using the STA channel through which the first device accesses the network when the first device determines that the P2P connection between the first device and the second device is not successfully established, establishing the P2P connection between the first device and the second device by using a channel supported by both the first device and the second device.