Commit 9296f7c6 authored by Max Lv's avatar Max Lv

fix some issues

parent eb174247
...@@ -17,5 +17,5 @@ script: ...@@ -17,5 +17,5 @@ script:
- wget https://raw.github.com/paulp/sbt-extras/master/sbt - wget https://raw.github.com/paulp/sbt-extras/master/sbt
- chmod u+x ./sbt - chmod u+x ./sbt
- cp local.sbt.example local.sbt - cp local.sbt.example local.sbt
- ./sbt android:package-release - ./sbt android:package-debug
- ./sbt deploy - ./sbt deploy
...@@ -71,8 +71,6 @@ object ShadowVpnService { ...@@ -71,8 +71,6 @@ object ShadowVpnService {
var sRunningInstance: WeakReference[ShadowVpnService] = null var sRunningInstance: WeakReference[ShadowVpnService] = null
var sConn: ParcelFileDescriptor = null
} }
class ShadowVpnService extends VpnService { class ShadowVpnService extends VpnService {
...@@ -87,6 +85,7 @@ class ShadowVpnService extends VpnService { ...@@ -87,6 +85,7 @@ class ShadowVpnService extends VpnService {
val MSG_HOST_CHANGE: Int = 4 val MSG_HOST_CHANGE: Int = 4
val MSG_STOP_SELF: Int = 5 val MSG_STOP_SELF: Int = 5
val VPN_MTU = 1500 val VPN_MTU = 1500
var conn: ParcelFileDescriptor = null
def getPid(name: String): Int = { def getPid(name: String): Int = {
try { try {
...@@ -243,13 +242,13 @@ class ShadowVpnService extends VpnService { ...@@ -243,13 +242,13 @@ class ShadowVpnService extends VpnService {
&& i != 172 && i != 192 && i != 10) builder.addRoute(i + ".0.0.0", 8) && i != 172 && i != 192 && i != 10) builder.addRoute(i + ".0.0.0", 8)
} }
ShadowVpnService.sConn = builder.establish() conn = builder.establish()
if (ShadowVpnService.sConn == null) { if (conn == null) {
stopSelf() stopSelf()
return return
} }
val fd = ShadowVpnService.sConn.getFd val fd = conn.getFd
val cmd = (BASE + "tun2socks --netif-ipaddr 172.16.0.2 --udpgw-remote-server-addr 158.255.208.201:7300 " + val cmd = (BASE + "tun2socks --netif-ipaddr 172.16.0.2 --udpgw-remote-server-addr 158.255.208.201:7300 " +
"--netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:%d --tunfd %d --tunmtu %d --pid " + BASE + "tun2socks.pid") "--netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:%d --tunfd %d --tunmtu %d --pid " + BASE + "tun2socks.pid")
...@@ -315,6 +314,10 @@ class ShadowVpnService extends VpnService { ...@@ -315,6 +314,10 @@ class ShadowVpnService extends VpnService {
ed.putBoolean("isRunning", false) ed.putBoolean("isRunning", false)
ed.putBoolean("isConnecting", false) ed.putBoolean("isConnecting", false)
ed.commit ed.commit
if (conn != null) {
conn.close()
conn = null
}
super.onDestroy() super.onDestroy()
markServiceStopped() markServiceStopped()
} }
......
...@@ -362,27 +362,28 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton. ...@@ -362,27 +362,28 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton.
protected override def onResume() { protected override def onResume() {
super.onResume() super.onResume()
val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
if (isServiceStarted) { if (getIntent.getAction != Shadowsocks.REQUEST_CONNECT) {
switchButton.setChecked(true) if (isServiceStarted) {
if (ShadowVpnService.isServiceStarted) { switchButton.setChecked(true)
val style = new Style.Builder() if (ShadowVpnService.isServiceStarted) {
.setBackgroundColorValue(Style.holoBlueLight) val style = new Style.Builder()
.setDuration(Style.DURATION_INFINITE) .setBackgroundColorValue(Style.holoBlueLight)
.build() .setDuration(Style.DURATION_INFINITE)
switchButton.setEnabled(false) .build()
Crouton.makeText(Shadowsocks.this, R.string.vpn_status, style).show() switchButton.setEnabled(false)
} Crouton.makeText(Shadowsocks.this, R.string.vpn_status, style).show()
} }
else { } else {
if (settings.getBoolean("isRunning", false)) { switchButton.setChecked(false)
new Thread { if (settings.getBoolean("isRunning", false)) {
override def run() { new Thread {
crash_recovery() override def run() {
handler.sendEmptyMessage(MSG_CRASH_RECOVER) crash_recovery()
} handler.sendEmptyMessage(MSG_CRASH_RECOVER)
}.start() }
}.start()
}
} }
switchButton.setChecked(false)
} }
setPreferenceEnabled() setPreferenceEnabled()
switchButton.setOnCheckedChangeListener(this) switchButton.setOnCheckedChangeListener(this)
...@@ -517,10 +518,6 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton. ...@@ -517,10 +518,6 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton.
def serviceStop() { def serviceStop() {
if (ShadowVpnService.isServiceStarted) { if (ShadowVpnService.isServiceStarted) {
if (ShadowVpnService.sConn != null) {
ShadowVpnService.sConn.close()
ShadowVpnService.sConn = null
}
stopService(new Intent(this, classOf[ShadowVpnService])) stopService(new Intent(this, classOf[ShadowVpnService]))
} }
if (ShadowsocksService.isServiceStarted) { if (ShadowsocksService.isServiceStarted) {
......
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