diff --git a/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala b/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala index 703cbcc8..debd6cef 100644 --- a/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala +++ b/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala @@ -62,7 +62,6 @@ trait ServiceBoundContext extends Context with IBinder.DeathRecipient { connection = new ShadowsocksServiceConnection() bindService(intent, connection, Context.BIND_AUTO_CREATE) - startService(intent) } } diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala index 7613556e..0bb2baab 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala @@ -43,6 +43,7 @@ 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 @@ -72,6 +73,11 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext { 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() {