librootkotlinx

Fixes #14, #27, #114, #117.
This commit is contained in:
Mygod
2020-06-21 05:33:39 +08:00
parent 7b1f610f9a
commit ad218d7ec6
51 changed files with 1781 additions and 574 deletions

View File

@@ -3,7 +3,9 @@ package be.mygod.vpnhotspot.net
import android.provider.Settings
import androidx.annotation.RequiresApi
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.root.RootManager
import be.mygod.vpnhotspot.root.SettingsGlobalPut
import be.mygod.vpnhotspot.util.Services
/**
* It's hard to change tethering rules with Tethering hardware acceleration enabled for now.
@@ -16,11 +18,18 @@ import be.mygod.vpnhotspot.util.RootSession
@RequiresApi(27)
object TetherOffloadManager {
private const val TETHER_OFFLOAD_DISABLED = "tether_offload_disabled"
var enabled: Boolean
get() = Settings.Global.getInt(app.contentResolver, TETHER_OFFLOAD_DISABLED, 0) == 0
set(value) {
RootSession.use {
it.exec("settings put global $TETHER_OFFLOAD_DISABLED ${if (value) 0 else 1}")
val enabled get() = Settings.Global.getInt(app.contentResolver, TETHER_OFFLOAD_DISABLED, 0) == 0
suspend fun setEnabled(value: Boolean) {
val int = if (value) 0 else 1
try {
check(Settings.Global.putInt(Services.context.contentResolver, TETHER_OFFLOAD_DISABLED, int))
} catch (e: SecurityException) {
try {
RootManager.use { it.execute(SettingsGlobalPut(TETHER_OFFLOAD_DISABLED, int.toString())) }
} catch (eRoot: Exception) {
eRoot.addSuppressed(e)
throw eRoot
}
}
}
}