以下看起来 2 个对等方的 DHCP 租约为 30 分钟,并且续订失败。
E/DhcpStateMachine: DHCP renew failed on p2p-wlan0-0: Timed out waiting for DHCP Renew to finish
D/WifiP2pService: GroupCreatedState{ what=196613 }
E/WifiP2pService: DHCP failed
服务广告商和服务浏览器都有IP地址,浏览器由DHCP在广告商上发布。如果 DHCP 无法更新,则连接丢失,设备必须重新连接。似乎在 29 分 18 秒时尝试续租,并在 30 分钟的租约时间超时。此时浏览器必须重新连接。如果 DHCP 服务器不记得浏览器的 IP 地址,或者如果框架总是发布一个新的 IP,那么你所描述的就会发生。希望这会有所帮助。
编辑:这篇文章似乎验证了组所有者充当 DHCP 服务器:Get peer device's IP address in wifi-direct p2p connection。不过,我不知道如何增加 WiFi-Direct 的租用时间。
编辑:此链接讨论了 android 上 DHCP 的一些问题:https://www.net.princeton.edu/android/android-stops-renewing-lease-keeps-using-IP-address-11236.html
编辑:可能的解决方案包含在 https://www.net.princeton.edu/android/android-11236-partial-workaround.html 中,附在下面。这个想法是使用组所有者设备上的设置。
程序
Depending upon the version of Android on your device, there should be a "Wi-Fi sleep policy" setting, a "Wi-Fi disconnect policy" setting, or a "Keep Wi-Fi on during Sleep" setting. (Your device will have only one of these; the name varies.) It should be available at (only) one of the following locations:
Settings
-> Wireless & networks
-> Wi-Fi settings
-> Menu (button)
-> Advanced
-> Wi-Fi sleep policy
Settings
-> Wireless & networks
-> Wi-Fi settings
-> Wi-Fi disconnect policy
Settings
-> Wireless & networks
-> Wi-Fi settings
-> Menu (button)
-> Advanced
-> Keep Wi-Fi on during Sleep
If the Wi-Fi settings item is greyed-out, you may need to turn on Wi-Fi before you can select this item.
If your device has a "Wi-Fi sleep policy" or " Wi-Fi disconnect policy", it should offer several choices. These choices available vary among different versions of Android. At least one of the choices should be "After 15 mins" or "When screen turns off". Select that choice.
Otherwise, if your device has a "Keep Wi-Fi on during Sleep" setting, it should offer several choices. These choices available may vary among different versions of Android. At least one of the choices should be "Never". Select that choice.
If you have any software installed on your Android device which modifies the way Android turns Wi-Fi on or off, then reconfigure that software so it no longer controls the device's Wi-Fi interface. Alternatively, disable or remove that software.
An example would be an application designed to keep your device's Wi-Fi interface always turned on. Another would be an application configured to turn on your device's Wi-Fi interface based on certain conditions (for example, location, time of day, or battery charge).
These applications are not the cause of the bugs. However, they can prevent this partial workaround from being effective, because these may be configured to override Android's "Wi-Fi Sleep Policy" (or "Wi-Fi disconnect policy"), causing the Wi-Fi interface to remain connected to the wireless network for an extended period while the Android device is asleep.
Every time you upgrade the Android software/firmware in the future, verify that the setting you selected above (the "Wi-Fi sleep policy", "Wi-Fi disconnect policy", or "Keep Wi-Fi on during Sleep" setting) remains configured as described above. Such upgrades sometimes modify existing settings; you must make a point of checking (and if necessary, changing) this setting immediately after upgrading.
Take care that any software you install in the future does not modify the way Android turns on or off Wi-Fi.
挖掘 p2 的源代码,底线是 p2p 的 dhcp 东西是由 ethernetworkfactory 完成的,绕过了本地 dhcp 服务器(请参阅http://book2s.com/java/src/package/com/android/server/ethernet/ethernetnetworkfactory.html#199b9c81a59238cafe64b4e28b0c71ce),这是一个有趣的代码片段:
/* Called by the NetworkFactory on the handler thread. */
public void onRequestNetwork() {
// TODO: Handle DHCP renew.
所以看来 dhcp 租约永远不会在 p2p 框架中更新(见下文)。坦率地说,我必须检查一下;如果为真,这是一个不平凡的错误。如果是真的,那么按照上述帖子每 25 分钟重新连接一次的解决方案可能是唯一的方法。注意: dhcp 更新发生在本机 dhcp 更新之前运行的租约更新时间的 48%(请参阅https://android.googlesource.com/platform/frameworks/base/+/c3a2858/core/java/android/net/DhcpStateMachine.java);相关行是
//Do it a bit earlier than half the lease duration time
//to beat the native DHCP client and avoid extra packets
//48% for one hour lease time = 29 minutes
所以在 p2pdirect 中,看起来有一个层避免本机 dhcp 更新,但自己没有实现它。