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

应用版本信息
应用名称:Ghostify
版本号:4.0
包名称:com.getghostify

MD5 校验值:a9a821418db4ad35214aeeb08c2f5902

反编译源代码说明

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


package m7;

import d7.o;
import d7.t;
import j4.d;
import j7.a;
import j7.a1;
import j7.b1;
import j7.d0;
import j7.q0;
import j7.y;
import j7.y0;
import j7.z;
import java.io.EOFException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Collections;
import java.util.Deque;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
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;
import l7.a3;
import l7.f1;
import l7.o0;
import l7.o2;
import l7.p0;
import l7.q2;
import l7.s;
import l7.t;
import l7.t0;
import l7.u0;
import l7.u2;
import l7.v0;
import l7.v1;
import l7.w;
import m7.b;
import m7.f;
import o7.b;
import o7.f;
import o8.p;
import o8.q;
import o8.r;
import o8.x;
import t2.q8;

public class g implements w, b.a {

    public static final Map<o7.a, a1> f7502a0;

    public static final Logger f7503b0;

    public static final f[] f7504c0;
    public int A;
    public e B;
    public j7.a C;
    public a1 D;
    public boolean E;
    public v0 F;
    public boolean G;
    public boolean H;
    public final SocketFactory I;
    public SSLSocketFactory J;
    public HostnameVerifier K;
    public int L;
    public final Deque<f> M;
    public final n7.a N;
    public ScheduledExecutorService O;
    public f1 P;
    public boolean Q;
    public long R;
    public long S;
    public boolean T;
    public final Runnable U;
    public final int V;
    public final boolean W;
    public final a3 X;
    public final q8 Y;
    public final y Z;

    public final InetSocketAddress f7505k;

    public final String f7506l;

    public final String f7507m;

    public final Random f7508n = new Random();

    public final j4.h<j4.g> f7509o;

    public final int f7510p;

    public v1.a f7511q;

    public m7.b f7512r;
    public m s;

    public final Object f7513t;
    public final d0 u;

    public int f7514v;

    public final Map<Integer, f> f7515w;

    public final Executor f7516x;

    public final o2 f7517y;

    public final int f7518z;

    public class a extends q8 {
        public a() {
        }

        @Override
        public void a() {
            g.this.f7511q.c(true);
        }

        @Override
        public void b() {
            g.this.f7511q.c(false);
        }
    }

    public class b implements Runnable {
        public b() {
        }

        @Override
        public void run() {
            Objects.requireNonNull(g.this);
            g gVar = g.this;
            Objects.requireNonNull(gVar);
            Objects.requireNonNull(g.this);
            gVar.B = new e(null, null);
            g gVar2 = g.this;
            gVar2.f7516x.execute(gVar2.B);
            synchronized (g.this.f7513t) {
                g gVar3 = g.this;
                gVar3.L = Integer.MAX_VALUE;
                gVar3.w();
            }
            Objects.requireNonNull(g.this);
            throw null;
        }
    }

    public class c implements Runnable {

        public final CountDownLatch f7521k;

        public final m7.a f7522l;

        public final o7.i f7523m;

        public class a implements o8.w {
            public a(c cVar) {
            }

            @Override
            public long G(o8.d dVar, long j9) {
                return -1L;
            }

            @Override
            public void close() {
            }

            @Override
            public x k() {
                return x.f8161d;
            }
        }

        public c(CountDownLatch countDownLatch, m7.a aVar, o7.i iVar) {
            this.f7521k = countDownLatch;
            this.f7522l = aVar;
            this.f7523m = iVar;
        }

