package g.i.a.c.r;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import g.i.a.c.p.a;
import g.i.a.c.p.f;
import g.i.a.c.q.i;
import g.i.a.c.q.j;
import io.netty.handler.codec.compression.Bzip2Constants;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
import java.util.UUID;

/* JADX INFO: loaded from: classes.dex */
public final class a extends g.i.a.c.p.a {
    public BluetoothGattCharacteristic E;
    public BluetoothGattCharacteristic F;
    public BluetoothGattCharacteristic G;

    public a(int i2) {
        this.f5611f = i2;
    }

    @Override // g.i.a.c.p.a
    public void c(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i2) {
        i iVarI;
        int i3;
        i iVarI2;
        int i4;
        i iVarI3;
        int i5;
        UUID uuid = bluetoothGattCharacteristic.getUuid();
        bluetoothGattCharacteristic.getValue();
        if (i2 == 0) {
            byte[] value = bluetoothGattCharacteristic.getValue();
            int length = value != null ? value.length : 0;
            if (f.a.f5639b.equals(uuid)) {
                f(value);
            } else if (f.b.f5640b.equals(uuid)) {
                StringBuilder sbF = g.a.a.a.a.F("PNP_ID: ");
                sbF.append(g.h.a.i.y(value));
                g.h.a.i.U3(sbF.toString());
                i().y(value);
            } else if (f.f5740f.equals(uuid)) {
                i().s(value, 0);
            } else if (f.f5736b.equals(uuid)) {
                if (length > 0) {
                    ByteBuffer byteBufferWrap = ByteBuffer.wrap(value);
                    byteBufferWrap.order(ByteOrder.LITTLE_ENDIAN);
                    if (length >= 6) {
                        byte[] bArr = new byte[6];
                        byteBufferWrap.get(bArr, 0, 6);
                        i().D = bArr;
                    }
                }
            } else if (f.f5737c.equals(uuid)) {
                if (length > 0) {
                    ByteBuffer byteBufferWrap2 = ByteBuffer.wrap(value);
                    byteBufferWrap2.order(ByteOrder.LITTLE_ENDIAN);
                    if (length == 2) {
                        iVarI3 = i();
                        i5 = byteBufferWrap2.getShort(0);
                    } else if (length >= 4) {
                        iVarI3 = i();
                        i5 = byteBufferWrap2.getInt(0);
                    }
                    iVarI3.E = i5 & 65535;
                }
            } else if (f.f5738d.equals(uuid)) {
                if (length > 0) {
                    ByteBuffer byteBufferWrap3 = ByteBuffer.wrap(value);
                    byteBufferWrap3.order(ByteOrder.LITTLE_ENDIAN);
                    if (length == 2) {
                        iVarI2 = i();
                        i4 = byteBufferWrap3.getShort(0) & 65535;
                    } else if (length >= 4) {
                        iVarI2 = i();
                        i4 = byteBufferWrap3.getInt(0);
                    }
                    iVarI2.F = i4;
                }
            } else if (!f.f5739e.equals(uuid)) {
                int iD = g.i.a.b.e.i.a.d(uuid);
                if (iD >= 65504 && iD <= 65519) {
                    i().b(value, 0);
                } else if (iD >= 65472 && iD <= 65487) {
                    i().c(iD, value);
                }
            } else if (length > 0) {
                ByteBuffer byteBufferWrap4 = ByteBuffer.wrap(value);
                byteBufferWrap4.order(ByteOrder.LITTLE_ENDIAN);
                if (length == 1) {
                    iVarI = i();
                    i3 = byteBufferWrap4.get(0);
                } else if (length == 2) {
                    iVarI = i();
                    i3 = byteBufferWrap4.getShort(0) & 65535;
                }
                iVarI.G = i3;
            }
        } else {
            g.h.a.i.E0(true, "Characteristic read error: " + i2);
            if (!f.f5740f.equals(uuid)) {
                g.h.a.i.w0("ignore exctption when read other info");
                return;
            }
            j(2);
        }
        n();
    }

