package g.i.a.c.w;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.content.Context;
import com.cvte.vman.instance.InvokeCmd;
import g.h.a.i;
import g.i.a.c.p.h;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;

/* JADX INFO: loaded from: classes.dex */
public abstract class c extends g.i.a.c.p.c {
    public BluetoothGattCharacteristic H0;
    public List<BluetoothGattCharacteristic> I0;
    public List<BluetoothGattCharacteristic> J0;
    public final BluetoothGattCallback K0;

    public class a extends BluetoothGattCallback {
        public a() {
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onCharacteristicChanged(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
            byte[] value = bluetoothGattCharacteristic.getValue();
            synchronized (this) {
                if (value == null) {
                    i.W3("notification data invalid");
                } else if (value.length < 2) {
                    i.W3("notification data invalid");
                } else {
                    int i2 = value[0] & 255;
                    int i3 = value[1] & 255;
                    i.V3(c.this.f5594f, String.format("responseType = %02X , requestOpCode = %02X", Integer.valueOf(i2), Integer.valueOf(i3)));
                    if (i2 == 16) {
                        if (i3 == 7) {
                            synchronized (c.this.V) {
                                i.w0("ignore connection parameters notification");
                                c.this.r0 = value;
                                c.this.t0 = true;
                                c.this.V.notifyAll();
                            }
                        } else if (i3 != 8) {
                            synchronized (c.this.V) {
                                c.this.r0 = value;
                                c.this.t0 = true;
                                c.this.V.notifyAll();
                            }
                        } else {
                            byte b2 = value.length >= 3 ? value[2] : (byte) 0;
                            i.w0("remote state changed, busyMode=" + ((int) b2));
                            synchronized (c.this.e0) {
                                c cVar = c.this;
                                cVar.f5593d0 = b2 == 1;
                                cVar.e0.notifyAll();
                            }
                        }
                    }
                }
            }
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onCharacteristicRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i2) {
            c cVar = c.this;
            if (i2 == 0) {
                cVar.f5608z = bluetoothGattCharacteristic.getValue();
            } else {
                cVar.M = i2 | 1024;
                i.W3(String.format(Locale.US, "read Characteristic error:0x%04X", Integer.valueOf(c.this.M)));
            }
            c.this.y();
        }

        /* JADX WARN: Removed duplicated region for block: B:10:0x002f  */
        /* JADX WARN: Removed duplicated region for block: B:9:0x001f  */
        @Override // android.bluetooth.BluetoothGattCallback
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void onCharacteristicWrite(android.bluetooth.BluetoothGatt r6, android.bluetooth.BluetoothGattCharacteristic r7, int r8) {
            /*
                r5 = this;
                byte[] r6 = r7.getValue()
                java.lang.String r0 = "characteristic'value is null, exception"
                r1 = 0
                if (r8 != 0) goto L33
                g.i.a.c.w.c r8 = g.i.a.c.w.c.this
                r8.C = r1
                g.i.a.c.w.c r8 = g.i.a.c.w.c.this
                java.util.UUID r8 = r8.C0
                if (r8 == 0) goto L95
                java.util.UUID r7 = r7.getUuid()
                boolean r7 = r8.equals(r7)
                if (r7 == 0) goto L95
                if (r6 == 0) goto L2f
            L1f:
                g.i.a.c.w.c r7 = g.i.a.c.w.c.this
                g.i.a.c.q.g r7 = r7.s()
                int r6 = r6.length
                r7.a(r6)
                g.i.a.c.w.c r6 = g.i.a.c.w.c.this
                r6.x()
                goto L95
            L2f:
                g.h.a.i.W3(r0)
                goto L95
            L33:
                r2 = 257(0x101, float:3.6E-43)
                r3 = 1
                r4 = 143(0x8f, float:2.0E-43)
                if (r8 == r2) goto L59
                if (r8 != r4) goto L3d
                goto L59
            L3d:
                g.i.a.c.w.c r6 = g.i.a.c.w.c.this
                r7 = r8 | 1024(0x400, float:1.435E-42)
                r6.M = r7
                java.lang.Object[] r6 = new java.lang.Object[r3]
                g.i.a.c.w.c r7 = g.i.a.c.w.c.this
                int r7 = r7.M
                java.lang.Integer r7 = java.lang.Integer.valueOf(r7)
                r6[r1] = r7
                java.lang.String r7 = "Characteristic write error: 0x%04X"
                java.lang.String r6 = java.lang.String.format(r7, r6)
                g.h.a.i.W3(r6)
                goto L95
            L59:
                g.i.a.c.w.c r2 = g.i.a.c.w.c.this
                java.util.UUID r2 = r2.C0
                if (r2 == 0) goto L95
                java.util.UUID r7 = r7.getUuid()
                boolean r7 = r2.equals(r7)
                if (r7 == 0) goto L95
                if (r8 != r4) goto L72
                g.i.a.c.w.c r7 = g.i.a.c.w.c.this
                r7.C = r1
                if (r6 == 0) goto L2f
                goto L1f
            L72:
                g.i.a.c.w.c r6 = g.i.a.c.w.c.this
                r6.C = r3
                g.i.a.c.w.c r6 = g.i.a.c.w.c.this
                boolean r6 = r6.f5594f
                if (r6 == 0) goto L95
                java.lang.StringBuilder r6 = new java.lang.StringBuilder
                r6.<init>()
                java.lang.String r7 = "write image packet error, status="
                r6.append(r7)
                r6.append(r8)
                java.lang.String r7 = ", please retry."
                r6.append(r7)
                java.lang.String r6 = r6.toString()
                g.h.a.i.w0(r6)
            L95:
                g.i.a.c.w.c r6 = g.i.a.c.w.c.this
                r6.q()
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.w.c.a.onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int):void");
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onConnectionStateChange(BluetoothGatt bluetoothGatt, int i2, int i3) {
            if (i2 != 0) {
                if (i3 == 0) {
                    c.this.B(0);
                }
                c.this.M = i2 | 2048;
            } else if (i3 == 2) {
                c cVar = c.this;
                if (cVar.f5600r) {
                    i.W3("task already aborted, ignore");
                    return;
                } else if (cVar.f5605w == 256) {
                    g.i.a.b.e.g.a.b(bluetoothGatt);
                    c.this.b0();
                    return;
                }
            } else if (i3 == 0) {
                if (c.this.E == 521) {
                    c.this.M = i2 | 2048;
                    c cVar2 = c.this;
                    if (cVar2.f5594f) {
                        i.w0(String.format("disconnect in OTA process, mErrorState:0x%04X ", Integer.valueOf(cVar2.M)));
                    }
                    c.this.q();
                }
                c.this.B(0);
            }
            synchronized (c.this.f5604v) {
                c cVar3 = c.this;
                if (cVar3.f5605w != 256) {
                    cVar3.f5603u = true;
                }
                c.this.f5604v.notifyAll();
            }
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onDescriptorWrite(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, int i2) {
            if (i2 != 0) {
                c.this.M = i2 | 1024;
            } else if (g.i.a.c.p.f.f5633b.equals(bluetoothGattDescriptor.getUuid())) {
                c.this.s0 = true;
            }
            c.this.n();
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onMtuChanged(BluetoothGatt bluetoothGatt, int i2, int i3) {
            if (i3 == 0) {
                Objects.requireNonNull(c.this);
                i.V3(false, "mtu=" + i2);
                if (c.this.r().F) {
                    c.this.W(i2);
                }
            }
            c.this.u0 = true;
            c.this.n();
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onPhyUpdate(BluetoothGatt bluetoothGatt, int i2, int i3, int i4) {
            super.onPhyUpdate(bluetoothGatt, i2, i3, i4);
            i.U3(String.format("onPhyUpdate: mConnectionState=0x%04X", Integer.valueOf(c.this.f5605w)));
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onServicesDiscovered(BluetoothGatt bluetoothGatt, int i2) {
            String strA;
            StringBuilder sbF;
            UUID uuid;
            c cVar = c.this;
            if (cVar.f5600r) {
                i.W3("task already aborted, ignore");
                return;
            }
            if (i2 == 0) {
                BluetoothGattService service = bluetoothGatt.getService(cVar.x0);
                cVar.y0 = service;
                if (service == null) {
                    g.a.a.a.a.u0(cVar.x0, g.a.a.a.a.F("OTA_SERVICE not found: "));
                } else {
                    if (cVar.f5594f) {
                        g.a.a.a.a.t0(cVar.x0, g.a.a.a.a.F("find OTA_SERVICE: "));
                    }
                    BluetoothGattService bluetoothGattService = cVar.y0;
                    UUID uuid2 = g.a;
                    BluetoothGattCharacteristic characteristic = bluetoothGattService.getCharacteristic(uuid2);
                    cVar.z0 = characteristic;
                    if (characteristic == null) {
                        g.a.a.a.a.j0("OTA_CONTROL_ENTER_OTA_MODE_CHARACTERISTIC not found: ", uuid2);
                    } else {
                        if (cVar.f5594f) {
                            g.a.a.a.a.i0("find OTA_CONTROL_ENTER_OTA_MODE_CHARACTERISTIC = ", uuid2);
                            g.a.a.a.a.U(cVar.z0);
                        }
                        cVar.z0.setWriteType(1);
                    }
                    BluetoothGattService bluetoothGattService2 = cVar.y0;
                    UUID uuid3 = g.f5761b;
                    BluetoothGattCharacteristic characteristic2 = bluetoothGattService2.getCharacteristic(uuid3);
                    cVar.H0 = characteristic2;
                    if (characteristic2 == null) {
                        g.a.a.a.a.j0("OTA_MAC_ADDR_CHARACTERISTIC_UUID not found:", uuid3);
                    } else if (cVar.f5594f) {
                        g.a.a.a.a.i0("find OTA_MAC_ADDR_CHARACTERISTIC_UUID = ", uuid3);
                        g.a.a.a.a.U(cVar.z0);
                    }
                    BluetoothGattService bluetoothGattService3 = cVar.y0;
                    UUID uuid4 = g.f5762c;
                    BluetoothGattCharacteristic characteristic3 = bluetoothGattService3.getCharacteristic(uuid4);
                    cVar.A0 = characteristic3;
                    if (characteristic3 == null) {
                        g.a.a.a.a.j0("OTA_DEVICE_INFO_CHARACTERISTIC_UUID not found:", uuid4);
                    } else if (cVar.f5594f) {
                        g.a.a.a.a.i0("find OTA_DEVICE_INFO_CHARACTERISTIC_UUID: ", uuid4);
                        g.a.a.a.a.U(cVar.A0);
                    }
                    cVar.I0 = new ArrayList();
                    int i3 = 65504;
                    while (true) {
                        if (i3 >= 65519) {
                            break;
                        }
                        UUID uuidA = g.i.a.b.e.i.a.a(i3);
                        BluetoothGattCharacteristic characteristic4 = cVar.y0.getCharacteristic(uuidA);
                        if (characteristic4 != null) {
                            if (cVar.f5594f) {
                                g.a.a.a.a.t0(uuidA, g.a.a.a.a.F("find image version characteristic: "));
                            }
                            cVar.I0.add(characteristic4);
                            i3++;
                        } else if (cVar.f5594f) {
                            g.a.a.a.a.t0(uuidA, g.a.a.a.a.F("not found image version characteristic:"));
                        }
                    }
                    cVar.J0 = new ArrayList();
                    for (int i4 = 65524; i4 < 65526; i4++) {
                        BluetoothGattCharacteristic characteristic5 = cVar.y0.getCharacteristic(g.i.a.b.e.i.a.a(i4));
                        if (characteristic5 == null) {
                            break;
                        }
                        cVar.J0.add(characteristic5);
                    }
                }
                c cVar2 = c.this;
                Objects.requireNonNull(cVar2);
                try {
                    cVar2.x0 = UUID.fromString(cVar2.r().R);
                    cVar2.B0 = UUID.fromString(cVar2.r().S);
                    cVar2.C0 = UUID.fromString(cVar2.r().T);
                    cVar2.D0 = UUID.fromString(cVar2.r().U);
                } catch (Exception e2) {
                    i.W3(e2.toString());
                }
                BluetoothGattService service2 = bluetoothGatt.getService(cVar2.B0);
                cVar2.E0 = service2;
                if (service2 == null) {
                    sbF = g.a.a.a.a.F("DFU_SERVICE not found:");
                    sbF.append(cVar2.B0);
                } else {
                    if (cVar2.f5594f) {
                        g.a.a.a.a.t0(cVar2.B0, g.a.a.a.a.F("find DFU_SERVICE: "));
                    }
                    BluetoothGattCharacteristic characteristic6 = cVar2.E0.getCharacteristic(cVar2.D0);
                    cVar2.F0 = characteristic6;
                    if (characteristic6 == null) {
                        sbF = g.a.a.a.a.F("not found DFU_CONTROL_POINT_UUID: ");
                        uuid = cVar2.D0;
                    } else {
                        if (cVar2.f5594f) {
                            g.a.a.a.a.t0(cVar2.D0, g.a.a.a.a.F("find DFU_CONTROL_POINT_UUID: "));
                        }
                        cVar2.F0.setWriteType(2);
                        g.a.a.a.a.U(cVar2.F0);
                        BluetoothGattCharacteristic characteristic7 = cVar2.E0.getCharacteristic(cVar2.C0);
                        cVar2.G0 = characteristic7;
                        if (characteristic7 == null) {
                            sbF = g.a.a.a.a.F("not found DFU_DATA_UUID: ");
                            uuid = cVar2.C0;
                        } else {
                            if (cVar2.f5594f) {
                                g.a.a.a.a.t0(cVar2.C0, g.a.a.a.a.F("find DFU_DATA_UUID: "));
                            }
                            cVar2.G0.setWriteType(1);
                            strA = g.i.a.b.e.g.a.a(cVar2.G0.getProperties());
                            i.w0(strA);
                            c.this.B(InvokeCmd.CMD_XBUG_SET_XBUG_DUMP_CVTE_LOG);
                            c.this.w();
                        }
                    }
                    sbF.append(uuid.toString());
                }
                strA = sbF.toString();
                i.w0(strA);
                c.this.B(InvokeCmd.CMD_XBUG_SET_XBUG_DUMP_CVTE_LOG);
                c.this.w();
            } else {
                cVar.M = i2 | 2048;
            }
            synchronized (c.this.f5604v) {
                c cVar3 = c.this;
                if (cVar3.f5605w == 515) {
                    cVar3.f5603u = true;
                }
                c.this.f5604v.notifyAll();
            }
        }
    }

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

    public int g0(String str, int i2) {
        BluetoothDevice remoteDevice;
        StringBuilder sb;
        int i3;
        int i4 = 0;
        while (!this.f5600r) {
            B(256);
            this.M = 0;
            this.f5603u = false;
            if (this.f5594f) {
                i.w0("Connecting to device..." + str);
            }
            BluetoothGatt bluetoothGattConnectGatt = null;
            try {
                remoteDevice = this.i0.getRemoteDevice(str);
            } catch (Exception e2) {
                i.W3(e2.toString());
                remoteDevice = null;
            }
            g.i.a.b.e.c cVar = this.p0;
            if (cVar != null) {
                cVar.k(str, this.K0);
                this.p0.d(str, this.K0);
                bluetoothGattConnectGatt = this.p0.f5342g.get(str);
                this.q0 = bluetoothGattConnectGatt;
                try {
                    synchronized (this.f5604v) {
                        if (!this.f5603u && this.M == 0) {
                            if (this.f5594f) {
                                i.w0("wait for connect gatt for 32000 ms");
                            }
                            this.f5604v.wait(32000L);
                        }
                    }
                } catch (InterruptedException e3) {
                    e = e3;
                    sb = new StringBuilder();
                    sb.append("Sleeping interrupted : ");
                    sb.append(e.toString());
                    i.W3(sb.toString());
                    this.M = 259;
                }
            } else if (remoteDevice != null) {
                bluetoothGattConnectGatt = remoteDevice.connectGatt(this.f5595m, false, this.K0);
                this.q0 = bluetoothGattConnectGatt;
                try {
                    synchronized (this.f5604v) {
                        if (!this.f5603u && this.M == 0) {
                            if (this.f5594f) {
                                i.w0("wait for connect gatt for 32000 ms");
                            }
                            this.f5604v.wait(32000L);
                        }
                    }
                } catch (InterruptedException e4) {
                    e = e4;
                    sb = new StringBuilder();
                    sb.append("Sleeping interrupted : ");
                    sb.append(e.toString());
                    i.W3(sb.toString());
                    this.M = 259;
                }
            } else {
                i.W3("device is null");
                this.q0 = null;
            }
            if (this.M == 0) {
                if (!this.f5603u) {
                    i.W3("wait for connect, but can not connect with no callback");
                    i3 = 260;
                } else if (bluetoothGattConnectGatt == null || this.f5605w != 515) {
                    StringBuilder sbF = g.a.a.a.a.F("connect with some error, please check. mConnectionState=");
                    sbF.append(this.f5605w);
                    i.W3(sbF.toString());
                    i3 = 264;
                }
                this.M = i3;
            }
            if (this.M == 0 && this.f5594f) {
                i.U3("connected the device which going to upgrade");
            }
            int i5 = this.M;
            if (i5 == 0) {
                return 0;
            }
            if ((i5 & (-2049)) != 133) {
                U(this.q0);
            } else {
                i.W3("connect fail with GATT_ERROR, do not need disconnect");
            }
            L(this.q0);
            try {
                Thread.sleep(1600L);
            } catch (InterruptedException unused) {
            }
            i4++;
            i.V3(false, "tryConnectTime=" + i4);
            if (i4 > i2) {
                return i5;
            }
        }
        return InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_DISPLAY_EDID_INFO;
    }

    public void h0(byte b2) {
        l0(new byte[]{4, b2});
    }

    public void i0(int i2, byte b2) {
        h hVar = new h(t().a, t().f5675k, i2, b2, null);
        if (this.f5594f) {
            i.w0(hVar.toString());
        }
        R(this.F0, hVar.a(), false);
        if (this.f5594f) {
            i.U3("... waiting DFU_VALIDATE_FW_IMAGE response");
        }
        byte b3 = c0()[2];
        if (b3 == 1) {
            return;
        }
        Object[] objArr = new Object[1];
        if (b3 == 5) {
            objArr[0] = Byte.valueOf(b3);
            throw g.a.a.a.a.c("0x%02X, Validate FW failed, CRC check error", objArr, "Validate FW failed", InvokeCmd.CMD_XBUG_VMAN_FUNTION_CHECK_TIMEOUT_BASE_GET);
        }
        objArr[0] = Byte.valueOf(b3);
        throw g.a.a.a.a.c("0x%02X(not supported), Validate FW failed", objArr, "Validate FW failed", 766);
    }

    public void j0(int i2, boolean z2) {
        if (this.f5600r) {
            i2 = 4128;
        }
        if (i2 != 4128) {
            z(260, true);
        }
        i.U3(String.format("error = 0x%04X, needReset=%b", Integer.valueOf(i2), Boolean.valueOf(z2)));
        if (z2) {
            w0();
        }
        this.m0.l();
        k(this.G);
        if (r().f(1)) {
            Y(i2);
        }
        g.i.a.c.m.a.b bVar = this.f5598p;
        if (bVar != null) {
            bVar.a(i2);
        }
        this.f5600r = true;
    }

    public void k0(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, g.i.a.c.l.e.a aVar) {
        int iG;
        j();
        this.M = 0;
        this.D = false;
        int i2 = this.U;
        byte[] bArr = new byte[i2];
        while (!this.D) {
            if (this.f5600r) {
                throw new g.i.a.c.g.c("user aborted", InvokeCmd.CMD_EXTENDDISPLAY_CTRL_GET_DISPLAY_EDID_INFO);
            }
            C();
            if (this.f5594f) {
                i.U3(s().toString());
            }
            try {
                if (s().f5711m == 0) {
                    int i3 = this.U;
                    byte[] bArr2 = new byte[i3];
                    aVar.g(bArr2, i3 - 12);
                    System.arraycopy(aVar.f5567r, 0, bArr, 0, 12);
                    System.arraycopy(bArr2, 0, bArr, 12, this.U - 12);
                    iG = this.U;
                } else {
                    iG = aVar.g(bArr, i2);
                }
                if (s().d() < this.U) {
                    i.U3("reach the end of the file, only read some");
                    iG = s().d();
                }
                int i4 = iG;
                if (i4 <= 0) {
                    if (s().o()) {
                        i.w0("image file has already been send over");
                        return;
                    }
                    i.W3("Error while reading file with size: " + i4);
                    throw new g.i.a.c.g.c("Error while reading file", 257);
                }
                if (t().f5681q) {
                    for (int i5 = i4; i5 > 0; i5 -= 16) {
                        if (i5 >= 16) {
                            int i6 = i4 - i5;
                            System.arraycopy(this.L.a(bArr, i6, 16), 0, bArr, i6, 16);
                            if (t().f5682r == 0) {
                                break;
                            }
                        }
                    }
                }
                Q(bluetoothGatt, bluetoothGattCharacteristic, bArr, i4, false);
                I();
                i();
            } catch (IOException unused) {
                throw new g.i.a.c.g.c("Error while reading file", 257);
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0034  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0044  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void l0(byte[] r5) throws g.i.a.c.g.c {
        /*
            r4 = this;
            r0 = 524(0x20c, float:7.34E-43)
            r1 = 1
            r4.z(r0, r1)
            r0 = 0
            java.lang.String r2 = "<< OPCODE_DFU_ACTIVE_IMAGE_RESET(0x04)"
            g.h.a.i.w0(r2)     // Catch: g.i.a.c.a -> L13
            android.bluetooth.BluetoothGattCharacteristic r2 = r4.F0     // Catch: g.i.a.c.a -> L13
            boolean r1 = r4.R(r2, r5, r0)     // Catch: g.i.a.c.a -> L13
            goto L28
        L13:
            r5 = move-exception
            int r2 = r5.f5446m
            r3 = 4128(0x1020, float:5.785E-42)
            if (r2 != r3) goto L1b
            goto L32
        L1b:
            g.i.a.c.q.f r2 = r4.r()
            boolean r2 = r2.f5709z
            if (r2 != 0) goto L2b
            java.lang.String r5 = "active cmd has no response, ignore"
            g.h.a.i.w0(r5)
        L28:
            r3 = r0
            r0 = r1
            goto L32
        L2b:
            java.lang.String r1 = "active cmd has no response, notify error"
            g.h.a.i.W3(r1)
            int r3 = r5.f5446m
        L32:
            if (r0 == 0) goto L44
            java.lang.String r5 = "image active success"
            g.h.a.i.V1(r5)
            int r5 = r4.M
            r4.Y(r5)
            g.i.a.c.l.e.a r5 = r4.G
            r4.k(r5)
            return
        L44:
            g.i.a.c.g.c r5 = new g.i.a.c.g.c
            r5.<init>(r3)
            throw r5
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.w.c.l0(byte[]):void");
    }

    public boolean m0(g.i.a.c.l.e.a aVar, int i2, int i3) {
        i.U3(String.format(Locale.US, "nextBinSize=%d, mBytesSentBuffer=%d, bufferSize=%d", Integer.valueOf(aVar.h()), Integer.valueOf(i2), Integer.valueOf(i3)));
        return aVar.h() + i2 > i3;
    }

    public void n0(byte b2) {
        byte[] bArrA = new byte[16];
        System.arraycopy(this.G.G, 0, bArrA, 0, 12);
        bArrA[12] = b2;
        int i2 = t().f5675k;
        if (t().f5681q) {
            bArrA = this.L.a(bArrA, 0, 16);
        }
        g.i.a.c.p.g gVar = new g.i.a.c.p.g(i2, bArrA, null);
        if (this.f5594f) {
            i.w0(gVar.toString());
        }
        R(this.F0, gVar.a(), false);
        byte b3 = c0()[2];
        if (b3 != 1) {
            throw g.a.a.a.a.c("0x%02X(not supported), start dfu failed", new Object[]{Byte.valueOf(b3)}, "start dfu failed", 766);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:105:0x00fe A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:14:0x005a A[Catch: IOException -> 0x02c0, TryCatch #0 {IOException -> 0x02c0, blocks: (B:10:0x004c, B:12:0x0051, B:15:0x0067, B:17:0x006b, B:19:0x007e, B:21:0x0085, B:24:0x0097, B:26:0x00b1, B:28:0x00b5, B:30:0x00ce, B:23:0x008f, B:25:0x009f, B:14:0x005a), top: B:96:0x004c }] */
    /* JADX WARN: Removed duplicated region for block: B:30:0x00ce A[Catch: IOException -> 0x02c0, TRY_LEAVE, TryCatch #0 {IOException -> 0x02c0, blocks: (B:10:0x004c, B:12:0x0051, B:15:0x0067, B:17:0x006b, B:19:0x007e, B:21:0x0085, B:24:0x0097, B:26:0x00b1, B:28:0x00b5, B:30:0x00ce, B:23:0x008f, B:25:0x009f, B:14:0x005a), top: B:96:0x004c }] */
    /* JADX WARN: Removed duplicated region for block: B:33:0x00f1  */
    /* JADX WARN: Removed duplicated region for block: B:41:0x012a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void o0(android.bluetooth.BluetoothGatt r18, android.bluetooth.BluetoothGattCharacteristic r19, g.i.a.c.l.e.a r20) {
        /*
            Method dump skipped, instruction units count: 721
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.w.c.o0(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, g.i.a.c.l.e.a):void");
    }

    public void p0(int i2) {
        int i3 = this.Z;
        if (i3 == 0) {
            if (t().f5675k < 2) {
                this.Z = 12;
            }
            i.V3(this.f5594f, String.format(Locale.US, "First Packet, mImageUpdateOffset=0x%08X(%d)", Integer.valueOf(this.Z), Integer.valueOf(this.Z)));
        } else {
            i.V3(this.f5594f, String.format(Locale.US, "mImageUpdateOffset=0x%08X(%d)", Integer.valueOf(i3), Integer.valueOf(this.Z)));
        }
        g.i.a.c.p.e eVar = new g.i.a.c.p.e(t().f5675k, i2, this.Z, null);
        if (this.f5594f) {
            i.w0(eVar.toString());
        }
        R(this.F0, eVar.a(), false);
        int i4 = s().f5711m;
        int i5 = this.Z;
        if (i4 == i5 || i5 == -1) {
            return;
        }
        i.w0("mBytesSent != mImageUpdateOffset, reload image bin file");
        K();
        g(this.Z, false);
    }

    public void q0() {
        l0(new byte[]{4});
    }

    public void r0() {
        g.i.a.c.q.i iVarT;
        String string;
        List<BluetoothGattCharacteristic> list = this.I0;
        byte[] bArr = null;
        if (list == null || list.size() <= 0) {
            i.w0("no ImageVersionCharacteristics to read");
            iVarT = t();
            iVarT.P = null;
        } else {
            for (BluetoothGattCharacteristic bluetoothGattCharacteristic : this.I0) {
                if (this.f5594f) {
                    StringBuilder sbF = g.a.a.a.a.F("read image version : ");
                    sbF.append(bluetoothGattCharacteristic.getUuid().toString());
                    string = sbF.toString();
                } else {
                    string = "read image version";
                }
                i.U3(string);
                byte[] bArrS = S(bluetoothGattCharacteristic);
                if (bArrS != null) {
                    if (bArr == null) {
                        bArr = bArrS;
                    } else {
                        byte[] bArr2 = new byte[bArr.length + bArrS.length];
                        System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
                        System.arraycopy(bArrS, 0, bArr2, bArr.length, bArrS.length);
                        bArr = bArr2;
                    }
                }
            }
            iVarT = t();
            iVarT.P = bArr;
        }
        iVarT.i();
    }

    public boolean s0() {
        if (this.A0 == null) {
            return false;
        }
        if (this.f5594f) {
            i.U3("start to read remote device info");
        }
        byte[] bArrS = S(this.A0);
        if (bArrS == null) {
            if (this.f5594f) {
                i.U3("read device info failed");
            }
            throw new g.i.a.c.g.c("read remote device info failed", 270);
        }
        t().t(bArrS);
        b(t().B);
        return true;
    }

    public boolean t0() {
        if (this.H0 == null) {
            return false;
        }
        if (this.f5594f) {
            i.U3("start to read remote dev Mac Addr info");
        }
        byte[] bArrS = S(this.H0);
        if (bArrS == null) {
            i.W3("Get remote dev Mac Addr info failed, do nothing.");
            throw new g.i.a.c.g.c("remote dev Mac Addr info error", 277);
        }
        if (bArrS.length >= 6) {
            byte[] bArr = new byte[6];
            System.arraycopy(bArrS, 0, bArr, 0, 6);
            t().D = bArr;
        }
        if (bArrS.length < 12) {
            return true;
        }
        byte[] bArr2 = new byte[6];
        System.arraycopy(bArrS, 6, bArr2, 0, 6);
        t().A = bArr2;
        return true;
    }

    public void u0() {
        String string;
        List<BluetoothGattCharacteristic> list = this.J0;
        byte[] bArr = null;
        if (list == null || list.size() <= 0) {
            i.w0("no ImageSectionCharacteristics to read");
            t().v(null);
            return;
        }
        for (BluetoothGattCharacteristic bluetoothGattCharacteristic : this.J0) {
            if (this.f5594f) {
                StringBuilder sbF = g.a.a.a.a.F("read image section size : ");
                sbF.append(bluetoothGattCharacteristic.getUuid().toString());
                string = sbF.toString();
            } else {
                string = "read image section size";
            }
            i.U3(string);
            byte[] bArrS = S(bluetoothGattCharacteristic);
            if (bArrS != null) {
                if (bArr == null) {
                    bArr = bArrS;
                } else {
                    byte[] bArr2 = new byte[bArr.length + bArrS.length];
                    System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
                    System.arraycopy(bArrS, 0, bArr2, bArr.length, bArrS.length);
                    bArr = bArr2;
                }
            }
        }
        t().v(bArr);
    }

    /* JADX WARN: Removed duplicated region for block: B:26:0x008d  */
    /* JADX WARN: Removed duplicated region for block: B:27:0x0090  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void v0() {
        /*
            r5 = this;
            boolean r0 = r5.f5600r
            if (r0 != 0) goto La5
            boolean r0 = r5.f5594f
            java.lang.String r1 = "isBufferCheckEnabled="
            java.lang.StringBuilder r1 = g.a.a.a.a.F(r1)
            g.i.a.c.q.i r2 = r5.t()
            boolean r2 = r2.f5680p
            r1.append(r2)
            java.lang.String r1 = r1.toString()
            g.h.a.i.x0(r0, r1)
            g.i.a.c.q.i r0 = r5.t()
            boolean r0 = r0.f5680p
            r1 = 0
            if (r0 == 0) goto L90
            android.bluetooth.BluetoothGattCharacteristic r0 = r5.F0
            r2 = 1
            if (r0 != 0) goto L32
            boolean r0 = r5.f5594f
            java.lang.String r3 = "no mControlPointCharacteristic found"
            g.h.a.i.X3(r0, r3)
            goto L8a
        L32:
            boolean r0 = r5.f5594f
            java.lang.String r3 = "<< OPCODE_DFU_ENABLE_BUFFER_CHECK_MODE(0x09)"
            g.h.a.i.x0(r0, r3)
            android.bluetooth.BluetoothGattCharacteristic r0 = r5.F0
            byte[] r3 = new byte[r2]
            r4 = 9
            r3[r1] = r4
            r5.R(r0, r3, r1)
            boolean r0 = r5.f5594f     // Catch: g.i.a.c.a -> L83
            java.lang.String r3 = "... Reading OPCODE_DFU_ENABLE_BUFFER_CHECK_MODE notification"
            g.h.a.i.x0(r0, r3)     // Catch: g.i.a.c.a -> L83
            r3 = 1600(0x640, double:7.905E-321)
            byte[] r0 = r5.V(r3)     // Catch: g.i.a.c.a -> L83
            g.i.a.c.q.i r3 = r5.t()     // Catch: g.i.a.c.a -> L83
            int r3 = r3.a     // Catch: g.i.a.c.a -> L83
            g.i.a.c.q.i r4 = r5.t()     // Catch: g.i.a.c.a -> L83
            int r4 = r4.f5675k     // Catch: g.i.a.c.a -> L83
            g.i.a.c.p.d r0 = g.i.a.c.p.d.a(r3, r4, r0)     // Catch: g.i.a.c.a -> L83
            if (r0 == 0) goto L81
            int r3 = r0.f5628b     // Catch: g.i.a.c.a -> L83
            if (r3 != r2) goto L69
            r3 = r2
            goto L6a
        L69:
            r3 = r1
        L6a:
            if (r3 == 0) goto L81
            int r3 = r0.f5629c     // Catch: g.i.a.c.a -> L83
            r5.b(r3)     // Catch: g.i.a.c.a -> L83
            boolean r3 = r0.f5630d     // Catch: g.i.a.c.a -> L83
            if (r3 == 0) goto L78
            int r0 = r0.f5631e     // Catch: g.i.a.c.a -> L83
            goto L7e
        L78:
            g.i.a.c.q.i r0 = r5.t()     // Catch: g.i.a.c.a -> L83
            int r0 = r0.V     // Catch: g.i.a.c.a -> L83
        L7e:
            r5.T(r0)     // Catch: g.i.a.c.a -> L83
        L81:
            r0 = r2
            goto L8b
        L83:
            java.lang.String r0 = "enableBufferCheck failed, just think remote is normal function."
            g.h.a.i.W3(r0)
            r5.M = r1
        L8a:
            r0 = r1
        L8b:
            if (r0 == 0) goto L90
            r5.Y = r2
            goto L92
        L90:
            r5.Y = r1
        L92:
            java.lang.String r0 = "mRemoteOtaFunctionInfo="
            java.lang.StringBuilder r0 = g.a.a.a.a.F(r0)
            int r2 = r5.Y
            r0.append(r2)
            java.lang.String r0 = r0.toString()
            g.h.a.i.V3(r1, r0)
            return
        La5:
            g.i.a.c.g.c r0 = new g.i.a.c.g.c
            r1 = 4128(0x1020, float:5.785E-42)
            java.lang.String r2 = "user aborted"
            r0.<init>(r2, r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.w.c.v0():void");
    }

    public boolean w0() {
        try {
            i.x0(this.f5594f, "<< OPCODE_DFU_RESET_SYSTEM (0x05)");
            return R(this.F0, new byte[]{5}, true);
        } catch (g.i.a.c.a e2) {
            i.w0(String.format("Send OPCODE_DFU_RESET_SYSTEM failed, ignore it, errorcode= 0x%04X", Integer.valueOf(e2.f5446m)));
            this.M = 0;
            return false;
        }
    }
}
