Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3234afda authored by Jernej Virag's avatar Jernej Virag Committed by Automerger Merge Worker
Browse files

Merge "Prevent loading of Icon resources from the wrong package" into tm-dev...

Merge "Prevent loading of Icon resources from the wrong package" into tm-dev am: e1e8b1b9 am: c4ebf2ba

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19601344



Change-Id: Ibfc955f61506dc3e4aad8e7b19eeb9b8a91e77dc
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4cce97fd c4ebf2ba
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.graphics.ImageDecoder;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.util.Size;

@@ -108,6 +109,12 @@ public class LocalImageResolver {
                }
                break;
            case Icon.TYPE_RESOURCE:
                if (!(TextUtils.isEmpty(icon.getResPackage())
                        || context.getPackageName().equals(icon.getResPackage()))) {
                    // We can't properly resolve icons from other packages here, so fall back.
                    return icon.loadDrawable(context);
                }

                Drawable result = resolveImage(icon.getResId(), context, maxWidth, maxHeight);
                if (result != null) {
                    return tintDrawable(icon, result);
+9 −0
Original line number Diff line number Diff line
@@ -270,4 +270,13 @@ public class LocalImageResolverTest {
        assertThat(bd.getBitmap().getHeight()).isEqualTo(originalHeight);

    }

    @Test
    public void resolveImage_iconWithOtherPackageResource_usesPackageContextDefinition()
            throws IOException {
        Icon icon = Icon.createWithResource("this_is_invalid", R.drawable.test32x24);
        Drawable d = LocalImageResolver.resolveImage(icon, mContext);
        // This drawable must not be loaded - if it was, the code ignored the package specification.
        assertThat(d).isNull();
    }
}