        @Override
        public void run() {
            r rVar;
            g gVar;
            e eVar;
            Socket b9;
            Socket socket;
            try {
                this.f7521k.await();
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
            a aVar = new a(this);
            Logger logger = p.f8132a;
            r rVar2 = new r(aVar);
            SSLSession sSLSession = null;
            try {
                try {
                    g gVar2 = g.this;
                    y yVar = gVar2.Z;
                    if (yVar == null) {
                        b9 = gVar2.I.createSocket(gVar2.f7505k.getAddress(), g.this.f7505k.getPort());
                    } else {
                        SocketAddress socketAddress = yVar.f5921k;
                        if (socketAddress instanceof InetSocketAddress) {
                            b9 = g.b(gVar2, yVar.f5922l, (InetSocketAddress) socketAddress, yVar.f5923m, yVar.f5924n);
                        } else {
                            throw new b1(a1.f5729l.g("Unsupported SocketAddress implementation " + g.this.Z.f5921k.getClass()));
                        }
                    }
                    Socket socket2 = b9;
                    g gVar3 = g.this;
                    SSLSocketFactory sSLSocketFactory = gVar3.J;
                    socket = socket2;
                    if (sSLSocketFactory != null) {
                        SSLSocket a9 = k.a(sSLSocketFactory, gVar3.K, socket2, gVar3.j(), g.this.k(), g.this.N);
                        sSLSession = a9.getSession();
                        socket = a9;
                    }
                    socket.setTcpNoDelay(true);
                    rVar = new r(p.c(socket));
                } catch (Throwable th) {
                    th = th;
                    rVar = rVar2;
                }
            } catch (b1 e9) {
                e = e9;
            } catch (Exception e10) {
                e = e10;
            }
            try {
                this.f7522l.d(p.b(socket), socket);
                g gVar4 = g.this;
                a.b a10 = gVar4.C.a();
                a10.c(j7.x.f5917a, socket.getRemoteSocketAddress());
                a10.c(j7.x.f5918b, socket.getLocalSocketAddress());
                a10.c(j7.x.f5919c, sSLSession);
                a10.c(o0.f6877a, sSLSession == null ? y0.NONE : y0.PRIVACY_AND_INTEGRITY);
                gVar4.C = a10.a();
                g gVar5 = g.this;
                gVar5.B = new e(gVar5, ((o7.f) this.f7523m).e(rVar, true));
                synchronized (g.this.f7513t) {
                    Objects.requireNonNull(g.this);
                    if (sSLSession != null) {
                        g gVar6 = g.this;
                        new z.b(sSLSession);
                        int i9 = j4.f.f5663a;
                        Objects.requireNonNull(gVar6);
                    }
                }
            } catch (b1 e11) {
                e = e11;
                rVar2 = rVar;
                g.this.v(0, o7.a.INTERNAL_ERROR, e.f5756k);
                gVar = g.this;
                eVar = new e(gVar, ((o7.f) this.f7523m).e(rVar2, true));
                gVar.B = eVar;
            } catch (Exception e12) {
                e = e12;
                rVar2 = rVar;
                g.this.a(e);
                gVar = g.this;
                eVar = new e(gVar, ((o7.f) this.f7523m).e(rVar2, true));
                gVar.B = eVar;
            } catch (Throwable th2) {
                th = th2;
                g gVar7 = g.this;
                gVar7.B = new e(gVar7, ((o7.f) this.f7523m).e(rVar, true));
                throw th;
            }
        }
    }

    public class d implements Runnable {
        public d() {
        }

        @Override
        public void run() {
            g gVar = g.this;
            gVar.f7516x.execute(gVar.B);
            synchronized (g.this.f7513t) {
                g gVar2 = g.this;
                gVar2.L = Integer.MAX_VALUE;
                gVar2.w();
            }
        }
    }

    public class e implements b.a, Runnable {

        public final h f7526k;

        public o7.b f7527l;

        public boolean f7528m;

        public e(g gVar, o7.b bVar) {
            h hVar = new h(Level.FINE, g.class);
            g.this = gVar;
            this.f7528m = true;
            this.f7527l = bVar;
            this.f7526k = hVar;
        }

        public e(o7.b bVar, h hVar) {
            this.f7528m = true;
            this.f7527l = null;
            this.f7526k = null;
        }

