Remove ProcessUtils
It's safe to say that Shadowsocks is only instantialized in the main process, so boom, problem solved.
This commit is contained in:
@@ -2,7 +2,6 @@ package com.github.shadowsocks
|
||||
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import com.github.shadowsocks.utils.ProcessUtils._
|
||||
|
||||
/**
|
||||
* @author chentaov5@gmail.com
|
||||
@@ -14,15 +13,11 @@ class ShadowsocksDeathRecipient(val mContext: ServiceBoundContext)
|
||||
|
||||
override def binderDied(): Unit = {
|
||||
Log.d(TAG, "[ShadowsocksDeathRecipient] binder died.")
|
||||
|
||||
mContext match {
|
||||
case ss: Shadowsocks =>
|
||||
inShadowsocks(mContext) {
|
||||
ss.deattachService
|
||||
ss.attachService
|
||||
}
|
||||
ss.deattachService
|
||||
ss.attachService
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import java.io.{BufferedReader, FileInputStream, InputStreamReader}
|
||||
|
||||
import android.content.Context
|
||||
import com.github.shadowsocks.utils.CloseUtils._
|
||||
|
||||
/**
|
||||
* @author chentaov5@gmail.com
|
||||
*/
|
||||
object ProcessUtils {
|
||||
def getCurrentProcessName = autoClose(new FileInputStream("/proc/self/cmdline")) { inputStream =>
|
||||
autoClose(new BufferedReader(new InputStreamReader(inputStream))) { reader =>
|
||||
val sb = new StringBuilder
|
||||
var c = 0
|
||||
while ({c = reader.read(); c > 0}) sb.append(c.asInstanceOf[Char])
|
||||
sb.toString()
|
||||
}
|
||||
}
|
||||
|
||||
def inShadowsocks(context: Context)(fun: => Unit) {
|
||||
if (context != null && getCurrentProcessName.equals(context.getPackageName)) fun
|
||||
}
|
||||
|
||||
|
||||
def inVpn(context: Context)(fun: => Unit) {
|
||||
if (context != null && getCurrentProcessName.equals(context.getPackageName + ":vpn")) fun
|
||||
}
|
||||
|
||||
|
||||
def inNat(context: Context)(fun: => Unit) {
|
||||
if (context != null && getCurrentProcessName.equals(context.getPackageName + ":nat")) fun
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user