Skip to content

[Color] HarmonizedColors#applyToContextIfAvailable sometimes crashes on Samsung devices running Android 15 #4927

@bubbleguuum

Description

@bubbleguuum

Version: 1.14.0-alpha04

Exclusively on various Samsung devices running Android 15, I got many automated crash reports triggered by HarmonizedColors#applyToContextIfAvailable:

Caused by: java.lang.IllegalArgumentException: Cannot modify resource loaders of ResourcesImpl not registered with ResourcesManager
at android.app.ResourcesManager$UpdateHandler.onLoadersChanged(ResourcesManager.java:2240)
at android.content.res.Resources.addLoaders(Resources.java:2692)
at com.google.android.material.color.ResourcesLoaderUtils.addResourcesLoaderToContext(ResourcesLoaderUtils.java:37)
at com.google.android.material.color.HarmonizedColors.applyToContextIfAvailable(HarmonizedColors.java:75)

It looks like this happen only when an Activity is recreated (for example on orientation change)

The IllegalArgumentException is thrown by the framework here:

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/app/ResourcesManager.java;drc=6d8e2819f0f3930d24b555f9f067d1880854ed19;l=1948

In fact the crash happens whenever ResourcesLoaderUtils#addResourcesLoaderToContext is called, thus this crash is also triggered if ColorResourcesOverride#applyIfPossible is called. There are probably other calls affected too.

So, I suppose Samsung screw something in its changes to theming or the system ?

On the app side, is there any other work-around than to guard these calls with a try-catch block catching IllegalArgumentException ?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions