Commit 333ee156 authored by Max Lv's avatar Max Lv

fix the crash_recover

parent 1403ef8a
...@@ -209,6 +209,7 @@ class Shadowsocks ...@@ -209,6 +209,7 @@ class Shadowsocks
private var switchButton: Switch = null private var switchButton: Switch = null
private var progressDialog: ProgressDialog = null private var progressDialog: ProgressDialog = null
private var settings: SharedPreferences = null private var settings: SharedPreferences = null
private var status: SharedPreferences = null
private var prepared = false private var prepared = false
private var state = State.INIT private var state = State.INIT
private var receiver: StateBroadcastReceiver = null private var receiver: StateBroadcastReceiver = null
...@@ -218,7 +219,7 @@ class Shadowsocks ...@@ -218,7 +219,7 @@ class Shadowsocks
msg.what match { msg.what match {
case MSG_CRASH_RECOVER => case MSG_CRASH_RECOVER =>
Crouton.makeText(Shadowsocks.this, R.string.crash_alert, Style.ALERT).show() Crouton.makeText(Shadowsocks.this, R.string.crash_alert, Style.ALERT).show()
settings.edit().putBoolean(Key.isRunning, false).apply() status.edit().putBoolean(Key.isRunning, false).commit()
case MSG_INITIAL_FINISH => case MSG_INITIAL_FINISH =>
clearDialog() clearDialog()
} }
...@@ -367,6 +368,7 @@ class Shadowsocks ...@@ -367,6 +368,7 @@ class Shadowsocks
switchButton = switchLayout.findViewById(R.id.switchButton).asInstanceOf[Switch] switchButton = switchLayout.findViewById(R.id.switchButton).asInstanceOf[Switch]
settings = PreferenceManager.getDefaultSharedPreferences(this) settings = PreferenceManager.getDefaultSharedPreferences(this)
status = getSharedPreferences(Key.status, Context.MODE_PRIVATE)
receiver = new StateBroadcastReceiver() receiver = new StateBroadcastReceiver()
registerReceiver(receiver, new IntentFilter(Action.UPDATE_STATE)) registerReceiver(receiver, new IntentFilter(Action.UPDATE_STATE))
...@@ -377,9 +379,8 @@ class Shadowsocks ...@@ -377,9 +379,8 @@ class Shadowsocks
} }
spawn { spawn {
settings.edit().putBoolean(Key.isRoot, Utils.getRoot).commit() settings.edit().putBoolean(Key.isRoot, Utils.getRoot).commit()
val update = getSharedPreferences(Key.update, Context.MODE_WORLD_WRITEABLE) if (!status.getBoolean(getVersionName, false)) {
if (!update.getBoolean(getVersionName, false)) { status.edit.putBoolean(getVersionName, true).apply()
update.edit.putBoolean(getVersionName, true).apply()
reset() reset()
} }
handler.sendEmptyMessage(MSG_INITIAL_FINISH) handler.sendEmptyMessage(MSG_INITIAL_FINISH)
...@@ -459,7 +460,7 @@ class Shadowsocks ...@@ -459,7 +460,7 @@ class Shadowsocks
switchButton.setChecked(false) switchButton.setChecked(false)
Crouton.cancelAllCroutons() Crouton.cancelAllCroutons()
setPreferenceEnabled(true) setPreferenceEnabled(true)
if (settings.getBoolean(Key.isRunning, false)) { if (status.getBoolean(Key.isRunning, false)) {
spawn { spawn {
crash_recovery() crash_recovery()
handler.sendEmptyMessage(MSG_CRASH_RECOVER) handler.sendEmptyMessage(MSG_CRASH_RECOVER)
......
...@@ -50,7 +50,7 @@ class ShadowsocksReceiver extends BroadcastReceiver { ...@@ -50,7 +50,7 @@ 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)
val update = context.getSharedPreferences(Key.update, Context.MODE_WORLD_READABLE) val status = context.getSharedPreferences(Key.status, Context.MODE_PRIVATE)
if (intent.getAction == Action.UPDATE_STATE) { if (intent.getAction == Action.UPDATE_STATE) {
val state = intent.getIntExtra(Extra.STATE, State.INIT) val state = intent.getIntExtra(Extra.STATE, State.INIT)
...@@ -59,7 +59,7 @@ class ShadowsocksReceiver extends BroadcastReceiver { ...@@ -59,7 +59,7 @@ class ShadowsocksReceiver extends BroadcastReceiver {
case State.CONNECTED => true case State.CONNECTED => true
case _ => false case _ => false
} }
settings.edit.putBoolean(Key.isRunning, running).commit() status.edit.putBoolean(Key.isRunning, running).commit()
return return
} }
...@@ -72,7 +72,7 @@ class ShadowsocksReceiver extends BroadcastReceiver { ...@@ -72,7 +72,7 @@ class ShadowsocksReceiver extends BroadcastReceiver {
} }
} }
val isAutoConnect: Boolean = settings.getBoolean(Key.isAutoConnect, false) val isAutoConnect: Boolean = settings.getBoolean(Key.isAutoConnect, false)
val isInstalled: Boolean = update.getBoolean(versionName, false) val isInstalled: Boolean = status.getBoolean(versionName, false)
if (isAutoConnect && isInstalled) { if (isAutoConnect && isInstalled) {
if (Utils.getRoot) { if (Utils.getRoot) {
if (ShadowsocksService.isServiceStarted(context)) return if (ShadowsocksService.isServiceStarted(context)) return
......
...@@ -54,7 +54,7 @@ import android.app.ActivityManager ...@@ -54,7 +54,7 @@ import android.app.ActivityManager
object Key { object Key {
val isRoot = "isRoot" val isRoot = "isRoot"
val update = "update" val status = "status"
val proxyedApps = "proxyedApps" val proxyedApps = "proxyedApps"
val isRunning = "isRunning" val isRunning = "isRunning"
...@@ -325,30 +325,9 @@ object Utils { ...@@ -325,30 +325,9 @@ object Utils {
* @return The Property, or NULL if not found * @return The Property, or NULL if not found
*/ */
def getSystemProperty(propName: String): String = { def getSystemProperty(propName: String): String = {
var line: String = null val p: Process = Runtime.getRuntime.exec("getprop " + propName)
var input: BufferedReader = null val lines = scala.io.Source.fromInputStream(p.getInputStream).getLines()
try { if (lines.hasNext) lines.next() else null
val p: Process = Runtime.getRuntime.exec("getprop " + propName)
input = new BufferedReader(new InputStreamReader(p.getInputStream), 1024)
line = input.readLine
input.close()
} catch {
case ex: IOException => {
Log.e(TAG, "Unable to read sysprop " + propName, ex)
return null
}
} finally {
if (input != null) {
try {
input.close()
} catch {
case ex: IOException => {
Log.e(TAG, "Exception while closing InputStream", ex)
}
}
}
}
line
} }
/** /**
...@@ -404,13 +383,13 @@ object Utils { ...@@ -404,13 +383,13 @@ object Utils {
def getAppIcon(c: Context, uid: Int): Drawable = { def getAppIcon(c: Context, uid: Int): Drawable = {
val pm: PackageManager = c.getPackageManager val pm: PackageManager = c.getPackageManager
var appIcon: Drawable = c.getResources.getDrawable(android.R.drawable.sym_def_app_icon) val icon: Drawable = c.getResources.getDrawable(android.R.drawable.sym_def_app_icon)
val packages: Array[String] = pm.getPackagesForUid(uid) val packages: Array[String] = pm.getPackagesForUid(uid)
if (packages != null) { if (packages != null) {
if (packages.length >= 1) { if (packages.length >= 1) {
try { try {
val appInfo: ApplicationInfo = pm.getApplicationInfo(packages(0), 0) val appInfo: ApplicationInfo = pm.getApplicationInfo(packages(0), 0)
appIcon = pm.getApplicationIcon(appInfo) return pm.getApplicationIcon(appInfo)
} catch { } catch {
case e: PackageManager.NameNotFoundException => { case e: PackageManager.NameNotFoundException => {
Log.e(c.getPackageName, "No package found matching with the uid " + uid) Log.e(c.getPackageName, "No package found matching with the uid " + uid)
...@@ -420,7 +399,7 @@ object Utils { ...@@ -420,7 +399,7 @@ object Utils {
} else { } else {
Log.e(c.getPackageName, "Package not found for uid " + uid) Log.e(c.getPackageName, "Package not found for uid " + uid)
} }
appIcon icon
} }
def getDataPath(ctx: Context): String = { def getDataPath(ctx: Context): String = {
......
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