        @Override
        public void run() {
            a1 a1Var;
            String name = Thread.currentThread().getName();
            Thread.currentThread().setName("OkHttpClientTransport");
            while (((f.c) this.f7527l).d(this)) {
                try {
                    f1 f1Var = g.this.P;
                    if (f1Var != null) {
                        f1Var.a();
                    }
                } catch (Throwable th) {
                    try {
                        g gVar = g.this;
                        o7.a aVar = o7.a.PROTOCOL_ERROR;
                        a1 f3 = a1.f5729l.g("error in frame handler").f(th);
                        Map<o7.a, a1> map = g.f7502a0;
                        gVar.v(0, aVar, f3);
                        try {
                            ((f.c) this.f7527l).f8075k.close();
                        } catch (IOException e9) {
                            e = e9;
                            g.f7503b0.log(Level.INFO, "Exception closing frame reader", (Throwable) e);
                            g.this.f7511q.a();
                            Thread.currentThread().setName(name);
                        }
                    } catch (Throwable th2) {
                        try {
                            ((f.c) this.f7527l).f8075k.close();
                        } catch (IOException e10) {
                            g.f7503b0.log(Level.INFO, "Exception closing frame reader", (Throwable) e10);
                        }
                        g.this.f7511q.a();
                        Thread.currentThread().setName(name);
                        throw th2;
                    }
                }
            }
            synchronized (g.this.f7513t) {
                a1Var = g.this.D;
            }
            if (a1Var == null) {
                a1Var = a1.f5730m.g("End of stream or IOException");
            }
            g.this.v(0, o7.a.INTERNAL_ERROR, a1Var);
            try {
                ((f.c) this.f7527l).f8075k.close();
            } catch (IOException e11) {
                e = e11;
                g.f7503b0.log(Level.INFO, "Exception closing frame reader", (Throwable) e);
                g.this.f7511q.a();
                Thread.currentThread().setName(name);
            }
            g.this.f7511q.a();
            Thread.currentThread().setName(name);
        }
    }

    static {
        EnumMap enumMap = new EnumMap(o7.a.class);
        o7.a aVar = o7.a.NO_ERROR;
        a1 a1Var = a1.f5729l;
        enumMap.put((EnumMap) aVar, (o7.a) a1Var.g("No error: A GRPC status of OK should have been sent"));
        enumMap.put((EnumMap) o7.a.PROTOCOL_ERROR, (o7.a) a1Var.g("Protocol error"));
        enumMap.put((EnumMap) o7.a.INTERNAL_ERROR, (o7.a) a1Var.g("Internal error"));
        enumMap.put((EnumMap) o7.a.FLOW_CONTROL_ERROR, (o7.a) a1Var.g("Flow control error"));
        enumMap.put((EnumMap) o7.a.STREAM_CLOSED, (o7.a) a1Var.g("Stream closed"));
        enumMap.put((EnumMap) o7.a.FRAME_TOO_LARGE, (o7.a) a1Var.g("Frame too large"));
        enumMap.put((EnumMap) o7.a.REFUSED_STREAM, (o7.a) a1.f5730m.g("Refused stream"));
        enumMap.put((EnumMap) o7.a.CANCEL, (o7.a) a1.f5723f.g("Cancelled"));
        enumMap.put((EnumMap) o7.a.COMPRESSION_ERROR, (o7.a) a1Var.g("Compression error"));
        enumMap.put((EnumMap) o7.a.CONNECT_ERROR, (o7.a) a1Var.g("Connect error"));
        enumMap.put((EnumMap) o7.a.ENHANCE_YOUR_CALM, (o7.a) a1.f5728k.g("Enhance your calm"));
        enumMap.put((EnumMap) o7.a.INADEQUATE_SECURITY, (o7.a) a1.f5726i.g("Inadequate security"));
        f7502a0 = Collections.unmodifiableMap(enumMap);
        f7503b0 = Logger.getLogger(g.class.getName());
        f7504c0 = new f[0];
    }

