mirror of
https://github.com/dovecoteescapee/ByeDPIAndroid.git
synced 2024-12-22 06:15:44 +00:00
Support for autorun on system boot
This commit is contained in:
parent
9d289f096e
commit
68daa4d2d6
@ -74,6 +74,18 @@
|
||||
android:name="android.service.quicksettings.action.QS_TILE"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.BootReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter android:priority="999">
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
<action android:name="android.intent.action.REBOOT" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,35 @@
|
||||
package io.github.dovecoteescapee.byedpi.receivers
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.VpnService
|
||||
import io.github.dovecoteescapee.byedpi.data.Mode
|
||||
import io.github.dovecoteescapee.byedpi.services.ServiceManager
|
||||
import io.github.dovecoteescapee.byedpi.utility.getPreferences
|
||||
import io.github.dovecoteescapee.byedpi.utility.mode
|
||||
|
||||
class BootReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val action = intent.action
|
||||
if (Intent.ACTION_BOOT_COMPLETED != action
|
||||
&& Intent.ACTION_REBOOT != action
|
||||
&& "android.intent.action.QUICKBOOT_POWERON" != action
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
val prefs = context.getPreferences()
|
||||
|
||||
if (!prefs.getBoolean("autostart", false) || !prefs.getBoolean("was_running", false)) {
|
||||
return
|
||||
}
|
||||
|
||||
val mode = prefs.mode()
|
||||
if (prefs.mode() == Mode.VPN && VpnService.prepare(context) != null) {
|
||||
return
|
||||
}
|
||||
|
||||
ServiceManager.start(context, mode)
|
||||
}
|
||||
}
|
@ -4,9 +4,11 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import io.github.dovecoteescapee.byedpi.data.Mode
|
||||
import io.github.dovecoteescapee.byedpi.data.START_ACTION
|
||||
import io.github.dovecoteescapee.byedpi.data.STOP_ACTION
|
||||
import io.github.dovecoteescapee.byedpi.utility.getPreferences
|
||||
|
||||
object ServiceManager {
|
||||
private val TAG: String = ServiceManager::class.java.simpleName
|
||||
@ -27,6 +29,7 @@ object ServiceManager {
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
context.getPreferences().edit { putBoolean("was_running", true) }
|
||||
}
|
||||
|
||||
fun stop(context: Context) {
|
||||
@ -46,5 +49,6 @@ object ServiceManager {
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
context.getPreferences().edit { putBoolean("was_running", false) }
|
||||
}
|
||||
}
|
||||
|
@ -72,4 +72,5 @@
|
||||
<string name="desync_https_category">HTTPS</string>
|
||||
<string name="byedpi_protocols_category">Protocols</string>
|
||||
<string name="byedpi_protocols_hint">Uncheck all to desync all traffic</string>
|
||||
<string name="autostart_setting">Autorun on system boot</string>
|
||||
</resources>
|
||||
|
@ -23,6 +23,11 @@
|
||||
android:defaultValue="vpn"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="autostart"
|
||||
android:title="@string/autostart_setting"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.takisoft.preferencex.EditTextPreference
|
||||
android:key="dns_ip"
|
||||
android:title="@string/dbs_ip_setting"
|
||||
|
Loading…
Reference in New Issue
Block a user