-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tile control and kernel sync (#320)
increase auto tunnel delay to 3 seconds optimize stats job by killing it when app is backgrounded fix tunnel launch from background add restart of services and tunnels after update
- Loading branch information
1 parent
3f4673b
commit 30851a7
Showing
22 changed files
with
235 additions
and
109 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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/zaneschepke/wireguardautotunnel/receiver/AppUpdateReceiver.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,47 @@ | ||
package com.zaneschepke.wireguardautotunnel.receiver | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository | ||
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope | ||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager | ||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService | ||
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class AppUpdateReceiver : BroadcastReceiver() { | ||
|
||
@Inject | ||
@ApplicationScope | ||
lateinit var applicationScope: CoroutineScope | ||
|
||
@Inject | ||
lateinit var appDataRepository: AppDataRepository | ||
|
||
@Inject | ||
lateinit var serviceManager: ServiceManager | ||
|
||
@Inject | ||
lateinit var tunnelService: TunnelService | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return | ||
applicationScope.launch { | ||
val settings = appDataRepository.settings.getSettings() | ||
if (settings.isAutoTunnelEnabled) { | ||
Timber.i("Restarting services after upgrade") | ||
serviceManager.startWatcherServiceForeground(context) | ||
} | ||
if (!settings.isAutoTunnelEnabled || settings.isAutoTunnelPaused) { | ||
val tunnels = appDataRepository.tunnels.getAll().filter { it.isActive } | ||
if (tunnels.isNotEmpty()) context.startTunnelBackground(tunnels.first().id) | ||
} | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...in/java/com/zaneschepke/wireguardautotunnel/service/foreground/TunnelBackgroundService.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,41 @@ | ||
package com.zaneschepke.wireguardautotunnel.service.foreground | ||
|
||
import android.app.Notification | ||
import android.os.Bundle | ||
import com.zaneschepke.wireguardautotunnel.R | ||
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class TunnelBackgroundService : ForegroundService() { | ||
|
||
@Inject | ||
lateinit var notificationService: NotificationService | ||
|
||
private val foregroundId = 123 | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
startForeground(foregroundId, createNotification()) | ||
} | ||
|
||
override fun startService(extras: Bundle?) { | ||
super.startService(extras) | ||
startForeground(foregroundId, createNotification()) | ||
} | ||
|
||
override fun stopService() { | ||
super.stopService() | ||
stopForeground(STOP_FOREGROUND_REMOVE) | ||
} | ||
|
||
private fun createNotification(): Notification { | ||
return notificationService.createNotification( | ||
getString(R.string.vpn_channel_id), | ||
getString(R.string.vpn_channel_name), | ||
getString(R.string.tunnel_start_text), | ||
description = "", | ||
) | ||
} | ||
} |
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
Oops, something went wrong.