facebook / fresco

An Android library for managing images and the memory they use.
https://frescolib.org/
MIT License
17.07k stars 3.75k forks source link

Cannot load Adaptive Icons (ProgressiveDecoder: unknown image format) #2173

Open bamsbamx opened 6 years ago

bamsbamx commented 6 years ago

Description

Trying to load the URI identifier for installed applications icons fails for some apps (system and non-system) and throws some logs:

D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.sonymobile.synchub/2131427328, firstEncodedBytes: 03000800840100000100, length: 388} D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.google.android.calendar/2130903042, firstEncodedBytes: 03000800480200000100, length: 584} D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.android.chrome/2131231050, firstEncodedBytes: 03000800540100000100, length: 340} D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.sonyericsson.organizer/2130903043, firstEncodedBytes: 03000800C80100000100, length: 456} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.google.android.apps.docs.editors.docs/2130838355, firstEncodedBytes: 030008008C0200000100, length: 652} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.google.android.apps.docs/2130837900, firstEncodedBytes: 03000800280200000100, length: 552} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.sonymobile.email/2130903040, firstEncodedBytes: 03000800280200000100, length: 552} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://flar2.exkernelmanager/2131558401, firstEncodedBytes: 03000800F40100000100, length: 500} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.google.android.inputmethod.latin/2130903043, firstEncodedBytes: 03000800280200000100, length: 552} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.google.android.gm/2130903042, firstEncodedBytes: 03000800280200000100, length: 552} D/skia: --- SkAndroidCodec::NewFromStream returned null D/skia: --- SkAndroidCodec::NewFromStream returned null W/unknown:ProgressiveDecoder: unknown image format, {uri: android.resource://com.google.android.googlequicksearchbox/2130903051, firstEncodedBytes: 03000800C80100000100, length: 456}

As seen in logs, it fails for applications like Chrome Browser, Docs, GMail, Google Calendar or even System keyboard

Reproduction

Just retrieve ApplicationInfo to access ApplicationInfo.icon class field, then parse the URI for such icon identifier and try to load:

LOADER

List<ApplicationInfo> appInfos = mPackageManager.getInstalledApplications(0);

LIST(RECYCLER)VIEW ADAPTER

ApplicationInfo info = appInfos.get(position);
if (info.icon != 0) {
    Uri uri = Uri.parse("android.resource://" + packageName + "/" + info.icon);
    holder.appIconSimpleDraweeView.setImageURI(uri);
}

Additional Information

    • Sony Xperia X Compact : Android Oreo 8.0.0
    • Samsung Galaxy S8 : Android Oreo 8.0.0
lambdapioneer commented 6 years ago

I'd guess that these would be XML resources which Fresco isn't able to process.

Can you dump the content of those URIs into files and provide them here?

bamsbamx commented 6 years ago

You may be right, the problem may come from being an XML file (the new Android Adaptive icons and, thus, returning an AdaptiveDrawable), but I cannot dump the URI contents right now.

However, loading them with Glide library (Picasso didnt work either) has been successful, by simply using

Glide.with(mContext).load(app.iconUri).into(holder.appIconImgView);

lambdapioneer commented 6 years ago

Thanks for the details @bamsbamx :) I've updated the issue's title to reflect this

If it works with Glide, I feel that we should be able to pull that off as well. However, this is probably low on our internal priority list which is why I'll mark this as help-wanted and starter-task.

In case you're interested: We always welcome pull-requests and have documentation on how to get started http://frescolib.org/docs/building-from-source.html

oprisnik commented 6 years ago

Fresco also supports custom decoder, so you can just add a custom decoder that handles the image properly (http://frescolib.org/docs/customizing-image-formats.html). Then, you don't need to build from source but just experiment with a custom decoder in your app and make it work. And as Daniel mentioned, pull requests are welcome.

fushenghua commented 6 years ago

good @oprisnik