package g.i.a.c.x;

import android.content.Context;
import com.cvte.vman.instance.InvokeCmd;
import g.h.a.i;
import g.i.a.a.a.a.c;
import g.i.a.b.e.h.d;
import g.i.a.b.e.h.e;
import g.i.a.c.l.c;
import g.i.a.c.o.b;
import g.i.a.c.q.f;
import g.i.a.c.q.g;
import io.netty.handler.traffic.AbstractTrafficShapingHandler;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/* JADX INFO: loaded from: classes.dex */
public class a extends b {
    public g.i.a.b.e.h.a m0;
    public volatile boolean n0;
    public C0087a o0;
    public volatile byte[] p0;
    public volatile boolean q0;
    public Set<Short> r0;
    public Map<Short, g.i.a.a.a.a.a> s0;
    public c t0;

    /* JADX INFO: renamed from: g.i.a.c.x.a$a, reason: collision with other inner class name */
    public class C0087a extends d {
        public C0087a() {
        }

        /* JADX WARN: Removed duplicated region for block: B:53:0x00e7  */
        /* JADX WARN: Removed duplicated region for block: B:54:0x00e9  */
        @Override // g.i.a.b.e.h.d
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void a(g.i.a.b.e.h.b r8) {
            /*
                Method dump skipped, instruction units count: 314
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.x.a.C0087a.a(g.i.a.b.e.h.b):void");
        }

        @Override // g.i.a.b.e.h.d
        public void b(int i2) {
            Objects.requireNonNull(a.this);
        }
    }

    public a(Context context, f fVar, g.i.a.c.m.a.b bVar) {
        super(context, fVar, bVar);
        this.p0 = null;
        this.q0 = false;
    }

    @Override // g.i.a.c.m.a.a
    public void A() {
        this.n0 = false;
        g.i.a.b.e.h.a aVar = this.m0;
        if (aVar != null) {
            aVar.j();
        }
    }

    @Override // g.i.a.c.o.b
    public boolean H(e eVar) {
        if (this.f5594f) {
            i.U3("start le scan");
        }
        this.n0 = true;
        g.i.a.b.e.h.a aVar = this.m0;
        if (aVar == null) {
            Q(eVar);
        } else {
            aVar.f5308c = eVar;
        }
        return this.m0.k();
    }

    @Override // g.i.a.c.o.b
    public void J() {
        int i2 = s().f5713o;
        int i3 = s().f5716r;
        if (i3 < 0 || i3 >= i2) {
            i.U3("invalid FileIndex: " + i3 + ", reset to 0");
            i3 = 0;
        }
        s().f5714p = i3;
        g.i.a.c.l.e.a aVar = this.F.get(i3);
        this.G = aVar;
        if (aVar != null) {
            if (this.f5594f) {
                i.U3(String.format("mCurBinInputStream's binId=0x%04X", Integer.valueOf(aVar.f5575z)));
            }
            g gVarS = s();
            g.i.a.c.l.e.a aVar2 = this.G;
            gVarS.n(aVar2.f5575z, aVar2.f5570u, aVar2.f5572w, aVar2.h(), r().f5707x);
        } else {
            i.V3(false, "mCurBinInputStream == null");
        }
        int i4 = i3 + 1;
        if (i4 < i2) {
            this.H = this.F.get(i4);
            this.I = i4;
        } else {
            this.H = null;
            this.I = -1;
        }
    }

    @Override // g.i.a.c.o.b
    public void K() {
        k(this.G);
        c.b bVar = new c.b();
        bVar.f5536e = r().f5698o;
        bVar.f5533b = r().f5700q;
        bVar.f5534c = this.Q;
        bVar.f5535d = r().c();
        bVar.a = this.f5595m;
        bVar.f5547p = this.S;
        bVar.f5541j = this.R;
        bVar.f5542k = t();
        bVar.f5545n = r().n();
        bVar.f5546o = r().o();
        boolean zP = r().p();
        int i2 = r().f5705v;
        bVar.f5543l = zP;
        bVar.f5544m = i2;
        List<g.i.a.c.l.e.a> listO = g.i.a.c.l.b.o(bVar.a());
        this.F = listO;
        if (listO == null || listO.size() <= 0) {
            i.x0(this.f5594f, "pendingImageInputStreams == null || pendingImageInputStreams.size() <= 0");
            throw new g.i.a.c.g.b("load image file error", 4097);
        }
        if (s().f5716r == 0) {
            this.l0 = new int[this.F.size()];
        }
        s().f5713o = this.F.size();
        if (this.f5594f) {
            i.U3(s().toString());
        }
        J();
    }

    public boolean L(short s2, byte[] bArr) {
        return N(s2, bArr, bArr != null ? bArr.length : -1, false);
    }

    public boolean M(short s2, byte[] bArr, int i2) {
        return N(s2, bArr, i2, false);
    }

    public boolean N(short s2, byte[] bArr, int i2, boolean z2) throws g.i.a.c.g.c {
        boolean zJ;
        if (this.f5600r && !z2) {
            throw new g.i.a.c.g.c("user aborted", InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_DISPLAY_EDID_INFO);
        }
        this.p0 = null;
        this.C = true;
        boolean z3 = false;
        this.B = false;
        if (this.t0 == null) {
            i.W3("mTransportLayer == null");
            zJ = false;
        } else {
            if (bArr != null && bArr.length > i2) {
                byte[] bArr2 = new byte[i2];
                System.arraycopy(bArr, 0, bArr2, 0, i2);
                bArr = bArr2;
            }
            zJ = this.t0.j(s2, bArr);
        }
        int i3 = 267;
        if (zJ) {
            synchronized (this.A) {
                try {
                    if (!this.B && this.f5605w == 515) {
                        this.A.wait(AbstractTrafficShapingHandler.DEFAULT_MAX_TIME);
                    }
                } catch (InterruptedException e2) {
                    i.W3("mWriteLock Sleeping interrupted,e:" + e2);
                    if (this.M == 0) {
                        this.M = 259;
                    }
                }
            }
            if (this.M == 0) {
                if (!this.B) {
                    i.x0(this.f5594f, "send command but no callback");
                    i3 = 261;
                } else if (this.C) {
                    i.x0(this.f5594f, "write failed");
                }
                this.M = i3;
            }
            z3 = zJ;
        } else {
            i.w0("write spp data error");
            this.M = 267;
        }
        if (this.M == 0) {
            return z3;
        }
        throw new g.i.a.c.g.c("Error while send command", this.M);
    }

    public void O(int i2) {
        this.f5592c0 = i2 > 16 ? 16 * (i2 / 16) : 16;
        g.a.a.a.a.m0(g.a.a.a.a.F("> mBufferCheckMtuSize="), this.f5592c0);
    }

    public byte[] P(long j2) {
        this.M = 0;
        this.q0 = true;
        try {
            synchronized (this.V) {
                if (this.M == 0 && this.p0 == null && this.f5605w == 515) {
                    this.q0 = false;
                    this.V.wait(j2);
                }
                if (this.M == 0 && !this.q0) {
                    i.W3("wait for notification, but not come");
                    this.M = 767;
                }
            }
        } catch (InterruptedException e2) {
            StringBuilder sbF = g.a.a.a.a.F("readNotificationResponse interrupted, ");
            sbF.append(e2.toString());
            i.D0(sbF.toString());
            this.M = 259;
        }
        if (this.M == 0) {
            return this.p0;
        }
        throw new g.i.a.c.g.c("Unable to receive notification", this.M);
    }

    public final void Q(e eVar) {
        if (this.o0 == null) {
            this.o0 = new C0087a();
        }
        this.m0 = new g.i.a.b.e.h.a(this.f5595m, eVar, this.o0);
    }

    public byte[] R() {
        return P(r().h0);
    }

    @Override // g.i.a.c.o.b, g.i.a.c.m.a.a
    public void u() {
        super.u();
        this.r0 = new HashSet();
        this.s0 = new HashMap();
        Q(null);
        this.f5599q = true;
        i.U3("initialize success");
    }
}
