Skip to content

Commit 80ee65f

Browse files
author
SBALAVIGNESH123
committed
Fix: Socket leak on handshake failure and incomplete Connect message
1 parent ece85ec commit 80ee65f

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableImpl.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -729,27 +729,36 @@ public void run() {
729729
// Start message processing thread
730730
new Thread(connection).start();
731731

732-
// Send our identity to the watch
733-
String localId = getLocalNodeId();
734-
connection.writeMessage(
735-
new RootMessage.Builder()
736-
.connect(new Connect.Builder()
737-
.id(localId)
738-
.name("Phone")
739-
.build())
740-
.build()
741-
);
732+
try {
733+
// Send our identity to the watch
734+
String localId = getLocalNodeId();
735+
connection.writeMessage(
736+
new RootMessage.Builder()
737+
.connect(new Connect.Builder()
738+
.id(localId)
739+
.name("Phone")
740+
.networkId(localId)
741+
.peerAndroidId(localId)
742+
.peerVersion(2)
743+
.build())
744+
.build()
745+
);
746+
} catch (IOException e) {
747+
Log.w(TAG, "Handshake failed, closing connection", e);
748+
connection.close();
749+
}
742750
}
743751
} catch (IOException e) {
744752
Log.d(TAG, "BT connection failed: " + e.getMessage());
745-
if (socket != null) {
753+
if (socket != null && !socket.isConnected()) {
746754
try {
747755
socket.close();
748756
} catch (IOException closeErr) {
749757
// Ignore
750758
}
751759
}
752760
}
761+
753762
}
754763
}
755764
} catch (Exception e) {

0 commit comments

Comments
 (0)