Commit 7fdf437e authored by Max Lv's avatar Max Lv

fix a crash of auto startup

parent 9de6c744
......@@ -5,8 +5,8 @@ import sbtandroid._
import sbtandroid.AndroidPlugin._
object App {
val version = "2.0.8"
val versionCode = 59
val version = "2.0.9"
val versionCode = 60
}
object General {
......
......@@ -53,14 +53,6 @@ class ShadowsocksRunnerActivity extends Activity {
lazy val settings = PreferenceManager.getDefaultSharedPreferences(this)
val handler = new Handler()
val receiver = new BroadcastReceiver() {
override def onReceive(context: Context, intent: Intent) {
if (intent.getAction == Intent.ACTION_USER_PRESENT) {
attachService()
}
}
}
val connection = new ServiceConnection {
override def onServiceConnected(name: ComponentName, service: IBinder) {
bgService = IShadowsocksService.Stub.asInterface(service)
......@@ -76,6 +68,7 @@ class ShadowsocksRunnerActivity extends Activity {
// Variables
var vpnEnabled = -1
var bgService: IShadowsocksService = null
var receiver:BroadcastReceiver = null
def isVpnEnabled: Boolean = {
if (vpnEnabled < 0) {
......@@ -127,6 +120,13 @@ class ShadowsocksRunnerActivity extends Activity {
val locked = km.inKeyguardRestrictedInputMode
if (locked) {
val filter = new IntentFilter(Intent.ACTION_USER_PRESENT)
receiver = new BroadcastReceiver() {
override def onReceive(context: Context, intent: Intent) {
if (intent.getAction == Intent.ACTION_USER_PRESENT) {
attachService()
}
}
}
registerReceiver(receiver, filter)
} else {
attachService()
......@@ -136,7 +136,10 @@ class ShadowsocksRunnerActivity extends Activity {
override def onDestroy() {
super.onDestroy()
deattachService()
if (receiver != null) {
unregisterReceiver(receiver)
receiver = null;
}
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
......
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