Skip to content

Commit

Permalink
refine DNS resolver on Lollipop
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Nov 5, 2014
1 parent 72824eb commit 1023870
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion jni/shadowsocks
18 changes: 11 additions & 7 deletions src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {

private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]

def isACLEnabled: Boolean = {
def isLollipopOrAbove: Boolean = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
true
} else {
Expand All @@ -90,7 +90,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {

def startShadowsocksDaemon() {

if (isACLEnabled && config.isGFWList) {
if (isLollipopOrAbove && config.isGFWList) {
val chn_list: Array[String] = getResources.getStringArray(R.array.chn_list_full)
ConfigUtils.printToFile(new File(Path.BASE + "chn.acl"))(p => {
chn_list.foreach(item => p.println(item))
Expand All @@ -107,7 +107,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
, "-m" , config.encMethod
, "-f" , Path.BASE + "ss-local.pid")

if (config.isGFWList && isACLEnabled) {
if (config.isGFWList && isLollipopOrAbove) {
cmd += "--acl"
cmd += (Path.BASE + "chn.acl")
}
Expand All @@ -133,7 +133,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {

def startDnsDaemon() {
val conf = {
ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163)
if (isLollipopOrAbove) {
ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", getString(R.string.exclude), 8163)
} else {
ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163)
}
}
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf)
Expand Down Expand Up @@ -164,7 +168,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
.addAddress(PRIVATE_VLAN.format("1"), 24)
.addDnsServer("8.8.8.8")

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
if (isLollipopOrAbove) {
if (!config.isGlobalProxy) {
val apps = AppManager.getProxiedApps(this, config.proxiedAppString)
val pkgSet: mutable.HashSet[String] = new mutable.HashSet[String]
Expand All @@ -191,7 +195,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {

if (InetAddressUtils.isIPv6Address(config.proxy)) {
builder.addRoute("0.0.0.0", 0)
} else if (!isACLEnabled && config.isGFWList) {
} else if (!isLollipopOrAbove && config.isGFWList) {
val gfwList = {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
getResources.getStringArray(R.array.simple_list)
Expand All @@ -207,7 +211,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
})
} else {
if (isACLEnabled) {
if (isLollipopOrAbove) {
builder.addRoute("0.0.0.0", 0)
} else {
for (i <- 1 to 223) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ object ConfigUtils {
|
|server {
| label = "china-servers";
| ip = 114.114.114.114, 114.114.115.115;
| ip = 114.114.114.114, 223.5.5.5;
| uptest = none;
| preset = on;
| include = %s;
Expand All @@ -151,8 +151,9 @@ object ConfigUtils {
|}
|
|server {
| label = "google-servers";
| ip = 8.8.8.8, 8.8.4.4;
| label = "local-server";
| ip = 127.0.0.1;
| port = %d;
| timeout = 5;
|}
|
Expand Down

0 comments on commit 1023870

Please sign in to comment.