refine #100
This commit is contained in:
@@ -49,8 +49,8 @@ import android.content.Context
|
||||
|
||||
trait BaseService {
|
||||
|
||||
var state = State.INIT
|
||||
var callbackCount = 0
|
||||
@volatile var state = State.INIT
|
||||
@volatile var callbackCount = 0
|
||||
|
||||
final val callbacks = new RemoteCallbackList[IShadowsocksServiceCallback]
|
||||
|
||||
@@ -105,15 +105,17 @@ trait BaseService {
|
||||
handler.post(new Runnable {
|
||||
override def run() {
|
||||
if (state != s) {
|
||||
val n = callbacks.beginBroadcast()
|
||||
for (i <- 0 to n - 1) {
|
||||
try {
|
||||
callbacks.getBroadcastItem(i).stateChanged(s, msg)
|
||||
} catch {
|
||||
case _: Exception => // Ignore
|
||||
if (callbackCount > 0) {
|
||||
val n = callbacks.beginBroadcast()
|
||||
for (i <- 0 to n - 1) {
|
||||
try {
|
||||
callbacks.getBroadcastItem(i).stateChanged(s, msg)
|
||||
} catch {
|
||||
case _: Exception => // Ignore
|
||||
}
|
||||
}
|
||||
callbacks.finishBroadcast()
|
||||
}
|
||||
callbacks.finishBroadcast()
|
||||
state = s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ class Shadowsocks
|
||||
val intent = new Intent(this, s)
|
||||
intent.setAction(Action.SERVICE)
|
||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
if (!isVpnEnabled) startService(new Intent(this, s))
|
||||
startService(new Intent(this, s))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -309,6 +309,11 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
override def onStartCommand(intent: Intent, flags: Int, startId: Int): Int = {
|
||||
Service.START_NOT_STICKY
|
||||
}
|
||||
|
||||
|
||||
def killProcesses() {
|
||||
Console.runRootCommand(Utils.getIptables + " -t nat -F OUTPUT")
|
||||
|
||||
@@ -328,10 +333,6 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
Console.runCommand(ab.toArray)
|
||||
}
|
||||
|
||||
override def onStartCommand(intent: Intent, flags: Int, startId: Int): Int = {
|
||||
Service.START_STICKY
|
||||
}
|
||||
|
||||
def flushDNS() {
|
||||
Console.runRootCommand(Array("ndc resolver flushdefaultif", "ndc resolver flushif wlan0"))
|
||||
}
|
||||
@@ -453,9 +454,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
filter.addAction(Action.CLOSE)
|
||||
receiver = new BroadcastReceiver() {
|
||||
def onReceive(p1: Context, p2: Intent) {
|
||||
spawn {
|
||||
stopRunner()
|
||||
}
|
||||
stopRunner()
|
||||
}
|
||||
}
|
||||
registerReceiver(receiver, filter)
|
||||
@@ -580,7 +579,6 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
|
||||
override def stopBackgroundService() {
|
||||
stopRunner()
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
override def getTag = TAG
|
||||
|
||||
@@ -253,7 +253,10 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
|
||||
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE)
|
||||
.asInstanceOf[NotificationManager]
|
||||
}
|
||||
|
||||
override def onStartCommand(intent: Intent, flags: Int, startId: Int): Int = {
|
||||
Service.START_NOT_STICKY
|
||||
}
|
||||
|
||||
override def onRevoke() {
|
||||
@@ -295,9 +298,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
filter.addAction(Intent.ACTION_SHUTDOWN)
|
||||
receiver = new BroadcastReceiver {
|
||||
def onReceive(p1: Context, p2: Intent) {
|
||||
spawn {
|
||||
stopRunner()
|
||||
}
|
||||
stopRunner()
|
||||
}
|
||||
}
|
||||
registerReceiver(receiver, filter)
|
||||
|
||||
Reference in New Issue
Block a user