Add a controlled Android scan pause to the manual BLE probe

This commit is contained in:
evgeny committed 2026-10-29 20:14:51 +01:00
1 parent 8ab25c1389
commit 05d78c9960
2 files changed
+13

No files matched your search

@@ -33,6 +33,10 @@ class BlePeerProbe : Instrumentation() {
NativeLib.setChatSetting("bluetooth_invites_enabled", "1")
}
check(BleRadio.nativeConfigure(flags)) { "configure refused" }
if (args.getString("pauseScan") == "true") {
Thread.sleep(2000)
check(BleRadio.pauseScanForProbe()) { "pause scan command refused" }
}
val seconds = (args.getString("seconds") ?: "100").toLong()
require(seconds in 1..600) { "seconds must be in 1..600" }
if (args.getString("invites") == "true") {
@@ -79,6 +79,15 @@ object BleRadio {
if (NativeLib.isReady() && !nativeConfigure(effective)) log("WARN", "Settings could not be queued")
if (effective == 0) state.value = 2
}
/** Только ручная instrumentation: отделить влияние scanning от передачи по уже открытому GATT. */
fun pauseScanForProbe(): Boolean = worker.post {
guarded {
val callback = checkNotNull(scan) { "Probe scan is not running" }
checkNotNull(scanner).stopScan(callback)
scan = null; scanner = null
log("INFO", "Scan paused for probe generation=$generation")
}
}
private fun log(level: String, text: String) { LogManager.addLog(level, "discovery", "BLE $text") }
private fun emit(type: Int, token: Long = 0, arg: Int = 0, text: String = "", data: ByteArray = byteArrayOf()) {
nativeEvent(generation, token, type, arg, text, data)