package g.i.a.c.z;

import android.content.Context;
import com.cvte.vman.instance.InvokeCmd;
import io.netty.handler.codec.compression.Bzip2Constants;
import java.io.IOException;
import no.nordicsemi.android.dfu.DfuBaseService;

/* JADX INFO: loaded from: classes.dex */
public class m extends k {
    public int v0;
    public boolean w0;

    public m(Context context, g.i.a.c.q.f fVar, g.i.a.c.m.a.b bVar) {
        super(context, fVar, bVar);
    }

    @Override // g.i.a.c.x.a, g.i.a.c.o.b
    public void J() {
        int i2 = s().f5713o;
        int i3 = s().f5716r;
        if (i3 < 0 || i3 >= i2) {
            g.h.a.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) {
                g.h.a.i.U3(String.format("mCurBinInputStream's binId=0x%04X", Integer.valueOf(aVar.f5575z)));
            }
            g.i.a.c.q.g gVarS = s();
            g.i.a.c.l.e.a aVar2 = this.G;
            gVarS.n(aVar2.f5575z, aVar2.f5570u, aVar2.f5572w, aVar2.h() + 12, r().f5707x);
        } else {
            g.h.a.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.m.a.a
    public void g(int i2, boolean z2) {
        if (i2 != 0) {
            try {
                int iMax = Math.max(i2 - 12, 0);
                byte[] bArr = new byte[s().f5710f];
                if (z2) {
                    this.G.g(bArr, iMax);
                } else {
                    this.G.read(bArr, 0, iMax);
                }
            } catch (IOException e2) {
                g.h.a.i.D0(e2.toString());
                return;
            }
        }
        s().r(i2);
    }

    @Override // g.i.a.c.m.a.a
    public void o() {
        int iV;
        try {
            setName("ProcessorXS0011ForceTemp");
            g.h.a.i.w0("ProcessorXS0011ForceTemp is running.");
            iV = v();
        } catch (Exception e2) {
            e2.printStackTrace();
            g.h.a.i.D0(e2.toString());
            X(0, false);
        }
        if (iV != 0) {
            X(iV, false);
            return;
        }
        z(InvokeCmd.CMD_XBUG_GET_VMAN_SERVICE_LOG_LEVEL, true);
        this.O = this.P;
        this.f5602t = true;
        this.J = 0;
        this.w0 = false;
        if (t0()) {
            if (t().f5686v) {
                g.h.a.i.U3("RWS, no need to disconnect manully");
                if (t().f5675k <= 5) {
                    Y(false);
                } else {
                    this.w0 = true;
                    if (t().f5687w == 1) {
                        this.v0 = 2;
                    } else {
                        int i2 = t().f5687w;
                        this.v0 = 1;
                    }
                    j0(0);
                }
                z(522, true);
                g.h.a.i.x0(this.f5594f, "wait master to handover ...");
                try {
                    Thread.sleep(((long) r().f5692b0) * 1000);
                } catch (InterruptedException unused) {
                }
                g.h.a.i.w0("start to upload secondary bud ...");
                this.f5602t = true;
                this.f5601s = false;
                this.J = 0;
                if (t0()) {
                    if (this.T) {
                        Y(true);
                        if (r().d(1)) {
                            g.i.a.b.e.b.a.c(this.i0.getRemoteDevice(this.O));
                            g.i.a.b.e.b.a.d(this.O);
                        }
                        z(Bzip2Constants.HUFFMAN_MAX_ALPHABET_SIZE, true);
                    }
                    z(523, true);
                }
            } else if (this.T) {
                Y(true);
                if (r().d(1)) {
                    g.i.a.b.e.b.a.c(this.i0.getRemoteDevice(this.O));
                    g.i.a.b.e.b.a.d(this.O);
                }
                z(Bzip2Constants.HUFFMAN_MAX_ALPHABET_SIZE, true);
            } else {
                z(523, true);
            }
        }
        k(this.G);
        if (this.E == 525) {
            z(259, true);
        }
        g.h.a.i.w0("ProcessorXS0011ForceTemp stopped.");
    }

    public boolean t0() {
        int iU0;
        boolean z2 = false;
        while (!this.f5600r) {
            try {
            } catch (g.i.a.c.a e2) {
                g.h.a.i.D0(g.h.a.i.T2(this.E) + ", " + e2.toString());
                int i2 = e2.f5446m;
                if (i2 == 4128) {
                    X(i2, true);
                } else if (i2 == 4097) {
                    X(i2, false);
                } else {
                    s0();
                    X(i2, false);
                }
            }
            if (!v0() || (iU0 = u0()) == 0) {
                return false;
            }
            if (iU0 == 2) {
                z2 = true;
            }
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e3) {
                e3.printStackTrace();
            }
            if (z2) {
                return z2;
            }
        }
        X(InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_DISPLAY_EDID_INFO, false);
        return false;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:52:0x019f  */
    /* JADX WARN: Type inference failed for: r2v27 */
    /* JADX WARN: Type inference failed for: r2v40 */
    /* JADX WARN: Type inference failed for: r2v8, types: [boolean] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int u0() throws g.i.a.c.g.c {
        /*
            Method dump skipped, instruction units count: 1202
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.z.m.u0():int");
    }

    public final boolean v0() throws g.i.a.c.g.c {
        g0(this.O);
        if (this.f5601s) {
            J();
        } else {
            this.f5601s = false;
            if (!this.f5600r) {
                z(InvokeCmd.CMD_XBUG_VMAN_FUNTION_CHECK_TIMEOUT_BASE_GET, true);
                try {
                    Thread.sleep(1500L);
                } catch (InterruptedException e2) {
                    e2.printStackTrace();
                }
                this.W = new g.i.a.c.q.i(17, 2);
                r0();
                if (t().f5686v) {
                    if (t().f5675k < 6) {
                        g.h.a.i.x0(this.f5594f, String.format("<< CMD_OTA_GET_OTHER_INFO (0x%04X)", (short) 1547));
                        byte[] bArrB0 = b0((short) 1547);
                        if (bArrB0 == null || bArrB0.length <= 0) {
                            t().f5688x = 0;
                        } else {
                            t().f5688x = bArrB0[0] & 1;
                        }
                        if (t().f5688x != 0) {
                            throw new g.i.a.c.g.c("rws state not ready", 282);
                        }
                    } else if (this.w0 && t().f5687w != this.v0) {
                        throw new g.i.a.c.g.c("role swap failed", DfuBaseService.NOTIFICATION_ID);
                    }
                }
                o0();
                if (t().N && t().f5675k >= 5) {
                    q0();
                }
                if (t().M == 3) {
                    p0();
                }
                if (this.f5594f) {
                    g.h.a.i.w0(t().toString());
                }
                K();
                this.f5601s = true;
                g.h.a.i.w0("Ota Environment prepared.");
            } else {
                X(InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_DISPLAY_EDID_INFO, false);
            }
        }
        if (this.G != null) {
            return true;
        }
        X(4097, false);
        return false;
    }
}
