All of the autofill processing happens in a job (#3545)
Some checks failed
Crowdin Push / Crowdin Push (push) Waiting to run
Scan / Check PR run (push) Failing after 0s
Scan / SAST scan (push) Has been skipped
Scan / Quality scan (push) Has been skipped
Test / Check PR run (push) Failing after 0s
Test / Test (push) Has been skipped

This commit is contained in:
David Perez 2024-07-17 15:05:11 -05:00 committed by GitHub
parent 7d18310f30
commit 96324f01d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 27 deletions

View file

@ -55,12 +55,15 @@ 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.
job.cancel()
job = scope.launch {
process(
autofillAppInfo = autofillAppInfo,
fillCallback = fillCallback,
fillRequest = request,
)
}
}
override fun processSaveRequest(
autofillAppInfo: AutofillAppInfo,
@ -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,8 +121,6 @@ class AutofillProcessorImpl(
)
when (autofillRequest) {
is AutofillRequest.Fillable -> {
job.cancel()
job = scope.launch {
// Fulfill the [autofillRequest].
val filledData = filledDataBuilder.build(
autofillRequest = autofillRequest,
@ -140,7 +141,6 @@ class AutofillProcessorImpl(
fillCallback.onSuccess(response)
}
}
AutofillRequest.Unfillable -> {
// If we are unable to fulfill the request, we should invoke the callback

View file

@ -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) {