fix a crash
This commit is contained in:
@@ -106,8 +106,9 @@ trait BaseService {
|
||||
override def run() {
|
||||
if (state != s) {
|
||||
val n = callbacks.beginBroadcast()
|
||||
val m = if (msg != null) msg.substring(0, 64) else null
|
||||
for (i <- 0 to n - 1) {
|
||||
callbacks.getBroadcastItem(i).stateChanged(s, msg.substring(0, 64))
|
||||
callbacks.getBroadcastItem(i).stateChanged(s, m)
|
||||
}
|
||||
callbacks.finishBroadcast()
|
||||
state = s
|
||||
|
||||
@@ -99,18 +99,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
private var timer: Timer = null
|
||||
private val TIMER_INTERVAL = 2
|
||||
|
||||
val handler: Handler = new Handler {
|
||||
override def handleMessage(msg: Message) {
|
||||
msg.what match {
|
||||
case Msg.CONNECT_SUCCESS =>
|
||||
changeState(State.CONNECTED)
|
||||
case Msg.CONNECT_FAIL =>
|
||||
changeState(State.STOPPED)
|
||||
case _ =>
|
||||
}
|
||||
super.handleMessage(msg)
|
||||
}
|
||||
}
|
||||
val handler: Handler = new Handler()
|
||||
|
||||
def startShadowsocksDaemon() {
|
||||
val cmd: String = (Path.BASE +
|
||||
@@ -463,7 +452,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
case ex: Exception =>
|
||||
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
|
||||
stopRunner()
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_FAIL, 500)
|
||||
changeState(State.STOPPED)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -488,13 +477,12 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
if (resolved && handleConnection) {
|
||||
notifyForegroundAlert(getString(R.string.forward_success),
|
||||
getString(R.string.service_running).format(config.profileName))
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_SUCCESS, 500)
|
||||
changeState(State.CONNECTED)
|
||||
} else {
|
||||
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
|
||||
stopRunner()
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_FAIL, 500)
|
||||
changeState(State.STOPPED)
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_FINISH, 500)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,20 +72,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
var apps: Array[ProxiedApp] = null
|
||||
var config: Config = null
|
||||
|
||||
val handler: Handler = new Handler {
|
||||
override def handleMessage(msg: Message) {
|
||||
msg.what match {
|
||||
case Msg.CONNECT_SUCCESS =>
|
||||
changeState(State.CONNECTED)
|
||||
case Msg.CONNECT_FAIL =>
|
||||
changeState(State.STOPPED)
|
||||
case Msg.VPN_ERROR =>
|
||||
if (msg.obj != null) changeState(State.STOPPED, msg.obj.asInstanceOf[String])
|
||||
case _ =>
|
||||
}
|
||||
super.handleMessage(msg)
|
||||
}
|
||||
}
|
||||
val handler: Handler = new Handler()
|
||||
|
||||
def startShadowsocksDaemon() {
|
||||
val cmd: String = (Path.BASE +
|
||||
@@ -178,10 +165,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
conn = builder.establish()
|
||||
} catch {
|
||||
case ex: IllegalStateException =>
|
||||
val msg = new Message()
|
||||
msg.what = Msg.VPN_ERROR
|
||||
msg.obj = ex.getMessage
|
||||
handler.sendMessage(msg)
|
||||
changeState(State.STOPPED, ex.getMessage)
|
||||
conn = null
|
||||
case ex: Exception => conn = null
|
||||
}
|
||||
@@ -314,7 +298,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
case ex: Exception =>
|
||||
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
|
||||
stopRunner()
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_FAIL, 500)
|
||||
changeState(State.STOPPED)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -337,13 +321,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
}
|
||||
|
||||
if (resolved && handleConnection) {
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_SUCCESS, 300)
|
||||
changeState(State.CONNECTED)
|
||||
} else {
|
||||
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_FAIL, 300)
|
||||
changeState(State.STOPPED)
|
||||
stopRunner()
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(Msg.CONNECT_FINISH, 300)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user