Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix splash screen freeze #6556

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.navigation.NavHostController
import co.touchlab.kermit.Logger
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.generated.NavGraphs
import com.ramcosta.composedestinations.generated.destinations.ChangelogDestination
@@ -56,6 +57,7 @@ fun MullvadApp() {

// Globally handle daemon dropped connection with NoDaemonScreen
LaunchedEffectCollect(serviceVm.uiSideEffect) {
Logger.i { "DaemonScreenEvent: $it" }
when (it) {
DaemonScreenEvent.Show ->
navigator.navigate(NoDaemonDestination) { launchSingleTop = true }
Original file line number Diff line number Diff line change
@@ -10,11 +10,15 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.compose.screen.MullvadApp
import net.mullvad.mullvadvpn.di.paymentModule
import net.mullvad.mullvadvpn.di.uiModule
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.requestNotificationPermissionIfMissing
import net.mullvad.mullvadvpn.lib.daemon.grpc.GrpcConnectivityState
import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService
import net.mullvad.mullvadvpn.lib.intent.IntentProvider
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.repository.PrivacyDisclaimerRepository
@@ -40,6 +44,7 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent {
private val privacyDisclaimerRepository by inject<PrivacyDisclaimerRepository>()
private val serviceConnectionManager by inject<ServiceConnectionManager>()
private val splashCompleteRepository by inject<SplashCompleteRepository>()
private val managementService by inject<ManagementService>()

private var isReadyNextDraw: Boolean = false

@@ -79,6 +84,20 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent {
}
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
lifecycleScope.launch {
if (privacyDisclaimerRepository.hasAcceptedPrivacyDisclosure()) {
// If service is to be started wait for it to be connected before dismissing Splash
// screen
managementService.connectionState
.filter { it is GrpcConnectivityState.Ready }
.first()
}
splashCompleteRepository.onSplashCompleted()
}
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
intentProvider.setStartIntent(intent)
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
@@ -147,9 +148,10 @@ class ManagementService(
channel
.connectivityFlow()
.map(ConnectivityState::toDomain)
.onEach { Logger.i("ManagementService connection state: $it") }
.stateIn(scope, SharingStarted.Eagerly, channel.getState(false).toDomain())

private val grpc =
private val grpc by lazy {
ManagementServiceGrpcKt.ManagementServiceCoroutineStub(channel)
.withExecutor(Dispatchers.IO.asExecutor())
.let {
@@ -158,6 +160,7 @@ class ManagementService(
} else it
}
.withWaitForReady()
}

private val _mutableDeviceState = MutableStateFlow<ModelDeviceState?>(null)
val deviceState: Flow<ModelDeviceState> = _mutableDeviceState.filterNotNull()
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@ class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider {
cacheDirectory = cacheDir.absolutePath,
apiEndpoint = apiEndpointConfiguration.apiEndpoint()
)
Logger.i("MullvadVpnService: Daemon initialized")
}

private fun emptyBinder() =