mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 06:25:21 +00:00
better tracking of first announce seen (#502)
This commit is contained in:
@@ -30,6 +30,8 @@ class BluetoothConnectionTracker(
|
||||
private val connectedDevices = ConcurrentHashMap<String, DeviceConnection>()
|
||||
private val subscribedDevices = CopyOnWriteArrayList<BluetoothDevice>()
|
||||
val addressPeerMap = ConcurrentHashMap<String, String>()
|
||||
// Track whether we have seen the first ANNOUNCE on a given device connection
|
||||
private val firstAnnounceSeen = ConcurrentHashMap<String, Boolean>()
|
||||
|
||||
// RSSI tracking from scan results (for devices we discover but may connect as servers)
|
||||
private val scanRSSI = ConcurrentHashMap<String, Int>()
|
||||
@@ -91,6 +93,8 @@ class BluetoothConnectionTracker(
|
||||
Log.d(TAG, "Tracker: Adding device connection for $deviceAddress (isClient: ${deviceConn.isClient}")
|
||||
connectedDevices[deviceAddress] = deviceConn
|
||||
pendingConnections.remove(deviceAddress)
|
||||
// Mark as awaiting first ANNOUNCE on this connection
|
||||
firstAnnounceSeen[deviceAddress] = false
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,6 +284,7 @@ class BluetoothConnectionTracker(
|
||||
addressPeerMap.remove(deviceAddress)
|
||||
}
|
||||
pendingConnections.remove(deviceAddress)
|
||||
firstAnnounceSeen.remove(deviceAddress)
|
||||
Log.d(TAG, "Cleaned up device connection for $deviceAddress")
|
||||
}
|
||||
|
||||
@@ -313,6 +318,21 @@ class BluetoothConnectionTracker(
|
||||
addressPeerMap.clear()
|
||||
pendingConnections.clear()
|
||||
scanRSSI.clear()
|
||||
firstAnnounceSeen.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark that we have received the first ANNOUNCE over this device connection.
|
||||
*/
|
||||
fun noteAnnounceReceived(deviceAddress: String) {
|
||||
firstAnnounceSeen[deviceAddress] = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the first ANNOUNCE has been seen for a device connection.
|
||||
*/
|
||||
fun hasSeenFirstAnnounce(deviceAddress: String): Boolean {
|
||||
return firstAnnounceSeen[deviceAddress] == true
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user