APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:Cairo Prices Helper
版本号:1.12.0
包名称:com.sa3dy.cairometrohelper

MD5 校验值:fcd6d9842512eca2b9815c1e5f441ae3

反编译源代码说明

i.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package c6;

import a6.b0;
import a6.c0;
import a6.d0;
import a6.h1;
import a6.j0;
import a6.j1;
import a6.y0;
import a6.z0;
import c6.b;
import c6.f;
import c6.h;
import c6.j;
import c6.q;
import e6.b;
import f6.a;
import f6.b;
import io.grpc.internal.c1;
import io.grpc.internal.d2;
import io.grpc.internal.i2;
import io.grpc.internal.k1;
import io.grpc.internal.o2;
import io.grpc.internal.q0;
import io.grpc.internal.r;
import io.grpc.internal.r0;
import io.grpc.internal.s;
import io.grpc.internal.v;
import io.grpc.internal.v0;
import io.grpc.internal.w0;
import java.io.EOFException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
import java.util.Collections;
import java.util.Deque;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class i implements v, b.a, q.d {
    private static final Map<e6.a, j1> W = Q();
    private static final Logger X = Logger.getLogger(i.class.getName());
    private final SocketFactory A;
    private SSLSocketFactory B;
    private HostnameVerifier C;
    private Socket D;
    private int E;
    private final Deque<h> F;
    private final d6.b G;
    private c1 H;
    private boolean I;
    private long J;
    private long K;
    private boolean L;
    private final Runnable M;
    private final int N;
    private final boolean O;
    private final o2 P;
    private final w0<h> Q;
    private d0.b R;
    final c0 S;
    int T;
    Runnable U;
    f2.e<Void> V;

    private final InetSocketAddress f1767a;

    private final String f1768b;

    private final String f1769c;

    private final Random f1770d;

    private final a2.o<a2.m> f1771e;

    private final int f1772f;

    private final e6.j f1773g;

    private k1.a f1774h;

    private c6.b f1775i;

    private q f1776j;

    private final Object f1777k;

    private final j0 f1778l;

    private int f1779m;

    private final Map<Integer, h> f1780n;

    private final Executor f1781o;

    private final d2 f1782p;

    private final ScheduledExecutorService f1783q;

    private final int f1784r;

    private int f1785s;

    private e f1786t;

    private a6.a f1787u;

    private j1 f1788v;

    private boolean f1789w;

    private v0 f1790x;

    private boolean f1791y;

    private boolean f1792z;

    class a extends w0<h> {
        a() {
        }

        @Override
        protected void b() {
            i.this.f1774h.c(true);
        }

        @Override
        protected void c() {
            i.this.f1774h.c(false);
        }
    }

    public class b implements o2.c {
        b() {
        }
    }

    class c implements Runnable {

        final CountDownLatch f1795l;

        final c6.a f1796m;

        class a implements i7.n {
            a() {
            }

            @Override
            public long P(i7.c cVar, long j7) {
                return -1L;
            }

            @Override
            public void close() {
            }
        }

        c(CountDownLatch countDownLatch, c6.a aVar) {
            this.f1795l = countDownLatch;
            this.f1796m = aVar;
        }

        @Override
        public void run() {
            i iVar;
            e eVar;
            Socket S;
            try {
                this.f1795l.await();
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
            i7.e b8 = i7.g.b(new a());
            SSLSession sSLSession = null;
            try {
                try {
                    i iVar2 = i.this;
                    c0 c0Var = iVar2.S;
                    if (c0Var == null) {
                        S = iVar2.A.createSocket(i.this.f1767a.getAddress(), i.this.f1767a.getPort());
                    } else {
                        if (!(c0Var.b() instanceof InetSocketAddress)) {
                            throw j1.f291t.q("Unsupported SocketAddress implementation " + i.this.S.b().getClass()).c();
                        }
                        i iVar3 = i.this;
                        S = iVar3.S(iVar3.S.c(), (InetSocketAddress) i.this.S.b(), i.this.S.d(), i.this.S.a());
                    }
                    Socket socket = S;
                    Socket socket2 = socket;
                    if (i.this.B != null) {
                        SSLSocket b9 = n.b(i.this.B, i.this.C, socket, i.this.W(), i.this.X(), i.this.G);
                        sSLSession = b9.getSession();
                        socket2 = b9;
                    }
                    socket2.setTcpNoDelay(true);
                    i7.e b10 = i7.g.b(i7.g.g(socket2));
                    this.f1796m.R(i7.g.e(socket2), socket2);
                    i iVar4 = i.this;
                    iVar4.f1787u = iVar4.f1787u.d().d(b0.f185a, socket2.getRemoteSocketAddress()).d(b0.f186b, socket2.getLocalSocketAddress()).d(b0.f187c, sSLSession).d(q0.f16179a, sSLSession == null ? h1.NONE : h1.PRIVACY_AND_INTEGRITY).a();
                    i iVar5 = i.this;
                    iVar5.f1786t = new e(iVar5.f1773g.a(b10, true));
                    synchronized (i.this.f1777k) {
                        i.this.D = (Socket) a2.k.o(socket2, "socket");
                        if (sSLSession != null) {
                            i.this.R = new d0.b(new d0.c(sSLSession));
                        }
                    }
                } catch (a6.k1 e8) {
                    i.this.k0(0, e6.a.INTERNAL_ERROR, e8.a());
                    iVar = i.this;
                    eVar = new e(iVar.f1773g.a(b8, true));
                    iVar.f1786t = eVar;
                } catch (Exception e9) {
                    i.this.d(e9);
                    iVar = i.this;
                    eVar = new e(iVar.f1773g.a(b8, true));
                    iVar.f1786t = eVar;
                }
            } catch (Throwable th) {
                i iVar6 = i.this;
                iVar6.f1786t = new e(iVar6.f1773g.a(b8, true));
                throw th;
            }
        }
    }

    class d implements Runnable {
        d() {
        }

        @Override
        public void run() {
            Runnable runnable = i.this.U;
            if (runnable != null) {
                runnable.run();
            }
            i.this.f1781o.execute(i.this.f1786t);
            synchronized (i.this.f1777k) {
                i.this.E = Integer.MAX_VALUE;
                i.this.l0();
            }
            f2.e<Void> eVar = i.this.V;
        }
    }

    class e implements b.a, Runnable {

        e6.b f1801m;

        private final j f1800l = new j(Level.FINE, (Class<?>) i.class);

        boolean f1802n = true;

        e(e6.b bVar) {
            this.f1801m = bVar;
        }

        private int a(List<e6.d> list) {
            long j7 = 0;
            for (int i8 = 0; i8 < list.size(); i8++) {
                e6.d dVar = list.get(i8);
                j7 += dVar.f14226a.z() + 32 + dVar.f14227b.z();
            }
            return (int) Math.min(j7, 2147483647L);
        }

        @Override
        public void e(boolean z7, int i8, int i9) {
            v0 v0Var;
            long j7 = (i8 << 32) | (i9 & 4294967295L);
            this.f1800l.e(j.a.INBOUND, j7);
            if (!z7) {
                synchronized (i.this.f1777k) {
                    i.this.f1775i.e(true, i8, i9);
                }
                return;
            }
            synchronized (i.this.f1777k) {
                v0Var = null;
                if (i.this.f1790x == null) {
                    i.X.warning("Received unexpected ping ack. No ping outstanding");
                } else if (i.this.f1790x.h() == j7) {
                    v0 v0Var2 = i.this.f1790x;
                    i.this.f1790x = null;
                    v0Var = v0Var2;
                } else {
                    i.X.log(Level.WARNING, String.format(Locale.US, "Received unexpected ping ack. Expecting %d, got %d", Long.valueOf(i.this.f1790x.h()), Long.valueOf(j7)));
                }
            }
            if (v0Var != null) {
                v0Var.d();
            }
        }

        @Override
        public void f(int i8, e6.a aVar) {
            this.f1800l.h(j.a.INBOUND, i8, aVar);
            j1 e8 = i.p0(aVar).e("Rst Stream");
            boolean z7 = e8.m() == j1.b.CANCELLED || e8.m() == j1.b.DEADLINE_EXCEEDED;
            synchronized (i.this.f1777k) {
                h hVar = (h) i.this.f1780n.get(Integer.valueOf(i8));
                if (hVar != null) {
                    j6.c.c("OkHttpClientTransport$ClientFrameHandler.rstStream", hVar.t().h0());
                    i.this.U(i8, e8, aVar == e6.a.REFUSED_STREAM ? r.a.REFUSED : r.a.PROCESSED, z7, null, null);
                }
            }
        }

        @Override
        public void g(int i8, long j7) {
            this.f1800l.k(j.a.INBOUND, i8, j7);
            if (j7 == 0) {
                if (i8 == 0) {
                    i.this.f0(e6.a.PROTOCOL_ERROR, "Received 0 flow control window increment.");
                    return;
                } else {
                    i.this.U(i8, j1.f291t.q("Received 0 flow control window increment."), r.a.PROCESSED, false, e6.a.PROTOCOL_ERROR, null);
                    return;
                }
            }
            boolean z7 = false;
            synchronized (i.this.f1777k) {
                if (i8 == 0) {
                    i.this.f1776j.g(null, (int) j7);
                    return;
                }
                h hVar = (h) i.this.f1780n.get(Integer.valueOf(i8));
                if (hVar != null) {
                    i.this.f1776j.g(hVar.t().b0(), (int) j7);
                } else if (!i.this.c0(i8)) {
                    z7 = true;
                }
                if (z7) {
                    i.this.f0(e6.a.PROTOCOL_ERROR, "Received window_update for unknown stream: " + i8);
                }
            }
        }

        @Override
        public void h(boolean z7, boolean z8, int i8, int i9, List<e6.d> list, e6.e eVar) {
            j1 j1Var;
            int a8;
            this.f1800l.d(j.a.INBOUND, i8, list, z8);
            boolean z9 = true;
            if (i.this.N == Integer.MAX_VALUE || (a8 = a(list)) <= i.this.N) {
                j1Var = null;
            } else {
                j1 j1Var2 = j1.f286o;
                Locale locale = Locale.US;
                Object[] objArr = new Object[3];
                objArr[0] = z8 ? "trailer" : "header";
                objArr[1] = Integer.valueOf(i.this.N);
                objArr[2] = Integer.valueOf(a8);
                j1Var = j1Var2.q(String.format(locale, "Response %s metadata larger than %d: %d", objArr));
            }
            synchronized (i.this.f1777k) {
                h hVar = (h) i.this.f1780n.get(Integer.valueOf(i8));
                if (hVar == null) {
                    if (i.this.c0(i8)) {
                        i.this.f1775i.f(i8, e6.a.STREAM_CLOSED);
                    }
                } else if (j1Var == null) {
                    j6.c.c("OkHttpClientTransport$ClientFrameHandler.headers", hVar.t().h0());
                    hVar.t().j0(list, z8);
                } else {
                    if (!z8) {
                        i.this.f1775i.f(i8, e6.a.CANCEL);
                    }
                    hVar.t().N(j1Var, false, new y0());
                }
                z9 = false;
            }
            if (z9) {
                i.this.f0(e6.a.PROTOCOL_ERROR, "Received header for unknown stream: " + i8);
            }
        }

        @Override
        public void i(boolean z7, e6.i iVar) {
            boolean z8;
            this.f1800l.i(j.a.INBOUND, iVar);
            synchronized (i.this.f1777k) {
                if (m.b(iVar, 4)) {
                    i.this.E = m.a(iVar, 4);
                }
                if (m.b(iVar, 7)) {
                    z8 = i.this.f1776j.f(m.a(iVar, 7));
                } else {
                    z8 = false;
                }
                if (this.f1802n) {
                    i.this.f1774h.d();
                    this.f1802n = false;
                }
                i.this.f1775i.B(iVar);
                if (z8) {
                    i.this.f1776j.h();
                }
                i.this.l0();
            }
        }

        @Override
        public void j() {
        }

        @Override
        public void k(boolean z7, int i8, i7.e eVar, int i9) {
            this.f1800l.b(j.a.INBOUND, i8, eVar.C(), i9, z7);
            h Z = i.this.Z(i8);
            if (Z != null) {
                long j7 = i9;
                eVar.f0(j7);
                i7.c cVar = new i7.c();
                cVar.l(eVar.C(), j7);
                j6.c.c("OkHttpClientTransport$ClientFrameHandler.data", Z.t().h0());
                synchronized (i.this.f1777k) {
                    Z.t().i0(cVar, z7);
                }
            } else {
                if (!i.this.c0(i8)) {
                    i.this.f0(e6.a.PROTOCOL_ERROR, "Received data for unknown stream: " + i8);
                    return;
                }
                synchronized (i.this.f1777k) {
                    i.this.f1775i.f(i8, e6.a.STREAM_CLOSED);
                }
                eVar.o(i9);
            }
            i.D(i.this, i9);
            if (i.this.f1785s >= i.this.f1772f * 0.5f) {
                synchronized (i.this.f1777k) {
                    i.this.f1775i.g(0, i.this.f1785s);
                }
                i.this.f1785s = 0;
            }
        }

        @Override
        public void l(int i8, e6.a aVar, i7.f fVar) {
            this.f1800l.c(j.a.INBOUND, i8, aVar, fVar);
            if (aVar == e6.a.ENHANCE_YOUR_CALM) {
                String E = fVar.E();
                i.X.log(Level.WARNING, String.format("%s: Received GOAWAY with ENHANCE_YOUR_CALM. Debug data: %s", this, E));
                if ("too_many_pings".equals(E)) {
                    i.this.M.run();
                }
            }
            j1 e8 = r0.h.s(aVar.f14216l).e("Received Goaway");
            if (fVar.z() > 0) {
                e8 = e8.e(fVar.E());
            }
            i.this.k0(i8, null, e8);
        }

        @Override
        public void m(int i8, int i9, int i10, boolean z7) {
        }

        @Override
        public void n(int i8, int i9, List<e6.d> list) {
            this.f1800l.g(j.a.INBOUND, i8, i9, list);
            synchronized (i.this.f1777k) {
                i.this.f1775i.f(i8, e6.a.PROTOCOL_ERROR);
            }
        }

        @Override
        public void run() {
            j1 j1Var;
            String name = Thread.currentThread().getName();
            Thread.currentThread().setName("OkHttpClientTransport");
            while (this.f1801m.m0(this)) {
                try {
                    if (i.this.H != null) {
                        i.this.H.m();
                    }
                } catch (Throwable th) {
                    try {
                        i.this.k0(0, e6.a.PROTOCOL_ERROR, j1.f291t.q("error in frame handler").p(th));
                        try {
                            this.f1801m.close();
                        } catch (IOException e8) {
                            e = e8;
                            i.X.log(Level.INFO, "Exception closing frame reader", (Throwable) e);
                            i.this.f1774h.a();
                            Thread.currentThread().setName(name);
                        }
                    } catch (Throwable th2) {
                        try {
                            this.f1801m.close();
                        } catch (IOException e9) {
                            i.X.log(Level.INFO, "Exception closing frame reader", (Throwable) e9);
                        }
                        i.this.f1774h.a();
                        Thread.currentThread().setName(name);
                        throw th2;
                    }
                }
            }
            synchronized (i.this.f1777k) {
                j1Var = i.this.f1788v;
            }
            if (j1Var == null) {
                j1Var = j1.f292u.q("End of stream or IOException");
            }
            i.this.k0(0, e6.a.INTERNAL_ERROR, j1Var);
            try {
                this.f1801m.close();
            } catch (IOException e10) {
                e = e10;
                i.X.log(Level.INFO, "Exception closing frame reader", (Throwable) e);
                i.this.f1774h.a();
                Thread.currentThread().setName(name);
            }
            i.this.f1774h.a();
            Thread.currentThread().setName(name);
        }
    }

    private i(f.C0053f c0053f, InetSocketAddress inetSocketAddress, String str, String str2, a6.a aVar, a2.o<a2.m> oVar, e6.j jVar, c0 c0Var, Runnable runnable) {
        this.f1770d = new Random();
        this.f1777k = new Object();
        this.f1780n = new HashMap();
        this.E = 0;
        this.F = new LinkedList();
        this.Q = new a();
        this.T = 30000;
        this.f1767a = (InetSocketAddress) a2.k.o(inetSocketAddress, "address");
        this.f1768b = str;
        this.f1784r = c0053f.f1747u;
        this.f1772f = c0053f.f1752z;
        this.f1781o = (Executor) a2.k.o(c0053f.f1739m, "executor");
        this.f1782p = new d2(c0053f.f1739m);
        this.f1783q = (ScheduledExecutorService) a2.k.o(c0053f.f1741o, "scheduledExecutorService");
        this.f1779m = 3;
        SocketFactory socketFactory = c0053f.f1743q;
        this.A = socketFactory == null ? SocketFactory.getDefault() : socketFactory;
        this.B = c0053f.f1744r;
        this.C = c0053f.f1745s;
        this.G = (d6.b) a2.k.o(c0053f.f1746t, "connectionSpec");
        this.f1771e = (a2.o) a2.k.o(oVar, "stopwatchFactory");
        this.f1773g = (e6.j) a2.k.o(jVar, "variant");
        this.f1769c = r0.g("okhttp", str2);
        this.S = c0Var;
        this.M = (Runnable) a2.k.o(runnable, "tooManyPingsRunnable");
        this.N = c0053f.B;
        this.P = c0053f.f1742p.a();
        this.f1778l = j0.a(getClass(), inetSocketAddress.toString());
        this.f1787u = a6.a.c().d(q0.f16180b, aVar).a();
        this.O = c0053f.C;
        a0();
    }

    public i(f.C0053f c0053f, InetSocketAddress inetSocketAddress, String str, String str2, a6.a aVar, c0 c0Var, Runnable runnable) {
        this(c0053f, inetSocketAddress, str, str2, aVar, r0.f16219w, new e6.g(), c0Var, runnable);
    }

    static int D(i iVar, int i8) {
        int i9 = iVar.f1785s + i8;
        iVar.f1785s = i9;
        return i9;
    }

    private static Map<e6.a, j1> Q() {
        EnumMap enumMap = new EnumMap(e6.a.class);
        e6.a aVar = e6.a.NO_ERROR;
        j1 j1Var = j1.f291t;
        enumMap.put((EnumMap) aVar, (e6.a) j1Var.q("No error: A GRPC status of OK should have been sent"));
        enumMap.put((EnumMap) e6.a.PROTOCOL_ERROR, (e6.a) j1Var.q("Protocol error"));
        enumMap.put((EnumMap) e6.a.INTERNAL_ERROR, (e6.a) j1Var.q("Internal error"));
        enumMap.put((EnumMap) e6.a.FLOW_CONTROL_ERROR, (e6.a) j1Var.q("Flow control error"));
        enumMap.put((EnumMap) e6.a.STREAM_CLOSED, (e6.a) j1Var.q("Stream closed"));
        enumMap.put((EnumMap) e6.a.FRAME_TOO_LARGE, (e6.a) j1Var.q("Frame too large"));
        enumMap.put((EnumMap) e6.a.REFUSED_STREAM, (e6.a) j1.f292u.q("Refused stream"));
        enumMap.put((EnumMap) e6.a.CANCEL, (e6.a) j1.f278g.q("Cancelled"));
        enumMap.put((EnumMap) e6.a.COMPRESSION_ERROR, (e6.a) j1Var.q("Compression error"));
        enumMap.put((EnumMap) e6.a.CONNECT_ERROR, (e6.a) j1Var.q("Connect error"));
        enumMap.put((EnumMap) e6.a.ENHANCE_YOUR_CALM, (e6.a) j1.f286o.q("Enhance your calm"));
        enumMap.put((EnumMap) e6.a.INADEQUATE_SECURITY, (e6.a) j1.f284m.q("Inadequate security"));
        return Collections.unmodifiableMap(enumMap);
    }

    private f6.b R(InetSocketAddress inetSocketAddress, String str, String str2) {
        f6.a a8 = new a.b().k("https").h(inetSocketAddress.getHostName()).j(inetSocketAddress.getPort()).a();
        b.C0088b d8 = new b.C0088b().e(a8).d("Host", a8.c() + ":" + a8.f()).d("User-Agent", this.f1769c);
        if (str != null && str2 != null) {
            d8.d("Proxy-Authorization", d6.c.a(str, str2));
        }
        return d8.c();
    }

    public Socket S(InetSocketAddress inetSocketAddress, InetSocketAddress inetSocketAddress2, String str, String str2) {
        Socket socket = null;
        try {
            socket = inetSocketAddress2.getAddress() != null ? this.A.createSocket(inetSocketAddress2.getAddress(), inetSocketAddress2.getPort()) : this.A.createSocket(inetSocketAddress2.getHostName(), inetSocketAddress2.getPort());
            socket.setTcpNoDelay(true);
            socket.setSoTimeout(this.T);
            i7.n g8 = i7.g.g(socket);
            i7.d a8 = i7.g.a(i7.g.e(socket));
            f6.b R = R(inetSocketAddress, str, str2);
            f6.a b8 = R.b();
            a8.h0(String.format(Locale.US, "CONNECT %s:%d HTTP/1.1", b8.c(), Integer.valueOf(b8.f()))).h0("\r\n");
            int b9 = R.a().b();
            for (int i8 = 0; i8 < b9; i8++) {
                a8.h0(R.a().a(i8)).h0(": ").h0(R.a().c(i8)).h0("\r\n");
            }
            a8.h0("\r\n");
            a8.flush();
            d6.j a9 = d6.j.a(g0(g8));
            do {
            } while (!g0(g8).equals(""));
            int i9 = a9.f14047b;
            if (i9 >= 200 && i9 < 300) {
                socket.setSoTimeout(0);
                return socket;
            }
            i7.c cVar = new i7.c();
            try {
                socket.shutdownOutput();
                g8.P(cVar, 1024L);
            } catch (IOException e8) {
                cVar.h0("Unable to read body: " + e8.toString());
            }
            try {
                socket.close();
            } catch (IOException unused) {
            }
            throw j1.f292u.q(String.format(Locale.US, "Response returned from proxy was not successful (expected 2xx, got %d %s). Response body:\n%s", Integer.valueOf(a9.f14047b), a9.f14048c, cVar.v0())).c();
        } catch (IOException e9) {
            if (socket != null) {
                r0.e(socket);
            }
            throw j1.f292u.q("Failed trying to connect with proxy").p(e9).c();
        }
    }

    private Throwable Y() {
        synchronized (this.f1777k) {
            j1 j1Var = this.f1788v;
            if (j1Var != null) {
                return j1Var.c();
            }
            return j1.f292u.q("Connection closed").c();
        }
    }

    private void a0() {
        synchronized (this.f1777k) {
            this.P.g(new b());
        }
    }

    private void d0(h hVar) {
        if (this.f1792z && this.F.isEmpty() && this.f1780n.isEmpty()) {
            this.f1792z = false;
            c1 c1Var = this.H;
            if (c1Var != null) {
                c1Var.o();
            }
        }
        if (hVar.y()) {
            this.Q.e(hVar, false);
        }
    }

    public void f0(e6.a aVar, String str) {
        k0(0, aVar, p0(aVar).e(str));
    }

    private static String g0(i7.n nVar) {
        i7.c cVar = new i7.c();
        while (nVar.P(cVar, 1L) != -1) {
            if (cVar.n0(cVar.size() - 1) == 10) {
                return cVar.y0();
            }
        }
        throw new EOFException("\\n not found: " + cVar.s0().v());
    }

    private void i0() {
        synchronized (this.f1777k) {
            this.f1775i.F();
            e6.i iVar = new e6.i();
            m.c(iVar, 7, this.f1772f);
            this.f1775i.K(iVar);
            if (this.f1772f > 65535) {
                this.f1775i.g(0, r1 - 65535);
            }
        }
    }

    private void j0(h hVar) {
        if (!this.f1792z) {
            this.f1792z = true;
            c1 c1Var = this.H;
            if (c1Var != null) {
                c1Var.n();
            }
        }
        if (hVar.y()) {
            this.Q.e(hVar, true);
        }
    }

    public void k0(int i8, e6.a aVar, j1 j1Var) {
        synchronized (this.f1777k) {
            if (this.f1788v == null) {
                this.f1788v = j1Var;
                this.f1774h.b(j1Var);
            }
            if (aVar != null && !this.f1789w) {
                this.f1789w = true;
                this.f1775i.i(0, aVar, new byte[0]);
            }
            Iterator<Map.Entry<Integer, h>> it = this.f1780n.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Integer, h> next = it.next();
                if (next.getKey().intValue() > i8) {
                    it.remove();
                    next.getValue().t().M(j1Var, r.a.REFUSED, false, new y0());
                    d0(next.getValue());
                }
            }
            for (h hVar : this.F) {
                hVar.t().M(j1Var, r.a.MISCARRIED, true, new y0());
                d0(hVar);
            }
            this.F.clear();
            n0();
        }
    }

    public boolean l0() {
        boolean z7 = false;
        while (!this.F.isEmpty() && this.f1780n.size() < this.E) {
            m0(this.F.poll());
            z7 = true;
        }
        return z7;
    }

    private void m0(h hVar) {
        a2.k.u(hVar.t().c0() == -1, "StreamId already assigned");
        this.f1780n.put(Integer.valueOf(this.f1779m), hVar);
        j0(hVar);
        hVar.t().f0(this.f1779m);
        if ((hVar.M() != z0.d.UNARY && hVar.M() != z0.d.SERVER_STREAMING) || hVar.O()) {
            this.f1775i.flush();
        }
        int i8 = this.f1779m;
        if (i8 < 2147483645) {
            this.f1779m = i8 + 2;
        } else {
            this.f1779m = Integer.MAX_VALUE;
            k0(Integer.MAX_VALUE, e6.a.NO_ERROR, j1.f292u.q("Stream ids exhausted"));
        }
    }

    private void n0() {
        if (this.f1788v == null || !this.f1780n.isEmpty() || !this.F.isEmpty() || this.f1791y) {
            return;
        }
        this.f1791y = true;
        c1 c1Var = this.H;
        if (c1Var != null) {
            c1Var.q();
        }
        v0 v0Var = this.f1790x;
        if (v0Var != null) {
            v0Var.f(Y());
            this.f1790x = null;
        }
        if (!this.f1789w) {
            this.f1789w = true;
            this.f1775i.i(0, e6.a.NO_ERROR, new byte[0]);
        }
        this.f1775i.close();
    }

    static j1 p0(e6.a aVar) {
        j1 j1Var = W.get(aVar);
        if (j1Var != null) {
            return j1Var;
        }
        return j1.f279h.q("Unknown http2 error code: " + aVar.f14216l);
    }

    public void T(boolean z7, long j7, long j8, boolean z8) {
        this.I = z7;
        this.J = j7;
        this.K = j8;
        this.L = z8;
    }

    public void U(int i8, j1 j1Var, r.a aVar, boolean z7, e6.a aVar2, y0 y0Var) {
        synchronized (this.f1777k) {
            h remove = this.f1780n.remove(Integer.valueOf(i8));
            if (remove != null) {
                if (aVar2 != null) {
                    this.f1775i.f(i8, e6.a.CANCEL);
                }
                if (j1Var != null) {
                    h.b t7 = remove.t();
                    if (y0Var == null) {
                        y0Var = new y0();
                    }
                    t7.M(j1Var, aVar, z7, y0Var);
                }
                if (!l0()) {
                    n0();
                    d0(remove);
                }
            }
        }
    }

    public a6.a V() {
        return this.f1787u;
    }

    String W() {
        URI b8 = r0.b(this.f1768b);
        return b8.getHost() != null ? b8.getHost() : this.f1768b;
    }

    int X() {
        URI b8 = r0.b(this.f1768b);
        return b8.getPort() != -1 ? b8.getPort() : this.f1767a.getPort();
    }

    h Z(int i8) {
        h hVar;
        synchronized (this.f1777k) {
            hVar = this.f1780n.get(Integer.valueOf(i8));
        }
        return hVar;
    }

    @Override
    public q.c[] a() {
        q.c[] cVarArr;
        synchronized (this.f1777k) {
            cVarArr = new q.c[this.f1780n.size()];
            int i8 = 0;
            Iterator<h> it = this.f1780n.values().iterator();
            while (it.hasNext()) {
                cVarArr[i8] = it.next().t().b0();
                i8++;
            }
        }
        return cVarArr;
    }

    @Override
    public void b(j1 j1Var) {
        synchronized (this.f1777k) {
            if (this.f1788v != null) {
                return;
            }
            this.f1788v = j1Var;
            this.f1774h.b(j1Var);
            n0();
        }
    }

    public boolean b0() {
        return this.B == null;
    }

    @Override
    public Runnable c(k1.a aVar) {
        this.f1774h = (k1.a) a2.k.o(aVar, "listener");
        if (this.I) {
            c1 c1Var = new c1(new c1.c(this), this.f1783q, this.J, this.K, this.L);
            this.H = c1Var;
            c1Var.p();
        }
        c6.a X2 = c6.a.X(this.f1782p, this, 10000);
        e6.c U = X2.U(this.f1773g.b(i7.g.a(X2), true));
        synchronized (this.f1777k) {
            c6.b bVar = new c6.b(this, U);
            this.f1775i = bVar;
            this.f1776j = new q(this, bVar);
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        this.f1782p.execute(new c(countDownLatch, X2));
        try {
            i0();
            countDownLatch.countDown();
            this.f1782p.execute(new d());
            return null;
        } catch (Throwable th) {
            countDownLatch.countDown();
            throw th;
        }
    }

    boolean c0(int i8) {
        boolean z7;
        synchronized (this.f1777k) {
            z7 = true;
            if (i8 >= this.f1779m || (i8 & 1) != 1) {
                z7 = false;
            }
        }
        return z7;
    }

    @Override
    public void d(Throwable th) {
        a2.k.o(th, "failureCause");
        k0(0, e6.a.INTERNAL_ERROR, j1.f292u.p(th));
    }

    @Override
    public j0 e() {
        return this.f1778l;
    }

    @Override
    public h h(z0<?, ?> z0Var, y0 y0Var, a6.c cVar, a6.k[] kVarArr) {
        a2.k.o(z0Var, "method");
        a2.k.o(y0Var, "headers");
        i2 h8 = i2.h(kVarArr, V(), y0Var);
        synchronized (this.f1777k) {
            try {
                try {
                    return new h(z0Var, y0Var, this.f1775i, this, this.f1776j, this.f1777k, this.f1784r, this.f1772f, this.f1768b, this.f1769c, h8, this.P, cVar, this.O);
                } catch (Throwable th) {
                    th = th;
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
            }
        }
    }

    @Override
    public void f(j1 j1Var) {
        b(j1Var);
        synchronized (this.f1777k) {
            Iterator<Map.Entry<Integer, h>> it = this.f1780n.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Integer, h> next = it.next();
                it.remove();
                next.getValue().t().N(j1Var, false, new y0());
                d0(next.getValue());
            }
            for (h hVar : this.F) {
                hVar.t().M(j1Var, r.a.MISCARRIED, true, new y0());
                d0(hVar);
            }
            this.F.clear();
            n0();
        }
    }

    @Override
    public void g(s.a aVar, Executor executor) {
        long nextLong;
        synchronized (this.f1777k) {
            boolean z7 = true;
            a2.k.t(this.f1775i != null);
            if (this.f1791y) {
                v0.g(aVar, executor, Y());
                return;
            }
            v0 v0Var = this.f1790x;
            if (v0Var != null) {
                nextLong = 0;
                z7 = false;
            } else {
                nextLong = this.f1770d.nextLong();
                a2.m mVar = this.f1771e.get();
                mVar.g();
                v0 v0Var2 = new v0(nextLong, mVar);
                this.f1790x = v0Var2;
                this.P.b();
                v0Var = v0Var2;
            }
            if (z7) {
                this.f1775i.e(false, (int) (nextLong >>> 32), (int) nextLong);
            }
            v0Var.a(aVar, executor);
        }
    }

    public void h0(h hVar) {
        this.F.remove(hVar);
        d0(hVar);
    }

    public void o0(h hVar) {
        if (this.f1788v != null) {
            hVar.t().M(this.f1788v, r.a.MISCARRIED, true, new y0());
        } else if (this.f1780n.size() < this.E) {
            m0(hVar);
        } else {
            this.F.add(hVar);
            j0(hVar);
        }
    }

    public String toString() {
        return a2.f.b(this).c("logId", this.f1778l.d()).d("address", this.f1767a).toString();
    }
}