WIP: Fix ANR caused by operationRepo.enqueue while loading is in progress #2231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
This PR will fix ANR caused by model store insertion while model store loading is stuck with some prolonged process.
Details
Motivation
Multiple users have reported that ANRs related to OneSignal have shown up in their analytics. We want to eliminate these ANRs to ensure smooth app start up.
Scope
This PR will alter the loading behavior for all models so that model insertion in the main thread becomes possible before loading is completed. The order will be correct because load() will insert cached items in the beginning of the list. However, it is possible for model to process the newly added item before loading is completed.
Others
This PR contains 4 commits.
Testing
Unit testing
I have included a test unit to simulate a model insertion while loading is blocked by a lengthy process. THE UNIT TEST HAS ONE PENDING TODO.
Manual testing
The first commit manually force the loading of operationRepo to take at least 5 seconds in order to simulate the issue. The second commit applies the fix and we can observe that ANR can no long occur.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is