fix: Android event handler lost after restart — g_event_handler now preserved
Root cause: instance_lite_restart was creating new thread without re-setting g_event_handler, causing all chat events (CHANNEL_UPDATED, CONNECT_RESULT, etc.) to be silently dropped after app restart. Fixes: - instance_lite_restart: save/restore g_event_handler across hard restart - instance_thread restart loop: re-call chat_event_set_handler after uasync_create - utun_bridge_restart: call instance_lite_set_event_handler before restart - AppEventHandler SharedFlow replay: 1 → 16 to not lose early init events - ViewModel: added diagnostic logging for channel/connect events - Keep diagnostic logs in instance_lite (set_handler, chat_event_forward NULL check) - instance_event_handler: removed static for cross-block forward declaration
This commit is contained in:
1 parent
ef637d33a6
commit
38eb51c679
5 files changed
+37
-9
No files matched your search
@@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
|
||||
object AppEventHandler : ChatEventCallback {
|
||||
private val _events = MutableSharedFlow<Pair<Int, ByteArray?>>(replay = 1, extraBufferCapacity = 64)
|
||||
private val _events = MutableSharedFlow<Pair<Int, ByteArray?>>(replay = 16, extraBufferCapacity = 64)
|
||||
val events: SharedFlow<Pair<Int, ByteArray?>> = _events
|
||||
|
||||
override fun onEvent(type: Int, data: ByteArray?) {
|
||||
|
||||
@@ -181,7 +181,7 @@ class ChatViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
2 -> { /* CONNECT_RESULT: [node_id:8][result:4][channel_id:8] */
|
||||
if (repo == null || data == null || data.size < 20) return
|
||||
if (repo == null || data == null || data.size < 20) { LogManager.addLog("WARN", "VM", "CONNECT_RESULT skipped repo=${repo != null} data=${data != null}"); return }
|
||||
val buf = java.nio.ByteBuffer.wrap(data).order(java.nio.ByteOrder.LITTLE_ENDIAN)
|
||||
val nodeId = buf.getLong()
|
||||
val result = buf.getInt()
|
||||
@@ -189,9 +189,10 @@ class ChatViewModel : ViewModel() {
|
||||
LogManager.addLog(
|
||||
if (result == 0) "INFO" else "ERROR",
|
||||
"JOIN", "connect to 0x%016x ch=$chId result=$result".format(nodeId))
|
||||
LogManager.addLog("INFO", "VM", "CONNECT_RESULT result=$result — refreshChannels")
|
||||
if (result == 0) refreshChannels()
|
||||
}
|
||||
4 -> if (repo != null) refreshChannels() /* CHANNEL_UPDATED */
|
||||
4 -> { if (repo != null) { LogManager.addLog("INFO", "VM", "CHANNEL_UPDATED — refreshChannels"); refreshChannels() } else { LogManager.addLog("WARN", "VM", "CHANNEL_UPDATED skipped — repo is NULL") } }
|
||||
12 -> LogManager.addLog("INFO", "VM", "service started")
|
||||
13 -> LogManager.addLog("INFO", "VM", "service stopped")
|
||||
16 -> { /* NODEINFO_UPDATED: [node_id:8][presence:1][up:1][best_rtt:2] */
|
||||
|
||||
Reference in new issue
Block a user