Prevent main thread queries

This commit is contained in:
Mygod
2019-03-18 17:13:31 +08:00
parent 160aaecbe5
commit 73137b8dcc
7 changed files with 19 additions and 18 deletions

View File

@@ -11,6 +11,7 @@ import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.util.parseNumericAddress
import be.mygod.vpnhotspot.util.putIfAbsentCompat
import be.mygod.vpnhotspot.widget.SmartSnackbar
import kotlinx.coroutines.runBlocking
import timber.log.Timber
import java.net.InetAddress
import java.util.concurrent.TimeUnit
@@ -26,7 +27,7 @@ object TrafficRecorder {
fun register(ip: InetAddress, downstream: String, mac: Long) {
val record = TrafficRecord(mac = mac, ip = ip, downstream = downstream)
AppDatabase.instance.trafficRecordDao.insert(record)
runBlocking { AppDatabase.instance.trafficRecordDao.insert(record) }
synchronized(this) {
DebugHelper.log(TAG, "Registering $ip%$downstream")
check(records.putIfAbsentCompat(Pair(ip, downstream), record) == null)
@@ -119,7 +120,7 @@ object TrafficRecorder {
check(record.sentBytes >= 0)
check(record.receivedPackets >= 0)
check(record.receivedBytes >= 0)
AppDatabase.instance.trafficRecordDao.insert(record)
runBlocking { AppDatabase.instance.trafficRecordDao.insert(record) }
}
foregroundListeners(records.values, oldRecords)
}