Nearby Connections 2.0: Advertiser restarts, but Discoverer connects using old Advertiser id

Deadly 提交于 2019-12-14 03:26:28

问题


I caught an interesting result

  • Advertiser advertised its endpoint id 'wjys'
  • Discoverer requested connection to 'wjys'
  • Advertiser restarted (stopAllEndpoints, disconnect from GoogleApiClient)
  • Advertiser advertised its new endpoint id 'PChU'
  • Discoverer discovered Advertiser again (id=PChU)
  • Discoverer gets onConnectionInitiated with the old id (wjys)
  • Both devices accept
  • Amazingly, the two devices could still communicate, even though Discoverer sent and received messages using old Advertiser id (wjys).

Is this behavior a bug?


回答1:


That's a bug. I've filed a ticket internally to get it fixed. If you stop advertising, you should not be connectable by anyone who saw the old advertisement. Let us know if you catch any other weird edge cases like this! :)

To understand why this bug happens, the following is a small part about how Connections works: The endpoint id is sent as a part of the advertisement, and it forms an id-mac address pair on the Discoverer side. When the Discoverer is told 'requestConnection', it tries to connect to the Mac address associated with the endpoint id. If the device has already stopped advertising, the discoverer will fail to connect, but the discoverer will retry internally a few times just to make sure. If the advertiser restarts advertising quickly enough, it becomes connectable again and the discoverer's retry may succeed (because the Bluetooth mac address never rotates). This is true even if the advertisement is different.



来源:https://stackoverflow.com/questions/46600384/nearby-connections-2-0-advertiser-restarts-but-discoverer-connects-using-old-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!