diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala index 73b61938..8df9e328 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala @@ -83,9 +83,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str show() } else if (forceShow) show() - def show() = { - service.startForeground(1, builder.build) - } + def show() = service.startForeground(1, builder.build) def destroy() { if (lockReceiver != null) { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala index 0bb2baab..9af9c182 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala @@ -43,7 +43,6 @@ import android.app.Service import android.content.Intent import android.net.VpnService import android.os.{IBinder, Handler} -import com.github.shadowsocks.utils.Action import com.github.shadowsocks.utils.ConfigUtils import com.github.shadowsocks.ShadowsocksApplication.app @@ -55,29 +54,18 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext { } override def onServiceConnected() { - handler.postDelayed(() => if (bgService != null) startBackgroundService(), 1000) - } - - def startBackgroundService() { - if (app.isNatEnabled) bgService.use(app.profileId) else { - val intent = VpnService.prepare(ShadowsocksRunnerService.this) - if (intent == null) { - if (bgService != null) { - bgService.use(app.profileId) - } + handler.postDelayed(() => if (bgService != null) { + if (app.isNatEnabled || VpnService.prepare(ShadowsocksRunnerService.this) == null) { + bgService.use(app.profileId) + bgService.getState // ensure the oneway call to use is finished } - } - stopSelf() + stopSelf() + }, 1000) } override def onCreate() { super.onCreate() attachService() - - val s = if (app.isNatEnabled) classOf[ShadowsocksNatService] else classOf[ShadowsocksVpnService] - val intent = new Intent(this, s) - intent.setAction(Action.SERVICE) - startService(intent) } override def onDestroy() {