-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Yggdrasil start after device boot (#39)
Implemented Yggdrasil start after device boot (even if Always-On VPN disabled).
- Loading branch information
Showing
7 changed files
with
93 additions
and
21 deletions.
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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/eu/neilalexander/yggdrasil/BootUpReceiver.kt
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,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) | ||
} | ||
} | ||
} |
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