    public g(InetSocketAddress inetSocketAddress, String str, String str2, j7.a aVar, Executor executor, SocketFactory socketFactory, SSLSocketFactory sSLSocketFactory, HostnameVerifier hostnameVerifier, n7.a aVar2, int i9, int i10, y yVar, Runnable runnable, int i11, a3 a3Var, boolean z8) {
        Object obj = new Object();
        this.f7513t = obj;
        this.f7515w = new HashMap();
        this.L = 0;
        this.M = new LinkedList();
        this.Y = new a();
        j4.f.j(inetSocketAddress, "address");
        this.f7505k = inetSocketAddress;
        this.f7506l = str;
        this.f7518z = i9;
        this.f7510p = i10;
        j4.f.j(executor, "executor");
        this.f7516x = executor;
        this.f7517y = new o2(executor);
        this.f7514v = 3;
        this.I = socketFactory == null ? SocketFactory.getDefault() : socketFactory;
        this.J = sSLSocketFactory;
        this.K = hostnameVerifier;
        j4.f.j(aVar2, "connectionSpec");
        this.N = aVar2;
        this.f7509o = p0.f6936q;
        StringBuilder sb = new StringBuilder();
        if (str2 != null) {
            sb.append(str2);
            sb.append(' ');
        }
        sb.append("grpc-java-");
        sb.append("okhttp");
        sb.append('/');
        sb.append("1.44.1");
        this.f7507m = sb.toString();
        this.Z = yVar;
        int i12 = j4.f.f5663a;
        this.U = runnable;
        this.V = i11;
        this.X = a3Var;
        this.u = d0.a(g.class, inetSocketAddress.toString());
        j7.a aVar3 = j7.a.f5707b;
        a.c<j7.a> cVar = o0.f6878b;
        IdentityHashMap identityHashMap = new IdentityHashMap(1);
        identityHashMap.put(cVar, aVar);
        for (Map.Entry<a.c<?>, Object> entry : aVar3.f5708a.entrySet()) {
            if (!identityHashMap.containsKey(entry.getKey())) {
                identityHashMap.put(entry.getKey(), entry.getValue());
            }
        }
        this.C = new j7.a(identityHashMap, null);
        this.W = z8;
        synchronized (obj) {
            int i13 = j4.f.f5663a;
        }
    }

    public static Socket b(g gVar, InetSocketAddress inetSocketAddress, InetSocketAddress inetSocketAddress2, String str, String str2) {
        Objects.requireNonNull(gVar);
        try {
            Socket createSocket = inetSocketAddress2.getAddress() != null ? gVar.I.createSocket(inetSocketAddress2.getAddress(), inetSocketAddress2.getPort()) : gVar.I.createSocket(inetSocketAddress2.getHostName(), inetSocketAddress2.getPort());
            createSocket.setTcpNoDelay(true);
            o8.w c9 = p.c(createSocket);
            q qVar = new q(p.b(createSocket));
            t d9 = gVar.d(inetSocketAddress, str, str2);
            o oVar = d9.f4098a;
            qVar.d0(String.format("CONNECT %s:%d HTTP/1.1", oVar.f4060d, Integer.valueOf(oVar.f4061e)));
            qVar.d0("\r\n");
            int d10 = d9.f4100c.d();
            for (int i9 = 0; i9 < d10; i9++) {
                qVar.d0(d9.f4100c.b(i9));
                qVar.d0(": ");
                qVar.d0(d9.f4100c.e(i9));
                qVar.d0("\r\n");
            }
            qVar.d0("\r\n");
            qVar.flush();
            g7.p a9 = g7.p.a(s(c9));
            do {
            } while (!s(c9).equals(""));
            int i10 = a9.f5356b;
            if (i10 >= 200 && i10 < 300) {
                return createSocket;
            }
            o8.d dVar = new o8.d();
            try {
                createSocket.shutdownOutput();
                ((o8.b) c9).G(dVar, 1024L);
            } catch (IOException e9) {
                dVar.D0("Unable to read body: " + e9.toString());
            }
            try {
                createSocket.close();
            } catch (IOException unused) {
            }
            throw new b1(a1.f5730m.g(String.format("Response returned from proxy was not successful (expected 2xx, got %d %s). Response body:\n%s", Integer.valueOf(a9.f5356b), a9.f5357c, dVar.t0())));
        } catch (IOException e10) {
            throw new b1(a1.f5730m.g("Failed trying to connect with proxy").f(e10));
        }
    }

