Skip to content

Commit b57ef34

Browse files
SUPERCILEXsjudd
authored andcommittedOct 5, 2018
Support loading resources from dynamic modules (#3308)
* Support loading resources from dynamic modules * Try creating child context first before defaulting to parent * Fix small nit Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent 00bae3a commit b57ef34

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
 

‎library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,27 @@ public Resource<Drawable> decode(@NonNull Uri source, int width, int height,
4747
@NonNull Options options) {
4848
@DrawableRes int resId = loadResourceIdFromUri(source);
4949
String packageName = source.getAuthority();
50-
Context targetContext = packageName.equals(context.getPackageName())
51-
? context : getContextForPackage(source, packageName);
50+
Context targetContext = findContextForPackage(source, packageName);
5251
// We can't get a theme from another application.
5352
Drawable drawable = DrawableDecoderCompat.getDrawable(context, targetContext, resId);
5453
return NonOwnedDrawableResource.newInstance(drawable);
5554
}
5655

5756
@NonNull
58-
private Context getContextForPackage(Uri source, String packageName) {
57+
private Context findContextForPackage(Uri source, String packageName) {
58+
// Fast path
59+
if (packageName.equals(context.getPackageName())) {
60+
return context;
61+
}
62+
5963
try {
6064
return context.createPackageContext(packageName, /*flags=*/ 0);
6165
} catch (NameNotFoundException e) {
66+
// The parent APK holds the correct context if the resource is located in a split
67+
if (packageName.contains(context.getPackageName())) {
68+
return context;
69+
}
70+
6271
throw new IllegalArgumentException(
6372
"Failed to obtain context or unrecognized Uri format for: " + source, e);
6473
}

0 commit comments

Comments
 (0)
Please sign in to comment.