package 㿎.ሽ.㿎;

import androidx.recyclerview.widget.RecyclerView;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import okhttp3.internal.http2.ErrorCode;
import okio.ByteString;
import ඓ.K.K.K.C1293;
import ᨨ.AbstractC1494;
import ᨨ.AbstractC1496;
import ᨨ.C1477;
import ᨨ.C1492;
import 㿎.ሽ.C2540;
import 㿎.ሽ.㿎.C2591;
import 㿎.ሽ.㿎.C2608;

/* renamed from: 㿎.ሽ.㿎.ⁱ  reason: contains not printable characters */
/* compiled from: Http2Reader */
public final class C2611 implements Closeable {

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final Logger f8802 = Logger.getLogger(C2590.class.getName());

    /* renamed from: ʬ  reason: contains not printable characters */
    public final C2613 f8803 = new C2613(this.f8805);

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C2608.C2610 f8804 = new C2608.C2610(RecyclerView.AbstractC0269.FLAG_APPEARED_IN_PRE_LAYOUT, this.f8803);

    /* renamed from: ῲ  reason: contains not printable characters */
    public final AbstractC1496 f8805;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final boolean f8806;

    /* renamed from: 㿎.ሽ.㿎.ⁱ$ῲ  reason: contains not printable characters */
    /* compiled from: Http2Reader */
    public interface AbstractC2612 {
    }

    /* renamed from: 㿎.ሽ.㿎.ⁱ$K  reason: contains not printable characters */
    /* compiled from: Http2Reader */
    public static final class C2613 implements AbstractC1494 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public int f8807;

        /* renamed from: ඓ  reason: contains not printable characters */
        public int f8808;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final AbstractC1496 f8809;

        /* renamed from: ⁱ  reason: contains not printable characters */
        public short f8810;

        /* renamed from: 㴹  reason: contains not printable characters */
        public int f8811;

        /* renamed from: 㸾  reason: contains not printable characters */
        public byte f8812;

        public C2613(AbstractC1496 r1) {
            this.f8809 = r1;
        }

        @Override // ᨨ.AbstractC1494, java.io.Closeable, java.lang.AutoCloseable
        public void close() throws IOException {
        }

        @Override // ᨨ.AbstractC1494
        public long read(C1492 r9, long j) throws IOException {
            int i;
            do {
                int i2 = this.f8811;
                if (i2 == 0) {
                    this.f8809.skip((long) this.f8810);
                    this.f8810 = 0;
                    if ((this.f8812 & 4) != 0) {
                        return -1;
                    }
                    i = this.f8808;
                    int r2 = C2611.m6879(this.f8809);
                    this.f8811 = r2;
                    this.f8807 = r2;
                    byte readByte = (byte) (this.f8809.readByte() & 255);
                    this.f8812 = (byte) (this.f8809.readByte() & 255);
                    if (C2611.f8802.isLoggable(Level.FINE)) {
                        C2611.f8802.fine(C2590.m6803(true, this.f8808, this.f8807, readByte, this.f8812));
                    }
                    this.f8808 = this.f8809.readInt() & Integer.MAX_VALUE;
                    if (readByte != 9) {
                        C2590.m6801("%s != TYPE_CONTINUATION", Byte.valueOf(readByte));
                        throw null;
                    }
                } else {
                    long read = this.f8809.read(r9, Math.min(j, (long) i2));
                    if (read == -1) {
                        return -1;
                    }
                    this.f8811 = (int) (((long) this.f8811) - read);
                    return read;
                }
            } while (this.f8808 == i);
            C2590.m6801("TYPE_CONTINUATION streamId changed", new Object[0]);
            throw null;
        }

