Fix crash on startup on Android 12. #432
Closed
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.
ItWasntMeWhoFarted on discord reported a crash on startup on a Pixel 3 https://pastebin.com/raw/6F79yg9u message link
My analysis from discord:
It's likely caused by the compat registerReceiver calling getApplicationContext (only on Android 12 or lower), which is initialized only after Application's attachBaseContext has finished
There was a change in january which made the compat registerReceiver always use getApplicationContext, which likely caused this regression during an AppCompat update https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:core/core/src/main/java/androidx/core/content/ContextCompat.java;l=649;bpv=1;bpt=0;drc=c283d06f837a2b93b8123d07b7ad5611ba36d9d4;dlc=5c86afb33905d66b89a29ce66362859bc48651e5
Moving the PackageStates.init() call out of
attachBaseContextand toonCreatefixes this, although the comment raises a concern that theRpcProvidermay run before Applications'sonCreatehas finished, but in my testing the calls to the provider only come through afteronCreate. Are there other reasons why this code was run inattachBaseContext?