Commit b18072e1 authored by Mygod's avatar Mygod

Auto start service on package upgrade

parent 0eef4711
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" /> <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
......
...@@ -25,6 +25,9 @@ import android.content.ComponentName ...@@ -25,6 +25,9 @@ import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build
import android.os.UserManager
import androidx.core.content.getSystemService
import com.github.shadowsocks.Core.app import com.github.shadowsocks.Core.app
import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.preference.DataStore
...@@ -40,11 +43,12 @@ class BootReceiver : BroadcastReceiver() { ...@@ -40,11 +43,12 @@ class BootReceiver : BroadcastReceiver() {
} }
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
val locked = when (intent.action) { val doStart = when (intent.action) {
Intent.ACTION_BOOT_COMPLETED -> false Intent.ACTION_BOOT_COMPLETED -> !DataStore.directBootAware
Intent.ACTION_LOCKED_BOOT_COMPLETED -> true // constant will be folded so no need to do version checks Intent.ACTION_LOCKED_BOOT_COMPLETED -> DataStore.directBootAware
else -> return else -> DataStore.directBootAware ||
Build.VERSION.SDK_INT >= 24 && app.getSystemService<UserManager>()?.isUserUnlocked != false
} }
if (DataStore.directBootAware == locked) Core.startService() if (doStart) Core.startService()
} }
} }
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