forked from MatsuriDayo/Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.nekohasekai.sagernet | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import io.nekohasekai.sagernet.bg.SubscriptionUpdater | ||
import io.nekohasekai.sagernet.database.DataStore | ||
import io.nekohasekai.sagernet.ktx.app | ||
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher | ||
|
||
class BootReceiver : BroadcastReceiver() { | ||
companion object { | ||
private val componentName by lazy { ComponentName(app, BootReceiver::class.java) } | ||
var enabled: Boolean | ||
get() = app.packageManager.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED | ||
set(value) = app.packageManager.setComponentEnabledSetting( | ||
componentName, if (value) PackageManager.COMPONENT_ENABLED_STATE_ENABLED | ||
else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP | ||
) | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
runOnDefaultDispatcher { | ||
SubscriptionUpdater.reconfigureUpdater() | ||
} | ||
|
||
if (!DataStore.persistAcrossReboot) { // sanity check | ||
enabled = false | ||
return | ||
} | ||
|
||
val doStart = when (intent.action) { | ||
Intent.ACTION_LOCKED_BOOT_COMPLETED -> false // DataStore.directBootAware | ||
else -> Build.VERSION.SDK_INT < 24 || SagerNet.user.isUserUnlocked | ||
} && DataStore.selectedProxy > 0 | ||
|
||
if (doStart) SagerNet.startService() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters