From 0374b93a64b9cbd087d0e898ac71a219a48f37d9 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 6 Jan 2019 00:55:57 +0800 Subject: [PATCH] Allow waiting in updating records --- .../java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt | 2 +- .../src/main/java/be/mygod/vpnhotspot/util/RootSession.kt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt index adce2343..809f7cc6 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt @@ -64,7 +64,7 @@ object TrafficRecorder { private fun doUpdate(timestamp: Long) { val oldRecords = LongSparseArray() - loop@ for (line in RootSession.use { it.execOutUnjoined("$IPTABLES -nvx -L vpnhotspot_fwd").drop(2) }) { + loop@ for (line in RootSession.use { it.execOutUnjoinedWithWait("$IPTABLES -nvx -L vpnhotspot_fwd").drop(2) }) { val columns = line.split("\\s+".toRegex()).filter { it.isNotEmpty() } try { check(columns.size >= 9) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt index 2c545ce5..cd466c6f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt @@ -111,6 +111,12 @@ class RootSession : AutoCloseable { checkOutput(command, result, false) return result.out } + fun execOutUnjoinedWithWait(command: String): List { + val result = execQuiet(command) + val message = checkOutput(command, result, false, false) + if (result.err.isNotEmpty()) Timber.i(message) + return result.out + } fun execOut(command: String): String = execOutUnjoined(command).joinToString("\n") /**