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

This commit is contained in:
Jernej Virag
2022-08-16 19:58:21 +00:00
committed by Android (Google) Code Review
2 changed files with 16 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import android.graphics.ImageDecoder;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.Size; import android.util.Size;
@@ -108,6 +109,12 @@ public class LocalImageResolver {
} }
break; break;
case Icon.TYPE_RESOURCE: 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); Drawable result = resolveImage(icon.getResId(), context, maxWidth, maxHeight);
if (result != null) { if (result != null) {
return tintDrawable(icon, result); return tintDrawable(icon, result);

View File

@@ -270,4 +270,13 @@ public class LocalImageResolverTest {
assertThat(bd.getBitmap().getHeight()).isEqualTo(originalHeight); 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();
}
} }