package g.i.a.c.o;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import com.cvte.vman.instance.InvokeCmd;
import g.h.a.i;
import g.i.a.b.e.h.e;
import g.i.a.c.g.c;
import g.i.a.c.l.c;
import g.i.a.c.q.f;
import g.i.a.c.q.g;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public abstract class b extends g.i.a.c.m.a.a {
    public BluetoothManager h0;
    public BluetoothAdapter i0;
    public final Object j0;
    public volatile boolean k0;
    public int[] l0;

    public b(Context context, f fVar, g.i.a.c.m.a.b bVar) {
        super(context, fVar, bVar);
        this.j0 = new Object();
        this.k0 = false;
        u();
    }

    public void E(BluetoothDevice bluetoothDevice, int i2) {
        String str;
        if (bluetoothDevice == null || (str = this.O) == null || !str.equals(bluetoothDevice.getAddress()) || i2 != 2) {
            return;
        }
        i.U3("profile connected");
        p();
    }

    public void F(e eVar) throws c {
        if (this.f5600r) {
            throw new c("user aborted", InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_DISPLAY_EDID_INFO);
        }
        z(InvokeCmd.CMD_XBUG_SET_XBUG_DUMP_CVTE_LOG, true);
        this.M = 0;
        this.k0 = false;
        H(eVar);
        try {
            synchronized (this.j0) {
                if (this.M == 0 && !this.k0) {
                    this.j0.wait(31000L);
                }
            }
        } catch (InterruptedException e2) {
            StringBuilder sbF = g.a.a.a.a.F("findRemoteDevice interrupted, e = ");
            sbF.append(e2.toString());
            i.W3(sbF.toString());
            this.M = 259;
        }
        if (this.M == 0 && !this.k0) {
            i.W3("didn't find the remote device");
            this.M = 265;
        }
        if (this.M != 0) {
            throw new c("Error while scan remote device", this.M);
        }
    }

    public BluetoothDevice G(String str) {
        try {
            return this.i0.getRemoteDevice(str);
        } catch (Exception e2) {
            i.W3(e2.toString());
            return null;
        }
    }

    public boolean H(e eVar) {
        return false;
    }

    public void I() {
        synchronized (this.e0) {
            if (this.f5593d0) {
                i.x0(this.f5594f, "Remote busy now, just wait!");
                try {
                    this.e0.wait(60000L);
                } catch (InterruptedException unused) {
                }
            }
        }
    }

    public void J() {
        int i2 = s().f5713o;
        int i3 = s().f5716r;
        if (i3 < 0 || i3 >= i2) {
            i.w0("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) {
            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;
        }
        if (this.f5594f) {
            i.U3(s().toString());
        }
    }

    public void K() throws g.i.a.c.g.b {
        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.f5541j = this.R;
        bVar.f5547p = r().f5697n;
        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 is null or empty");
            throw new g.i.a.c.g.b("no available file to update", 4097);
        }
        if (s().f5716r == 0) {
            this.l0 = new int[this.F.size()];
        }
        s().f5713o = this.F.size();
        J();
    }

    /* JADX WARN: Removed duplicated region for block: B:9:0x0025  */
    @Override // g.i.a.c.m.a.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void u() {
        /*
            r3 = this;
            super.u()
            g.i.a.c.q.i r0 = new g.i.a.c.q.i
            int r1 = r3.f5596n
            r2 = 2
            r0.<init>(r1, r2)
            r3.W = r0
            android.bluetooth.BluetoothManager r0 = r3.h0
            if (r0 != 0) goto L25
            android.content.Context r0 = r3.f5595m
            java.lang.String r1 = "bluetooth"
            java.lang.Object r0 = r0.getSystemService(r1)
            android.bluetooth.BluetoothManager r0 = (android.bluetooth.BluetoothManager) r0
            r3.h0 = r0
            if (r0 != 0) goto L25
            java.lang.String r0 = "Unable to initialize BluetoothManager."
        L21:
            g.h.a.i.W3(r0)
            return
        L25:
            android.bluetooth.BluetoothManager r0 = r3.h0
            android.bluetooth.BluetoothAdapter r0 = r0.getAdapter()
            r3.i0 = r0
            if (r0 != 0) goto L32
            java.lang.String r0 = "Unable to obtain a BluetoothAdapter."
            goto L21
        L32:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.o.b.u():void");
    }

    @Override // g.i.a.c.m.a.a
    public int v() {
        int iV = super.v();
        if (iV != 0) {
            return iV;
        }
        if (BluetoothAdapter.checkBluetoothAddress(this.P)) {
            return 0;
        }
        if (!this.f5594f) {
            i.w0("invalid address: ");
            return InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_HDMI_IN_OUT;
        }
        StringBuilder sbF = g.a.a.a.a.F("invalid address: ");
        sbF.append(this.P);
        i.W3(sbF.toString());
        return InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_HDMI_IN_OUT;
    }
}
