VPN Hotspot 2.0: Client+ (#39)
Fix #13, #38. I don't have a lot of confidence that this would work very well for every device. Also here's an SQL command that hopefully somebody could make into the app for me: `SELECT TrafficRecord.mac, SUM(TrafficRecord.sentPackets), SUM(TrafficRecord.sentBytes), SUM(TrafficRecord.receivedPackets), SUM(TrafficRecord.receivedBytes) FROM TrafficRecord LEFT JOIN TrafficRecord AS Next ON TrafficRecord.id = Next.previousId WHERE Next.id IS NULL GROUP BY TrafficRecord.mac;`
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package be.mygod.vpnhotspot.util
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.util.Log
|
||||
import androidx.core.os.postDelayed
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.concurrent.withLock
|
||||
@@ -14,6 +16,8 @@ class RootSession : AutoCloseable {
|
||||
companion object {
|
||||
private const val TAG = "RootSession"
|
||||
|
||||
val handler = Handler(HandlerThread("$TAG-HandlerThread").apply { start() }.looper)
|
||||
|
||||
private val monitor = ReentrantLock()
|
||||
private fun onUnlock() {
|
||||
if (monitor.holdCount == 1) instance?.startTimeout()
|
||||
@@ -72,8 +76,10 @@ class RootSession : AutoCloseable {
|
||||
shell.close()
|
||||
if (instance == this) instance = null
|
||||
}
|
||||
private fun startTimeout() = app.handler.postDelayed(60 * 1000, this) { monitor.withLock { close() } }
|
||||
private fun haltTimeout() = app.handler.removeCallbacksAndMessages(this)
|
||||
private fun startTimeout() = handler.postDelayed(TimeUnit.MINUTES.toMillis(5), this) {
|
||||
monitor.withLock { close() }
|
||||
}
|
||||
private fun haltTimeout() = handler.removeCallbacksAndMessages(this)
|
||||
|
||||
/**
|
||||
* Don't care about the results, but still sync.
|
||||
@@ -95,11 +101,12 @@ class RootSession : AutoCloseable {
|
||||
}).exec()
|
||||
}
|
||||
fun exec(command: String) = checkOutput(command, execQuiet(command))
|
||||
fun execOut(command: String): String {
|
||||
fun execOutUnjoined(command: String): List<String> {
|
||||
val result = execQuiet(command)
|
||||
checkOutput(command, result, false)
|
||||
return result.out.joinToString("\n")
|
||||
return result.out
|
||||
}
|
||||
fun execOut(command: String): String = execOutUnjoined(command).joinToString("\n")
|
||||
|
||||
/**
|
||||
* This transaction is different from what you may have in mind since you can revert it after committing it.
|
||||
|
||||
Reference in New Issue
Block a user