    public static void c(g gVar, o7.a aVar, String str) {
        Objects.requireNonNull(gVar);
        gVar.v(0, aVar, z(aVar).a(str));
    }

    public static String s(o8.w wVar) {
        o8.d dVar = new o8.d();
        while (((o8.b) wVar).G(dVar, 1L) != -1) {
            if (dVar.v(dVar.f8107l - 1) == 10) {
                return dVar.Y();
            }
        }
        StringBuilder t8 = androidx.activity.b.t("\\n not found: ");
        t8.append(dVar.U().j());
        throw new EOFException(t8.toString());
    }

    public static a1 z(o7.a aVar) {
        a1 a1Var = f7502a0.get(aVar);
        if (a1Var != null) {
            return a1Var;
        }
        a1 a1Var2 = a1.f5724g;
        StringBuilder t8 = androidx.activity.b.t("Unknown http2 error code: ");
        t8.append(aVar.f8038k);
        return a1Var2.g(t8.toString());
    }

    @Override
    public void a(Throwable th) {
        int i9 = j4.f.f5663a;
        v(0, o7.a.INTERNAL_ERROR, a1.f5730m.f(th));
    }

    public final t d(InetSocketAddress inetSocketAddress, String str, String str2) {
        o.b bVar = new o.b();
        bVar.h("https");
        bVar.d(inetSocketAddress.getHostName());
        bVar.f(inetSocketAddress.getPort());
        o a9 = bVar.a();
        t.b bVar2 = new t.b();
        bVar2.d(a9);
        bVar2.b("Host", a9.f4060d + ":" + a9.f4061e);
        bVar2.b("User-Agent", this.f7507m);
        if (str != null && str2 != null) {
            bVar2.b("Proxy-Authorization", o8.t.c(str, str2));
        }
        return bVar2.a();
    }

    @Override
    public Runnable e(v1.a aVar) {
        o2 o2Var;
        Runnable dVar;
        j4.f.j(aVar, "listener");
        this.f7511q = aVar;
        if (this.Q) {
            this.O = (ScheduledExecutorService) q2.a(p0.f6935p);
            f1 f1Var = new f1(new f1.c(this), this.O, this.R, this.S, this.T);
            this.P = f1Var;
            synchronized (f1Var) {
                if (f1Var.f6558d) {
                    f1Var.b();
                }
            }
        }
        if (this.f7505k == null) {
            synchronized (this.f7513t) {
                m7.b bVar = new m7.b(this, null, null);
                this.f7512r = bVar;
                this.s = new m(this, bVar);
            }
            o2Var = this.f7517y;
            dVar = new b();
        } else {
            m7.a aVar2 = new m7.a(this.f7517y, this);
            o7.f fVar = new o7.f();
            Logger logger = p.f8132a;
            f.d dVar2 = new f.d(new q(aVar2), true);
            synchronized (this.f7513t) {
                m7.b bVar2 = new m7.b(this, dVar2, new h(Level.FINE, g.class));
                this.f7512r = bVar2;
                this.s = new m(this, bVar2);
            }
            CountDownLatch countDownLatch = new CountDownLatch(1);
            this.f7517y.execute(new c(countDownLatch, aVar2, fVar));
            try {
                t();
                countDownLatch.countDown();
                o2Var = this.f7517y;
                dVar = new d();
            } catch (Throwable th) {
                countDownLatch.countDown();
                throw th;
            }
        }
        o2Var.execute(dVar);
        return null;
    }

