Commit 9a3ed94f authored by Mygod's avatar Mygod

Refine error handling in services

parent 0191d1d0
...@@ -62,6 +62,7 @@ trait BaseService extends Service { ...@@ -62,6 +62,7 @@ trait BaseService extends Service {
case class NameNotResolvedException() extends IOException case class NameNotResolvedException() extends IOException
case class KcpcliParseException(cause: Throwable) extends Exception(cause) case class KcpcliParseException(cause: Throwable) extends Exception(cause)
case class NullConnectionException() extends NullPointerException
var timer: Timer = _ var timer: Timer = _
var trafficMonitorThread: TrafficMonitorThread = _ var trafficMonitorThread: TrafficMonitorThread = _
...@@ -141,8 +142,7 @@ trait BaseService extends Service { ...@@ -141,8 +142,7 @@ trait BaseService extends Service {
} }
def checkProfile(profile: Profile) = if (TextUtils.isEmpty(profile.host) || TextUtils.isEmpty(profile.password)) { def checkProfile(profile: Profile) = if (TextUtils.isEmpty(profile.host) || TextUtils.isEmpty(profile.password)) {
changeState(State.STOPPED, getString(R.string.proxy_empty)) stopRunner(true, getString(R.string.proxy_empty))
stopRunner(true)
false false
} else true } else true
...@@ -200,6 +200,7 @@ trait BaseService extends Service { ...@@ -200,6 +200,7 @@ trait BaseService extends Service {
case _: NameNotResolvedException => stopRunner(true, getString(R.string.invalid_server)) case _: NameNotResolvedException => stopRunner(true, getString(R.string.invalid_server))
case exc: KcpcliParseException => case exc: KcpcliParseException =>
stopRunner(true, getString(R.string.service_failed) + ": " + exc.cause.getMessage) stopRunner(true, getString(R.string.service_failed) + ": " + exc.cause.getMessage)
case _: NullConnectionException => stopRunner(true, getString(R.string.reboot_required))
case exc: Throwable => case exc: Throwable =>
stopRunner(true, getString(R.string.service_failed) + ": " + exc.getMessage) stopRunner(true, getString(R.string.service_failed) + ": " + exc.getMessage)
exc.printStackTrace() exc.printStackTrace()
......
...@@ -379,16 +379,8 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -379,16 +379,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
builder.addRoute("8.8.0.0", 16) builder.addRoute("8.8.0.0", 16)
try { conn = builder.establish()
conn = builder.establish() if (conn == null) throw new NullConnectionException
if (conn == null) changeState(State.STOPPED, getString(R.string.reboot_required))
} catch {
case ex: Exception =>
ex.printStackTrace()
app.track(ex)
stopRunner(true, ex.getMessage)
return -1
}
val fd = conn.getFd val fd = conn.getFd
......
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