Skip to content

Commit

Permalink
disable NAT mode again
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Nov 17, 2014
1 parent 8f41ea2 commit efb6140
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
18 changes: 10 additions & 8 deletions src/main/scala/com/github/shadowsocks/Shadowsocks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,15 @@ class Shadowsocks

Console.runCommand(ab.toArray)

ab.clear()
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`")
ab.append("rm /data/data/com.github.shadowsocks/redsocks.conf")
ab.append("rm /data/data/com.github.shadowsocks/redsocks.pid")
ab.append(Utils.getIptables + " -t nat -F OUTPUT")
if (!Utils.isLollipopOrAbove) {
ab.clear()
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`")
ab.append("rm /data/data/com.github.shadowsocks/redsocks.conf")
ab.append("rm /data/data/com.github.shadowsocks/redsocks.pid")
ab.append(Utils.getIptables + " -t nat -F OUTPUT")

Console.runRootCommand(ab.toArray)
Console.runRootCommand(ab.toArray)
}
}

private def getVersionName: String = {
Expand Down Expand Up @@ -500,7 +502,7 @@ class Shadowsocks

// Bind to the service
spawn {
val isRoot = Console.isRoot
val isRoot = !Utils.isLollipopOrAbove && Console.isRoot
handler.post(new Runnable {
override def run() {
status.edit.putBoolean(Key.isRoot, isRoot).commit()
Expand Down Expand Up @@ -770,7 +772,7 @@ class Shadowsocks
if (pref != null) {
if (Seq(Key.isGlobalProxy, Key.proxyedApps)
.contains(name)) {
pref.setEnabled(enabled && !isVpnEnabled)
pref.setEnabled(enabled && (Utils.isLollipopOrAbove || !isVpnEnabled))
} else {
pref.setEnabled(enabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ShadowsocksRunnerActivity extends Activity {

def isVpnEnabled: Boolean = {
if (vpnEnabled < 0) {
vpnEnabled = if (!Console.isRoot) {
vpnEnabled = if (Utils.isLollipopOrAbove || !Console.isRoot) {
1
} else {
0
Expand Down
18 changes: 5 additions & 13 deletions src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {

private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]

def isLollipopOrAbove: Boolean = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
true
} else {
false
}
}

def isByass(net: SubnetUtils): Boolean = {
val info = net.getInfo
info.isInRange(config.proxy)
Expand All @@ -105,7 +97,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {

def startShadowsocksDaemon() {

if (isLollipopOrAbove && config.route != Route.ALL) {
if (Utils.isLollipopOrAbove && config.route != Route.ALL) {
val acl: Array[String] = config.route match {
case Route.BYPASS_LAN => getResources.getStringArray(R.array.private_route)
case Route.BYPASS_CHN => getResources.getStringArray(R.array.chn_route_full)
Expand All @@ -125,7 +117,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
, "-m", config.encMethod
, "-f", Path.BASE + "ss-local.pid")

if (isLollipopOrAbove && config.route != Route.ALL) {
if (Utils.isLollipopOrAbove && config.route != Route.ALL) {
cmd += "--acl"
cmd += (Path.BASE + "acl.list")
}
Expand All @@ -151,7 +143,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {

def startDnsDaemon() {
val conf = {
if (isLollipopOrAbove) {
if (Utils.isLollipopOrAbove) {
ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", getString(R.string.exclude), 8163)
} else {
ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163)
Expand Down Expand Up @@ -186,7 +178,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
.addAddress(PRIVATE_VLAN.format("1"), 24)
.addDnsServer("8.8.8.8")

if (isLollipopOrAbove) {
if (Utils.isLollipopOrAbove) {
if (!config.isGlobalProxy) {
val apps = AppManager.getProxiedApps(this, config.proxiedAppString)
val pkgSet: mutable.HashSet[String] = new mutable.HashSet[String]
Expand Down Expand Up @@ -214,7 +206,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (InetAddressUtils.isIPv6Address(config.proxy)) {
builder.addRoute("0.0.0.0", 0)
} else {
if (!isLollipopOrAbove) {
if (!Utils.isLollipopOrAbove) {
config.route match {
case Route.ALL =>
for (i <- 1 to 223) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/com/github/shadowsocks/utils/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ object Utils {
var data_path: String = null
var rootTries = 0

def isLollipopOrAbove: Boolean = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
true
} else {
false
}
}

def getSignature(context: Context): String = {
val info = context
.getPackageManager
Expand Down

0 comments on commit efb6140

Please sign in to comment.