    public void f(int i9, a1 a1Var, s.a aVar, boolean z8, o7.a aVar2, j7.p0 p0Var) {
        synchronized (this.f7513t) {
            f remove = this.f7515w.remove(Integer.valueOf(i9));
            if (remove != null) {
                if (aVar2 != null) {
                    this.f7512r.o(i9, o7.a.CANCEL);
                }
                if (a1Var != null) {
                    f.b bVar = remove.f7493n;
                    if (p0Var == null) {
                        p0Var = new j7.p0();
                    }
                    bVar.j(a1Var, aVar, z8, p0Var);
                }
                if (!w()) {
                    y();
                    r(remove);
                }
            }
        }
    }

    @Override
    public d0 g() {
        return this.u;
    }

    public f[] h() {
        f[] fVarArr;
        synchronized (this.f7513t) {
            fVarArr = (f[]) this.f7515w.values().toArray(f7504c0);
        }
        return fVarArr;
    }

    @Override
    public void i(t.a aVar, Executor executor) {
        long nextLong;
        Runnable t0Var;
        synchronized (this.f7513t) {
            boolean z8 = true;
            if (!(this.f7512r != null)) {
                throw new IllegalStateException();
            }
            if (this.G) {
                Throwable l9 = l();
                Logger logger = v0.f7059g;
                v0.a(executor, new u0(aVar, l9));
                return;
            }
            v0 v0Var = this.F;
            if (v0Var != null) {
                nextLong = 0;
                z8 = false;
            } else {
                nextLong = this.f7508n.nextLong();
                j4.g gVar = this.f7509o.get();
                gVar.c();
                v0 v0Var2 = new v0(nextLong, gVar);
                this.F = v0Var2;
                this.X.f6418e++;
                v0Var = v0Var2;
            }
            if (z8) {
                this.f7512r.g(false, (int) (nextLong >>> 32), (int) nextLong);
            }
            synchronized (v0Var) {
                if (!v0Var.f7063d) {
                    v0Var.f7062c.put(aVar, executor);
                    return;
                }
                Throwable th = v0Var.f7064e;
                if (th != null) {
                    t0Var = new u0(aVar, th);
                } else {
                    t0Var = new t0(aVar, v0Var.f7065f);
                }
                v0.a(executor, t0Var);
            }
        }
    }

    public String j() {
        URI a9 = p0.a(this.f7506l);
        return a9.getHost() != null ? a9.getHost() : this.f7506l;
    }

    public int k() {
        URI a9 = p0.a(this.f7506l);
        return a9.getPort() != -1 ? a9.getPort() : this.f7505k.getPort();
    }

    public final Throwable l() {
        synchronized (this.f7513t) {
            a1 a1Var = this.D;
            if (a1Var != null) {
                Objects.requireNonNull(a1Var);
                return new b1(a1Var);
            }
            return new b1(a1.f5730m.g("Connection closed"));
        }
    }

    public f m(int i9) {
        f fVar;
        synchronized (this.f7513t) {
            fVar = this.f7515w.get(Integer.valueOf(i9));
        }
        return fVar;
    }

    @Override
    public void n(a1 a1Var) {
        s.a aVar = s.a.PROCESSED;
        q(a1Var);
        synchronized (this.f7513t) {
            Iterator<Map.Entry<Integer, f>> it = this.f7515w.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Integer, f> next = it.next();
                it.remove();
                next.getValue().f7493n.j(a1Var, aVar, false, new j7.p0());
                r(next.getValue());
            }
            for (f fVar : this.M) {
                fVar.f7493n.j(a1Var, aVar, true, new j7.p0());
                r(fVar);
            }
            this.M.clear();
            y();
        }
    }

