diff --git a/src/main/scala/com/github/shadowsocks/BaseService.scala b/src/main/scala/com/github/shadowsocks/BaseService.scala index 1bc5a11e..f02ba7df 100644 --- a/src/main/scala/com/github/shadowsocks/BaseService.scala +++ b/src/main/scala/com/github/shadowsocks/BaseService.scala @@ -62,6 +62,7 @@ trait BaseService extends Service { case class NameNotResolvedException() extends IOException case class KcpcliParseException(cause: Throwable) extends Exception(cause) + case class NullConnectionException() extends NullPointerException var timer: Timer = _ var trafficMonitorThread: TrafficMonitorThread = _ @@ -141,8 +142,7 @@ trait BaseService extends Service { } def checkProfile(profile: Profile) = if (TextUtils.isEmpty(profile.host) || TextUtils.isEmpty(profile.password)) { - changeState(State.STOPPED, getString(R.string.proxy_empty)) - stopRunner(true) + stopRunner(true, getString(R.string.proxy_empty)) false } else true @@ -200,6 +200,7 @@ trait BaseService extends Service { case _: NameNotResolvedException => stopRunner(true, getString(R.string.invalid_server)) case exc: KcpcliParseException => stopRunner(true, getString(R.string.service_failed) + ": " + exc.cause.getMessage) + case _: NullConnectionException => stopRunner(true, getString(R.string.reboot_required)) case exc: Throwable => stopRunner(true, getString(R.string.service_failed) + ": " + exc.getMessage) exc.printStackTrace() diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index 9629611d..8cc447ae 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -379,16 +379,8 @@ class ShadowsocksVpnService extends VpnService with BaseService { builder.addRoute("8.8.0.0", 16) - try { - conn = builder.establish() - 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 - } + conn = builder.establish() + if (conn == null) throw new NullConnectionException val fd = conn.getFd