Commit bdac32bd authored by Max Lv's avatar Max Lv

inter-process persistent preferences

parent 8f9ebabd
......@@ -174,11 +174,12 @@ class ShadowVpnService extends VpnService {
return
}
settings.edit().putBoolean("isRunning", true).commit()
settings.edit().putBoolean(Key.isRunning, true).commit()
changeState(State.CONNECTING)
config = Extra.get(intent)
Extra.save(settings, config)
new Thread(new Runnable {
def run() {
......@@ -376,7 +377,7 @@ class ShadowVpnService extends VpnService {
def destroy() {
changeState(State.STOPPED)
settings.edit.putBoolean("isRunning", false).commit
settings.edit.putBoolean(Key.isRunning, false).commit
EasyTracker.getTracker.sendEvent(TAG, "stop", getVersionName, 0L)
if (receiver != null) {
unregisterReceiver(receiver)
......
......@@ -211,18 +211,16 @@ class Shadowsocks
private val handler: Handler = new Handler {
override def handleMessage(msg: Message) {
val ed: SharedPreferences.Editor = settings.edit
msg.what match {
case MSG_CRASH_RECOVER =>
Crouton.makeText(Shadowsocks.this, R.string.crash_alert, Style.ALERT).show()
ed.putBoolean("isRunning", false)
settings.edit().putBoolean(Key.isRunning, false).apply()
case MSG_INITIAL_FINISH =>
if (progressDialog != null) {
progressDialog.dismiss()
progressDialog = null
}
}
ed.commit
super.handleMessage(msg)
}
}
......@@ -380,9 +378,7 @@ class Shadowsocks
}
}
if (!settings.getBoolean(versionName, false)) {
val edit: SharedPreferences.Editor = settings.edit
edit.putBoolean(versionName, true)
edit.commit
settings.edit.putBoolean(versionName, true).apply()
reset()
}
handler.sendEmptyMessage(MSG_INITIAL_FINISH)
......
......@@ -127,18 +127,16 @@ class ShadowsocksService extends Service {
val handler: Handler = new Handler {
override def handleMessage(msg: Message) {
val ed: SharedPreferences.Editor = settings.edit
msg.what match {
case MSG_CONNECT_SUCCESS =>
changeState(State.CONNECTED)
ed.putBoolean("isRunning", true)
settings.edit().putBoolean(Key.isRunning, true).apply()
case MSG_CONNECT_FAIL =>
changeState(State.STOPPED)
case MSG_STOP_SELF =>
stopSelf()
case _ =>
}
ed.commit
super.handleMessage(msg)
}
}
......@@ -215,6 +213,7 @@ class ShadowsocksService extends Service {
changeState(State.CONNECTING)
config = Extra.get(intent)
Extra.save(settings, config)
new Thread(new Runnable {
def run() {
......@@ -395,9 +394,7 @@ class ShadowsocksService extends Service {
killProcesses()
}
}.start()
val ed: SharedPreferences.Editor = settings.edit
ed.putBoolean("isRunning", false)
ed.commit
settings.edit.putBoolean(Key.isRunning, false).apply()
if (receiver != null) {
unregisterReceiver(receiver)
receiver = null
......
......@@ -53,6 +53,8 @@ import android.graphics.{Canvas, Bitmap}
import android.app.ActivityManager
object Key {
val isRunning = "isRunning"
val isGlobalProxy = "isGlobalProxy"
val isGFWList = "isGFWList"
val isBypassApps = "isBypassApps"
......@@ -96,6 +98,24 @@ 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.isDNSProxy, config.isDNSProxy)
edit.putBoolean(Key.isHTTPProxy, config.isHTTPProxy)
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)
......
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