From 3375aecd61e5ca830eab462b0e2688157afc1c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Thu, 4 Jul 2024 10:16:55 +0200 Subject: [PATCH] Bind ServiceConnectionManager to Activity --- .../net/mullvad/mullvadvpn/di/UiModule.kt | 5 ++-- .../net/mullvad/mullvadvpn/ui/MainActivity.kt | 26 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt index 5ecf8ecbd940..371a30bdf1c5 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt @@ -24,6 +24,7 @@ import net.mullvad.mullvadvpn.repository.RelayOverridesRepository import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.SplashCompleteRepository import net.mullvad.mullvadvpn.repository.SplitTunnelingRepository +import net.mullvad.mullvadvpn.ui.MainActivity import net.mullvad.mullvadvpn.ui.serviceconnection.AppVersionInfoRepository import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager import net.mullvad.mullvadvpn.usecase.AccountExpiryNotificationUseCase @@ -97,9 +98,9 @@ val uiModule = module { single(named(SELF_PACKAGE_NAME)) { androidContext().packageName } viewModel { SplitTunnelingViewModel(get(), get(), Dispatchers.Default) } - single { ApplicationsProvider(get(), get(named(SELF_PACKAGE_NAME))) } - single { ServiceConnectionManager(androidContext()) } + single { ApplicationsProvider(get(), get(named(SELF_PACKAGE_NAME))) } + scope { scoped { ServiceConnectionManager(androidContext()) } } single { InetAddressValidator.getInstance() } single { androidContext().resources } single { androidContext().assets } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt index 8339a25f615d..1d9de026afb0 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -21,22 +21,27 @@ import net.mullvad.mullvadvpn.repository.PrivacyDisclaimerRepository import net.mullvad.mullvadvpn.repository.SplashCompleteRepository import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager import net.mullvad.mullvadvpn.viewmodel.NoDaemonViewModel -import org.koin.android.ext.android.getKoin +import org.koin.android.ext.android.inject +import org.koin.android.scope.AndroidScopeComponent +import org.koin.androidx.scope.activityScope import org.koin.core.context.loadKoinModules -class MainActivity : ComponentActivity() { +class MainActivity : ComponentActivity(), AndroidScopeComponent { + override val scope by activityScope() + private val requestNotificationPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { // NotificationManager.areNotificationsEnabled is used to check the state rather than // handling the callback value. } - private lateinit var privacyDisclaimerRepository: PrivacyDisclaimerRepository - private lateinit var serviceConnectionManager: ServiceConnectionManager - private lateinit var splashCompleteRepository: SplashCompleteRepository + private val intentProvider by inject() + private val noDaemonViewModel by inject() + private val privacyDisclaimerRepository by inject() + private val serviceConnectionManager by inject() + private val splashCompleteRepository by inject() + private var isReadyNextDraw: Boolean = false - private lateinit var noDaemonViewModel: NoDaemonViewModel - private lateinit var intentProvider: IntentProvider override fun onCreate(savedInstanceState: Bundle?) { loadKoinModules(listOf(uiModule, paymentModule)) @@ -44,13 +49,6 @@ class MainActivity : ComponentActivity() { // Tell the system that we will draw behind the status bar and navigation bar WindowCompat.setDecorFitsSystemWindows(window, false) - with(getKoin()) { - privacyDisclaimerRepository = get() - serviceConnectionManager = get() - noDaemonViewModel = get() - intentProvider = get() - splashCompleteRepository = get() - } lifecycle.addObserver(noDaemonViewModel) installSplashScreen().setKeepOnScreenCondition {