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,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 -> {

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