@@ -355,6 +355,15 @@ private class P2pStateMachine extends StateMachine {
355355 private WifiMonitor mWifiMonitor = new WifiMonitor (this , mWifiNative );
356356
357357 private final WifiP2pDeviceList mPeers = new WifiP2pDeviceList ();
358+ /* During a connection, supplicant can tell us that a device was lost. From a supplicant's
359+ * perspective, the discovery stops during connection and it purges device since it does
360+ * not get latest updates about the device without being in discovery state.
361+ *
362+ * From the framework perspective, the device is still there since we are connecting or
363+ * connected to it. so we keep these devices in a seperate list, so that they are removed
364+ * when connection is cancelled or lost
365+ */
366+ private final WifiP2pDeviceList mPeersLostDuringConnection = new WifiP2pDeviceList ();
358367 private final WifiP2pGroupList mGroups = new WifiP2pGroupList (null ,
359368 new GroupDeleteListener () {
360369 @ Override
@@ -746,6 +755,10 @@ public void enter() {
746755 public boolean processMessage (Message message ) {
747756 if (DBG ) logd (getName () + message .toString ());
748757 switch (message .what ) {
758+ case WifiMonitor .SUP_DISCONNECTION_EVENT :
759+ loge ("Unexpected loss of p2p socket connection" );
760+ transitionTo (mP2pDisabledState );
761+ break ;
749762 case WifiStateMachine .CMD_ENABLE_P2P :
750763 //Nothing to do
751764 break ;
@@ -1066,7 +1079,8 @@ public boolean processMessage(Message message) {
10661079 break ;
10671080 }
10681081 // Do nothing
1069- if (DBG ) logd ("Retain connecting device " + device );
1082+ if (DBG ) logd ("Add device to lost list " + device );
1083+ mPeersLostDuringConnection .update (device );
10701084 break ;
10711085 case WifiP2pManager .DISCOVER_PEERS :
10721086 /* Discovery will break negotiation */
@@ -1401,7 +1415,8 @@ public boolean processMessage(Message message) {
14011415 device = (WifiP2pDevice ) message .obj ;
14021416 //Device loss for a connected device indicates it is not in discovery any more
14031417 if (mGroup .contains (device )) {
1404- if (DBG ) logd ("Lost " + device +" , do nothing" );
1418+ if (DBG ) logd ("Add device to lost list " + device );
1419+ mPeersLostDuringConnection .update (device );
14051420 return HANDLED ;
14061421 }
14071422 // Do the regular device lost handling
@@ -1853,7 +1868,7 @@ private void updatePersistentNetworks(boolean reload) {
18531868 private int connect (WifiP2pConfig config , boolean tryInvocation ) {
18541869
18551870 if (config == null ) {
1856- loge ("invalid argument. " );
1871+ loge ("config is null " );
18571872 return CONNECT_FAILURE ;
18581873 }
18591874
@@ -1863,7 +1878,7 @@ private int connect(WifiP2pConfig config, boolean tryInvocation) {
18631878
18641879 WifiP2pDevice dev = mPeers .get (config .deviceAddress );
18651880 if (dev == null ) {
1866- loge ("target device is not found." );
1881+ loge ("target device not found " + config . deviceAddress );
18671882 return CONNECT_FAILURE ;
18681883 }
18691884
@@ -2142,6 +2157,8 @@ private void handleGroupCreationFailure() {
21422157 /* After cancelling group formation, new connections on existing peers can fail
21432158 * at supplicant. Flush and restart discovery */
21442159 mWifiNative .p2pFlush ();
2160+ if (mPeers .remove (mPeersLostDuringConnection )) sendP2pPeersChangedBroadcast ();
2161+ mPeersLostDuringConnection .clear ();
21452162 mServiceDiscReqId = null ;
21462163 sendMessage (WifiP2pManager .DISCOVER_PEERS );
21472164 }
@@ -2174,6 +2191,8 @@ private void handleGroupRemoved() {
21742191
21752192 mGroup = null ;
21762193 mWifiNative .p2pFlush ();
2194+ if (mPeers .remove (mPeersLostDuringConnection )) sendP2pPeersChangedBroadcast ();
2195+ mPeersLostDuringConnection .clear ();
21772196 mServiceDiscReqId = null ;
21782197 if (changed ) sendP2pPeersChangedBroadcast ();
21792198 }
0 commit comments