rive-app / rive-app/rive-android

StrictMode violation: system font list loads on main thread

Open
#419 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
Kotlin
Stars
538
Forks
66
PR merge metrics
No merged PRs in 30d

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
                      }
                  })
              }
          )
      }
  }
  1. Enable StrictMode as above.
  2. Launch the activity so RiveAnimationView is attached.
  3. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing FontHelper.getSystemFontList() from the custom FileAssetLoader during RiveAnimationView attachment, then inspect the SystemFontsParser.parseFontsXML path mentioned in the report. Determine how system font metadata is loaded and define a completion check that no disk IO occurs on the main thread while font loading remains usable for text assets.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.