mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 15:25:20 +00:00
fix: wifi aware socket binding (#533)
* wifi aware wip * wifi aware wip * starting to work * werk * dms work * wip * fix(wifi-aware): use bindSocket and scoped IPv6 instead of bindProcessToNetwork * Merge branch 'upstream/main' into fix/wifi-aware-socket-binding * Fix Wi-Fi Aware connectivity and UI integration post-merge - Replace bindProcessToNetwork with bindSocket for VPN compatibility. - Implement Scoped IPv6 address resolution (aware0) for mesh routing. - Bridge Wi-Fi Aware incoming messages to AppStateStore for UI visibility. - Fix syntax errors and variable name conflicts in Debug UI. * Enhance Wi-Fi Aware robustness and debug UI display - Clean up transport resources (sockets, server sockets, network callbacks) immediately on peer disconnection. - Implement resolveScopedAddress to show scoped IPv6 (e.g., %aware0) in Debug UI. - Fix Map type mismatch warning in ChatViewModel bridge. - Filter self-ID from peer cleanup tables to prevent recursive self-removal. * Share GossipSyncManager across transports to prevent redundant message synchronization - Registered BluetoothMeshService's GossipSyncManager as a singleton in MeshServiceHolder. - Modified WifiAwareMeshService to use the shared GossipSyncManager if available. - Added background cleanup for peer mappings on socket disconnection. - Fixed Kotlin type mismatch during nickname map merging. * Restore VPN acquisition logic and improve peer cleanup - Revert removal of NET_CAPABILITY_NOT_VPN to allow hardware handle acquisition while VPN is active. - Refactor handlePeerDisconnection to more reliably cleanup initial and routed IDs. - Switch cleanup logging to debug level to reduce log noise. --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com> Co-authored-by: aidenvalue <>
This commit is contained in:
co-authored by
callebtc
aidenvalue <>
parent
903a4584a8
commit
0c7505b588
@@ -112,6 +112,8 @@ class MainActivity : OrientationAwareActivity() {
|
||||
// Ensure foreground service is running and get mesh instance from holder
|
||||
try { com.bitchat.android.service.MeshForegroundService.start(applicationContext) } catch (_: Exception) { }
|
||||
meshService = com.bitchat.android.service.MeshServiceHolder.getOrCreate(applicationContext)
|
||||
// Expose BLE mesh to Wi‑Fi Aware controller for cross-transport relays
|
||||
try { com.bitchat.android.wifiaware.WifiAwareController.setBleMeshService(meshService) } catch (_: Exception) { }
|
||||
bluetoothStatusManager = BluetoothStatusManager(
|
||||
activity = this,
|
||||
context = this,
|
||||
@@ -159,6 +161,52 @@ class MainActivity : OrientationAwareActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bridge Wi‑Fi Aware callbacks into ChatViewModel (reusing BLE delegate methods)
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
com.bitchat.android.wifiaware.WifiAwareController.running.collect { running ->
|
||||
val svc = com.bitchat.android.wifiaware.WifiAwareController.getService()
|
||||
if (running && svc != null) {
|
||||
svc.delegate = object : com.bitchat.android.wifiaware.WifiAwareMeshDelegate {
|
||||
override fun didReceiveMessage(message: com.bitchat.android.model.BitchatMessage) {
|
||||
if (message.isPrivate) {
|
||||
message.senderPeerID?.let { pid -> com.bitchat.android.services.AppStateStore.addPrivateMessage(pid, message) }
|
||||
} else if (message.channel != null) {
|
||||
com.bitchat.android.services.AppStateStore.addChannelMessage(message.channel, message)
|
||||
} else {
|
||||
com.bitchat.android.services.AppStateStore.addPublicMessage(message)
|
||||
}
|
||||
chatViewModel.didReceiveMessage(message)
|
||||
}
|
||||
override fun didUpdatePeerList(peers: List<String>) {
|
||||
chatViewModel.didUpdatePeerList(peers)
|
||||
}
|
||||
override fun didReceiveChannelLeave(channel: String, fromPeer: String) {
|
||||
chatViewModel.didReceiveChannelLeave(channel, fromPeer)
|
||||
}
|
||||
override fun didReceiveDeliveryAck(messageID: String, recipientPeerID: String) {
|
||||
chatViewModel.didReceiveDeliveryAck(messageID, recipientPeerID)
|
||||
}
|
||||
override fun didReceiveReadReceipt(messageID: String, recipientPeerID: String) {
|
||||
chatViewModel.didReceiveReadReceipt(messageID, recipientPeerID)
|
||||
}
|
||||
override fun decryptChannelMessage(encryptedContent: ByteArray, channel: String): String? {
|
||||
return chatViewModel.decryptChannelMessage(encryptedContent, channel)
|
||||
}
|
||||
override fun getNickname(): String? {
|
||||
return chatViewModel.getNickname()
|
||||
}
|
||||
override fun isFavorite(peerID: String): Boolean {
|
||||
return try {
|
||||
com.bitchat.android.favorites.FavoritesPersistenceService.shared.getFavoriteStatus(peerID)?.isMutual == true
|
||||
} catch (_: Exception) { false }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only start onboarding process if we're in the initial CHECKING state
|
||||
// This prevents restarting onboarding on configuration changes
|
||||
@@ -347,6 +395,12 @@ class MainActivity : OrientationAwareActivity() {
|
||||
bluetoothStatusManager.logBluetoothStatus()
|
||||
mainViewModel.updateBluetoothStatus(bluetoothStatusManager.checkBluetoothStatus())
|
||||
|
||||
val bleRequired = try { com.bitchat.android.ui.debug.DebugPreferenceManager.getBleEnabled(true) } catch (_: Exception) { true }
|
||||
if (!bleRequired) {
|
||||
// Skip BLE checks entirely when BLE is disabled in debug settings
|
||||
checkLocationAndProceed()
|
||||
return
|
||||
}
|
||||
when (mainViewModel.bluetoothStatus.value) {
|
||||
BluetoothStatus.ENABLED -> {
|
||||
// Bluetooth is enabled, check location services next
|
||||
@@ -513,8 +567,9 @@ class MainActivity : OrientationAwareActivity() {
|
||||
else -> BatteryOptimizationStatus.ENABLED
|
||||
}
|
||||
|
||||
val bleRequired2 = try { com.bitchat.android.ui.debug.DebugPreferenceManager.getBleEnabled(true) } catch (_: Exception) { true }
|
||||
when {
|
||||
currentBluetoothStatus != BluetoothStatus.ENABLED -> {
|
||||
bleRequired2 && currentBluetoothStatus != BluetoothStatus.ENABLED -> {
|
||||
// Bluetooth still disabled, but now we have permissions to enable it
|
||||
Log.d("MainActivity", "Permissions granted, but Bluetooth still disabled. Showing Bluetooth enable screen.")
|
||||
mainViewModel.updateBluetoothStatus(currentBluetoothStatus)
|
||||
|
||||
Reference in New Issue
Block a user