package m4;

import I2.C0317a;
import I2.C0325i;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
import k4.AbstractC2384C;
import k4.AbstractC2399l;
import k4.AbstractC2400m;
import k4.C2394g;
import k4.C2401n;

/* JADX INFO: renamed from: m4.f0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC2504f0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final Logger f20995a = Logger.getLogger(AbstractC2504f0.class.getName());

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Set f20996b = Collections.unmodifiableSet(EnumSet.of(k4.q0.OK, k4.q0.INVALID_ARGUMENT, k4.q0.NOT_FOUND, k4.q0.ALREADY_EXISTS, k4.q0.FAILED_PRECONDITION, k4.q0.ABORTED, k4.q0.OUT_OF_RANGE, k4.q0.DATA_LOSS));

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final k4.b0 f20997c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final k4.b0 f20998d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final k4.e0 f20999e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final k4.b0 f21000f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final k4.e0 f21001g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final k4.b0 f21002h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final k4.b0 f21003i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final k4.b0 f21004j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final k4.b0 f21005k;
    public static final long l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final C2549u1 f21006m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public static final C0317a f21007n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public static final C2495c0 f21008o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final i2 f21009p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final i2 f21010q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final C2498d0 f21011r;

    static {
        Charset.forName("US-ASCII");
        f20997c = new k4.b0("grpc-timeout", new i2(11));
        C2401n c2401n = k4.g0.f19867d;
        f20998d = new k4.b0("grpc-encoding", c2401n);
        f20999e = k4.K.a("grpc-accept-encoding", new i2(10));
        f21000f = new k4.b0("content-encoding", c2401n);
        f21001g = k4.K.a("accept-encoding", new i2(10));
        f21002h = new k4.b0("content-length", c2401n);
        f21003i = new k4.b0("content-type", c2401n);
        f21004j = new k4.b0("te", c2401n);
        f21005k = new k4.b0("user-agent", c2401n);
        E3.e.f1142c.getClass();
        TimeUnit timeUnit = TimeUnit.SECONDS;
        l = timeUnit.toNanos(20L);
        TimeUnit.HOURS.toNanos(2L);
        timeUnit.toNanos(20L);
        f21006m = new C2549u1();
        f21007n = new C0317a("io.grpc.internal.CALL_OPTIONS_RPC_OWNED_BY_BALANCER", 5);
        f21008o = new C2495c0();
        f21009p = new i2(8);
        f21010q = new i2(9);
        f21011r = new C2498d0(0);
    }

    public static URI a(String str) {
        String str2;
        A4.g.o(str, "authority");
        try {
            str2 = str;
            try {
                return new URI(null, str2, null, null, null);
            } catch (URISyntaxException e6) {
                e = e6;
                throw new IllegalArgumentException("Invalid authority: ".concat(str2), e);
            }
        } catch (URISyntaxException e7) {
            e = e7;
            str2 = str;
        }
    }

    public static void b(Closeable closeable) {
        try {
            closeable.close();
        } catch (IOException e6) {
            f20995a.log(Level.WARNING, "exception caught in closeQuietly", (Throwable) e6);
        }
    }

    public static AbstractC2400m[] c(C2394g c2394g, k4.g0 g0Var, int i6, boolean z6) {
        List list = c2394g.f19862e;
        int size = list.size();
        AbstractC2400m[] abstractC2400mArr = new AbstractC2400m[size + 1];
        C2394g c2394g2 = C2394g.f19857i;
        C0325i c0325i = new C0325i(c2394g, i6, z6);
        for (int i7 = 0; i7 < list.size(); i7++) {
            abstractC2400mArr[i7] = ((AbstractC2399l) list.get(i7)).a(c0325i, g0Var);
        }
        abstractC2400mArr[size] = f21008o;
        return abstractC2400mArr;
    }

    public static String d(InetSocketAddress inetSocketAddress) {
        try {
            return (String) InetSocketAddress.class.getMethod("getHostString", new Class[0]).invoke(inetSocketAddress, new Object[0]);
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return inetSocketAddress.getHostName();
        }
    }

    public static J3.D e(String str) {
        Boolean bool = Boolean.TRUE;
        String.format(Locale.ROOT, str, 0);
        return new J3.D(Executors.defaultThreadFactory(), str, new AtomicLong(0L), bool);
    }

    public static InterfaceC2556x f(k4.O o6, boolean z6) {
        C2537q0 c2537q0;
        AbstractC2384C abstractC2384C = o6.f19819a;
        if (abstractC2384C == null) {
            c2537q0 = null;
        } else {
            C2548u0 c2548u0 = (C2548u0) abstractC2384C.j();
            c2537q0 = c2548u0.f21192v;
            if (c2537q0 == null) {
                c2548u0.f21182k.execute(new RunnableC2525m0(c2548u0, 1));
                c2537q0 = null;
            }
        }
        if (c2537q0 != null) {
            t4.r rVar = o6.f19820b;
            return rVar == null ? c2537q0 : new Y(rVar, c2537q0);
        }
        k4.r0 r0Var = o6.f19821c;
        if (!r0Var.e()) {
            if (o6.f19822d) {
                return new Y(h(r0Var), EnumC2550v.f21203c);
            }
            if (!z6) {
                return new Y(h(r0Var), EnumC2550v.f21201a);
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0029  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0035  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static k4.r0 g(int i6) {
        k4.q0 q0Var;
        if ((i6 < 100 || i6 >= 200) && i6 != 400) {
            if (i6 == 401) {
                q0Var = k4.q0.UNAUTHENTICATED;
            } else if (i6 == 403) {
                q0Var = k4.q0.PERMISSION_DENIED;
            } else if (i6 == 404) {
                q0Var = k4.q0.UNIMPLEMENTED;
            } else if (i6 == 429) {
                q0Var = k4.q0.UNAVAILABLE;
            } else if (i6 != 431) {
                switch (i6) {
                    case 502:
                    case 503:
                    case 504:
                        break;
                    default:
                        q0Var = k4.q0.UNKNOWN;
                        break;
                }
            } else {
                q0Var = k4.q0.INTERNAL;
            }
        }
        return q0Var.a().g("HTTP status code " + i6);
    }

    public static k4.r0 h(k4.r0 r0Var) {
        A4.g.k(r0Var != null);
        if (!f20996b.contains(r0Var.f19949a)) {
            return r0Var;
        }
        return k4.r0.f19945m.g("Inappropriate status code from control plane: " + r0Var.f19949a + " " + r0Var.f19950b).f(r0Var.f19951c);
    }
}
