package g.i.a.c.v;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.content.Context;
import com.cvte.vman.instance.InvokeCmd;
import g.h.a.i;
import io.netty.handler.codec.dns.DnsRecord;
import io.netty.handler.codec.memcache.binary.BinaryMemcacheOpcodes;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

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

    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;
                    Objects.requireNonNull(b.this);
                    if (i2 == 16) {
                        if (i3 == 7) {
                            synchronized (b.this.V) {
                                b bVar = b.this;
                                if (bVar.N0 == 7) {
                                    bVar.r0 = value;
                                    b.this.t0 = true;
                                    b.this.V.notifyAll();
                                } else {
                                    i.V3(false, "ignore connection parameters notification");
                                }
                            }
                        } else if (i3 != 8) {
                            synchronized (b.this.V) {
                                b.this.r0 = value;
                                b.this.t0 = true;
                                b.this.V.notifyAll();
                            }
                        } else {
                            byte b2 = value.length >= 3 ? value[2] : (byte) 0;
                            i.V3(b.this.f5594f, "remote state changed, busyMode=" + ((int) b2));
                            synchronized (b.this.e0) {
                                b bVar2 = b.this;
                                bVar2.f5593d0 = b2 == 1;
                                bVar2.e0.notifyAll();
                            }
                        }
                    }
                }
            }
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onCharacteristicRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i2) {
            b bVar = b.this;
            if (i2 == 0) {
                bVar.f5608z = bluetoothGattCharacteristic.getValue();
            } else {
                bVar.M = i2 | 1024;
                i.W3(String.format(Locale.US, "read Characteristic error:0x%04X", Integer.valueOf(b.this.M)));
            }
            b.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.v.b r8 = g.i.a.c.v.b.this
                r8.C = r1
                g.i.a.c.v.b r8 = g.i.a.c.v.b.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.v.b r7 = g.i.a.c.v.b.this
                g.i.a.c.q.g r7 = r7.s()
                int r6 = r6.length
                r7.a(r6)
                g.i.a.c.v.b r6 = g.i.a.c.v.b.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.v.b r6 = g.i.a.c.v.b.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.v.b r7 = g.i.a.c.v.b.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.v.b r2 = g.i.a.c.v.b.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.v.b r7 = g.i.a.c.v.b.this
                r7.C = r1
                if (r6 == 0) goto L2f
                goto L1f
            L72:
                g.i.a.c.v.b r6 = g.i.a.c.v.b.this
                r6.C = r3
                g.i.a.c.v.b r6 = g.i.a.c.v.b.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.v.b r6 = g.i.a.c.v.b.this
                r6.q()
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.v.b.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) {
                    b.this.B(0);
                }
                b.this.M = i2 | 2048;
            } else if (i3 == 2) {
                b bVar = b.this;
                if (bVar.f5600r) {
                    i.W3("task already aborted, ignore");
                    return;
                } else if (bVar.f5605w == 256) {
                    g.i.a.b.e.g.a.b(bluetoothGatt);
                    b.this.b0();
                    return;
                }
            } else if (i3 == 0) {
                if (b.this.E == 521) {
                    b.this.M = i2 | 2048;
                    b bVar2 = b.this;
                    if (bVar2.f5594f) {
                        i.w0(String.format("disconnect in OTA process, mErrorState: 0x%04X", Integer.valueOf(bVar2.M)));
                    }
                    b.this.q();
                }
                b.this.B(0);
            }
            b.this.w();
        }

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

        @Override // android.bluetooth.BluetoothGattCallback
        public void onMtuChanged(BluetoothGatt bluetoothGatt, int i2, int i3) {
            if (i3 == 0 && b.this.r().F) {
                b.this.W(i2);
            }
            b.this.u0 = true;
            b.this.n();
        }

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

        /* JADX WARN: Removed duplicated region for block: B:61:0x016d  */
        /* JADX WARN: Removed duplicated region for block: B:64:0x0179  */
        @Override // android.bluetooth.BluetoothGattCallback
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void onServicesDiscovered(android.bluetooth.BluetoothGatt r5, int r6) {
            /*
                Method dump skipped, instruction units count: 441
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.v.b.a.onServicesDiscovered(android.bluetooth.BluetoothGatt, int):void");
        }
    }

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

    public void g0() {
        i.U3("<< OPCODE_DFU_START_DFU(0x01)");
        byte[] bArr = new byte[16];
        System.arraycopy(this.G.f5567r, 0, bArr, 0, 12);
        byte[] bArr2 = new byte[17];
        bArr2[0] = 1;
        if (t().f5681q) {
            System.arraycopy(this.L.a(bArr, 0, 16), 0, bArr2, 1, 16);
        } else {
            System.arraycopy(bArr, 0, bArr2, 1, 16);
        }
        R(this.F0, bArr2, false);
        if (this.f5594f) {
            i.U3("... Reading OPCODE_DFU_START_DFU(0x01) notification");
        }
        byte b2 = c0()[2];
        if (b2 != 1) {
            throw g.a.a.a.a.y0("0x%02X(not supported), start dfu failed", new Object[]{Byte.valueOf(b2)}, "start dfu failed", 766);
        }
    }

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

    public void i0(int i2, int i3) {
        byte[] bArr = {2, (byte) (i2 & DnsRecord.CLASS_ANY), (byte) ((i2 >> 8) & DnsRecord.CLASS_ANY), (byte) (i3 & DnsRecord.CLASS_ANY), (byte) ((i3 >> 8) & DnsRecord.CLASS_ANY), (byte) ((i3 >> 16) & DnsRecord.CLASS_ANY), (byte) ((i3 >> 24) & DnsRecord.CLASS_ANY)};
        i.w0("<< OPCODE_DFU_RECEIVE_FW_IMAGE (0x02)");
        R(this.F0, bArr, false);
    }

    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) {
            z0();
        }
        g.i.a.b.e.h.c cVar = this.m0;
        if (cVar != null) {
            cVar.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;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x005f A[Catch: IOException -> 0x026f, TryCatch #0 {IOException -> 0x026f, blocks: (B:13:0x0051, B:15:0x0056, B:18:0x006c, B:20:0x0070, B:22:0x0083, B:24:0x008a, B:26:0x00ab, B:28:0x00af, B:30:0x00b3, B:31:0x00c2, B:33:0x00cc, B:35:0x00d8, B:25:0x0099, B:17:0x005f), top: B:91:0x0051 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void k0(android.bluetooth.BluetoothGatt r19, android.bluetooth.BluetoothGattCharacteristic r20, g.i.a.c.l.e.a r21) {
        /*
            Method dump skipped, instruction units count: 640
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.v.b.k0(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, g.i.a.c.l.e.a):void");
    }

    public void l0(boolean z2) {
        i.w0("<< OPCODE_DFU_ENSURE_CURRENT_BUFFER(0x0C)");
        R(this.F0, new byte[]{BinaryMemcacheOpcodes.GETK, !z2 ? 1 : 0}, false);
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0036  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0048  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void m0(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
            boolean r2 = r4.f5594f     // Catch: g.i.a.c.a -> L15
            java.lang.String r3 = "<< OPCODE_DFU_ACTIVE_IMAGE_RESET(0x04)"
            g.h.a.i.x0(r2, r3)     // Catch: g.i.a.c.a -> L15
            android.bluetooth.BluetoothGattCharacteristic r2 = r4.F0     // Catch: g.i.a.c.a -> L15
            boolean r1 = r4.R(r2, r5, r0)     // Catch: g.i.a.c.a -> L15
            goto L2a
        L15:
            r5 = move-exception
            int r2 = r5.f5446m
            r3 = 4128(0x1020, float:5.785E-42)
            if (r2 != r3) goto L1d
            goto L34
        L1d:
            g.i.a.c.q.f r2 = r4.r()
            boolean r2 = r2.f5709z
            if (r2 != 0) goto L2d
            java.lang.String r5 = "active cmd has no response, ignore"
            g.h.a.i.w0(r5)
        L2a:
            r3 = r0
            r0 = r1
            goto L34
        L2d:
            java.lang.String r1 = "active cmd has no response, notify error"
            g.h.a.i.W3(r1)
            int r3 = r5.f5446m
        L34:
            if (r0 == 0) goto L48
            boolean r5 = r4.f5594f
            java.lang.String r0 = "image active success"
            g.h.a.i.x0(r5, r0)
            int r5 = r4.M
            r4.Y(r5)
            g.i.a.c.l.e.a r5 = r4.G
            r4.k(r5)
            return
        L48:
            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.v.b.m0(byte[]):void");
    }

    public boolean n0(g.i.a.c.l.e.a aVar, int i2, int i3) {
        i.V3(this.f5594f, 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 int o0(String str) {
        BluetoothGatt bluetoothGattConnectGatt;
        StringBuilder sb;
        BluetoothDevice bluetoothDeviceG = G(str);
        if (bluetoothDeviceG == null) {
            return 264;
        }
        B(256);
        this.M = 0;
        this.f5603u = false;
        if (this.f5594f) {
            i.U3(String.format("Connecting to device:%s, isConnectedCallbackCome=%b", i.S0(str, true), Boolean.valueOf(this.f5603u)));
        }
        g.i.a.b.e.c cVar = this.p0;
        if (cVar != null) {
            cVar.k(str, this.M0);
            this.p0.d(str, this.M0);
            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 e2) {
                e = e2;
                sb = new StringBuilder();
                sb.append("Sleeping interrupted : ");
                sb.append(e.toString());
                i.W3(sb.toString());
                this.M = 259;
            }
        } else {
            bluetoothGattConnectGatt = bluetoothDeviceG.connectGatt(this.f5595m, false, this.M0);
            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;
            }
        }
        if (this.M == 0) {
            if (!this.f5603u) {
                i.W3("wait for connect, but can not connect with no callback");
                this.M = 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());
                this.M = 264;
            } else if (this.f5594f) {
                i.U3("connected the device which going to upgrade");
            }
        }
        return this.M;
    }

    public boolean p0(int i2) {
        String strL;
        i.w0(String.format("<< OPCODE_DFU_CHECK_CURRENT_BUFFER(0x0B) , crc=0x%04X", Integer.valueOf(i2)));
        R(this.F0, new byte[]{BinaryMemcacheOpcodes.VERSION}, false);
        if (this.f5594f) {
            i.w0("... waiting CHECK_CURRENT_BUFFER response");
        }
        byte[] bArrC0 = c0();
        byte b2 = bArrC0[2];
        if (b2 == 1) {
            int i3 = ((bArrC0[4] << 8) & 65280) | (bArrC0[3] & 255);
            if (i3 == i2) {
                return true;
            }
            strL = g.a.a.a.a.o("CRC check error, local: ", i2, ", remote : ", i3);
        } else {
            strL = g.a.a.a.a.l("check current buffer failed, status: ", b2);
        }
        i.W3(strL);
        return false;
    }

    public void q0(int i2) {
        int i3;
        int i4;
        if (this.f5594f) {
            i.w0("<< OPCODE_DFU_REPORT_TARGET_IMAGE_INFO(0x06)");
        }
        R(this.F0, new byte[]{6, (byte) (i2 & DnsRecord.CLASS_ANY), (byte) ((i2 >> 8) & DnsRecord.CLASS_ANY)}, false);
        if (this.f5594f) {
            i.U3("... Reading OPCODE_DFU_REPORT_TARGET_IMAGE_INFO(0x06) notification");
        }
        byte[] bArrC0 = c0();
        int length = bArrC0 != null ? bArrC0.length : 0;
        if ((length > 2 ? bArrC0[2] : (byte) -2) != 1) {
            throw g.a.a.a.a.y0("0x%02X, Get target image info failed", new Object[]{766}, "Get target image info failed", 766);
        }
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArrC0);
        byteBufferWrap.order(ByteOrder.LITTLE_ENDIAN);
        if (length >= 11) {
            i3 = byteBufferWrap.getShort(3) & 65535;
            i4 = 7;
        } else {
            if (length < 9) {
                this.Z = 0;
                i3 = 0;
                i.w0(String.format(Locale.US, "mOriginalFwVersion=%d, mImageUpdateOffset=0x%08X(%d)", Integer.valueOf(i3), Integer.valueOf(this.Z), Integer.valueOf(this.Z)));
            }
            i3 = byteBufferWrap.getShort(3) & 65535;
            i4 = 5;
        }
        this.Z = byteBufferWrap.getInt(i4);
        i.w0(String.format(Locale.US, "mOriginalFwVersion=%d, mImageUpdateOffset=0x%08X(%d)", Integer.valueOf(i3), Integer.valueOf(this.Z), Integer.valueOf(this.Z)));
    }

    public void r0(int i2) {
        byte[] bArr = {3, (byte) (i2 & DnsRecord.CLASS_ANY), (byte) ((i2 >> 8) & DnsRecord.CLASS_ANY)};
        i.w0("<< OPCODE_DFU_VALIDATE_FW_IMAGE (0x03)");
        R(this.F0, bArr, false);
        int i3 = t().f5674j;
        int iMax = InvokeCmd.CMD_PMSCTRL_SET_PMS_WAKEUP_SOURCES;
        if ((i3 == 5 || t().f5674j == 9 || t().f5674j == 12) && s().f5710f > 2097152) {
            iMax = Math.max(((s().f5710f / 1048576) + 1) * 4 * 1000, InvokeCmd.CMD_PMSCTRL_SET_PMS_WAKEUP_SOURCES);
        }
        if (this.f5594f) {
            g.a.a.a.a.a0("... waiting DFU_VALIDATE_FW_IMAGE response for ", iMax);
        }
        byte b2 = V(iMax)[2];
        if (b2 == 1) {
            return;
        }
        if (b2 != 5) {
            throw g.a.a.a.a.y0("0x%02X(not supported), Validate FW failed", new Object[]{Byte.valueOf(b2)}, "Validate FW failed", 766);
        }
        throw g.a.a.a.a.y0("0x%02X, Validate FW failed, CRC check error", new Object[]{Byte.valueOf(b2)}, "Validate FW failed", InvokeCmd.CMD_XBUG_VMAN_FUNTION_CHECK_TIMEOUT_BASE_GET);
    }

    public void s0() {
        m0(new byte[]{4});
    }

    public void t0() {
        if (r().A.longValue() > 0) {
            try {
                Thread.sleep(r().A.longValue());
            } catch (InterruptedException unused) {
            }
        }
    }

    public int u0() {
        byte[] bArrV;
        if (this.F0 == null) {
            i.W3("no mControlPointCharacteristic found");
            return 0;
        }
        i.w0("<< OPCODE_DFU_ENABLE_BUFFER_CHECK_MODE(0x09)");
        R(this.F0, new byte[]{9}, false);
        try {
            if (this.f5594f) {
                i.w0("... Reading OPCODE_DFU_ENABLE_BUFFER_CHECK_MODE notification");
            }
            bArrV = V(1600L);
        } catch (g.i.a.c.a unused) {
            i.W3("Read DFU_REPORT_OTA_FUNCTION_VERSION exception, just think remote is normal function.");
            this.M = 0;
        }
        if (bArrV[2] != 1) {
            i.w0("Read DFU_REPORT_OTA_FUNCTION_VERSION failed, just think remote is normal function.");
            return 0;
        }
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArrV);
        byteBufferWrap.order(ByteOrder.LITTLE_ENDIAN);
        int i2 = (((short) (byteBufferWrap.get(4) & 255)) << 8) | ((short) (byteBufferWrap.get(3) & 255));
        int i3 = ((short) (byteBufferWrap.get(5) & 255)) | (((short) (byteBufferWrap.get(6) & 255)) << 8);
        if (this.f5594f) {
            i.U3("maxBufferSize=" + i2 + ", bufferCheckMtuSize=" + i3);
        }
        b(i2);
        T(i3);
        return 1;
    }

    public void v0() {
        if (t().f5675k != 0) {
            List<BluetoothGattCharacteristic> list = this.L0;
            byte[] bArr = null;
            if (list == null || list.size() <= 0) {
                g.i.a.c.q.i iVarT = t();
                iVarT.P = null;
                iVarT.i();
                i.w0("no ImageVersionCharacteristics to read");
                return;
            }
            for (BluetoothGattCharacteristic bluetoothGattCharacteristic : this.L0) {
                i.U3("read image version");
                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;
                    }
                }
            }
            g.i.a.c.q.i iVarT2 = t();
            iVarT2.P = bArr;
            iVarT2.i();
            return;
        }
        if (this.J0 != null) {
            i.U3("read patch version");
            byte[] bArrS2 = S(this.J0);
            if (bArrS2 != null) {
                try {
                    ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArrS2);
                    byteBufferWrap.order(ByteOrder.LITTLE_ENDIAN);
                    t().E = (t().f5674j > 3 && (t().f5674j == 5 || t().f5674j == 9 || t().f5674j == 12)) ? byteBufferWrap.getInt(0) : byteBufferWrap.getShort(0) & 65535;
                } catch (Exception e2) {
                    i.W3(e2.toString());
                }
            }
        }
        if (this.I0 != null) {
            i.U3("read app version");
            byte[] bArrS3 = S(this.I0);
            if (bArrS3 != null) {
                try {
                    ByteBuffer byteBufferWrap2 = ByteBuffer.wrap(bArrS3);
                    byteBufferWrap2.order(ByteOrder.LITTLE_ENDIAN);
                    t().F = (t().f5674j > 3 && (t().f5674j == 5 || t().f5674j == 9 || t().f5674j == 12)) ? byteBufferWrap2.getInt(0) : byteBufferWrap2.getShort(0) & 65535;
                } catch (Exception e3) {
                    i.D0(e3.toString());
                }
            }
        }
        if (this.K0 != null) {
            i.U3("read patch extension version");
            byte[] bArrS4 = S(this.K0);
            if (bArrS4 != null) {
                ByteBuffer byteBufferWrap3 = ByteBuffer.wrap(bArrS4);
                byteBufferWrap3.order(ByteOrder.LITTLE_ENDIAN);
                t().G = byteBufferWrap3.getShort(0) & 65535;
            }
        }
    }

    public boolean w0() {
        BluetoothGattCharacteristic bluetoothGattCharacteristic = this.H0;
        if (bluetoothGattCharacteristic == null) {
            return false;
        }
        byte[] bArrS = S(bluetoothGattCharacteristic);
        if (bArrS == null || bArrS.length < 6) {
            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);
        }
        byte[] bArr = new byte[6];
        System.arraycopy(bArrS, 0, bArr, 0, 6);
        t().D = bArr;
        return true;
    }

    public void x0() {
        i.w0("<<  OPCODE_DFU_REPORT_CURRENT_BUFFER_SIZE(0x0A)");
        R(this.F0, new byte[]{10}, false);
        if (this.f5594f) {
            i.w0("... Reading OPCODE_DFU_REPORT_CURRENT_BUFFER_SIZE notification");
        }
        byte[] bArrC0 = c0();
        byte b2 = bArrC0[2];
        if (b2 != 1) {
            i.W3("Get remote buffer size info failed, status: " + ((int) b2));
            throw new g.i.a.c.g.c("Get remote buffer size info failed", b2 | 512);
        }
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArrC0);
        byteBufferWrap.order(ByteOrder.LITTLE_ENDIAN);
        int i2 = byteBufferWrap.getInt(3);
        i.U3(String.format(Locale.US, "maxBufferCheckSize=(0x%04X, %d)", Integer.valueOf(i2), Integer.valueOf(i2)));
        b(i2);
    }

    public int y0() {
        byte[] bArrV;
        byte b2;
        if (this.F0 == null) {
            i.W3("no mControlPointCharacteristic found");
            return 0;
        }
        i.U3("<< OPCODE_DFU_REPORT_OTA_FUNCTION_VERSION(0x09)");
        R(this.F0, new byte[]{9}, false);
        try {
            if (this.f5594f) {
                i.w0("Reading OPCODE_DFU_REPORT_OTA_FUNCTION_VERSION notification");
            }
            bArrV = V(1600L);
            b2 = bArrV[2];
        } catch (g.i.a.c.a unused) {
            i.W3("Reading OPCODE_DFU_REPORT_OTA_FUNCTION_VERSION notification failed, just think remote is normal function.");
            this.M = 0;
        }
        if (b2 == 1) {
            ByteBuffer.wrap(bArrV).order(ByteOrder.LITTLE_ENDIAN);
            return 1;
        }
        i.W3("reportOtaFunctionVersion failed, status: " + ((int) b2));
        return 0;
    }

    public boolean z0() {
        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.W3(String.format("Send OPCODE_DFU_RESET_SYSTEM failed, ignore it, errorcode= 0x%04X", Integer.valueOf(e2.f5446m)));
            this.M = 0;
            return false;
        }
    }
}