        @Override // ᨨ.AbstractC1494
        public C1477 timeout() {
            return this.f8809.timeout();
        }
    }

    public C2611(AbstractC1496 r2, boolean z) {
        this.f8805 = r2;
        this.f8806 = z;
    }

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

    /* renamed from: K  reason: contains not printable characters */
    public void m6881(AbstractC2612 r7) throws IOException {
        if (!this.f8806) {
            ByteString r72 = this.f8805.m3813((long) C2590.f8713.size());
            if (f8802.isLoggable(Level.FINE)) {
                f8802.fine(C2540.m6642("<< CONNECTION %s", r72.hex()));
            }
            if (!C2590.f8713.equals(r72)) {
                C2590.m6801("Expected a connection header but was %s", r72.utf8());
                throw null;
            }
        } else if (!m6883(true, r7)) {
            C2590.m6801("Required SETTINGS preface not received", new Object[0]);
            throw null;
        }
    }

    /* JADX DEBUG: Multi-variable search result rejected for r4v1, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r5v4, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r3v1, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r3v8, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r4v6, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r4v7, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r12v27, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r3v12, resolved type: boolean */
    /* JADX DEBUG: Multi-variable search result rejected for r12v39, resolved type: boolean */
    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: K  reason: contains not printable characters */
    public boolean m6883(boolean z, AbstractC2612 r13) throws IOException {
        short s = 0;
        boolean z2 = false;
        short s2 = 0;
        short s3 = 0;
        try {
            this.f8805.m3823(9);
            int r1 = m6879(this.f8805);
            if (r1 < 0 || r1 > 16384) {
                C2590.m6801("FRAME_SIZE_ERROR: %s", Integer.valueOf(r1));
                throw null;
            }
            byte readByte = (byte) (this.f8805.readByte() & 255);
            if (!z || readByte == 4) {
                byte readByte2 = (byte) (this.f8805.readByte() & 255);
                int readInt = this.f8805.readInt() & Integer.MAX_VALUE;
                if (f8802.isLoggable(Level.FINE)) {
                    f8802.fine(C2590.m6803(true, readInt, r1, readByte, readByte2));
                }
                switch (readByte) {
                    case 0:
                        if (readInt != 0) {
                            boolean z3 = (readByte2 & 1) != 0;
                            if (!((readByte2 & 32) != 0)) {
                                if ((readByte2 & 8) != 0) {
                                    s = (short) (this.f8805.readByte() & 255);
                                }
                                int r12 = m6878(r1, readByte2, s);
                                AbstractC1496 r14 = this.f8805;
                                C2591.C2598 r132 = (C2591.C2598) r13;
                                if (C2591.this.m6810(readInt)) {
                                    C2591.this.m6817(readInt, r14, r12, z3);
                                } else {
                                    C2621 r3 = C2591.this.m6812(readInt);
                                    if (r3 == null) {
                                        C2591.this.m6809(readInt, ErrorCode.PROTOCOL_ERROR);
                                        long j = (long) r12;
                                        C2591.this.m6811(j);
                                        r14.skip(j);
                                    } else {
                                        r3.f8856.m6915(r14, (long) r12);
                                        if (z3) {
                                            r3.m6907();
                                        }
                                    }
                                }
                                this.f8805.skip((long) s);
                                break;
                            } else {
                                C2590.m6801("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA", new Object[0]);
                                throw null;
                            }
                        } else {
                            C2590.m6801("PROTOCOL_ERROR: TYPE_DATA streamId == 0", new Object[0]);
                            throw null;
                        }
                    case 1:
                        if (readInt != 0) {
                            boolean z4 = (readByte2 & 1) != 0;
                            if ((readByte2 & 8) != 0) {
                                s3 = (short) (this.f8805.readByte() & 255);
                            }
                            if ((readByte2 & 32) != 0) {
                                m6882(r13, readInt);
                                r1 -= 5;
                            }
                            ((C2591.C2598) r13).m6835(z4, readInt, -1, m6880(m6878(r1, readByte2, s3), s3, readByte2, readInt));
                            break;
                        } else {
                            C2590.m6801("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0", new Object[0]);
                            throw null;
                        }
                    case 2:
                        if (r1 != 5) {
                            C2590.m6801("TYPE_PRIORITY length: %d != 5", Integer.valueOf(r1));
                            throw null;
                        } else if (readInt != 0) {
                            m6882(r13, readInt);
                            break;
                        } else {
                            C2590.m6801("TYPE_PRIORITY streamId == 0", new Object[0]);
                            throw null;
                        }
                    case 3:
                        if (r1 != 4) {
                            C2590.m6801("TYPE_RST_STREAM length: %d != 4", Integer.valueOf(r1));
                            throw null;
                        } else if (readInt != 0) {
                            int readInt2 = this.f8805.readInt();
                            ErrorCode fromHttp2 = ErrorCode.fromHttp2(readInt2);
                            if (fromHttp2 != null) {
                                C2591.C2598 r133 = (C2591.C2598) r13;
                                if (C2591.this.m6810(readInt)) {
                                    C2591.this.m6816(readInt, fromHttp2);
                                    break;
                                } else {
                                    C2621 r122 = C2591.this.m6805(readInt);
                                    if (r122 != null) {
                                        r122.m6908(fromHttp2);
                                        break;
                                    }
                                }
                            } else {
                                C2590.m6801("TYPE_RST_STREAM unexpected error code: %d", Integer.valueOf(readInt2));
                                throw null;
                            }
                        } else {
                            C2590.m6801("TYPE_RST_STREAM streamId == 0", new Object[0]);
                            throw null;
                        }
                        break;
                    case 4:
                        if (readInt != 0) {
                            C2590.m6801("TYPE_SETTINGS streamId != 0", new Object[0]);
                            throw null;
                        } else if ((readByte2 & 1) != 0) {
                            if (r1 == 0) {
                                ((C2591.C2598) r13).m6829();
                                break;
                            } else {
                                C2590.m6801("FRAME_SIZE_ERROR ack frame should be empty!", new Object[0]);
                                throw null;
                            }
                        } else if (r1 % 6 == 0) {
                            C2615 r123 = new C2615();
                            for (int i = 0; i < r1; i += 6) {
                                int readShort = this.f8805.readShort() & 65535;
                                int readInt3 = this.f8805.readInt();
                                switch (readShort) {
                                    case 2:
                                        if (!(readInt3 == 0 || readInt3 == 1)) {
                                            C2590.m6801("PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1", new Object[0]);
                                            throw null;
                                        }
                                    case 3:
                                        readShort = 4;
                                        break;
                                    case 4:
                                        readShort = 7;
                                        if (readInt3 >= 0) {
                                            break;
                                        } else {
                                            C2590.m6801("PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1", new Object[0]);
                                            throw null;
                                        }
                                    case 5:
                                        if (readInt3 >= 16384 && readInt3 <= 16777215) {
                                            break;
                                        } else {
                                            C2590.m6801("PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: %s", Integer.valueOf(readInt3));
                                            throw null;
                                        }
                                        break;
                                }
                                r123.m6885(readShort, readInt3);
                            }
                            ((C2591.C2598) r13).m6836(false, r123);
                            break;
                        } else {
                            C2590.m6801("TYPE_SETTINGS length %% 6 != 0: %s", Integer.valueOf(r1));
                            throw null;
                        }
                        break;
                    case 5:
                        if (readInt != 0) {
                            if ((readByte2 & 8) != 0) {
                                s2 = (short) (this.f8805.readByte() & 255);
                            }
                            C2591.this.m6815(this.f8805.readInt() & Integer.MAX_VALUE, m6880(m6878(r1 - 4, readByte2, s2), s2, readByte2, readInt));
                            break;
                        } else {
                            C2590.m6801("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0", new Object[0]);
                            throw null;
                        }
                    case 6:
                        if (r1 != 8) {
                            C2590.m6801("TYPE_PING length != 8: %s", Integer.valueOf(r1));
                            throw null;
                        } else if (readInt == 0) {
                            int readInt4 = this.f8805.readInt();
                            int readInt5 = this.f8805.readInt();
                            if ((readByte2 & 1) != 0) {
                                z2 = true;
                            }
                            ((C2591.C2598) r13).m6834(z2, readInt4, readInt5);
                            break;
                        } else {
                            C2590.m6801("TYPE_PING streamId != 0", new Object[0]);
                            throw null;
                        }
                    case 7:
                        if (r1 < 8) {
                            C2590.m6801("TYPE_GOAWAY length < 8: %s", Integer.valueOf(r1));
                            throw null;
                        } else if (readInt == 0) {
                            int readInt6 = this.f8805.readInt();
                            int readInt7 = this.f8805.readInt();
                            int i2 = r1 - 8;
                            ErrorCode fromHttp22 = ErrorCode.fromHttp2(readInt7);
                            if (fromHttp22 != null) {
                                ByteString byteString = ByteString.EMPTY;
                                if (i2 > 0) {
                                    byteString = this.f8805.m3813((long) i2);
                                }
                                ((C2591.C2598) r13).m6833(readInt6, fromHttp22, byteString);
                                break;
                            } else {
                                C2590.m6801("TYPE_GOAWAY unexpected error code: %d", Integer.valueOf(readInt7));
                                throw null;
                            }
                        } else {
                            C2590.m6801("TYPE_GOAWAY streamId != 0", new Object[0]);
                            throw null;
                        }
                    case 8:
                        if (r1 == 4) {
                            long readInt8 = ((long) this.f8805.readInt()) & 2147483647L;
                            if (readInt8 != 0) {
                                ((C2591.C2598) r13).m6832(readInt, readInt8);
                                break;
                            } else {
                                C2590.m6801("windowSizeIncrement was 0", Long.valueOf(readInt8));
                                throw null;
                            }
                        } else {
                            C2590.m6801("TYPE_WINDOW_UPDATE length !=4: %s", Integer.valueOf(r1));
                            throw null;
                        }
                    default:
                        this.f8805.skip((long) r1);
                        break;
                }
                return true;
            }
            C2590.m6801("Expected a SETTINGS frame but was %s", Byte.valueOf(readByte));
            throw null;
        } catch (IOException unused) {
            return false;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final List<C2614> m6880(int i, short s, byte b, int i2) throws IOException {
        C2613 k = this.f8803;
        k.f8811 = i;
        k.f8807 = i;
        k.f8810 = s;
        k.f8812 = b;
        k.f8808 = i2;
        C2608.C2610 k2 = this.f8804;
        while (!k2.f8796.m3821()) {
            int readByte = k2.f8796.readByte() & 255;
            if (readByte == 128) {
                throw new IOException("index == 0");
            } else if ((readByte & 128) == 128) {
                int r3 = k2.m6874(readByte, 127) - 1;
                if (k2.m6877(r3)) {
                    k2.f8798.add(C2608.f8784[r3]);
                } else {
                    int r4 = k2.m6873(r3 - C2608.f8784.length);
                    if (r4 >= 0) {
                        C2614[] kArr = k2.f8795;
                        if (r4 < kArr.length) {
                            k2.f8798.add(kArr[r4]);
                        }
                    }
                    StringBuilder r42 = C1293.m3416("Header index too large ");
                    r42.append(r3 + 1);
                    throw new IOException(r42.toString());
                }
            } else if (readByte == 64) {
                ByteString r32 = k2.m6869();
                C2608.m6861(r32);
                k2.m6876(-1, new C2614(r32, k2.m6869()));
            } else if ((readByte & 64) == 64) {
                k2.m6876(-1, new C2614(k2.m6870(k2.m6874(readByte, 63) - 1), k2.m6869()));
            } else if ((readByte & 32) == 32) {
                k2.f8800 = k2.m6874(readByte, 31);
                int i3 = k2.f8800;
                if (i3 < 0 || i3 > k2.f8794) {
                    StringBuilder r43 = C1293.m3416("Invalid dynamic table size update ");
                    r43.append(k2.f8800);
                    throw new IOException(r43.toString());
                }
                int i4 = k2.f8801;
                if (i3 < i4) {
                    if (i3 == 0) {
                        k2.m6875();
                    } else {
                        k2.m6871(i4 - i3);
                    }
                }
            } else if (readByte == 16 || readByte == 0) {
                ByteString r33 = k2.m6869();
                C2608.m6861(r33);
                k2.f8798.add(new C2614(r33, k2.m6869()));
            } else {
                k2.f8798.add(new C2614(k2.m6870(k2.m6874(readByte, 15) - 1), k2.m6869()));
            }
        }
        return this.f8804.m6872();
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m6882(AbstractC2612 r5, int i) throws IOException {
        int readInt = this.f8805.readInt();
        ((C2591.C2598) r5).m6831(i, readInt & Integer.MAX_VALUE, (this.f8805.readByte() & 255) + 1, (Integer.MIN_VALUE & readInt) != 0);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6879(AbstractC1496 r2) throws IOException {
        return (r2.readByte() & 255) | ((r2.readByte() & 255) << 16) | ((r2.readByte() & 255) << 8);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6878(int i, byte b, short s) throws IOException {
        if ((b & 8) != 0) {
            i--;
        }
        if (s <= i) {
            return (short) (i - s);
        }
        C2590.m6801("PROTOCOL_ERROR padding %s > remaining length %s", Short.valueOf(s), Integer.valueOf(i));
        throw null;
    }
}
