diff --git a/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt b/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt index 3a75b29e..6ee3838c 100644 --- a/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt +++ b/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt @@ -46,6 +46,7 @@ class Acl { val networkAclParser = "^IMPORT_URL\\s*<(.+)>\\s*$".toRegex() fun getFile(id: String) = File(app.filesDir, id + ".acl") + val customRules: Acl get() { val acl = Acl() try { @@ -143,6 +144,7 @@ class Acl { for (item in (if (bypass) proxySubnets else bypassSubnets).asIterable()) this.subnets.add(item) return this } + fun fromId(id: String): Acl = fromReader(Acl.getFile(id).bufferedReader()) fun flatten(depth: Int): Acl { diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt index 65895f72..d0676073 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -238,6 +238,22 @@ object BaseService { Acl.getFile(if (route == Acl.CUSTOM_RULES) Acl.CUSTOM_RULES_FLATTENED else route) } + fun getListFile(): File? { + val aclFile = getAclFile() ?: return null + val listFile = File(aclFile.absolutePath + ".lst") + val list = StringBuilder() + aclFile.bufferedReader().useLines { + for (line in it) { + if (line.startsWith("^(.*\\.)?")) { + list.append(line.substring(8).replace("\\","").replace("$","")) + list.append("\n") + } + } + } + listFile.bufferedWriter().use { it.write(list.toString()) } + return listFile + } + fun createNotification(): ServiceNotification fun startRunner() { diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt index 5de7aabc..0df77ac4 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt @@ -89,7 +89,7 @@ object LocalDnsService { .put("PrimaryDNS", localDns) .put("AlternativeDNS", remoteDns) .put("IPNetworkFile", "china_ip_list.txt") - .put("DomainFile", getAclFile()!!.absolutePath) + .put("DomainFile", getListFile()!!.absolutePath) Acl.CHINALIST -> config .put("PrimaryDNS", localDns) .put("AlternativeDNS", remoteDns)