mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-29 06:35:08 +03:00
Implemented Yggdrasil start after device boot (#39)
Implemented Yggdrasil start after device boot (even if Always-On VPN disabled).
This commit is contained in:
parent
055aab328d
commit
a07412d02d
7 changed files with 93 additions and 21 deletions
|
@ -0,0 +1,40 @@
|
|||
package eu.neilalexander.yggdrasil
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.VpnService
|
||||
import android.util.Log
|
||||
import androidx.preference.PreferenceManager
|
||||
|
||||
class BootUpReceiver : BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "BootUpReceiver"
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action != Intent.ACTION_BOOT_COMPLETED) {
|
||||
Log.w(TAG, "Wrong action: ${intent.action}")
|
||||
}
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (!preferences.getBoolean(PREF_KEY_ENABLED, false)) {
|
||||
Log.i(TAG, "Yggdrasil disabled, not starting service")
|
||||
return
|
||||
}
|
||||
Log.i(TAG, "Yggdrasil enabled, starting service")
|
||||
val serviceIntent = Intent(context, PacketTunnelProvider::class.java)
|
||||
serviceIntent.action = PacketTunnelProvider.ACTION_START
|
||||
|
||||
val vpnIntent = VpnService.prepare(context)
|
||||
if (vpnIntent != null) {
|
||||
Log.i(TAG, "Need to ask for VPN permission")
|
||||
val notification = createPermissionMissingNotification(context)
|
||||
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.notify(444, notification)
|
||||
} else {
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue