Skip to content

Commit efb6140

Browse files
committed
disable NAT mode again
1 parent 8f41ea2 commit efb6140

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

src/main/scala/com/github/shadowsocks/Shadowsocks.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,15 @@ class Shadowsocks
338338

339339
Console.runCommand(ab.toArray)
340340

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

347-
Console.runRootCommand(ab.toArray)
348+
Console.runRootCommand(ab.toArray)
349+
}
348350
}
349351

350352
private def getVersionName: String = {
@@ -500,7 +502,7 @@ class Shadowsocks
500502

501503
// Bind to the service
502504
spawn {
503-
val isRoot = Console.isRoot
505+
val isRoot = !Utils.isLollipopOrAbove && Console.isRoot
504506
handler.post(new Runnable {
505507
override def run() {
506508
status.edit.putBoolean(Key.isRoot, isRoot).commit()
@@ -770,7 +772,7 @@ class Shadowsocks
770772
if (pref != null) {
771773
if (Seq(Key.isGlobalProxy, Key.proxyedApps)
772774
.contains(name)) {
773-
pref.setEnabled(enabled && !isVpnEnabled)
775+
pref.setEnabled(enabled && (Utils.isLollipopOrAbove || !isVpnEnabled))
774776
} else {
775777
pref.setEnabled(enabled)
776778
}

src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ShadowsocksRunnerActivity extends Activity {
7272

7373
def isVpnEnabled: Boolean = {
7474
if (vpnEnabled < 0) {
75-
vpnEnabled = if (!Console.isRoot) {
75+
vpnEnabled = if (Utils.isLollipopOrAbove || !Console.isRoot) {
7676
1
7777
} else {
7878
0

src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
7474

7575
private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]
7676

77-
def isLollipopOrAbove: Boolean = {
78-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
79-
true
80-
} else {
81-
false
82-
}
83-
}
84-
8577
def isByass(net: SubnetUtils): Boolean = {
8678
val info = net.getInfo
8779
info.isInRange(config.proxy)
@@ -105,7 +97,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
10597

10698
def startShadowsocksDaemon() {
10799

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

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

152144
def startDnsDaemon() {
153145
val conf = {
154-
if (isLollipopOrAbove) {
146+
if (Utils.isLollipopOrAbove) {
155147
ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", getString(R.string.exclude), 8163)
156148
} else {
157149
ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163)
@@ -186,7 +178,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
186178
.addAddress(PRIVATE_VLAN.format("1"), 24)
187179
.addDnsServer("8.8.8.8")
188180

189-
if (isLollipopOrAbove) {
181+
if (Utils.isLollipopOrAbove) {
190182
if (!config.isGlobalProxy) {
191183
val apps = AppManager.getProxiedApps(this, config.proxiedAppString)
192184
val pkgSet: mutable.HashSet[String] = new mutable.HashSet[String]
@@ -214,7 +206,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
214206
if (InetAddressUtils.isIPv6Address(config.proxy)) {
215207
builder.addRoute("0.0.0.0", 0)
216208
} else {
217-
if (!isLollipopOrAbove) {
209+
if (!Utils.isLollipopOrAbove) {
218210
config.route match {
219211
case Route.ALL =>
220212
for (i <- 1 to 223) {

src/main/scala/com/github/shadowsocks/utils/Utils.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ object Utils {
8080
var data_path: String = null
8181
var rootTries = 0
8282

83+
def isLollipopOrAbove: Boolean = {
84+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
85+
true
86+
} else {
87+
false
88+
}
89+
}
90+
8391
def getSignature(context: Context): String = {
8492
val info = context
8593
.getPackageManager

0 commit comments

Comments
 (0)