package defpackage;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/* renamed from: ᵮᵦᵗ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4221 implements Closeable {

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public static final Logger f15815 = Logger.getLogger(AbstractC5398.class.getName());

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C3018 f15816;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final InterfaceC4777 f15817;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final C4649 f15818;

    public C4221(InterfaceC4777 interfaceC4777) {
        this.f15817 = interfaceC4777;
        C3018 c3018 = new C3018(interfaceC4777);
        this.f15816 = c3018;
        this.f15818 = new C4649(c3018);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        this.f15817.close();
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m9171(C1487 c1487, int i, int i2) throws IOException {
        int i3;
        Object[] array;
        if (i < 8) {
            C0910.m3045(AbstractC2990.m7313(i, "TYPE_GOAWAY length < 8: "));
            return;
        }
        if (i2 != 0) {
            C0910.m3045("TYPE_GOAWAY streamId != 0");
            return;
        }
        int i4 = this.f15817.readInt();
        int i5 = this.f15817.readInt();
        int i6 = i - 8;
        int[] iArrM4098 = AbstractC1327.m4098(14);
        int length = iArrM4098.length;
        int i7 = 0;
        while (true) {
            if (i7 >= length) {
                i3 = 0;
                break;
            }
            i3 = iArrM4098[i7];
            if (AbstractC1327.m4088(i3) == i5) {
                break;
            } else {
                i7++;
            }
        }
        if (i3 == 0) {
            C0910.m3045(AbstractC2990.m7313(i5, "TYPE_GOAWAY unexpected error code: "));
            return;
        }
        C2185 c2185Mo3272 = C2185.f8597;
        if (i6 > 0) {
            c2185Mo3272 = this.f15817.mo3272(i6);
        }
        c2185Mo3272.mo5840();
        C4560 c4560 = c1487.f5989;
        synchronized (c4560) {
            array = c4560.f16971.values().toArray(new C4498[0]);
            c4560.f16970 = true;
        }
        for (C4498 c4498 : (C4498[]) array) {
            if (c4498.f16765 > i4 && c4498.m9587()) {
                c4498.m9578(8);
                c1487.f5989.m9715(c4498.f16765);
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:66:0x010f, code lost:
    
        if (r6 == false) goto L68;
     */
    /* JADX WARN: Code restructure failed: missing block: B:67:0x0111, code lost:
    
        r9.m9586(defpackage.C2609.f10095, true);
     */
    /* renamed from: ˏᵙ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void m9172(defpackage.C1487 r17, int r18, int r19, final int r20) throws java.io.IOException {
        /*
            Method dump skipped, instructions count: 298
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C4221.m9172(ˋᐧʽˑ, int, int, int):void");
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final List m9173(int i, int i2, int i3, int i4) throws IOException {
        C3018 c3018 = this.f15816;
        c3018.f11627 = i;
        c3018.f11626 = i;
        c3018.f11625 = i2;
        c3018.f11630 = i3;
        c3018.f11629 = i4;
        C4649 c4649 = this.f15818;
        C2753 c2753 = c4649.f17216;
        ArrayList arrayList = c4649.f17218;
        while (!c2753.mo3284()) {
            byte b = c2753.readByte();
            byte[] bArr = AbstractC1348.f5567;
            int i5 = b & 255;
            if (i5 == 128) {
                C0910.m3045("index == 0");
                return null;
            }
            if ((b & 128) == 128) {
                int iM9829 = c4649.m9829(i5, 127);
                int i6 = iM9829 - 1;
                if (i6 >= 0) {
                    C1162[] c1162Arr = AbstractC5457.f20492;
                    if (i6 <= c1162Arr.length - 1) {
                        arrayList.add(c1162Arr[i6]);
                    }
                }
                int length = c4649.f17213 + 1 + (i6 - AbstractC5457.f20492.length);
                if (length >= 0) {
                    C1162[] c1162Arr2 = c4649.f17219;
                    if (length < c1162Arr2.length) {
                        arrayList.add(c1162Arr2[length]);
                    }
                }
                C0910.m3045(AbstractC2990.m7313(iM9829, "Header index too large "));
                return null;
            }
            if (i5 == 64) {
                C1162[] c1162Arr3 = AbstractC5457.f20492;
                C2185 c2185M9833 = c4649.m9833();
                AbstractC5457.m11096(c2185M9833);
                c4649.m9830(new C1162(c2185M9833, c4649.m9833()));
            } else if ((b & 64) == 64) {
                c4649.m9830(new C1162(c4649.m9832(c4649.m9829(i5, 63) - 1), c4649.m9833()));
            } else if ((b & 32) == 32) {
                int iM98292 = c4649.m9829(i5, 31);
                c4649.f17217 = iM98292;
                if (iM98292 < 0 || iM98292 > 4096) {
                    throw new IOException("Invalid dynamic table size update " + c4649.f17217);
                }
                int i7 = c4649.f17214;
                if (iM98292 < i7) {
                    if (iM98292 == 0) {
                        AbstractC1658.m4733(c4649.f17219, null);
                        c4649.f17213 = c4649.f17219.length - 1;
                        c4649.f17215 = 0;
                        c4649.f17214 = 0;
                    } else {
                        c4649.m9831(i7 - iM98292);
                    }
                }
            } else if (i5 == 16 || i5 == 0) {
                C1162[] c1162Arr4 = AbstractC5457.f20492;
                C2185 c2185M98332 = c4649.m9833();
                AbstractC5457.m11096(c2185M98332);
                arrayList.add(new C1162(c2185M98332, c4649.m9833()));
            } else {
                arrayList.add(new C1162(c4649.m9832(c4649.m9829(i5, 15) - 1), c4649.m9833()));
            }
        }
        List listM6825 = AbstractC2767.m6825(arrayList);
        arrayList.clear();
        return listM6825;
    }

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final void m9174(C1487 c1487, int i, int i2, int i3) throws IOException {
        int i4;
        if (i3 == 0) {
            C0910.m3045("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0");
            return;
        }
        if ((i2 & 8) != 0) {
            byte b = this.f15817.readByte();
            byte[] bArr = AbstractC1348.f5567;
            i4 = b & 255;
        } else {
            i4 = 0;
        }
        int i5 = this.f15817.readInt() & Integer.MAX_VALUE;
        List listM9173 = m9173(ᵼᵙᵖᵱ.ᵞʡ(i - 4, i2, i4), i4, i2, i3);
        C4560 c4560 = c1487.f5989;
        synchronized (c4560) {
            if (c4560.f16961.contains(Integer.valueOf(i5))) {
                c4560.m9714(i5, 2);
                return;
            }
            c4560.f16961.add(Integer.valueOf(i5));
            C0897.m3015(c4560.f16964, c4560.f16979 + '[' + i5 + "] onRequest", new C2108(c4560, i5, listM9173));
        }
    }

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final void m9175(C1487 c1487, int i, int i2, int i3) throws IOException {
        if (i != 8) {
            C0910.m3045(AbstractC2990.m7313(i, "TYPE_PING length != 8: "));
            return;
        }
        if (i3 != 0) {
            C0910.m3045("TYPE_PING streamId != 0");
            return;
        }
        int i4 = this.f15817.readInt();
        int i5 = this.f15817.readInt();
        boolean z = (i2 & 1) != 0;
        C4560 c4560 = c1487.f5989;
        if (!z) {
            C0897.m3015(c4560.f16968, AbstractC1327.m4107(new StringBuilder(), c1487.f5989.f16979, " ping"), new C1961(c1487.f5989, i4, i5, 1));
            return;
        }
        synchronized (c4560) {
            try {
                if (i4 == 1) {
                    c4560.f16973++;
                } else if (i4 == 2) {
                    c4560.f16965++;
                } else if (i4 == 3) {
                    c4560.notifyAll();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final void m9176(C1487 c1487, int i, int i2, int i3) throws IOException {
        int i4;
        if (i3 == 0) {
            C0910.m3045("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0");
            return;
        }
        boolean z = false;
        boolean z2 = (i2 & 1) != 0;
        if ((i2 & 8) != 0) {
            byte b = this.f15817.readByte();
            byte[] bArr = AbstractC1348.f5567;
            i4 = b & 255;
        } else {
            i4 = 0;
        }
        if ((i2 & 32) != 0) {
            InterfaceC4777 interfaceC4777 = this.f15817;
            interfaceC4777.readInt();
            interfaceC4777.readByte();
            byte[] bArr2 = AbstractC1348.f5567;
            i -= 5;
        }
        List listM9173 = m9173(ᵼᵙᵖᵱ.ᵞʡ(i, i2, i4), i4, i2, i3);
        C4560 c4560 = c1487.f5989;
        if (i3 != 0 && (i3 & 1) == 0) {
            z = true;
        }
        if (z) {
            C0897.m3015(c4560.f16964, c4560.f16979 + '[' + i3 + "] onHeaders", new C2108(c4560, i3, listM9173, z2));
            return;
        }
        synchronized (c4560) {
            C4498 c4498M9713 = c4560.m9713(i3);
            if (c4498M9713 != null) {
                c4498M9713.m9586(AbstractC4061.m8922(listM9173), z2);
                return;
            }
            if (c4560.f16970) {
                return;
            }
            if (i3 <= c4560.f16978) {
                return;
            }
            if (i3 % 2 == c4560.f16972 % 2) {
                return;
            }
            C4498 c4498 = new C4498(i3, c4560, false, z2, AbstractC4061.m8922(listM9173));
            c4560.f16978 = i3;
            c4560.f16971.put(Integer.valueOf(i3), c4498);
            C0897.m3015(c4560.f16956.m7606(), c4560.f16979 + '[' + i3 + "] onStream", new C4475(c4560, 4, c4498));
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:87:0x012d, code lost:
    
        defpackage.C0910.m3045(defpackage.AbstractC2990.m7313(r7, "PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: "));
     */
    /* JADX WARN: Code restructure failed: missing block: B:88:0x0136, code lost:
    
        return false;
     */
    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean m9177(boolean r13, defpackage.C1487 r14) throws java.lang.Exception {
        /*
            Method dump skipped, instructions count: 570
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C4221.m9177(boolean, ˋᐧʽˑ):boolean");
    }
}
