Commit 8cbfad80 authored by Max Lv's avatar Max Lv

refine NAT mode on Lollipop

parent 9857e427
...@@ -15,7 +15,7 @@ rm -rf assets/armeabi-v7a ...@@ -15,7 +15,7 @@ rm -rf assets/armeabi-v7a
rm -rf assets/x86 rm -rf assets/x86
mkdir -p assets/armeabi-v7a mkdir -p assets/armeabi-v7a
mkdir -p assets/x86 mkdir -p assets/x86
for app in iptables pdnsd redsocks ss-local ss-tunnel tun2socks for app in pdnsd redsocks ss-local ss-tunnel tun2socks
do do
try mv libs/armeabi-v7a/$app assets/armeabi-v7a/ try mv libs/armeabi-v7a/$app assets/armeabi-v7a/
try mv libs/x86/$app assets/x86/ try mv libs/x86/$app assets/x86/
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks" package="com.github.shadowsocks"
android:versionCode="87" android:versionCode="88"
android:versionName="2.4.7"> android:versionName="2.5.0">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
<service <service
android:name=".ShadowsocksNatService" android:name=".ShadowsocksNatService"
android:process=":nat"
android:exported="false"> android:exported="false">
</service> </service>
......
...@@ -300,13 +300,13 @@ openssl_subdirs := $(addprefix $(LOCAL_PATH)/openssl/,$(addsuffix /Android.mk, \ ...@@ -300,13 +300,13 @@ openssl_subdirs := $(addprefix $(LOCAL_PATH)/openssl/,$(addsuffix /Android.mk, \
include $(openssl_subdirs) include $(openssl_subdirs)
# Iptables # Iptables
LOCAL_PATH := $(ROOT_PATH) # LOCAL_PATH := $(ROOT_PATH)
iptables_subdirs := $(addprefix $(LOCAL_PATH)/iptables/,$(addsuffix /Android.mk, \ # iptables_subdirs := $(addprefix $(LOCAL_PATH)/iptables/,$(addsuffix /Android.mk, \
iptables \ # iptables \
extensions \ # extensions \
libiptc \ # libiptc \
)) # ))
include $(iptables_subdirs) # include $(iptables_subdirs)
# Import cpufeatures # Import cpufeatures
$(call import-module,android/cpufeatures) $(call import-module,android/cpufeatures)
...@@ -123,7 +123,7 @@ object Shadowsocks { ...@@ -123,7 +123,7 @@ object Shadowsocks {
val FEATRUE_PREFS = Array(Key.route, Key.isGlobalProxy, Key.proxyedApps, val FEATRUE_PREFS = Array(Key.route, Key.isGlobalProxy, Key.proxyedApps,
Key.isUdpDns, Key.isAutoConnect) Key.isUdpDns, Key.isAutoConnect)
val EXECUTABLES = Array(Executable.IPTABLES, Executable.PDNSD, Executable.REDSOCKS, Executable.SS_TUNNEL, Executable.SS_LOCAL, Executable.TUN2SOCKS) val EXECUTABLES = Array(Executable.PDNSD, Executable.REDSOCKS, Executable.SS_TUNNEL, Executable.SS_LOCAL, Executable.TUN2SOCKS)
// Helper functions // Helper functions
def updateListPreference(pref: Preference, value: String) { def updateListPreference(pref: Preference, value: String) {
...@@ -261,7 +261,7 @@ class Shadowsocks ...@@ -261,7 +261,7 @@ class Shadowsocks
override def run() { override def run() {
switchButton.setEnabled(true) switchButton.setEnabled(true)
} }
}, 1000) }, 2000)
} }
switchButton.setOnCheckedChangeListener(this) switchButton.setOnCheckedChangeListener(this)
} }
...@@ -322,38 +322,34 @@ class Shadowsocks ...@@ -322,38 +322,34 @@ class Shadowsocks
} }
private def crash_recovery() { private def crash_recovery() {
val ab = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]()
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/ss-local.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/ss-tunnel.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/tun2socks.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.pid")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.conf")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.cache")
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("kill -9 `cat /data/data/com.github.shadowsocks/ss-tunnel.pid`") for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks")) {
ab.append("rm /data/data/com.github.shadowsocks/ss-tunnel.conf") cmd.append("chmod 666 %s%s-nat.pid".format(Path.BASE, task))
ab.append("rm /data/data/com.github.shadowsocks/ss-tunnel.pid") cmd.append("chmod 666 %s%s-vpn.pid".format(Path.BASE, task))
}
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`") Console.runRootCommand(cmd.toArray)
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.pid") cmd.clear()
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.conf")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.cache")
Console.runRootCommand(ab.toArray) for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks")) {
Console.runRootCommand(Utils.getIptables + " -t nat -F OUTPUT") try {
val pid_nat = scala.io.Source.fromFile(Path.BASE + task + "-nat.pid").mkString.trim.toInt
val pid_vpn = scala.io.Source.fromFile(Path.BASE + task + "-vpn.pid").mkString.trim.toInt
cmd.append("kill -9 %d".format(pid_nat))
cmd.append("kill -9 %d".format(pid_vpn))
Process.killProcess(pid_nat)
Process.killProcess(pid_vpn)
} catch {
case e: Throwable => Log.e(Shadowsocks.TAG, "unable to kill " + task, e)
} }
cmd.append("rm -f %s%s-nat.pid".format(Path.BASE, task))
cmd.append("rm -f %s%s-nat.conf".format(Path.BASE, task))
cmd.append("rm -f %s%s-vpn.pid".format(Path.BASE, task))
cmd.append("rm -f %s%s-vpn.conf".format(Path.BASE, task))
}
Console.runCommand(cmd.toArray)
Console.runRootCommand(cmd.toArray)
Console.runRootCommand(Utils.getIptables + " -t nat -F OUTPUT")
} }
private def getVersionName: String = { private def getVersionName: String = {
......
...@@ -41,15 +41,14 @@ package com.github.shadowsocks ...@@ -41,15 +41,14 @@ package com.github.shadowsocks
import java.io.File import java.io.File
import java.lang.reflect.{InvocationTargetException, Method} import java.lang.reflect.{InvocationTargetException, Method}
import java.util.{Timer, TimerTask} import java.util.Timer
import android.app.{Notification, NotificationManager, PendingIntent, Service} import android.app.{Notification, NotificationManager, PendingIntent, Service}
import android.content._ import android.content._
import android.content.pm.{PackageInfo, PackageManager} import android.content.pm.{PackageInfo, PackageManager}
import android.net.ConnectivityManager import android.net.{Network, ConnectivityManager}
import android.os._ import android.os._
import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationCompat
import android.support.v4.net.ConnectivityManagerCompat
import android.util.Log import android.util.Log
import com.github.shadowsocks.aidl.Config import com.github.shadowsocks.aidl.Config
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
...@@ -94,7 +93,7 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -94,7 +93,7 @@ class ShadowsocksNatService extends Service with BaseService {
private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication] private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]
def setDns(dns: String) { def setDnsForAllNetwork(dns: String) {
val manager = getSystemService(Context.CONNECTIVITY_SERVICE).asInstanceOf[ConnectivityManager] val manager = getSystemService(Context.CONNECTIVITY_SERVICE).asInstanceOf[ConnectivityManager]
val networks = manager.getAllNetworks val networks = manager.getAllNetworks
val cmdBuf = new ArrayBuffer[String]() val cmdBuf = new ArrayBuffer[String]()
...@@ -108,20 +107,33 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -108,20 +107,33 @@ class ShadowsocksNatService extends Service with BaseService {
Console.runRootCommand(cmdBuf.toArray) Console.runRootCommand(cmdBuf.toArray)
} }
def setupDns() = {
setDnsForAllNetwork("127.0.0.1")
}
def resetDns() = {
setDnsForAllNetwork("8.8.8.8 208.67.222.222 114.114.114.114")
}
def destroyConnectionReceiver() {
if (conReceiver != null) {
unregisterReceiver(conReceiver)
conReceiver = null
}
resetDns()
}
def initConnectionReceiver() { def initConnectionReceiver() {
setupDns()
val filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION) val filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
conReceiver = new BroadcastReceiver { conReceiver = new BroadcastReceiver {
override def onReceive(context: Context, intent: Intent): Unit = { override def onReceive(context: Context, intent: Intent) = {
setDns("127.0.0.1") setupDns()
} }
} }
registerReceiver(conReceiver, filter) registerReceiver(conReceiver, filter)
} }
def resetDns() = {
setDns("8.8.8.8 208.67.222.222 114.114.114.114")
}
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
if (config.route != Route.ALL) { if (config.route != Route.ALL) {
val acl: Array[String] = config.route match { val acl: Array[String] = config.route match {
...@@ -136,15 +148,15 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -136,15 +148,15 @@ class ShadowsocksNatService extends Service with BaseService {
val conf = ConfigUtils val conf = ConfigUtils
.SHADOWSOCKS.format(config.proxy, config.remotePort, config.localPort, .SHADOWSOCKS.format(config.proxy, config.remotePort, config.localPort,
config.sitekey, config.encMethod, 10) config.sitekey, config.encMethod, 10)
ConfigUtils.printToFile(new File(Path.BASE + "ss-local.json"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "ss-local-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmd = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]
cmd += (Path.BASE + "ss-local" cmd += (Path.BASE + "ss-local"
, "-b" , "127.0.0.1" , "-b" , "127.0.0.1"
, "-c" , Path.BASE + "ss-local.json" , "-c" , Path.BASE + "ss-local-nat.conf"
, "-f" , Path.BASE + "ss-local.pid") , "-f" , Path.BASE + "ss-local-nat.pid")
if (config.route != Route.ALL) { if (config.route != Route.ALL) {
cmd += "--acl" cmd += "--acl"
...@@ -160,15 +172,15 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -160,15 +172,15 @@ class ShadowsocksNatService extends Service with BaseService {
val conf = ConfigUtils val conf = ConfigUtils
.SHADOWSOCKS.format(config.proxy, config.remotePort, 8153, .SHADOWSOCKS.format(config.proxy, config.remotePort, 8153,
config.sitekey, config.encMethod, 10) config.sitekey, config.encMethod, 10)
ConfigUtils.printToFile(new File(Path.BASE + "ss-tunnel.json"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "ss-tunnel-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmd = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]
cmd += (Path.BASE + "ss-tunnel" , "-u" cmd += (Path.BASE + "ss-tunnel" , "-u"
, "-b" , "127.0.0.1" , "-b" , "127.0.0.1"
, "-L" , "8.8.8.8:53" , "-L" , "8.8.8.8:53"
, "-c" , Path.BASE + "ss-tunnel.json" , "-c" , Path.BASE + "ss-tunnel-nat.conf"
, "-f" , Path.BASE + "ss-tunnel.pid") , "-f" , Path.BASE + "ss-tunnel-nat.pid")
if (Utils.isLollipopOrAbove) { if (Utils.isLollipopOrAbove) {
cmd += ("-l" , "53") cmd += ("-l" , "53")
...@@ -188,7 +200,7 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -188,7 +200,7 @@ class ShadowsocksNatService extends Service with BaseService {
val conf = ConfigUtils val conf = ConfigUtils
.SHADOWSOCKS.format(config.proxy, config.remotePort, 8163, .SHADOWSOCKS.format(config.proxy, config.remotePort, 8163,
config.sitekey, config.encMethod, 10) config.sitekey, config.encMethod, 10)
ConfigUtils.printToFile(new File(Path.BASE + "ss-tunnel.json"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "ss-tunnel-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmdBuf = new ArrayBuffer[String] val cmdBuf = new ArrayBuffer[String]
...@@ -196,8 +208,8 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -196,8 +208,8 @@ class ShadowsocksNatService extends Service with BaseService {
, "-b" , "127.0.0.1" , "-b" , "127.0.0.1"
, "-l" , "8163" , "-l" , "8163"
, "-L" , "8.8.8.8:53" , "-L" , "8.8.8.8:53"
, "-c" , Path.BASE + "ss-tunnel.json" , "-c" , Path.BASE + "ss-tunnel-nat.conf"
, "-f" , Path.BASE + "ss-tunnel.pid") , "-f" , Path.BASE + "ss-tunnel-nat.pid")
if (BuildConfig.DEBUG) Log.d(TAG, cmdBuf.mkString(" ")) if (BuildConfig.DEBUG) Log.d(TAG, cmdBuf.mkString(" "))
Console.runCommand(cmdBuf.mkString(" ")) Console.runCommand(cmdBuf.mkString(" "))
...@@ -207,15 +219,15 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -207,15 +219,15 @@ class ShadowsocksNatService extends Service with BaseService {
def startDnsDaemon() { def startDnsDaemon() {
val conf = if (Utils.isLollipopOrAbove) { val conf = if (Utils.isLollipopOrAbove) {
ConfigUtils ConfigUtils
.PDNSD_BYPASS.format("127.0.0.1", 53, getString(R.string.exclude), 8163) .PDNSD_BYPASS.format("127.0.0.1", 53, Path.BASE + "pdnsd-nat.pid", getString(R.string.exclude), 8163)
} else { } else {
ConfigUtils ConfigUtils
.PDNSD_BYPASS.format("127.0.0.1", 8153, getString(R.string.exclude), 8163) .PDNSD_BYPASS.format("127.0.0.1", 8153, Path.BASE + "pdnsd-nat.pid", getString(R.string.exclude), 8163)
} }
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "pdnsd-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmd = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf" val cmd = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd-nat.conf"
if (BuildConfig.DEBUG) Log.d(TAG, cmd) if (BuildConfig.DEBUG) Log.d(TAG, cmd)
...@@ -241,9 +253,9 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -241,9 +253,9 @@ class ShadowsocksNatService extends Service with BaseService {
def startRedsocksDaemon() { def startRedsocksDaemon() {
val conf = ConfigUtils.REDSOCKS.format(config.localPort) val conf = ConfigUtils.REDSOCKS.format(config.localPort)
val cmd = Path.BASE + "redsocks -p %sredsocks.pid -c %sredsocks.conf" val cmd = Path.BASE + "redsocks -p %sredsocks-nat.pid -c %sredsocks-nat.conf"
.format(Path.BASE, Path.BASE) .format(Path.BASE, Path.BASE)
ConfigUtils.printToFile(new File(Path.BASE + "redsocks.conf"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "redsocks-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
...@@ -334,17 +346,25 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -334,17 +346,25 @@ class ShadowsocksNatService extends Service with BaseService {
def killProcesses() { def killProcesses() {
val cmd = new ArrayBuffer[String]() val cmd = new ArrayBuffer[String]()
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks")) {
cmd.append("chmod 666 %s%s-nat.pid".format(Path.BASE, task))
}
Console.runRootCommand(cmd.toArray)
cmd.clear()
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks")) { for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks")) {
try { try {
val pid = scala.io.Source.fromFile(Path.BASE + task + ".pid").mkString.trim.toInt val pid = scala.io.Source.fromFile(Path.BASE + task + "-nat.pid").mkString.trim.toInt
Process.killProcess(pid)
cmd.append("kill -9 %d".format(pid)) cmd.append("kill -9 %d".format(pid))
cmd.append("rm -rf %s%s.pid", Path.BASE, task) Process.killProcess(pid)
Log.d(TAG, "kill pid: " + pid)
} catch { } catch {
case e: Throwable => Log.e(TAG, "unable to kill " + task, e) case e: Throwable => Log.e(TAG, "unable to kill " + task, e)
} }
cmd.append("rm -f %s%s-nat.pid".format(Path.BASE, task))
cmd.append("rm -f %s%s-nat.conf".format(Path.BASE, task))
} }
Console.runRootCommand(cmd.toArray) Console.runRootCommand(cmd.toArray)
Console.runRootCommand(Utils.getIptables + " -t nat -F OUTPUT") Console.runRootCommand(Utils.getIptables + " -t nat -F OUTPUT")
} }
...@@ -507,8 +527,14 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -507,8 +527,14 @@ class ShadowsocksNatService extends Service with BaseService {
override def stopRunner() { override def stopRunner() {
// change the state // clean up recevier
changeState(State.STOPPED) if (closeReceiver != null) {
unregisterReceiver(closeReceiver)
closeReceiver = null
}
if (Utils.isLollipopOrAbove) {
destroyConnectionReceiver()
}
// send event // send event
application.tracker.send(new HitBuilders.EventBuilder() application.tracker.send(new HitBuilders.EventBuilder()
...@@ -531,20 +557,10 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -531,20 +557,10 @@ class ShadowsocksNatService extends Service with BaseService {
stopSelf() stopSelf()
} }
// clean up recevier
if (closeReceiver != null) {
unregisterReceiver(closeReceiver)
closeReceiver = null
}
if (Utils.isLollipopOrAbove) {
if (conReceiver != null) {
unregisterReceiver(conReceiver)
conReceiver = null
}
resetDns()
}
stopForegroundCompat(1) stopForegroundCompat(1)
// change the state
changeState(State.STOPPED)
} }
override def stopBackgroundService() { override def stopBackgroundService() {
......
...@@ -40,14 +40,12 @@ ...@@ -40,14 +40,12 @@
package com.github.shadowsocks package com.github.shadowsocks
import java.io.File import java.io.File
import java.net.InetAddress
import android.app._ import android.app._
import android.content._ import android.content._
import android.content.pm.{PackageInfo, PackageManager} import android.content.pm.{PackageInfo, PackageManager}
import android.net.{LocalServerSocket, VpnService, LocalSocket, LocalSocketAddress} import android.net.VpnService
import android.os._ import android.os._
import android.support.v4.app.NotificationCompat
import android.util.Log import android.util.Log
import com.github.shadowsocks.aidl.Config import com.github.shadowsocks.aidl.Config
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
...@@ -110,15 +108,15 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -110,15 +108,15 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val conf = ConfigUtils val conf = ConfigUtils
.SHADOWSOCKS.format(config.proxy, config.remotePort, config.localPort, .SHADOWSOCKS.format(config.proxy, config.remotePort, config.localPort,
config.sitekey, config.encMethod, 10) config.sitekey, config.encMethod, 10)
ConfigUtils.printToFile(new File(Path.BASE + "ss-local.json"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "ss-local-vpn.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmd = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]
cmd +=(Path.BASE + "ss-local", "-u" cmd +=(Path.BASE + "ss-local", "-u"
, "-b", "127.0.0.1" , "-b", "127.0.0.1"
, "-c", Path.BASE + "ss-local.json" , "-c", Path.BASE + "ss-local-vpn.conf"
, "-f", Path.BASE + "ss-local.pid") , "-f", Path.BASE + "ss-local-vpn.pid")
if (Utils.isLollipopOrAbove && config.route != Route.ALL) { if (Utils.isLollipopOrAbove && config.route != Route.ALL) {
cmd += "--acl" cmd += "--acl"
...@@ -133,7 +131,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -133,7 +131,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val conf = ConfigUtils val conf = ConfigUtils
.SHADOWSOCKS.format(config.proxy, config.remotePort, 8163, .SHADOWSOCKS.format(config.proxy, config.remotePort, 8163,
config.sitekey, config.encMethod, 10) config.sitekey, config.encMethod, 10)
ConfigUtils.printToFile(new File(Path.BASE + "ss-tunnel.json"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "ss-tunnel-vpn.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmd = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]
...@@ -141,8 +139,8 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -141,8 +139,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
, "-b", "127.0.0.1" , "-b", "127.0.0.1"
, "-l", "8163" , "-l", "8163"
, "-L", "8.8.8.8:53" , "-L", "8.8.8.8:53"
, "-c", Path.BASE + "ss-tunnel.json" , "-c", Path.BASE + "ss-tunnel-vpn.conf"
, "-f", Path.BASE + "ss-tunnel.pid") , "-f", Path.BASE + "ss-tunnel-vpn.pid")
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" ")) if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
Console.runCommand(cmd.mkString(" ")) Console.runCommand(cmd.mkString(" "))
...@@ -151,15 +149,15 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -151,15 +149,15 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def startDnsDaemon() { def startDnsDaemon() {
val conf = { val conf = {
if (Utils.isLollipopOrAbove) { if (Utils.isLollipopOrAbove) {
ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", 8153, getString(R.string.exclude), 8163) ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", 8153, Path.BASE + "pdnsd-vpn.pid", getString(R.string.exclude), 8163)
} else { } else {
ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163) ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163)
} }
} }
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "pdnsd-vpn.conf"))(p => {
p.println(conf) p.println(conf)
}) })
val cmd = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf" val cmd = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd-vpn.conf"
if (BuildConfig.DEBUG) Log.d(TAG, cmd) if (BuildConfig.DEBUG) Log.d(TAG, cmd)
Console.runCommand(cmd) Console.runCommand(cmd)
...@@ -312,7 +310,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -312,7 +310,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
+ "--tunfd %d " + "--tunfd %d "
+ "--tunmtu %d " + "--tunmtu %d "
+ "--loglevel 3 " + "--loglevel 3 "
+ "--pid %stun2socks.pid") + "--pid %stun2socks-vpn.pid")
.format(PRIVATE_VLAN.format("2"), config.localPort, fd, VPN_MTU, Path.BASE) .format(PRIVATE_VLAN.format("2"), config.localPort, fd, VPN_MTU, Path.BASE)
if (config.isUdpDns) if (config.isUdpDns)
...@@ -321,12 +319,12 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -321,12 +319,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
cmd += " --dnsgw %s:8153".format(PRIVATE_VLAN.format("1")) cmd += " --dnsgw %s:8153".format(PRIVATE_VLAN.format("1"))
if (Utils.isLollipopOrAbove) { if (Utils.isLollipopOrAbove) {
cmd += " --fake-proc"; cmd += " --fake-proc"
} }
if (BuildConfig.DEBUG) Log.d(TAG, cmd) if (BuildConfig.DEBUG) Log.d(TAG, cmd)
System.exec(cmd); System.exec(cmd)
} }
/** Called when the activity is first created. */ /** Called when the activity is first created. */
...@@ -366,9 +364,8 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -366,9 +364,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def killProcesses() { def killProcesses() {
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "tun2socks")) { for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "tun2socks")) {
try { try {
val pid = scala.io.Source.fromFile(Path.BASE + task + ".pid").mkString.trim.toInt val pid = scala.io.Source.fromFile(Path.BASE + task + "-vpn.pid").mkString.trim.toInt
Process.killProcess(pid) Process.killProcess(pid)
Log.d(TAG, "kill pid: " + pid)
} catch { } catch {
case e: Throwable => Log.e(TAG, "unable to kill " + task, e) case e: Throwable => Log.e(TAG, "unable to kill " + task, e)
} }
......
...@@ -137,7 +137,7 @@ object ConfigUtils { ...@@ -137,7 +137,7 @@ object ConfigUtils {
| max_ttl = 1w; | max_ttl = 1w;
| timeout = 10; | timeout = 10;
| daemon = on; | daemon = on;
| pid_file = "/data/data/com.github.shadowsocks/pdnsd.pid"; | pid_file = "%s";
|} |}
| |
|server { |server {
......
...@@ -68,8 +68,8 @@ object Utils { ...@@ -68,8 +68,8 @@ object Utils {
val DEFAULT_SHELL: String = "/system/bin/sh" val DEFAULT_SHELL: String = "/system/bin/sh"
val DEFAULT_ROOT: String = "/system/bin/su" val DEFAULT_ROOT: String = "/system/bin/su"
val ALTERNATIVE_ROOT: String = "/system/xbin/su" val ALTERNATIVE_ROOT: String = "/system/xbin/su"
val DEFAULT_IPTABLES: String = "/data/data/com.github.shadowsocks/iptables" val DEFAULT_IPTABLES: String = "/system/bin/iptables"
val ALTERNATIVE_IPTABLES: String = "/system/bin/iptables" val ALTERNATIVE_IPTABLES: String = "/data/data/com.github.shadowsocks/iptables"
val TIME_OUT: Int = -99 val TIME_OUT: Int = -99
var initialized: Boolean = false var initialized: Boolean = false
var hasRedirectSupport: Int = -1 var hasRedirectSupport: Int = -1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment