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

fix some issues

parent eb174247
......@@ -17,5 +17,5 @@ script:
- wget https://raw.github.com/paulp/sbt-extras/master/sbt
- chmod u+x ./sbt
- cp local.sbt.example local.sbt
- ./sbt android:package-release
- ./sbt android:package-debug
- ./sbt deploy
......@@ -71,8 +71,6 @@ object ShadowVpnService {
var sRunningInstance: WeakReference[ShadowVpnService] = null
var sConn: ParcelFileDescriptor = null
}
class ShadowVpnService extends VpnService {
......@@ -87,6 +85,7 @@ class ShadowVpnService extends VpnService {
val MSG_HOST_CHANGE: Int = 4
val MSG_STOP_SELF: Int = 5
val VPN_MTU = 1500
var conn: ParcelFileDescriptor = null
def getPid(name: String): Int = {
try {
......@@ -243,13 +242,13 @@ class ShadowVpnService extends VpnService {
&& i != 172 && i != 192 && i != 10) builder.addRoute(i + ".0.0.0", 8)
}
ShadowVpnService.sConn = builder.establish()
if (ShadowVpnService.sConn == null) {
conn = builder.establish()
if (conn == null) {
stopSelf()
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 " +
"--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 {
ed.putBoolean("isRunning", false)
ed.putBoolean("isConnecting", false)
ed.commit
if (conn != null) {
conn.close()
conn = null
}
super.onDestroy()
markServiceStopped()
}
......
......@@ -362,6 +362,7 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton.
protected override def onResume() {
super.onResume()
val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
if (getIntent.getAction != Shadowsocks.REQUEST_CONNECT) {
if (isServiceStarted) {
switchButton.setChecked(true)
if (ShadowVpnService.isServiceStarted) {
......@@ -372,8 +373,8 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton.
switchButton.setEnabled(false)
Crouton.makeText(Shadowsocks.this, R.string.vpn_status, style).show()
}
}
else {
} else {
switchButton.setChecked(false)
if (settings.getBoolean("isRunning", false)) {
new Thread {
override def run() {
......@@ -382,7 +383,7 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton.
}
}.start()
}
switchButton.setChecked(false)
}
}
setPreferenceEnabled()
switchButton.setOnCheckedChangeListener(this)
......@@ -517,10 +518,6 @@ class Shadowsocks extends UnifiedSherlockPreferenceActivity with CompoundButton.
def serviceStop() {
if (ShadowVpnService.isServiceStarted) {
if (ShadowVpnService.sConn != null) {
ShadowVpnService.sConn.close()
ShadowVpnService.sConn = null
}
stopService(new Intent(this, classOf[ShadowVpnService]))
}
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