Commit fcdeb514 authored by Mygod's avatar Mygod

Remove ProcessUtils

It's safe to say that Shadowsocks is only instantialized in the main process, so boom, problem solved.
parent 270d4360
......@@ -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
}
case _ =>
}
}
}
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
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment