Commit 39c765c7 authored by Max Lv's avatar Max Lv

refine crash recover

parent bdac32bd
......@@ -5,8 +5,8 @@ import org.scalasbt.androidplugin._
import org.scalasbt.androidplugin.AndroidKeys._
object App {
val version = "1.5.1"
val versionCode = 29
val version = "1.5.2"
val versionCode = 30
}
object General {
......
......@@ -67,6 +67,7 @@
<receiver android:name=".ShadowsocksReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="com.github.shadowsocks.ACTION_UPDATE_STATE"/>
</intent-filter>
</receiver>
......
......@@ -42,7 +42,6 @@ import android.content._
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os._
import android.preference.PreferenceManager
import android.support.v4.app.NotificationCompat
import android.util.Log
import com.google.analytics.tracking.android.EasyTracker
......@@ -78,7 +77,6 @@ class ShadowVpnService extends VpnService {
var udpgw: String = null
var notificationManager: NotificationManager = null
var receiver: BroadcastReceiver = null
var settings: SharedPreferences = null
var apps: Array[ProxiedApp] = null
var config: Config = null
......@@ -174,12 +172,9 @@ class ShadowVpnService extends VpnService {
return
}
settings.edit().putBoolean(Key.isRunning, true).commit()
changeState(State.CONNECTING)
config = Extra.get(intent)
Extra.save(settings, config)
new Thread(new Runnable {
def run() {
......@@ -358,7 +353,6 @@ class ShadowVpnService extends VpnService {
super.onCreate()
EasyTracker.getTracker.setStartSession(true)
EasyTracker.getTracker.sendEvent(TAG, "start", getVersionName, 0L)
settings = PreferenceManager.getDefaultSharedPreferences(this)
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE)
.asInstanceOf[NotificationManager]
......@@ -377,7 +371,6 @@ class ShadowVpnService extends VpnService {
def destroy() {
changeState(State.STOPPED)
settings.edit.putBoolean(Key.isRunning, false).commit
EasyTracker.getTracker.sendEvent(TAG, "stop", getVersionName, 0L)
if (receiver != null) {
unregisterReceiver(receiver)
......
......@@ -360,8 +360,7 @@ class Shadowsocks
receiver = new StateBroadcastReceiver()
registerReceiver(receiver, new IntentFilter(Action.UPDATE_STATE))
val init: Boolean = !settings.getBoolean("isRunning", false) &&
!settings.getBoolean("isConnecting", false)
val init: Boolean = !Shadowsocks.isServiceStarted(this)
if (init) {
if (progressDialog == null) {
progressDialog = ProgressDialog.show(this, "", getString(R.string.initializing), true, true)
......@@ -459,7 +458,7 @@ class Shadowsocks
switchButton.setChecked(false)
Crouton.cancelAllCroutons()
setPreferenceEnabled(true)
if (settings.getBoolean("isRunning", false)) {
if (settings.getBoolean(Key.isRunning, false)) {
new Thread {
override def run() {
crash_recovery()
......@@ -714,4 +713,5 @@ class Shadowsocks
onStateChanged(state, message)
}
}
}
......@@ -50,6 +50,18 @@ class ShadowsocksReceiver extends BroadcastReceiver {
def onReceive(context: Context, intent: Intent) {
val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
if (intent.getAction == Action.UPDATE_STATE) {
val state = intent.getIntExtra(Extra.STATE, State.INIT)
val running = state match {
case State.CONNECTING => true
case State.CONNECTED => true
case _ => false
}
settings.edit.putBoolean(Key.isRunning, running).apply()
return
}
var versionName: String = null
try {
versionName = context.getPackageManager.getPackageInfo(context.getPackageName, 0).versionName
......
......@@ -45,7 +45,6 @@ import android.content._
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os._
import android.preference.PreferenceManager
import android.support.v4.app.NotificationCompat
import android.util.Log
import com.google.analytics.tracking.android.EasyTracker
......@@ -105,7 +104,6 @@ class ShadowsocksService extends Service {
var config: Config = null
var hasRedirectSupport = false
var apps: Array[ProxiedApp] = null
var settings: SharedPreferences = null
var mSetForeground: Method = null
var mStartForeground: Method = null
......@@ -130,7 +128,6 @@ class ShadowsocksService extends Service {
msg.what match {
case MSG_CONNECT_SUCCESS =>
changeState(State.CONNECTED)
settings.edit().putBoolean(Key.isRunning, true).apply()
case MSG_CONNECT_FAIL =>
changeState(State.STOPPED)
case MSG_STOP_SELF =>
......@@ -213,7 +210,6 @@ class ShadowsocksService extends Service {
changeState(State.CONNECTING)
config = Extra.get(intent)
Extra.save(settings, config)
new Thread(new Runnable {
def run() {
......@@ -347,7 +343,6 @@ class ShadowsocksService extends Service {
super.onCreate()
EasyTracker.getTracker.setStartSession(true)
EasyTracker.getTracker.sendEvent(TAG, "start", getVersionName, 0L)
settings = PreferenceManager.getDefaultSharedPreferences(this)
notificationManager = this
.getSystemService(Context.NOTIFICATION_SERVICE)
.asInstanceOf[NotificationManager]
......@@ -394,7 +389,6 @@ class ShadowsocksService extends Service {
killProcesses()
}
}.start()
settings.edit.putBoolean(Key.isRunning, false).apply()
if (receiver != null) {
unregisterReceiver(receiver)
receiver = null
......
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