diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index edda018b..df93594b 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -118,7 +118,6 @@ diff --git a/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl b/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl index 7245721e..d8999810 100644 --- a/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl +++ b/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl @@ -9,4 +9,5 @@ interface IShadowsocksService { oneway void unregisterCallback(IShadowsocksServiceCallback cb); oneway void use(in int profileId); + void useSync(in int profileId); } diff --git a/src/main/scala/com/github/shadowsocks/BaseService.scala b/src/main/scala/com/github/shadowsocks/BaseService.scala index e8db2fdf..eccec110 100644 --- a/src/main/scala/com/github/shadowsocks/BaseService.scala +++ b/src/main/scala/com/github/shadowsocks/BaseService.scala @@ -114,6 +114,8 @@ trait BaseService extends Service { case _ => Log.w(BaseService.this.getClass.getSimpleName, "Illegal state when invoking use: " + state) } }) + + override def useSync(profileId: Int) = use(profileId) } def checkProfile(profile: Profile) = if (TextUtils.isEmpty(profile.host) || TextUtils.isEmpty(profile.password)) { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala index 590ab4f2..d4ea05e7 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala @@ -54,17 +54,14 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext { } override def onServiceConnected() { - if (bgService != null) { + handler.postDelayed(() => if (bgService != null) { if (app.isNatEnabled) startBackgroundService() else if (VpnService.prepare(ShadowsocksRunnerService.this) == null) startBackgroundService() - } - handler.postDelayed(() => stopSelf() , 1000) + stopSelf() + }, 1000) } - def startBackgroundService() = { - bgService.use(app.profileId) - bgService.getState // ensure the oneway call to use is finished - } + def startBackgroundService() = bgService.useSync(app.profileId) override def onCreate() { super.onCreate()