From 028c5a64634abad0e17b38bf7a3eabceefca6a21 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 25 Jul 2014 16:25:17 +0800 Subject: [PATCH] fix #100 --- .../scala/com/github/shadowsocks/Shadowsocks.scala | 4 ++-- .../github/shadowsocks/ShadowsocksVpnService.scala | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index fb51012a..cbaa4686 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -507,7 +507,7 @@ class Shadowsocks val intent = new Intent(this, s) intent.setAction(Action.SERVICE) bindService(intent, connection, Context.BIND_AUTO_CREATE) - startService(new Intent(this, s)) + if (!isVpnEnabled) startService(new Intent(this, s)) } } @@ -518,9 +518,9 @@ class Shadowsocks } catch { case ignored: RemoteException => // Nothing } - unbindService(connection) bgService = null } + unbindService(connection) } override def onRestoreInstanceState(inState: Bundle) { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index 32b0fc3e..464f771a 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -52,12 +52,12 @@ import org.apache.http.conn.util.InetAddressUtils import android.os.Message import scala.concurrent.ops._ import org.apache.commons.net.util.SubnetUtils -import java.net.InetAddress import com.github.shadowsocks.utils._ import scala.Some import com.github.shadowsocks.aidl.{IShadowsocksService, Config} import scala.collection.mutable.ArrayBuffer import java.io.File +import java.net.InetAddress class ShadowsocksVpnService extends VpnService with BaseService { @@ -118,8 +118,13 @@ class ShadowsocksVpnService extends VpnService with BaseService { def startVpn() { + val openIntent: Intent = new Intent(this, classOf[Shadowsocks]) + openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + val configIntent = PendingIntent.getActivity(this, 0, openIntent, 0) + val builder = new Builder() builder + .setConfigureIntent(configIntent) .setSession(config.profileName) .setMtu(VPN_MTU) .addAddress(PRIVATE_VLAN.format("1"), 24) @@ -265,10 +270,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { Console.runCommand(ab.toArray) } - override def onStartCommand(intent: Intent, flags: Int, startId: Int): Int = { - Service.START_STICKY - } - override def startRunner(c: Config) { config = c @@ -383,7 +384,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { override def stopBackgroundService() { stopRunner() - stopSelf() } override def getTag = TAG