Support switching to NAT/VPN without restarting the app

This commit is contained in:
Mygod
2015-11-08 18:46:42 +08:00
parent 1f0f92113d
commit 4906ce8af5
7 changed files with 31 additions and 58 deletions
@@ -64,18 +64,12 @@ class ShadowsocksRunnerService extends Service {
}
// Variables
var vpnEnabled = -1
var bgService: IShadowsocksService = null
var isRoot: Option[Boolean] = None
var bgService: IShadowsocksService = _
def isVpnEnabled: Boolean = {
if (vpnEnabled < 0) {
vpnEnabled = if ((!Utils.isLollipopOrAbove || status.getBoolean(Key.isNAT, false)) && Console.isRoot) {
0
} else {
1
}
}
if (vpnEnabled == 1) true else false
if (isRoot.isEmpty) isRoot = Some(Console.isRoot)
!(isRoot.get && status.getBoolean(Key.isNAT, !Utils.isLollipopOrAbove))
}
override def onBind(intent: Intent): IBinder = {