Merge "Move Native Graphics initialization into ViewScreenshotTestRule." into udc-dev am: 05bdb35bb6 am: a82688d8c5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23494571

Change-Id: Iabaeac9ebb10b23d2e18135f72324b0fe1639a01
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ram Peri
2023-06-02 15:00:58 +00:00
committed by Automerger Merge Worker

View File

@@ -62,6 +62,15 @@ open class ViewScreenshotTestRule(
private val isRobolectric = if (Build.FINGERPRINT.contains("robolectric")) true else false
override fun apply(base: Statement, description: Description): Statement {
if (isRobolectric) {
// In robolectric mode, we enable NATIVE graphics and unpack font and icu files.
// We need to use reflection, as this library is only needed and therefore
// only available in deviceless mode.
val nativeLoaderClassName = "org.robolectric.nativeruntime.DefaultNativeRuntimeLoader"
val defaultNativeRuntimeLoader = Class.forName(nativeLoaderClassName)
System.setProperty("robolectric.graphicsMode", "NATIVE")
defaultNativeRuntimeLoader.getMethod("injectAndLoad").invoke(null)
}
val ruleToApply = if (isRobolectric) roboRule else delegateRule
return ruleToApply.apply(base, description)
}