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

refine crash recover

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