Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +29,7 @@ object ServiceManager {
ContextCompat.startForegroundService(context, intent)
}
}
context.getPreferences().edit { putBoolean("was_running", true) }
}

fun stop(context: Context) {
Expand All @@ -46,5 +49,6 @@ object ServiceManager {
ContextCompat.startForegroundService(context, intent)
}
}
context.getPreferences().edit { putBoolean("was_running", false) }
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/main_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down