    @Override // g.i.a.c.p.a
    public void d(g.i.a.c.a0.b bVar, String str, BluetoothGatt bluetoothGatt, BluetoothGattService bluetoothGattService, BluetoothGattService bluetoothGattService2, a.c cVar) {
        List<j> list;
        j jVar;
        super.d(bVar, str, bluetoothGatt, bluetoothGattService, bluetoothGattService2, cVar);
        BluetoothGattService bluetoothGattService3 = this.f5613n;
        if (bluetoothGattService3 != null) {
            UUID uuid = f.a;
            BluetoothGattCharacteristic characteristic = bluetoothGattService3.getCharacteristic(uuid);
            this.E = characteristic;
            if (characteristic == null) {
                g.h.a.i.w0("OTA_CONTROL_ENTER_OTA_MODE_CHARACTERISTIC not found");
            } else {
                g.h.a.i.V3(true, "find OTA_CONTROL_ENTER_OTA_MODE_CHARACTERISTIC = " + uuid);
            }
            BluetoothGattService bluetoothGattService4 = this.f5613n;
            UUID uuid2 = f.f5736b;
            BluetoothGattCharacteristic characteristic2 = bluetoothGattService4.getCharacteristic(uuid2);
            this.F = characteristic2;
            if (characteristic2 == null) {
                g.h.a.i.w0("OTA_DEVICE_MAC_CHARACTERISTIC_UUID not found");
            } else {
                g.h.a.i.U3("find OTA_DEVICE_MAC_CHARACTERISTIC_UUID = " + uuid2);
                g.a.a.a.a.V(this.F);
            }
            BluetoothGattCharacteristic characteristic3 = this.f5613n.getCharacteristic(f.f5740f);
            this.G = characteristic3;
            if (characteristic3 == null) {
                g.h.a.i.w0("OTA_DEVICE_INFO_CHARACTERISTIC_UUID not found");
            }
            for (int i2 = 65472; i2 <= 65487; i2++) {
                BluetoothGattCharacteristic characteristic4 = this.f5613n.getCharacteristic(g.i.a.b.e.i.a.a(i2));
                if (characteristic4 == null) {
                    break;
                }
                this.f5617r.add(characteristic4);
            }
            int i3 = 65504;
            while (true) {
                if (i3 > 65519) {
                    break;
                }
                UUID uuidA = g.i.a.b.e.i.a.a(i3);
                BluetoothGattCharacteristic characteristic5 = this.f5613n.getCharacteristic(uuidA);
                if (characteristic5 == null) {
                    StringBuilder sbF = g.a.a.a.a.F("not found image version characteristic:");
                    sbF.append(uuidA.toString());
                    g.h.a.i.V3(false, sbF.toString());
                    break;
                } else {
                    StringBuilder sbF2 = g.a.a.a.a.F("find image version characteristic: ");
                    sbF2.append(uuidA.toString());
                    g.h.a.i.V3(true, sbF2.toString());
                    this.f5617r.add(characteristic5);
                    i3++;
                }
            }
        }
        if (this.f5614o == null) {
            StringBuilder sbF3 = g.a.a.a.a.F("not find DFU_SERVICE_UUID = ");
            sbF3.append(e.a);
            g.h.a.i.X3(true, sbF3.toString());
            if (this.E == null) {
                return;
            }
            list = this.f5619t;
            jVar = new j(0);
        } else {
            StringBuilder sbF4 = g.a.a.a.a.F("find DFU_SERVICE_UUID = ");
            sbF4.append(this.f5614o.getUuid());
            g.h.a.i.x0(true, sbF4.toString());
            BluetoothGattService bluetoothGattService5 = this.f5614o;
            UUID uuid3 = e.f5735b;
            BluetoothGattCharacteristic characteristic6 = bluetoothGattService5.getCharacteristic(uuid3);
            if (characteristic6 != null) {
                g.h.a.i.x0(true, "find DFU_EXTEND_FLASH_CHARACTERISTIC = " + uuid3);
                this.f5619t.add(new j(17));
                g.h.a.i.w0(g.i.a.b.e.g.a.a(characteristic6.getProperties()));
                return;
            }
            g.h.a.i.x0(true, "DFU_EXTEND_FLASH_CHARACTERISTIC not found");
            g.a.a.a.a.T(16, this.f5619t);
            if (this.E == null) {
                return;
            }
            list = this.f5619t;
            jVar = new j(0);
        }
        list.add(jVar);
    }

    @Override // g.i.a.c.p.a
    public void m() {
        j(257);
        if (this.f5615p != null) {
            j(Bzip2Constants.HUFFMAN_MAX_ALPHABET_SIZE);
            g.a.a.a.a.l0("read battery level :", h(this.f5615p), true);
        }
        if (this.f5616q != null) {
            j(259);
            g.a.a.a.a.l0("read PnP_ID :", h(this.f5616q), true);
        }
        if (this.G != null) {
            j(260);
            boolean zH = h(this.G);
            g.a.a.a.a.l0("read device info :", zH, true);
            if (!zH) {
                this.f5617r.clear();
                j(2);
                return;
            }
        }
        if (this.F != null) {
            j(261);
            g.a.a.a.a.l0("read device mac :", h(this.F), true);
        }
        for (BluetoothGattCharacteristic bluetoothGattCharacteristic : this.f5617r) {
            int iD = g.i.a.b.e.i.a.d(bluetoothGattCharacteristic.getUuid());
            g.h.a.i.V3(false, String.format("uuidShortValue=0x%4x", Integer.valueOf(iD)));
            if (iD >= 65472 && iD <= 65487) {
                j(266);
                g.a.a.a.a.l0("read debug info :", h(bluetoothGattCharacteristic), false);
            } else if (iD >= 65504 && iD <= 65519) {
                j(267);
                g.h.a.i.x0(true, "read image version :" + h(bluetoothGattCharacteristic));
            }
        }
        this.f5617r.clear();
        j(1);
    }
}
