add aidl
This commit is contained in:
+33
-7
@@ -1,11 +1,12 @@
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.{Intent, SharedPreferences, Context}
|
||||
import com.github.shadowsocks.ShadowsocksApplication
|
||||
import com.google.tagmanager.Container
|
||||
import scalaj.http.{HttpOptions, Http}
|
||||
import com.github.shadowsocks.aidl.Config
|
||||
|
||||
object Config {
|
||||
object ConfigUtils {
|
||||
val SHADOWSOCKS = "{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}"
|
||||
val REDSOCKS = "base {" +
|
||||
" log_debug = off;" +
|
||||
@@ -83,10 +84,35 @@ object Config {
|
||||
val method = proxy(3).trim
|
||||
|
||||
new Config(config.isGlobalProxy, config.isGFWList, config.isBypassApps, config.isTrafficStat,
|
||||
config.profileName, host, password, method, port, config.localPort, config.proxiedAppString)
|
||||
config.profileName, host, password, method, config.proxiedAppString, port, config.localPort)
|
||||
}
|
||||
}
|
||||
|
||||
case class Config(isGlobalProxy: Boolean, isGFWList: Boolean, isBypassApps: Boolean,
|
||||
isTrafficStat: Boolean, profileName: String, var proxy: String, sitekey: String,
|
||||
encMethod: String, remotePort: Int, localPort: Int, proxiedAppString: String)
|
||||
def load(settings: SharedPreferences): Config = {
|
||||
val isGlobalProxy = settings.getBoolean(Key.isGlobalProxy, false)
|
||||
val isGFWList = settings.getBoolean(Key.isGFWList, false)
|
||||
val isBypassApps = settings.getBoolean(Key.isBypassApps, false)
|
||||
val isTrafficStat = settings.getBoolean(Key.isTrafficStat, false)
|
||||
|
||||
val profileName = settings.getString(Key.profileName, "default")
|
||||
val proxy = settings.getString(Key.proxy, "127.0.0.1")
|
||||
val sitekey = settings.getString(Key.sitekey, "default")
|
||||
val encMethod = settings.getString(Key.encMethod, "table")
|
||||
val remotePort: Int = try {
|
||||
settings.getString(Key.remotePort, "1984").toInt
|
||||
} catch {
|
||||
case ex: NumberFormatException =>
|
||||
1984
|
||||
}
|
||||
val localPort: Int = try {
|
||||
settings.getString(Key.localPort, "1984").toInt
|
||||
} catch {
|
||||
case ex: NumberFormatException =>
|
||||
1984
|
||||
}
|
||||
val proxiedAppString = settings.getString(Key.proxied, "")
|
||||
|
||||
new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, profileName, proxy, sitekey,
|
||||
encMethod, proxiedAppString, remotePort, localPort)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import android.content.{Intent, SharedPreferences}
|
||||
import com.github.shadowsocks.aidl.Config
|
||||
|
||||
object Msg {
|
||||
val CONNECT_FINISH = 1
|
||||
val CONNECT_SUCCESS = 2
|
||||
val CONNECT_FAIL = 3
|
||||
val VPN_ERROR = 6
|
||||
}
|
||||
|
||||
object Path {
|
||||
val BASE = "/data/data/com.github.shadowsocks/"
|
||||
@@ -37,100 +45,21 @@ object Scheme {
|
||||
val SS = "ss"
|
||||
}
|
||||
|
||||
object Mode {
|
||||
val NAT = 0
|
||||
val VPN = 1
|
||||
}
|
||||
|
||||
object State {
|
||||
val INIT = 0
|
||||
val CONNECTING = 1
|
||||
val CONNECTED = 2
|
||||
val STOPPED = 3
|
||||
def isAvailable(state: Int): Boolean = state != CONNECTED && state != CONNECTING
|
||||
}
|
||||
|
||||
object Action {
|
||||
val CLOSE = "com.github.shadowsocks.ACTION_SHUTDOWN"
|
||||
val UPDATE_STATE = "com.github.shadowsocks.ACTION_UPDATE_STATE"
|
||||
val CLOSE = "com.github.shadowsocks.CLOSE"
|
||||
val UPDATE_FRAGMENT = "com.github.shadowsocks.ACTION_UPDATE_FRAGMENT"
|
||||
val UPDATE_PREFS = "com.github.shadowsocks.ACTION_UPDATE_PREFS"
|
||||
}
|
||||
|
||||
object Extra {
|
||||
val STATE = "state"
|
||||
val MESSAGE = "message"
|
||||
|
||||
def save(settings: SharedPreferences, config: Config) {
|
||||
val edit = settings.edit()
|
||||
|
||||
edit.putBoolean(Key.isGlobalProxy, config.isGlobalProxy)
|
||||
edit.putBoolean(Key.isGFWList, config.isGFWList)
|
||||
edit.putBoolean(Key.isBypassApps, config.isBypassApps)
|
||||
edit.putBoolean(Key.isTrafficStat, config.isTrafficStat)
|
||||
|
||||
edit.putString(Key.profileName, config.profileName)
|
||||
edit.putString(Key.proxy, config.proxy)
|
||||
edit.putString(Key.sitekey, config.sitekey)
|
||||
edit.putString(Key.encMethod, config.encMethod)
|
||||
edit.putString(Key.remotePort, config.remotePort.toString)
|
||||
edit.putString(Key.localPort, config.localPort.toString)
|
||||
|
||||
edit.apply()
|
||||
}
|
||||
|
||||
def get(intent: Intent): Config = {
|
||||
val isGlobalProxy = intent.getBooleanExtra(Key.isGlobalProxy, false)
|
||||
val isGFWList = intent.getBooleanExtra(Key.isGFWList, false)
|
||||
val isBypassApps = intent.getBooleanExtra(Key.isBypassApps, false)
|
||||
val isTrafficStat = intent.getBooleanExtra(Key.isTrafficStat, false)
|
||||
|
||||
val profileName = intent.getStringExtra(Key.profileName)
|
||||
val proxy = intent.getStringExtra(Key.proxy)
|
||||
val sitekey = intent.getStringExtra(Key.sitekey)
|
||||
val encMethod = intent.getStringExtra(Key.encMethod)
|
||||
val remotePort = intent.getIntExtra(Key.remotePort, 1984)
|
||||
val localPort = intent.getIntExtra(Key.localPort, 1984)
|
||||
val proxiedString = intent.getStringExtra(Key.proxied)
|
||||
|
||||
new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, profileName, proxy, sitekey,
|
||||
encMethod, remotePort, localPort, proxiedString)
|
||||
}
|
||||
|
||||
def put(settings: SharedPreferences, intent: Intent) {
|
||||
val isGlobalProxy = settings.getBoolean(Key.isGlobalProxy, false)
|
||||
val isGFWList = settings.getBoolean(Key.isGFWList, false)
|
||||
val isBypassApps = settings.getBoolean(Key.isBypassApps, false)
|
||||
val isTrafficStat = settings.getBoolean(Key.isTrafficStat, false)
|
||||
|
||||
|
||||
val profileName = settings.getString(Key.profileName, "default")
|
||||
val proxy = settings.getString(Key.proxy, "127.0.0.1")
|
||||
val sitekey = settings.getString(Key.sitekey, "default")
|
||||
val encMethod = settings.getString(Key.encMethod, "table")
|
||||
val remotePort: Int = try {
|
||||
settings.getString(Key.remotePort, "1984").toInt
|
||||
} catch {
|
||||
case ex: NumberFormatException => {
|
||||
1984
|
||||
}
|
||||
}
|
||||
val localProt: Int = try {
|
||||
settings.getString(Key.localPort, "1984").toInt
|
||||
} catch {
|
||||
case ex: NumberFormatException => {
|
||||
1984
|
||||
}
|
||||
}
|
||||
val proxiedAppString = settings.getString(Key.proxied, "")
|
||||
|
||||
intent.putExtra(Key.isGlobalProxy, isGlobalProxy)
|
||||
intent.putExtra(Key.isGFWList, isGFWList)
|
||||
intent.putExtra(Key.isBypassApps, isBypassApps)
|
||||
intent.putExtra(Key.isTrafficStat, isTrafficStat)
|
||||
|
||||
intent.putExtra(Key.profileName, profileName)
|
||||
intent.putExtra(Key.proxy, proxy)
|
||||
intent.putExtra(Key.sitekey, sitekey)
|
||||
intent.putExtra(Key.encMethod, encMethod)
|
||||
intent.putExtra(Key.remotePort, remotePort)
|
||||
intent.putExtra(Key.localPort, localProt)
|
||||
|
||||
intent.putExtra(Key.proxied, proxiedAppString)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user