[Test Harness] Add custom ContextThemeWrapper to improve test harness behavior in previews #1414
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.
Adds a custom
ContextThemeWrapper
to work around the issue that currently causesTestHarness
to fail in previews.The cause of the crash is that
Context.createConfigurationContext
returnsnull
forBridgeContext
in layoutlib: https://cs.android.com/android/platform/superproject/+/master:frameworks/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java;l=1380;drc=58bd418e161b5d4fdde39b46523d3e49269117e3ContextThemeWrapper
uses thisContext.createConfigurationContext
internally and assumes it is not null, which causes the crash.The
androidx.appcompat.view.ContextThemeWrapper
has a fallback mechanism for older API versions using a deprecatedResources
constructor, so this PR adds a customContextThemeWrapper
based on the appcompat one that uses that fallback mechanism in caseContext.createConfigurationContext
is null.This improves behavior, preventing the crash, but doesn't remove all of the limitations. In particular, alternate resources are not loaded (such as the string not translated in the below image), which is probably related to how layoutlib manages resources.