HACK: make Resources.mDrawableCache of type ThemedResourceCache, but only for F-Droid

This field is directly accessed by androidx and some androidx version
expect it to be a Map while other expect a ThemedResourceCache. This
mess is probably caused by reporting an age old Build.SDK_INT.
This commit is contained in:
Julian Winkler 2025-03-25 18:56:20 +01:00
parent df4d4721ce
commit 820b9d7ec5
2 changed files with 16 additions and 1 deletions

View file

@ -125,6 +125,8 @@ public class Context extends Object {
application_info.nativeLibraryDir = (new File(Environment.getExternalStorageDirectory(), "lib")).getAbsolutePath(); application_info.nativeLibraryDir = (new File(Environment.getExternalStorageDirectory(), "lib")).getAbsolutePath();
application_info.sourceDir = native_get_apk_path(); application_info.sourceDir = native_get_apk_path();
package_manager = new PackageManager(); package_manager = new PackageManager();
r.applyPackageQuirks(application_info.packageName);
} }
private static native String native_get_apk_path(); private static native String native_get_apk_path();

View file

@ -109,7 +109,7 @@ public class Resources {
/*package*/ final Object mAccessLock = new Object(); /*package*/ final Object mAccessLock = new Object();
/*package*/ final Configuration mTmpConfig = new Configuration(); /*package*/ final Configuration mTmpConfig = new Configuration();
/*package*/ TypedValue mTmpValue = new TypedValue(); /*package*/ TypedValue mTmpValue = new TypedValue();
/*package*/ final Map<Long,WeakReference<Drawable.ConstantState>> mDrawableCache = new HashMap<Long,WeakReference<Drawable.ConstantState>>(0); /*package*/ Object mDrawableCache = new HashMap<Long,WeakReference<Drawable.ConstantState>>(0);
private final ConfigurationBoundResourceCache<ComplexColor> mComplexColorCache = new ConfigurationBoundResourceCache<>(this); private final ConfigurationBoundResourceCache<ComplexColor> mComplexColorCache = new ConfigurationBoundResourceCache<>(this);
/*package*/ final LongSparseArray<WeakReference<Drawable.ConstantState>> mColorDrawableCache = new LongSparseArray<WeakReference<Drawable.ConstantState>>(0); /*package*/ final LongSparseArray<WeakReference<Drawable.ConstantState>> mColorDrawableCache = new LongSparseArray<WeakReference<Drawable.ConstantState>>(0);
/*package*/ boolean mPreloading; /*package*/ boolean mPreloading;
@ -213,6 +213,19 @@ public class Resources {
// assets.ensureStringBlocks(); // assets.ensureStringBlocks();
} }
public void applyPackageQuirks(String packageName) {
// F-Droid expects mDrawableCache to be a ThemedResourceCache while most other apps expect a Map
if ("org.fdroid.fdroid".equals(packageName)) {
mDrawableCache = new ThemedResourceCache<Drawable>() {
@Override
protected boolean shouldInvalidateEntry(Drawable entry, int configChanges) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'shouldInvalidateEntry'");
}
};
}
}
/** /**
* Return a global shared Resources object that provides access to only * Return a global shared Resources object that provides access to only
* system resources (no application resources), and is not configured for * system resources (no application resources), and is not configured for