    @Override
    public l7.r o(q0 q0Var, j7.p0 p0Var, j7.c cVar, j7.i[] iVarArr) {
        Object obj;
        j4.f.j(q0Var, "method");
        j4.f.j(p0Var, "headers");
        u2 u2Var = new u2(iVarArr);
        for (j7.i iVar : iVarArr) {
            Objects.requireNonNull(iVar);
        }
        Object obj2 = this.f7513t;
        synchronized (obj2) {
            try {
                obj = obj2;
            } catch (Throwable th) {
                th = th;
                obj = obj2;
            }
            try {
                f fVar = new f(q0Var, p0Var, this.f7512r, this, this.s, this.f7513t, this.f7518z, this.f7510p, this.f7506l, this.f7507m, u2Var, this.X, cVar, this.W);
                return fVar;
            } catch (Throwable th2) {
                th = th2;
                while (true) {
                    try {
                        break;
                    } catch (Throwable th3) {
                        th = th3;
                    }
                }
                throw th;
            }
        }
    }

    public boolean p(int i9) {
        boolean z8;
        synchronized (this.f7513t) {
            z8 = true;
            if (i9 >= this.f7514v || (i9 & 1) != 1) {
                z8 = false;
            }
        }
        return z8;
    }

    @Override
    public void q(a1 a1Var) {
        synchronized (this.f7513t) {
            if (this.D != null) {
                return;
            }
            this.D = a1Var;
            this.f7511q.d(a1Var);
            y();
        }
    }

    public final void r(f fVar) {
        if (this.H && this.M.isEmpty() && this.f7515w.isEmpty()) {
            this.H = false;
            f1 f1Var = this.P;
            if (f1Var != null) {
                synchronized (f1Var) {
                    if (!f1Var.f6558d) {
                        int i9 = f1Var.f6559e;
                        if (i9 == 2 || i9 == 3) {
                            f1Var.f6559e = 1;
                        }
                        if (f1Var.f6559e == 4) {
                            f1Var.f6559e = 5;
                        }
                    }
                }
            }
        }
        if (fVar.f6385c) {
            this.Y.c(fVar, false);
        }
    }

    public void t() {
        synchronized (this.f7513t) {
            m7.b bVar = this.f7512r;
            Objects.requireNonNull(bVar);
            try {
                bVar.f7447l.j();
            } catch (IOException e9) {
                bVar.f7446k.a(e9);
            }
            o7.h hVar = new o7.h();
            hVar.b(7, 0, this.f7510p);
            m7.b bVar2 = this.f7512r;
            bVar2.f7448m.f(2, hVar);
            try {
                bVar2.f7447l.i0(hVar);
            } catch (IOException e10) {
                bVar2.f7446k.a(e10);
            }
            if (this.f7510p > 65535) {
                this.f7512r.e(0, r1 - 65535);
            }
        }
    }

    public String toString() {
        d.b a9 = j4.d.a(this);
        a9.b("logId", this.u.f5780c);
        a9.d("address", this.f7505k);
        return a9.toString();
    }

    public final void u(f fVar) {
        if (!this.H) {
            this.H = true;
            f1 f1Var = this.P;
            if (f1Var != null) {
                f1Var.b();
            }
        }
        if (fVar.f6385c) {
            this.Y.c(fVar, true);
        }
    }

