package coil.util;

import Z0.o;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import androidx.lifecycle.InterfaceC1113w;
import androidx.lifecycle.r;
import i.C2236c;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;
import x1.AbstractC3209a;
import y1.j;

/* JADX INFO: renamed from: coil.util.-Contexts, reason: invalid class name */
/* JADX INFO: loaded from: classes.dex */
public final class Contexts {
    public static final Drawable getDrawableCompat(Resources resources, int i6, Resources.Theme theme) {
        ThreadLocal threadLocal = j.f26164a;
        Drawable drawable = resources.getDrawable(i6, theme);
        if (drawable != null) {
            return drawable;
        }
        throw new IllegalStateException(o.l("Invalid resource ID: ", i6).toString());
    }

    public static final r getLifecycle(Context context) {
        Object baseContext = context;
        while (!(baseContext instanceof InterfaceC1113w)) {
            if (!(baseContext instanceof ContextWrapper)) {
                return null;
            }
            baseContext = ((ContextWrapper) baseContext).getBaseContext();
        }
        return ((InterfaceC1113w) baseContext).getLifecycle();
    }

    public static final Drawable getXmlDrawableCompat(Context context, Resources resources, int i6) throws XmlPullParserException, IOException {
        XmlResourceParser xml = resources.getXml(i6);
        int next = xml.next();
        while (next != 2 && next != 1) {
            next = xml.next();
        }
        if (next == 2) {
            return getDrawableCompat(resources, i6, context.getTheme());
        }
        throw new XmlPullParserException("No start tag found.");
    }

    public static final boolean isPermissionGranted(Context context, String str) {
        return AbstractC3209a.checkSelfPermission(context, str) == 0;
    }

    public static final <T> T requireSystemService(Context context) {
        kotlin.jvm.internal.o.m();
        throw null;
    }

    public static final Drawable getDrawableCompat(Context context, int i6) {
        Drawable drawableC = C2236c.a().c(context, i6);
        if (drawableC != null) {
            return drawableC;
        }
        throw new IllegalStateException(o.l("Invalid resource ID: ", i6).toString());
    }
}
