Commit 0018a7ca authored by Mygod's avatar Mygod

Fix NAT mode not working after task removed from recent

parent 51ceb3da
...@@ -42,7 +42,7 @@ package com.github.shadowsocks ...@@ -42,7 +42,7 @@ package com.github.shadowsocks
import java.util.{Timer, TimerTask} import java.util.{Timer, TimerTask}
import android.app.Service import android.app.Service
import android.content.Context import android.content.{Intent, Context}
import android.os.{Handler, RemoteCallbackList} import android.os.{Handler, RemoteCallbackList}
import com.github.shadowsocks.aidl.{Config, IShadowsocksService, IShadowsocksServiceCallback} import com.github.shadowsocks.aidl.{Config, IShadowsocksService, IShadowsocksServiceCallback}
import com.github.shadowsocks.utils.{State, TrafficMonitor, TrafficMonitorThread} import com.github.shadowsocks.utils.{State, TrafficMonitor, TrafficMonitorThread}
...@@ -110,6 +110,7 @@ trait BaseService extends Service { ...@@ -110,6 +110,7 @@ trait BaseService extends Service {
def startRunner(config: Config) { def startRunner(config: Config) {
this.config = config this.config = config
startService(new Intent(getContext, getClass))
TrafficMonitor.reset() TrafficMonitor.reset()
trafficMonitorThread = new TrafficMonitorThread() trafficMonitorThread = new TrafficMonitorThread()
trafficMonitorThread.start() trafficMonitorThread.start()
...@@ -124,6 +125,12 @@ trait BaseService extends Service { ...@@ -124,6 +125,12 @@ trait BaseService extends Service {
trafficMonitorThread.stopThread() trafficMonitorThread.stopThread()
trafficMonitorThread = null trafficMonitorThread = null
} }
// change the state
changeState(State.STOPPED)
// stop the service if nothing has bound to it
stopSelf()
} }
def updateTrafficTotal(tx: Long, rx: Long) { def updateTrafficTotal(tx: Long, rx: Long) {
......
...@@ -54,8 +54,6 @@ trait ServiceBoundContext extends Context { ...@@ -54,8 +54,6 @@ trait ServiceBoundContext extends Context {
connection = new ShadowsocksServiceConnection() connection = new ShadowsocksServiceConnection()
bindService(intent, connection, Context.BIND_AUTO_CREATE) bindService(intent, connection, Context.BIND_AUTO_CREATE)
startService(new Intent(this, s))
} }
} }
......
...@@ -458,8 +458,6 @@ class ShadowsocksNatService extends BaseService { ...@@ -458,8 +458,6 @@ class ShadowsocksNatService extends BaseService {
override def stopRunner() { override def stopRunner() {
super.stopRunner()
// channge the state // channge the state
changeState(State.STOPPING) changeState(State.STOPPING)
...@@ -476,11 +474,7 @@ class ShadowsocksNatService extends BaseService { ...@@ -476,11 +474,7 @@ class ShadowsocksNatService extends BaseService {
// reset NAT // reset NAT
killProcesses() killProcesses()
// stop the service if nothing has bound to it super.stopRunner()
stopSelf()
// change the state
changeState(State.STOPPED)
} }
override def getTag = TAG override def getTag = TAG
......
...@@ -113,8 +113,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -113,8 +113,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
override def stopRunner() { override def stopRunner() {
super.stopRunner()
if (vpnThread != null) { if (vpnThread != null) {
vpnThread.stopThread() vpnThread.stopThread()
vpnThread = null vpnThread = null
...@@ -136,17 +134,13 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -136,17 +134,13 @@ class ShadowsocksVpnService extends VpnService with BaseService {
conn = null conn = null
} }
// stop the service if nothing has bound to it
stopSelf()
// clean up recevier // clean up recevier
if (closeReceiver != null) { if (closeReceiver != null) {
unregisterReceiver(closeReceiver) unregisterReceiver(closeReceiver)
closeReceiver = null closeReceiver = null
} }
// channge the state super.stopRunner()
changeState(State.STOPPED)
} }
def getVersionName: String = { def getVersionName: String = {
......
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