fix #148
This commit is contained in:
@@ -14,6 +14,7 @@ public class Config implements Parcelable {
|
||||
public String profileName = "Untitled";
|
||||
public String proxy = "127.0.0.1";
|
||||
public String sitekey = "null";
|
||||
public String route = "all";
|
||||
|
||||
public String encMethod = "rc4";
|
||||
public String proxiedAppString = "";
|
||||
@@ -33,7 +34,7 @@ public class Config implements Parcelable {
|
||||
|
||||
public Config(boolean isGlobalProxy, boolean isGFWList, boolean isBypassApps,
|
||||
boolean isTrafficStat, boolean isUdpDns, String profileName, String proxy, String sitekey,
|
||||
String encMethod, String proxiedAppString, int remotePort, int localPort) {
|
||||
String encMethod, String proxiedAppString, String route, int remotePort, int localPort) {
|
||||
this.isGlobalProxy = isGlobalProxy;
|
||||
this.isGFWList = isGFWList;
|
||||
this.isBypassApps = isBypassApps;
|
||||
@@ -44,6 +45,7 @@ public class Config implements Parcelable {
|
||||
this.sitekey = sitekey;
|
||||
this.encMethod = encMethod;
|
||||
this.proxiedAppString = proxiedAppString;
|
||||
this.route = route;
|
||||
this.remotePort = remotePort;
|
||||
this.localPort = localPort;
|
||||
}
|
||||
@@ -63,6 +65,7 @@ public class Config implements Parcelable {
|
||||
sitekey = in.readString();
|
||||
encMethod = in.readString();
|
||||
proxiedAppString = in.readString();
|
||||
route = in.readString();
|
||||
remotePort = in.readInt();
|
||||
localPort = in.readInt();
|
||||
}
|
||||
@@ -82,6 +85,7 @@ public class Config implements Parcelable {
|
||||
out.writeString(sitekey);
|
||||
out.writeString(encMethod);
|
||||
out.writeString(proxiedAppString);
|
||||
out.writeString(route);
|
||||
out.writeInt(remotePort);
|
||||
out.writeInt(localPort);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
<string name="dns_proxy_summary">重定向 DNS 查询到远程服务器</string>
|
||||
<string name="auto_set_gfwlist">国内路由</string>
|
||||
<string name="auto_set_gfwlist_summary">绕过所有位于中国的网站</string>
|
||||
<string name="route_list">路由</string>
|
||||
<string name="route_list_summary">绕过指定路由列表中的地址</string>
|
||||
<string name="auto_set_proxy">全局代理</string>
|
||||
<string name="auto_set_proxy_summary">设置系统代理</string>
|
||||
<string name="proxied_apps">局部代理</string>
|
||||
@@ -76,4 +78,10 @@
|
||||
<item>手动设置</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="route_entry">
|
||||
<item>全局</item>
|
||||
<item>绕过局域网地址</item>
|
||||
<item>绕过局域网及中国大陆地址</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -38,7 +38,36 @@
|
||||
<item>seed-cfb</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="private_list">
|
||||
<string-array name="route_entry">
|
||||
<item>All</item>
|
||||
<item>Bypass LAN</item>
|
||||
<item>Bypass LAN & China</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="route_value">
|
||||
<item>all</item>
|
||||
<item>bypass-lan</item>
|
||||
<item>bypass-china</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="private_route">
|
||||
<item>0.0.0.0/8</item>
|
||||
<item>10.0.0.0/8</item>
|
||||
<item>100.64.0.0/10</item>
|
||||
<item>127.0.0.0/8</item>
|
||||
<item>169.254.0.0/16</item>
|
||||
<item>172.16.0.0/12</item>
|
||||
<item>192.0.0.0/29</item>
|
||||
<item>192.0.2.0/24</item>
|
||||
<item>192.88.99.0/24</item>
|
||||
<item>192.168.0.0/16</item>
|
||||
<item>198.18.0.0/15</item>
|
||||
<item>198.51.100.0/24</item>
|
||||
<item>203.0.113.0/24</item>
|
||||
<item>224.0.0.0/3</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="bypass_private_route">
|
||||
<item>1.0.0.0/8</item>
|
||||
<item>2.0.0.0/7</item>
|
||||
<item>4.0.0.0/6</item>
|
||||
@@ -162,7 +191,10 @@
|
||||
<item>208.0.0.0/4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="chn_list_full">
|
||||
<string-array name="chn_route_full">
|
||||
<item>10.0.0.0/8</item>
|
||||
<item>172.16.0.0/12</item>
|
||||
<item>192.168.0.0/16</item>
|
||||
<item>1.0.1.0/24</item>
|
||||
<item>1.0.2.0/23</item>
|
||||
<item>1.0.8.0/21</item>
|
||||
@@ -222,7 +254,6 @@
|
||||
<item>1.192.0.0/13</item>
|
||||
<item>1.202.0.0/15</item>
|
||||
<item>1.204.0.0/14</item>
|
||||
<item>10.0.0.0/8</item>
|
||||
<item>14.0.0.0/21</item>
|
||||
<item>14.0.12.0/22</item>
|
||||
<item>14.1.0.0/22</item>
|
||||
@@ -1924,7 +1955,6 @@
|
||||
<item>171.116.0.0/14</item>
|
||||
<item>171.120.0.0/13</item>
|
||||
<item>171.208.0.0/12</item>
|
||||
<item>172.16.0.0/12</item>
|
||||
<item>175.0.0.0/12</item>
|
||||
<item>175.16.0.0/13</item>
|
||||
<item>175.24.0.0/14</item>
|
||||
@@ -2028,7 +2058,6 @@
|
||||
<item>183.184.0.0/13</item>
|
||||
<item>183.192.0.0/10</item>
|
||||
<item>192.124.154.0/24</item>
|
||||
<item>192.168.0.0/16</item>
|
||||
<item>192.188.170.0/24</item>
|
||||
<item>202.0.100.0/23</item>
|
||||
<item>202.0.122.0/23</item>
|
||||
@@ -3970,9 +3999,8 @@
|
||||
<item>223.255.252.0/23</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="chn_list">
|
||||
<string-array name="chn_route">
|
||||
<item>0.0.0.0/7</item>
|
||||
<item>10.0.0.0/8</item>
|
||||
<item>14.0.0.0/8</item>
|
||||
<item>27.0.0.0/8</item>
|
||||
<item>36.0.0.0/8</item>
|
||||
@@ -4017,7 +4045,7 @@
|
||||
<item>220.0.0.0/6</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="gfw_list">
|
||||
<string-array name="gfw_route">
|
||||
<item>1.0.0.0/23</item>
|
||||
<item>1.0.4.0/22</item>
|
||||
<item>1.0.16.0/20</item>
|
||||
@@ -8507,7 +8535,7 @@
|
||||
<item>223.255.254.0/23</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="simple_list">
|
||||
<string-array name="simple_route">
|
||||
<item>1.0.0.0/15</item>
|
||||
<item>1.2.0.0/16</item>
|
||||
<item>1.4.0.0/14</item>
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
<string name="auto_set_gfwlist">CHN Route</string>
|
||||
<string name="auto_set_gfwlist_summary">Bypass all sites located in China
|
||||
</string>
|
||||
<string name="route_list">Route</string>
|
||||
<string name="route_list_summary">Bypass IP addresses in the route list</string>
|
||||
<string name="auto_set_proxy">Global Proxy</string>
|
||||
<string name="auto_set_proxy_summary">Set up system-wide proxy
|
||||
</string>
|
||||
|
||||
@@ -48,12 +48,14 @@
|
||||
<PreferenceCategory
|
||||
android:title="@string/feature_cat">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="isGFWList"
|
||||
android:summary="@string/auto_set_gfwlist_summary"
|
||||
android:title="@string/auto_set_gfwlist">
|
||||
</CheckBoxPreference>
|
||||
<com.github.shadowsocks.preferences.SummaryListPreference
|
||||
android:defaultValue="all"
|
||||
android:key="route"
|
||||
android:entries="@array/route_entry"
|
||||
android:entryValues="@array/route_value"
|
||||
android:summary="@string/route_list_summary"
|
||||
android:title="@string/route_list">
|
||||
</com.github.shadowsocks.preferences.SummaryListPreference>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="isGlobalProxy"
|
||||
|
||||
@@ -120,15 +120,15 @@ object Shadowsocks {
|
||||
val PREFS_NAME = "Shadowsocks"
|
||||
val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey,
|
||||
Key.encMethod)
|
||||
val FEATRUE_PREFS = Array(Key.isGFWList, Key.isGlobalProxy, Key.proxyedApps,
|
||||
val FEATRUE_PREFS = Array(Key.route, Key.isGlobalProxy, Key.proxyedApps,
|
||||
Key.isUdpDns, Key.isAutoConnect)
|
||||
|
||||
val EXECUTABLES = Array(Executable.PDNSD, Executable.REDSOCKS, Executable.IPTABLES)
|
||||
|
||||
// Helper functions
|
||||
def updateListPreference(pref: Preference, value: String) {
|
||||
pref.setSummary(value)
|
||||
pref.asInstanceOf[ListPreference].setValue(value)
|
||||
pref.setSummary(pref.asInstanceOf[ListPreference].getEntry)
|
||||
}
|
||||
|
||||
def updatePasswordEditTextPreference(pref: Preference, value: String) {
|
||||
@@ -158,7 +158,7 @@ object Shadowsocks {
|
||||
case Key.localPort => updateSummaryEditTextPreference(pref, profile.localPort.toString)
|
||||
case Key.sitekey => updatePasswordEditTextPreference(pref, profile.password)
|
||||
case Key.encMethod => updateListPreference(pref, profile.method)
|
||||
case Key.isGFWList => updateCheckBoxPreference(pref, profile.chnroute)
|
||||
case Key.route => updateListPreference(pref, profile.route)
|
||||
case Key.isGlobalProxy => updateCheckBoxPreference(pref, profile.global)
|
||||
case Key.isUdpDns => updateCheckBoxPreference(pref, profile.udpdns)
|
||||
case _ =>
|
||||
|
||||
@@ -93,19 +93,14 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
|
||||
private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]
|
||||
|
||||
def isACLEnabled: Boolean = {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
def startShadowsocksDaemon() {
|
||||
if (isACLEnabled && 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))
|
||||
if (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)
|
||||
}
|
||||
ConfigUtils.printToFile(new File(Path.BASE + "acl.list"))(p => {
|
||||
acl.foreach(item => p.println(item))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,11 +112,11 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
, "-l" , config.localPort.toString
|
||||
, "-k" , config.sitekey
|
||||
, "-m" , config.encMethod
|
||||
, "-f" , (Path.BASE + "ss-local.pid"))
|
||||
, "-f" , Path.BASE + "ss-local.pid")
|
||||
|
||||
if (config.isGFWList && isACLEnabled) {
|
||||
if (config.route != Route.ALL) {
|
||||
cmd += "--acl"
|
||||
cmd += (Path.BASE + "chn.acl")
|
||||
cmd += (Path.BASE + "acl.list")
|
||||
}
|
||||
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
|
||||
@@ -140,7 +135,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
, "-p" , config.remotePort.toString
|
||||
, "-k" , config.sitekey
|
||||
, "-m" , config.encMethod
|
||||
, "-f" , (Path.BASE + "ss-tunnel.pid"))
|
||||
, "-f" , Path.BASE + "ss-tunnel.pid")
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
|
||||
Core.sstunnel(cmd.toArray)
|
||||
} else {
|
||||
@@ -298,15 +293,6 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1"))
|
||||
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " + myUid))
|
||||
|
||||
if (config.isGFWList) {
|
||||
if (!isACLEnabled)
|
||||
{
|
||||
val chn_list: Array[String] = getResources.getStringArray(R.array.chn_list)
|
||||
for (item <- chn_list) {
|
||||
init_sb.append(cmd_bypass.replace("0.0.0.0", item))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasRedirectSupport) {
|
||||
init_sb
|
||||
.append(Utils.getIptables + " -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to "
|
||||
|
||||
@@ -64,7 +64,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
val TAG = "ShadowsocksVpnService"
|
||||
|
||||
val VPN_MTU = 1500
|
||||
|
||||
val PRIVATE_VLAN = "26.26.26.%s"
|
||||
|
||||
var conn: ParcelFileDescriptor = null
|
||||
@@ -88,28 +87,47 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
info.isInRange(config.proxy)
|
||||
}
|
||||
|
||||
def isPrivateA(a: Int): Boolean = {
|
||||
if (a == 10 || a == 192 || a == 172) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
def isPrivateB(a: Int, b: Int): Boolean = {
|
||||
if (a == 10 || (a == 192 && b == 168) || (a == 172 && b >= 16 && b < 32)) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
def startShadowsocksDaemon() {
|
||||
|
||||
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))
|
||||
if (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)
|
||||
}
|
||||
ConfigUtils.printToFile(new File(Path.BASE + "acl.list"))(p => {
|
||||
acl.foreach(item => p.println(item))
|
||||
})
|
||||
}
|
||||
|
||||
val cmd = new ArrayBuffer[String]
|
||||
cmd += ("ss-local" , "-u"
|
||||
, "-b" , "127.0.0.1"
|
||||
, "-s" , config.proxy
|
||||
, "-p" , config.remotePort.toString
|
||||
, "-l" , config.localPort.toString
|
||||
, "-k" , config.sitekey
|
||||
, "-m" , config.encMethod
|
||||
, "-f" , Path.BASE + "ss-local.pid")
|
||||
cmd +=("ss-local", "-u"
|
||||
, "-b", "127.0.0.1"
|
||||
, "-s", config.proxy
|
||||
, "-p", config.remotePort.toString
|
||||
, "-l", config.localPort.toString
|
||||
, "-k", config.sitekey
|
||||
, "-m", config.encMethod
|
||||
, "-f", Path.BASE + "ss-local.pid")
|
||||
|
||||
if (config.isGFWList && isLollipopOrAbove) {
|
||||
if (isLollipopOrAbove && config.route != Route.ALL) {
|
||||
cmd += "--acl"
|
||||
cmd += (Path.BASE + "chn.acl")
|
||||
cmd += (Path.BASE + "acl.list")
|
||||
}
|
||||
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
|
||||
@@ -118,15 +136,15 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
|
||||
def startDnsTunnel() = {
|
||||
val cmd = new ArrayBuffer[String]
|
||||
cmd += ("ss-tunnel"
|
||||
, "-b" , "127.0.0.1"
|
||||
, "-l" , "8163"
|
||||
, "-L" , "8.8.8.8:53"
|
||||
, "-s" , config.proxy
|
||||
, "-p" , config.remotePort.toString
|
||||
, "-k" , config.sitekey
|
||||
, "-m" , config.encMethod
|
||||
, "-f" , Path.BASE + "ss-tunnel.pid")
|
||||
cmd +=("ss-tunnel"
|
||||
, "-b", "127.0.0.1"
|
||||
, "-l", "8163"
|
||||
, "-L", "8.8.8.8:53"
|
||||
, "-s", config.proxy
|
||||
, "-p", config.remotePort.toString
|
||||
, "-k", config.sitekey
|
||||
, "-m", config.encMethod
|
||||
, "-f", Path.BASE + "ss-tunnel.pid")
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
|
||||
Core.sstunnel(cmd.toArray)
|
||||
}
|
||||
@@ -195,52 +213,76 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
|
||||
if (InetAddressUtils.isIPv6Address(config.proxy)) {
|
||||
builder.addRoute("0.0.0.0", 0)
|
||||
} else if (!isLollipopOrAbove && config.isGFWList) {
|
||||
val gfwList = {
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
||||
getResources.getStringArray(R.array.simple_list)
|
||||
} else {
|
||||
getResources.getStringArray(R.array.gfw_list)
|
||||
}
|
||||
}
|
||||
gfwList.foreach(cidr => {
|
||||
val net = new SubnetUtils(cidr)
|
||||
if (!isByass(net)) {
|
||||
val addr = cidr.split('/')
|
||||
builder.addRoute(addr(0), addr(1).toInt)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (isLollipopOrAbove) {
|
||||
val privateList = getResources.getStringArray(R.array.private_list)
|
||||
privateList.foreach(cidr => {
|
||||
val addr = cidr.split('/')
|
||||
builder.addRoute(addr(0), addr(1).toInt)
|
||||
})
|
||||
} else {
|
||||
for (i <- 1 to 223) {
|
||||
if (i != 26 && i != 127) {
|
||||
val addr = i.toString + ".0.0.0"
|
||||
val cidr = addr + "/8"
|
||||
val net = new SubnetUtils(cidr)
|
||||
if (!isLollipopOrAbove) {
|
||||
config.route match {
|
||||
case Route.ALL =>
|
||||
for (i <- 1 to 223) {
|
||||
if (i != 26 && i != 127) {
|
||||
val addr = i.toString + ".0.0.0"
|
||||
val cidr = addr + "/8"
|
||||
val net = new SubnetUtils(cidr)
|
||||
|
||||
if (!isByass(net)) {
|
||||
if (!InetAddress.getByName(addr).isSiteLocalAddress) {
|
||||
builder.addRoute(addr, 8)
|
||||
}
|
||||
} else {
|
||||
for (j <- 0 to 255) {
|
||||
val subAddr = i.toString + "." + j.toString + ".0.0"
|
||||
val subCidr = subAddr + "/16"
|
||||
val subNet = new SubnetUtils(subCidr)
|
||||
if (!isByass(subNet)) {
|
||||
if (!InetAddress.getByName(subAddr).isSiteLocalAddress) {
|
||||
builder.addRoute(subAddr, 16)
|
||||
if (!isByass(net)) {
|
||||
builder.addRoute(addr, 8)
|
||||
} else {
|
||||
for (j <- 0 to 255) {
|
||||
val subAddr = i.toString + "." + j.toString + ".0.0"
|
||||
val subCidr = subAddr + "/16"
|
||||
val subNet = new SubnetUtils(subCidr)
|
||||
if (!isByass(subNet)) {
|
||||
builder.addRoute(subAddr, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case Route.BYPASS_LAN =>
|
||||
for (i <- 1 to 223) {
|
||||
if (i != 26 && i != 127) {
|
||||
val addr = i.toString + ".0.0.0"
|
||||
val cidr = addr + "/8"
|
||||
val net = new SubnetUtils(cidr)
|
||||
|
||||
if (!isByass(net) && !isPrivateA(i)) {
|
||||
builder.addRoute(addr, 8)
|
||||
} else {
|
||||
for (j <- 0 to 255) {
|
||||
val subAddr = i.toString + "." + j.toString + ".0.0"
|
||||
val subCidr = subAddr + "/16"
|
||||
val subNet = new SubnetUtils(subCidr)
|
||||
if (!isByass(subNet) && !isPrivateB(i, j)) {
|
||||
builder.addRoute(subAddr, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case Route.BYPASS_CHN =>
|
||||
val list = {
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
||||
getResources.getStringArray(R.array.simple_route)
|
||||
} else {
|
||||
getResources.getStringArray(R.array.gfw_route)
|
||||
}
|
||||
}
|
||||
list.foreach(cidr => {
|
||||
val net = new SubnetUtils(cidr)
|
||||
if (!isByass(net)) {
|
||||
val addr = cidr.split('/')
|
||||
builder.addRoute(addr(0), addr(1).toInt)
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (config.route == Route.ALL) {
|
||||
builder.addRoute("0.0.0.0", 0)
|
||||
} else {
|
||||
val privateList = getResources.getStringArray(R.array.bypass_private_route)
|
||||
privateList.foreach(cidr => {
|
||||
val addr = cidr.split('/')
|
||||
builder.addRoute(addr(0), addr(1).toInt)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,6 +482,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
}
|
||||
|
||||
override def getTag = TAG
|
||||
|
||||
override def getServiceMode = Mode.VPN
|
||||
|
||||
override def getContext = getBaseContext
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ object DBHelper {
|
||||
}
|
||||
|
||||
class DBHelper(val context: Context)
|
||||
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 8) {
|
||||
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 9) {
|
||||
|
||||
lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile])
|
||||
|
||||
@@ -64,6 +64,9 @@ class DBHelper(val context: Context)
|
||||
if (oldVersion != newVersion) {
|
||||
if (oldVersion < 8) {
|
||||
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;")
|
||||
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN route VARCHAR;")
|
||||
} else if (oldVersion < 9) {
|
||||
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN route VARCHAR;")
|
||||
} else {
|
||||
profileDao.executeRaw("DROP TABLE IF EXISTS 'profile';")
|
||||
onCreate(database, connectionSource)
|
||||
|
||||
@@ -66,6 +66,9 @@ class Profile {
|
||||
@DatabaseField
|
||||
var date: String = ""
|
||||
|
||||
@DatabaseField
|
||||
var route: String = ""
|
||||
|
||||
@DatabaseField
|
||||
var upload: Int = 0
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
Log.e(Shadowsocks.TAG, "getProfile", ex)
|
||||
return None
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
edit.putString(Key.localPort, profile.localPort.toString)
|
||||
edit.putString(Key.proxied, profile.individual)
|
||||
edit.putInt(Key.profileId, profile.id)
|
||||
edit.putString(Key.route, profile.route)
|
||||
edit.commit()
|
||||
|
||||
profile
|
||||
@@ -149,19 +150,18 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
profile.host = settings.getString(Key.proxy, "127.0.0.1")
|
||||
profile.password = settings.getString(Key.sitekey, "default")
|
||||
profile.method = settings.getString(Key.encMethod, "table")
|
||||
profile.route = settings.getString(Key.route, "all")
|
||||
profile.remotePort = try {
|
||||
Integer.valueOf(settings.getString(Key.remotePort, "1984"))
|
||||
} catch {
|
||||
case ex: NumberFormatException => {
|
||||
case ex: NumberFormatException =>
|
||||
1984
|
||||
}
|
||||
}
|
||||
profile.localPort = try {
|
||||
Integer.valueOf(settings.getString(Key.localPort, "1984"))
|
||||
} catch {
|
||||
case ex: NumberFormatException => {
|
||||
case ex: NumberFormatException =>
|
||||
1984
|
||||
}
|
||||
}
|
||||
profile.individual = settings.getString(Key.proxied, "")
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class SummaryListPreference(context: Context, attrs: AttributeSet)
|
||||
|
||||
override def setValue(text: String) {
|
||||
super.setValue(text)
|
||||
setSummary(text.toUpperCase)
|
||||
setSummary(getEntry)
|
||||
}
|
||||
|
||||
override def setSummary(summary: CharSequence) {
|
||||
|
||||
@@ -198,7 +198,7 @@ object ConfigUtils {
|
||||
val method = proxy(3).trim
|
||||
|
||||
new Config(config.isGlobalProxy, config.isGFWList, config.isBypassApps, config.isTrafficStat,
|
||||
config.isUdpDns, config.profileName, host, password, method, config.proxiedAppString, port,
|
||||
config.isUdpDns, config.profileName, host, password, method, config.proxiedAppString, config.route, port,
|
||||
config.localPort)
|
||||
}
|
||||
|
||||
@@ -213,6 +213,8 @@ object ConfigUtils {
|
||||
val proxy = settings.getString(Key.proxy, "127.0.0.1")
|
||||
val sitekey = settings.getString(Key.sitekey, "default")
|
||||
val encMethod = settings.getString(Key.encMethod, "table")
|
||||
val route = settings.getString(Key.route, "all")
|
||||
|
||||
val remotePort: Int = try {
|
||||
settings.getString(Key.remotePort, "1984").toInt
|
||||
} catch {
|
||||
@@ -228,6 +230,6 @@ object ConfigUtils {
|
||||
val proxiedAppString = settings.getString(Key.proxied, "")
|
||||
|
||||
new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, isUdpDns, profileName, proxy,
|
||||
sitekey, encMethod, proxiedAppString, remotePort, localPort)
|
||||
sitekey, encMethod, proxiedAppString, route, remotePort, localPort)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ object Key {
|
||||
val isRoot = "isRoot"
|
||||
val status = "status"
|
||||
val proxyedApps = "proxyedApps"
|
||||
val route = "route"
|
||||
|
||||
val isRunning = "isRunning"
|
||||
val isAutoConnect = "isAutoConnect"
|
||||
@@ -110,3 +111,9 @@ object Action {
|
||||
val UPDATE_FRAGMENT = "com.github.shadowsocks.ACTION_UPDATE_FRAGMENT"
|
||||
val UPDATE_PREFS = "com.github.shadowsocks.ACTION_UPDATE_PREFS"
|
||||
}
|
||||
|
||||
object Route {
|
||||
val ALL = "all"
|
||||
val BYPASS_LAN = "bypass-lan"
|
||||
val BYPASS_CHN = "bypass-china"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user