From 3c15faf6edca82592048f71bf7025e8b18149287 Mon Sep 17 00:00:00 2001 From: Marinov Date: Fri, 6 Mar 2026 12:58:10 +0200 Subject: [PATCH] [MS-1379] Read intent data directly from OrchestratorFragment to avoid multiple copies of arguments in associated VMs --- .../orchestrator/OrchestratorActivity.kt | 17 ------------ .../orchestrator/OrchestratorFragment.kt | 27 ++++++++++++++----- .../res/navigation/graph_orchestration.xml | 7 ----- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorActivity.kt b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorActivity.kt index c83cad484e..a1e6437f15 100644 --- a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorActivity.kt +++ b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorActivity.kt @@ -3,12 +3,9 @@ package com.simprints.feature.orchestrator import android.content.Intent import android.os.Bundle import android.os.PersistableBundle -import androidx.core.os.bundleOf import androidx.navigation.findNavController import com.simprints.core.tools.activity.BaseActivity -import com.simprints.feature.clientapi.models.ClientApiConstants import com.simprints.feature.orchestrator.databinding.ActivityOrchestratorBinding -import com.simprints.infra.config.store.LastCallingPackageStore import com.simprints.infra.logging.LoggingConstants.CrashReportTag.ORCHESTRATION import com.simprints.infra.logging.Simber import com.simprints.infra.orchestration.data.results.AppResult @@ -24,9 +21,6 @@ internal class OrchestratorActivity : BaseActivity() { @Inject lateinit var activityTracker: ExecutionTracker - @Inject - lateinit var lastCallingPackageStore: LastCallingPackageStore - /** * Flag for the navigation graph initialization state. The graph should only be initialized once * during the existence of this activity, and the flag tracks graph's state. @@ -59,19 +53,8 @@ internal class OrchestratorActivity : BaseActivity() { if (activityTracker.isMain(activity = this)) { if (!isGraphInitialized) { - val action = intent.action.orEmpty() - val extras = intent.extras ?: bundleOf() - Simber.setUserProperty("Intent_received", action) - Simber.setUserProperty("Caller", callingPackage.orEmpty()) - - // Some co-sync functionality depends on the exact package name of the caller app, - // e.g. to switch content providers of debug and release variants of the caller app - extras.putString(ClientApiConstants.CALLER_PACKAGE_NAME, callingPackage) - lastCallingPackageStore.lastCallingPackageName = callingPackage - findNavController(R.id.orchestrationHost).setGraph( R.navigation.graph_orchestration, - OrchestratorFragmentArgs(action, extras).toBundle(), ) isGraphInitialized = true } diff --git a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorFragment.kt b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorFragment.kt index 0d8fa60d6d..667f7c4f90 100644 --- a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorFragment.kt +++ b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorFragment.kt @@ -2,11 +2,11 @@ package com.simprints.feature.orchestrator import android.os.Bundle import android.view.View +import androidx.core.os.bundleOf import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs import com.simprints.core.domain.response.AppErrorReason import com.simprints.core.livedata.LiveDataEventObserver import com.simprints.core.livedata.LiveDataEventWithContentObserver @@ -16,6 +16,7 @@ import com.simprints.feature.alert.AlertResult import com.simprints.feature.alert.toArgs import com.simprints.feature.clientapi.ClientApiViewModel import com.simprints.feature.clientapi.extensions.getResultCodeFromExtras +import com.simprints.feature.clientapi.models.ClientApiConstants import com.simprints.feature.consent.ConsentContract import com.simprints.feature.enrollast.EnrolLastBiometricContract import com.simprints.feature.exitform.ExitFormContract @@ -30,6 +31,7 @@ import com.simprints.feature.selectsubject.SelectSubjectContract import com.simprints.feature.setup.SetupContract import com.simprints.feature.validatepool.ValidateSubjectPoolContract import com.simprints.fingerprint.capture.FingerprintCaptureContract +import com.simprints.infra.config.store.LastCallingPackageStore import com.simprints.infra.logging.LoggingConstants.CrashReportTag.ORCHESTRATION import com.simprints.infra.logging.Simber import com.simprints.infra.orchestration.data.responses.AppConfirmationResponse @@ -72,7 +74,10 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) { @Inject lateinit var orchestratorCache: OrchestratorCache - private val args by navArgs() + @Inject + lateinit var lastCallingPackageStore: LastCallingPackageStore + + private val intentAction get() = requireActivity().intent.action.orEmpty() private val loginCheckVm by viewModels() private val clientApiVm by viewModels() @@ -231,7 +236,7 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) { if (response.request == null) { clientApiVm.handleErrorResponse( - args.requestAction, + intentAction, AppErrorResponse(AppErrorReason.UNEXPECTED_ERROR), ) } else { @@ -257,7 +262,7 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) { } is AppErrorResponse -> { - clientApiVm.handleErrorResponse(args.requestAction, response.response) + clientApiVm.handleErrorResponse(intentAction, response.response) } } } @@ -282,8 +287,18 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) { Simber.i("Start processing action request", tag = ORCHESTRATION) if (loginCheckVm.isDeviceSafe()) { lifecycleScope.launch { - val actionRequest = - clientApiVm.handleIntent(args.requestAction, args.requestParams) + val extras = requireActivity().intent.extras ?: bundleOf() + val callingPackage = requireActivity().callingPackage + + Simber.setUserProperty("Intent_received", intentAction) + Simber.setUserProperty("Caller", callingPackage.orEmpty()) + + // Some co-sync functionality depends on the exact package name of the caller app, + // e.g. to switch content providers of debug and release variants of the caller app + lastCallingPackageStore.lastCallingPackageName = callingPackage + extras.putString(ClientApiConstants.CALLER_PACKAGE_NAME, callingPackage) + + val actionRequest = clientApiVm.handleIntent(intentAction, extras) if (actionRequest != null) { Simber.i("Action request parsed successfully", tag = ORCHESTRATION) loginCheckVm.validateSignInAndProceed(actionRequest) diff --git a/feature/orchestrator/src/main/res/navigation/graph_orchestration.xml b/feature/orchestrator/src/main/res/navigation/graph_orchestration.xml index 43cb91cf24..b2407a6e56 100644 --- a/feature/orchestrator/src/main/res/navigation/graph_orchestration.xml +++ b/feature/orchestrator/src/main/res/navigation/graph_orchestration.xml @@ -10,13 +10,6 @@ android:name="com.simprints.feature.orchestrator.OrchestratorFragment" android:label="ClientApiFragment" tools:layout="@layout/fragment_orchestrator"> - - -