diff --git a/app/src/main/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorImpl.kt index a6d17403f..7b0c92781 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorImpl.kt @@ -55,11 +55,14 @@ class AutofillProcessorImpl( // Set the listener so that any long running work is cancelled when it is no longer needed. cancellationSignal.setOnCancelListener { job.cancel() } // Process the OS data and handle invoking the callback with the result. - process( - autofillAppInfo = autofillAppInfo, - fillCallback = fillCallback, - fillRequest = request, - ) + job.cancel() + job = scope.launch { + process( + autofillAppInfo = autofillAppInfo, + fillCallback = fillCallback, + fillRequest = request, + ) + } } override fun processSaveRequest( @@ -106,7 +109,7 @@ class AutofillProcessorImpl( /** * Process the [fillRequest] and invoke the [FillCallback] with the response. */ - private fun process( + private suspend fun process( autofillAppInfo: AutofillAppInfo, fillCallback: FillCallback, fillRequest: FillRequest, @@ -118,28 +121,25 @@ class AutofillProcessorImpl( ) when (autofillRequest) { is AutofillRequest.Fillable -> { - job.cancel() - job = scope.launch { - // Fulfill the [autofillRequest]. - val filledData = filledDataBuilder.build( - autofillRequest = autofillRequest, - ) - val saveInfo = saveInfoBuilder.build( - autofillAppInfo = autofillAppInfo, - autofillPartition = autofillRequest.partition, - fillRequest = fillRequest, - packageName = autofillRequest.packageName, - ) + // Fulfill the [autofillRequest]. + val filledData = filledDataBuilder.build( + autofillRequest = autofillRequest, + ) + val saveInfo = saveInfoBuilder.build( + autofillAppInfo = autofillAppInfo, + autofillPartition = autofillRequest.partition, + fillRequest = fillRequest, + packageName = autofillRequest.packageName, + ) - // Load the filledData and saveInfo into a FillResponse. - val response = fillResponseBuilder.build( - autofillAppInfo = autofillAppInfo, - filledData = filledData, - saveInfo = saveInfo, - ) + // Load the filledData and saveInfo into a FillResponse. + val response = fillResponseBuilder.build( + autofillAppInfo = autofillAppInfo, + filledData = filledData, + saveInfo = saveInfo, + ) - fillCallback.onSuccess(response) - } + fillCallback.onSuccess(response) } AutofillRequest.Unfillable -> { diff --git a/app/src/test/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorTest.kt index 31abbcd29..e91fc18a4 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/autofill/processor/AutofillProcessorTest.kt @@ -107,6 +107,7 @@ class AutofillProcessorTest { fillCallback = fillCallback, request = fillRequest, ) + testDispatcher.scheduler.runCurrent() // Verify verify(exactly = 1) { @@ -445,9 +446,9 @@ class AutofillProcessorTest { verify(exactly = 1) { // These run as they are not part of the coroutine cancellationSignal.setOnCancelListener(any()) - parser.parse(autofillAppInfo = appInfo, fillRequest = fillRequest) } coVerify(exactly = 0) { + parser.parse(autofillAppInfo = appInfo, fillRequest = fillRequest) filledDataBuilder.build(autofillRequest = autofillRequest) } verify(exactly = 0) {