-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Labels
Description
Description
When a RiveAnimationView is attached on Android with a custom FileAssetLoader that calls FontHelper.getSystemFontList(), StrictMode reports an UnbufferedIoViolation. The call performs disk IO (parsing fonts.xml) on the main thread during view attachment, so any app that enables StrictMode and loads a Rive animation with text will hit the violation.
Provide a Repro
class SampleActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build()
)
setContentView(
RiveAnimationView(this).apply {
setRiveResource(R.raw.sample_with_text)
setAssetLoader(object : FileAssetLoader() {
override fun loadContents(asset: FileAsset, inBandBytes: ByteArray): Boolean {
if (asset is FontAsset) {
if (inBandBytes.isNotEmpty() && asset.decode(inBandBytes)) return true
// This triggers FontHelper.getSystemFontList() -> disk IO on main thread.
val families = FontHelper.getSystemFontList()
val firstFont = families.firstOrNull()?.fonts?.values?.firstOrNull()?.firstOrNull()
return firstFont?.let { asset.decode(FontHelper.getFontBytes(it)) } ?: false
}
return false
}
})
}
)
}
}
- Enable StrictMode as above.
- Launch the activity so RiveAnimationView is attached.
- Observe the StrictMode logcat entry: StrictMode policy violation: UnbufferedIoViolation originating from FontHelper.getSystemFontList() during SystemFontsParser.parseFontsXML.
Source .riv/.rev file
Any .riv file
Expected behavior
Loading system fonts (or any font metadata) should not perform disk IO on the main thread. The call should either run asynchronously, cache results before UI usage, or expose an async API so apps can avoid StrictMode violations.
seankim-android