-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add boot receiver to start daemon service
- Loading branch information
1 parent
2182825
commit 4ee4f5f
Showing
13 changed files
with
112 additions
and
5 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
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
39 changes: 39 additions & 0 deletions
39
android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/BootCompletedReceiver.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,39 @@ | ||
package net.mullvad.mullvadvpn.compose.util | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import net.mullvad.mullvadvpn.di.APP_PREFERENCES_NAME | ||
import net.mullvad.mullvadvpn.lib.common.constant.KEY_CONNECT_ACTION | ||
import net.mullvad.mullvadvpn.lib.common.constant.VPN_SERVICE_CLASS | ||
import net.mullvad.mullvadvpn.repository.IS_CONNECT_ON_BOOT_ENABLED_KEY | ||
|
||
private const val TAG = "AAAAAAAAAAAABootBroadCast" | ||
|
||
class BootCompletedReceiver : BroadcastReceiver() { | ||
|
||
override fun onReceive(context: Context?, mBootIntent: Intent?) { | ||
if (mBootIntent?.action == "android.intent.action.BOOT_COMPLETED") { | ||
context?.let { | ||
if (isConnectOnBootEnabled(it)) { | ||
startDaemonService(it) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun isConnectOnBootEnabled(context: Context): Boolean { | ||
return context | ||
.getSharedPreferences(APP_PREFERENCES_NAME, Context.MODE_PRIVATE) | ||
.getBoolean(IS_CONNECT_ON_BOOT_ENABLED_KEY, false) | ||
} | ||
|
||
private fun startDaemonService(context: Context) { | ||
val intent = | ||
Intent().apply { | ||
setClassName(context.packageName, VPN_SERVICE_CLASS) | ||
action = KEY_CONNECT_ACTION | ||
} | ||
context.startForegroundService(intent) | ||
} | ||
} |
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
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