diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt index 3128870ae5ee..7fd9c8391572 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt @@ -13,7 +13,7 @@ import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy import net.mullvad.mullvadvpn.lib.shared.DeviceRepository import net.mullvad.mullvadvpn.lib.shared.LocaleRepository import net.mullvad.mullvadvpn.lib.shared.RelayLocationTranslationRepository -import net.mullvad.mullvadvpn.lib.shared.VpnProfileUseCase +import net.mullvad.mullvadvpn.lib.shared.PrepareVpnUseCase import org.koin.android.ext.koin.androidContext import org.koin.core.qualifier.named import org.koin.dsl.module @@ -30,7 +30,7 @@ val appModule = module { ) } - single { VpnProfileUseCase(androidContext()) } + single { PrepareVpnUseCase(androidContext()) } single { BuildVersion(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) } single { IntentProvider() } diff --git a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxy.kt b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxy.kt index 08a0a517f08e..baf404d89c09 100644 --- a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxy.kt +++ b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxy.kt @@ -11,7 +11,7 @@ import net.mullvad.mullvadvpn.lib.model.TunnelState class ConnectionProxy( private val managementService: ManagementService, translationRepository: RelayLocationTranslationRepository, - private val vpnProfileUseCase: VpnProfileUseCase, + private val prepareVpnUseCase: PrepareVpnUseCase, ) { val tunnelState = combine(managementService.tunnelState, translationRepository.translations) { @@ -34,7 +34,7 @@ class ConnectionProxy( copy(city = translations[city] ?: city, country = translations[country] ?: country) suspend fun connect(): Either = either { - vpnProfileUseCase.prepareVpn().mapLeft(ConnectError::NotPrepared).bind() + prepareVpnUseCase.invoke().mapLeft(ConnectError::NotPrepared).bind() managementService.connect().bind() } diff --git a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/VpnProfileUseCase.kt b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/PrepareVpnUseCase.kt similarity index 63% rename from android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/VpnProfileUseCase.kt rename to android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/PrepareVpnUseCase.kt index cebac0be04be..7f7ec88120b3 100644 --- a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/VpnProfileUseCase.kt +++ b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/PrepareVpnUseCase.kt @@ -6,6 +6,6 @@ import net.mullvad.mullvadvpn.lib.common.util.prepareVpnSafe import net.mullvad.mullvadvpn.lib.model.PrepareError import net.mullvad.mullvadvpn.lib.model.Prepared -class VpnProfileUseCase(private val applicationContext: Context) { - fun prepareVpn(): Either = applicationContext.prepareVpnSafe() +class PrepareVpnUseCase(private val applicationContext: Context) { + fun invoke(): Either = applicationContext.prepareVpnSafe() } diff --git a/android/lib/shared/src/test/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxyTest.kt b/android/lib/shared/src/test/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxyTest.kt index 24a14ce782f0..b9d276c34ba9 100644 --- a/android/lib/shared/src/test/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxyTest.kt +++ b/android/lib/shared/src/test/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxyTest.kt @@ -17,20 +17,20 @@ import org.junit.jupiter.api.Test class ConnectionProxyTest { private val mockManagementService: ManagementService = mockk(relaxed = true) - private val mockVpnPermissionRepository: VpnProfileUseCase = mockk() + private val mockVpnPermissionRepository: PrepareVpnUseCase = mockk() private val mockTranslationRepository: RelayLocationTranslationRepository = mockk(relaxed = true) private val connectionProxy: ConnectionProxy = ConnectionProxy( managementService = mockManagementService, - vpnProfileUseCase = mockVpnPermissionRepository, + prepareVpnUseCase = mockVpnPermissionRepository, translationRepository = mockTranslationRepository, ) @Test fun `connect with vpn permission allowed should call managementService connect`() = runTest { - every { mockVpnPermissionRepository.prepareVpn() } returns Prepared.right() + every { mockVpnPermissionRepository.invoke() } returns Prepared.right() connectionProxy.connect() coVerify(exactly = 1) { mockManagementService.connect() } } @@ -38,7 +38,7 @@ class ConnectionProxyTest { @Test fun `connect with vpn permission not allowed should not call managementService connect`() = runTest { - every { mockVpnPermissionRepository.prepareVpn() } returns + every { mockVpnPermissionRepository.invoke() } returns PrepareError.NotPrepared(Intent()).left() connectionProxy.connect() coVerify(exactly = 0) { mockManagementService.connect() } diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/tunnelstate/TunnelStateNotificationProvider.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/tunnelstate/TunnelStateNotificationProvider.kt index e9c52bba4835..cb589096d974 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/tunnelstate/TunnelStateNotificationProvider.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/tunnelstate/TunnelStateNotificationProvider.kt @@ -23,12 +23,12 @@ import net.mullvad.mullvadvpn.lib.model.PrepareError import net.mullvad.mullvadvpn.lib.model.TunnelState import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy import net.mullvad.mullvadvpn.lib.shared.DeviceRepository -import net.mullvad.mullvadvpn.lib.shared.VpnProfileUseCase +import net.mullvad.mullvadvpn.lib.shared.PrepareVpnUseCase import net.mullvad.mullvadvpn.service.notifications.NotificationProvider class TunnelStateNotificationProvider( connectionProxy: ConnectionProxy, - vpnPermissionRepository: VpnProfileUseCase, + vpnPermissionRepository: PrepareVpnUseCase, deviceRepository: DeviceRepository, channelId: NotificationChannelId, scope: CoroutineScope, @@ -50,7 +50,7 @@ class TunnelStateNotificationProvider( tunnelState( tunnelState, actionAfterDisconnect, - vpnPermissionRepository.prepareVpn().leftOrNull(), + vpnPermissionRepository.invoke().leftOrNull(), ) return@combine NotificationUpdate.Notify(