package coil.map;

import S4.p;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import coil.request.Options;
import java.util.List;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes.dex */
public final class ResourceUriMapper implements Mapper<Uri, Uri> {
    private final boolean isApplicable(Uri uri) {
        String authority;
        return o.c(uri.getScheme(), "android.resource") && (authority = uri.getAuthority()) != null && !p.Q0(authority) && uri.getPathSegments().size() == 2;
    }

    @Override // coil.map.Mapper
    public Uri map(Uri uri, Options options) throws PackageManager.NameNotFoundException {
        if (!isApplicable(uri)) {
            return null;
        }
        String authority = uri.getAuthority();
        if (authority == null) {
            authority = "";
        }
        Resources resourcesForApplication = options.getContext().getPackageManager().getResourcesForApplication(authority);
        List<String> pathSegments = uri.getPathSegments();
        int identifier = resourcesForApplication.getIdentifier(pathSegments.get(1), pathSegments.get(0), authority);
        if (identifier == 0) {
            throw new IllegalStateException(("Invalid android.resource URI: " + uri).toString());
        }
        return Uri.parse("android.resource://" + authority + '/' + identifier);
    }
}
