Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Nov 25, 2024
1 parent e71f8b7 commit 42d123b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.VpnProfileRepository
import net.mullvad.mullvadvpn.lib.shared.VpnProfileUseCase
import org.koin.android.ext.koin.androidContext
import org.koin.core.qualifier.named
import org.koin.dsl.module
Expand All @@ -33,7 +33,7 @@ val appModule = module {
single { IntentProvider() }
single { AccountRepository(get(), get(), MainScope()) }
single { DeviceRepository(get()) }
single { VpnProfileRepository(androidContext()) }
single { VpnProfileUseCase(androidContext()) }
single { ConnectionProxy(get(), get(), get()) }
single { LocaleRepository(get()) }
single { RelayLocationTranslationRepository(get(), get(), MainScope()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
import net.mullvad.mullvadvpn.lib.shared.DeviceRepository
import net.mullvad.mullvadvpn.lib.shared.VpnProfileRepository
import net.mullvad.mullvadvpn.lib.shared.VpnProfileUseCase
import net.mullvad.mullvadvpn.repository.InAppNotificationController
import net.mullvad.mullvadvpn.repository.NewDeviceRepository
import net.mullvad.mullvadvpn.usecase.LastKnownLocationUseCase
Expand All @@ -49,7 +49,7 @@ class ConnectViewModel(
private val paymentUseCase: PaymentUseCase,
private val connectionProxy: ConnectionProxy,
lastKnownLocationUseCase: LastKnownLocationUseCase,
private val vpnPermissionRepository: VpnProfileRepository,
private val vpnPermissionRepository: VpnProfileUseCase,
private val resources: Resources,
private val isPlayBuild: Boolean,
private val packageName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
import net.mullvad.mullvadvpn.lib.shared.DeviceRepository
import net.mullvad.mullvadvpn.lib.shared.VpnProfileRepository
import net.mullvad.mullvadvpn.lib.shared.VpnProfileUseCase
import net.mullvad.mullvadvpn.repository.InAppNotification
import net.mullvad.mullvadvpn.repository.InAppNotificationController
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
Expand Down Expand Up @@ -88,7 +88,7 @@ class ConnectViewModelTest {
private val mockLastKnownLocationUseCase: LastKnownLocationUseCase = mockk()

// VpnPermissionRepository
private val mockVpnPermissionRepository: VpnProfileRepository = mockk(relaxed = true)
private val mockVpnPermissionRepository: VpnProfileUseCase = mockk(relaxed = true)

@BeforeEach
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ sealed interface NotificationAction {

data object Dismiss : Tunnel

data class RequestPermission(val prepareIntent: Intent) : Tunnel
data object RequestVpnProfile : Tunnel
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.mullvad.mullvadvpn.lib.model.TunnelState
class ConnectionProxy(
private val managementService: ManagementService,
translationRepository: RelayLocationTranslationRepository,
private val vpnPermissionRepository: VpnProfileRepository,
private val vpnProfileUseCase: VpnProfileUseCase,
) {
val tunnelState =
combine(managementService.tunnelState, translationRepository.translations) {
Expand All @@ -34,7 +34,7 @@ class ConnectionProxy(
copy(city = translations[city] ?: city, country = translations[country] ?: country)

suspend fun connect(): Either<ConnectError, Boolean> = either {
vpnPermissionRepository.prepareVpn().mapLeft(ConnectError::NotPrepared).bind()
vpnProfileUseCase.prepareVpn().mapLeft(ConnectError::NotPrepared).bind()
managementService.connect().bind()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 VpnProfileRepository(private val applicationContext: Context) {
class VpnProfileUseCase(private val applicationContext: Context) {
fun prepareVpn(): Either<PrepareError, Prepared> = applicationContext.prepareVpnSafe()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import org.junit.jupiter.api.Test
class ConnectionProxyTest {

private val mockManagementService: ManagementService = mockk(relaxed = true)
private val mockVpnPermissionRepository: VpnProfileRepository = mockk()
private val mockVpnPermissionRepository: VpnProfileUseCase = mockk()
private val mockTranslationRepository: RelayLocationTranslationRepository =
mockk(relaxed = true)

private val connectionProxy: ConnectionProxy =
ConnectionProxy(
managementService = mockManagementService,
vpnPermissionRepository = mockVpnPermissionRepository,
vpnProfileUseCase = mockVpnPermissionRepository,
translationRepository = mockTranslationRepository,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ private fun NotificationTunnelState.contentTitleResourceId(context: Context): St
internal fun NotificationAction.Tunnel.toCompatAction(context: Context): NotificationCompat.Action {

val pendingIntent =
if (this is NotificationAction.Tunnel.RequestPermission) {
if (this is NotificationAction.Tunnel.RequestVpnProfile) {
val intent =
Intent().apply {
setClassName(context.packageName, MAIN_ACTIVITY_CLASS)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
setAction(KEY_REQUEST_VPN_PROFILE)
putExtra("intent", prepareIntent)
}

PendingIntent.getActivity(context, 1, intent, SdkUtils.getSupportedPendingIntentFlags())
Expand All @@ -91,15 +90,15 @@ fun NotificationAction.Tunnel.titleResource() =
when (this) {
NotificationAction.Tunnel.Cancel -> R.string.cancel
NotificationAction.Tunnel.Connect,
is NotificationAction.Tunnel.RequestPermission -> R.string.connect
is NotificationAction.Tunnel.RequestVpnProfile -> R.string.connect
NotificationAction.Tunnel.Disconnect -> R.string.disconnect
NotificationAction.Tunnel.Dismiss -> R.string.dismiss
}

fun NotificationAction.Tunnel.toKey() =
when (this) {
NotificationAction.Tunnel.Connect -> KEY_CONNECT_ACTION
is NotificationAction.Tunnel.RequestPermission -> KEY_REQUEST_VPN_PROFILE
is NotificationAction.Tunnel.RequestVpnProfile -> KEY_REQUEST_VPN_PROFILE
NotificationAction.Tunnel.Cancel,
NotificationAction.Tunnel.Disconnect,
NotificationAction.Tunnel.Dismiss -> KEY_DISCONNECT_ACTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.VpnProfileRepository
import net.mullvad.mullvadvpn.lib.shared.VpnProfileUseCase
import net.mullvad.mullvadvpn.service.notifications.NotificationProvider

class TunnelStateNotificationProvider(
connectionProxy: ConnectionProxy,
vpnPermissionRepository: VpnProfileRepository,
vpnPermissionRepository: VpnProfileUseCase,
deviceRepository: DeviceRepository,
channelId: NotificationChannelId,
scope: CoroutineScope,
Expand Down Expand Up @@ -122,12 +122,11 @@ class TunnelStateNotificationProvider(
private fun NotificationTunnelState.toAction(): NotificationAction.Tunnel =
when (this) {
is NotificationTunnelState.Disconnected -> {
when (val error = prepareError) {
when (prepareError) {
is PrepareError.OtherAlwaysOnApp,
is PrepareError.LegacyLockdown,
null -> NotificationAction.Tunnel.Connect
is PrepareError.NotPrepared ->
NotificationAction.Tunnel.RequestPermission(error.prepareIntent)
is PrepareError.NotPrepared -> NotificationAction.Tunnel.RequestVpnProfile
}
}
NotificationTunnelState.Disconnecting -> NotificationAction.Tunnel.Connect
Expand Down

0 comments on commit 42d123b

Please sign in to comment.