From 737524831b57fc84cf2d012d94b6d5bd0759c406 Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Sat, 27 Jul 2024 07:21:27 -0400 Subject: [PATCH] fix: auto tunnel tile bug Fixes bug where auto tunnel tile was the opposite state Closes #241 --- .../service/tile/AutoTunnelControlTile.kt | 20 ++++++++++++------- .../service/tile/TunnelControlTile.kt | 18 +++++++++++------ buildSrc/src/main/kotlin/Constants.kt | 4 ++-- .../android/en-US/changelogs/34800.txt | 5 +++++ 4 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/34800.txt diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/AutoTunnelControlTile.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/AutoTunnelControlTile.kt index 939bcaf..a70056c 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/AutoTunnelControlTile.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/AutoTunnelControlTile.kt @@ -3,10 +3,15 @@ package com.zaneschepke.wireguardautotunnel.service.tile import android.os.Build import android.service.quicksettings.Tile import android.service.quicksettings.TileService +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.ServiceLifecycleDispatcher +import androidx.lifecycle.lifecycleScope import com.zaneschepke.wireguardautotunnel.R import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository import com.zaneschepke.wireguardautotunnel.module.ApplicationScope +import com.zaneschepke.wireguardautotunnel.module.ServiceScope import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope @@ -16,7 +21,7 @@ import timber.log.Timber import javax.inject.Inject @AndroidEntryPoint -class AutoTunnelControlTile : TileService() { +class AutoTunnelControlTile : TileService(), LifecycleOwner { @Inject lateinit var appDataRepository: AppDataRepository @@ -24,15 +29,13 @@ class AutoTunnelControlTile : TileService() { @Inject lateinit var serviceManager: ServiceManager - @Inject - @ApplicationScope - lateinit var applicationScope: CoroutineScope + private val dispatcher = ServiceLifecycleDispatcher(this) private var manualStartConfig: TunnelConfig? = null override fun onStartListening() { super.onStartListening() - applicationScope.launch { + lifecycleScope.launch { val settings = appDataRepository.settings.getSettings() when (settings.isAutoTunnelEnabled) { true -> { @@ -44,7 +47,6 @@ class AutoTunnelControlTile : TileService() { setTileDescription(this@AutoTunnelControlTile.getString(R.string.active)) } } - false -> { setTileDescription(this@AutoTunnelControlTile.getString(R.string.disabled)) setUnavailable() @@ -61,9 +63,10 @@ class AutoTunnelControlTile : TileService() { override fun onClick() { super.onClick() unlockAndRun { - applicationScope.launch { + lifecycleScope.launch { try { appDataRepository.toggleWatcherServicePause() + onStartListening() } catch (e: Exception) { Timber.e(e.message) } finally { @@ -98,4 +101,7 @@ class AutoTunnelControlTile : TileService() { } qsTile.updateTile() } + + override val lifecycle: Lifecycle + get() = dispatcher.lifecycle } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/TunnelControlTile.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/TunnelControlTile.kt index b9d8abc..7386912 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/TunnelControlTile.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tile/TunnelControlTile.kt @@ -3,6 +3,11 @@ package com.zaneschepke.wireguardautotunnel.service.tile import android.os.Build import android.service.quicksettings.Tile import android.service.quicksettings.TileService +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.LifecycleService +import androidx.lifecycle.ServiceLifecycleDispatcher +import androidx.lifecycle.lifecycleScope import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository import com.zaneschepke.wireguardautotunnel.module.ApplicationScope @@ -17,7 +22,7 @@ import timber.log.Timber import javax.inject.Inject @AndroidEntryPoint -class TunnelControlTile : TileService() { +class TunnelControlTile : TileService(), LifecycleOwner { @Inject lateinit var appDataRepository: AppDataRepository @@ -28,16 +33,14 @@ class TunnelControlTile : TileService() { @Inject lateinit var serviceManager: ServiceManager - @Inject - @ApplicationScope - lateinit var applicationScope: CoroutineScope + private val dispatcher = ServiceLifecycleDispatcher(this) private var manualStartConfig: TunnelConfig? = null override fun onStartListening() { super.onStartListening() Timber.d("On start listening called") - applicationScope.launch { + lifecycleScope.launch { when (vpnService.getState()) { TunnelState.UP -> { setActive() @@ -67,7 +70,7 @@ class TunnelControlTile : TileService() { override fun onClick() { super.onClick() unlockAndRun { - applicationScope.launch { + lifecycleScope.launch { try { if (vpnService.getState() == TunnelState.UP) { serviceManager.stopVpnServiceForeground( @@ -113,4 +116,7 @@ class TunnelControlTile : TileService() { } qsTile.updateTile() } + + override val lifecycle: Lifecycle + get() = dispatcher.lifecycle } diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index f89a1bd..bf4cb10 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -1,7 +1,7 @@ object Constants { - const val VERSION_NAME = "3.4.7" + const val VERSION_NAME = "3.4.8" const val JVM_TARGET = "17" - const val VERSION_CODE = 34700 + const val VERSION_CODE = 34800 const val TARGET_SDK = 34 const val MIN_SDK = 26 const val APP_ID = "com.zaneschepke.wireguardautotunnel" diff --git a/fastlane/metadata/android/en-US/changelogs/34800.txt b/fastlane/metadata/android/en-US/changelogs/34800.txt new file mode 100644 index 0000000..dff7fa4 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/34800.txt @@ -0,0 +1,5 @@ +What's new: +- Fixes for AndroidTV UI tunnel control +- Fixes portrait lock bug +- Fixes pin lock bypass bug +- Fixes auto tunnel tile bug \ No newline at end of file