    public final void v(int i9, o7.a aVar, a1 a1Var) {
        s.a aVar2 = s.a.REFUSED;
        synchronized (this.f7513t) {
            if (this.D == null) {
                this.D = a1Var;
                this.f7511q.d(a1Var);
            }
            if (aVar != null && !this.E) {
                this.E = true;
                this.f7512r.W(0, aVar, new byte[0]);
            }
            Iterator<Map.Entry<Integer, f>> it = this.f7515w.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Integer, f> next = it.next();
                if (next.getKey().intValue() > i9) {
                    it.remove();
                    next.getValue().f7493n.j(a1Var, aVar2, false, new j7.p0());
                    r(next.getValue());
                }
            }
            for (f fVar : this.M) {
                fVar.f7493n.j(a1Var, aVar2, true, new j7.p0());
                r(fVar);
            }
            this.M.clear();
            y();
        }
    }

    public final boolean w() {
        boolean z8 = false;
        while (!this.M.isEmpty() && this.f7515w.size() < this.L) {
            x(this.M.poll());
            z8 = true;
        }
        return z8;
    }

    public final void x(f fVar) {
        j4.f.n(fVar.f7492m == -1, "StreamId already assigned");
        this.f7515w.put(Integer.valueOf(this.f7514v), fVar);
        u(fVar);
        f.b bVar = fVar.f7493n;
        int i9 = this.f7514v;
        boolean z8 = f.this.f7492m == -1;
        int i10 = j4.f.f5663a;
        if (z8) {
            f.this.f7492m = i9;
            f.b bVar2 = f.this.f7493n;
            if (bVar2.f6396j != null) {
                synchronized (bVar2.f6537b) {
                    j4.f.n(!bVar2.f6541f, "Already allocated");
                    bVar2.f6541f = true;
                }
                bVar2.g();
                a3 a3Var = bVar2.f6538c;
                a3Var.f6415b++;
                a3Var.f6414a.a();
                if (bVar.I) {
                    m7.b bVar3 = bVar.F;
                    f fVar2 = f.this;
                    bVar3.i(fVar2.f7496q, false, fVar2.f7492m, 0, bVar.f7500y);
                    for (a7.n nVar : f.this.f7489j.f7049a) {
                        Objects.requireNonNull((j7.i) nVar);
                    }
                    bVar.f7500y = null;
                    if (bVar.f7501z.f8107l > 0) {
                        bVar.G.a(bVar.A, f.this.f7492m, bVar.f7501z, bVar.B);
                    }
                    bVar.I = false;
                }
                q0.c cVar = fVar.f7487h.f5875a;
                if ((cVar != q0.c.UNARY && cVar != q0.c.SERVER_STREAMING) || fVar.f7496q) {
                    this.f7512r.flush();
                }
                int i11 = this.f7514v;
                if (i11 < 2147483645) {
                    this.f7514v = i11 + 2;
                    return;
                } else {
                    this.f7514v = Integer.MAX_VALUE;
                    v(Integer.MAX_VALUE, o7.a.NO_ERROR, a1.f5730m.g("Stream ids exhausted"));
                    return;
                }
            }
            throw new IllegalStateException();
        }
        throw new IllegalStateException(o8.t.G("the stream has been started with id %s", Integer.valueOf(i9)));
    }

    public final void y() {
        if (this.D == null || !this.f7515w.isEmpty() || !this.M.isEmpty() || this.G) {
            return;
        }
        this.G = true;
        f1 f1Var = this.P;
        if (f1Var != null) {
            synchronized (f1Var) {
                if (f1Var.f6559e != 6) {
                    f1Var.f6559e = 6;
                    ScheduledFuture<?> scheduledFuture = f1Var.f6560f;
                    if (scheduledFuture != null) {
                        scheduledFuture.cancel(false);
                    }
                    ScheduledFuture<?> scheduledFuture2 = f1Var.f6561g;
                    if (scheduledFuture2 != null) {
                        scheduledFuture2.cancel(false);
                        f1Var.f6561g = null;
                    }
                }
            }
            q2.b(p0.f6935p, this.O);
            this.O = null;
        }
        v0 v0Var = this.F;
        if (v0Var != null) {
            Throwable l9 = l();
            synchronized (v0Var) {
                if (!v0Var.f7063d) {
                    v0Var.f7063d = true;
                    v0Var.f7064e = l9;
                    Map<t.a, Executor> map = v0Var.f7062c;
                    v0Var.f7062c = null;
                    for (Map.Entry<t.a, Executor> entry : map.entrySet()) {
                        v0.a(entry.getValue(), new u0(entry.getKey(), l9));
                    }
                }
            }
            this.F = null;
        }
        if (!this.E) {
            this.E = true;
            this.f7512r.W(0, o7.a.NO_ERROR, new byte[0]);
        }
        this.f7512r.close();
    }
}