From bd0ffaf1cd54fd95acc8b438261977200d720c93 Mon Sep 17 00:00:00 2001 From: Sergejs Luhmirins Date: Thu, 30 Oct 2025 09:52:28 +0200 Subject: [PATCH] MS-1224 Add a broadcast receiver to clean orchestration caches on application update --- .../orchestrator/src/main/AndroidManifest.xml | 9 ++++ .../receivers/CacheResetReceiver.kt | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/receivers/CacheResetReceiver.kt diff --git a/feature/orchestrator/src/main/AndroidManifest.xml b/feature/orchestrator/src/main/AndroidManifest.xml index caac1a04d6..1c4aa436b3 100644 --- a/feature/orchestrator/src/main/AndroidManifest.xml +++ b/feature/orchestrator/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ + + + + + + + diff --git a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/receivers/CacheResetReceiver.kt b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/receivers/CacheResetReceiver.kt new file mode 100644 index 0000000000..b714c146b2 --- /dev/null +++ b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/receivers/CacheResetReceiver.kt @@ -0,0 +1,41 @@ +package com.simprints.feature.orchestrator.receivers + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.simprints.core.ExcludedFromGeneratedTestCoverageReports +import com.simprints.core.SessionCoroutineScope +import com.simprints.feature.orchestrator.cache.OrchestratorCache +import com.simprints.infra.events.session.SessionEventRepository +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import javax.inject.Inject + +/** + * Cached step structure might change between SID versions therefore caches should be cleared to avoid unmarshalling exceptions. + * Since we do not support cross-version sessions, any ongoing scopes should be closed as well. + */ +@ExcludedFromGeneratedTestCoverageReports("Platform glue code") +@AndroidEntryPoint +internal class CacheResetReceiver : BroadcastReceiver() { + @Inject + @SessionCoroutineScope + lateinit var externalScope: CoroutineScope + + @Inject + lateinit var sessionEventRepository: SessionEventRepository + + @Inject + lateinit var orchestratorCache: OrchestratorCache + + override fun onReceive( + context: Context, + intent: Intent, + ) { + if (Intent.ACTION_MY_PACKAGE_REPLACED == intent.action) { + orchestratorCache.clearCache() + externalScope.launch { sessionEventRepository.closeCurrentSession() } + } + } +}