package g.i.a.c.t;

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

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

    public a() {
        this.f5611f = 20;
    }

    @Override // g.i.a.c.p.a
    public void c(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i2) {
        UUID uuid = bluetoothGattCharacteristic.getUuid();
        byte[] value = bluetoothGattCharacteristic.getValue();
        if (i2 == 0) {
            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(i.y(value));
                i.U3(sbF.toString());
                i().y(value);
            } else if (g.i.a.c.w.g.f5762c.equals(uuid)) {
                i().u(value);
            } else if (!g.i.a.c.w.g.f5761b.equals(uuid)) {
                int iD = g.i.a.b.e.i.a.d(uuid);
                if (iD >= 65504 && iD <= 65519) {
                    i().e(value);
                } else if (iD >= 65472 && iD <= 65487) {
                    i().c(iD, value);
                } else if (iD >= 65524 && iD <= 65526) {
                    i().d(value);
                }
            } else 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 {
            i.X3(true, "Characteristic read error: " + i2);
            if (!g.i.a.c.w.g.f5762c.equals(uuid)) {
                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) {
        super.d(bVar, str, bluetoothGatt, bluetoothGattService, bluetoothGattService2, cVar);
        BluetoothGattService bluetoothGattService3 = this.f5613n;
        if (bluetoothGattService3 == null) {
            i.w0("mOtaService is null");
        } else {
            UUID uuid = g.i.a.c.w.g.a;
            BluetoothGattCharacteristic characteristic = bluetoothGattService3.getCharacteristic(uuid);
            this.E = characteristic;
            if (characteristic == null) {
                i.w0("OTA_CONTROL_ENTER_OTA_MODE_CHARACTERISTIC not found");
            } else {
                i.V3(true, "find OTA_CONTROL_ENTER_OTA_MODE_CHARACTERISTIC = " + uuid);
            }
            BluetoothGattService bluetoothGattService4 = this.f5613n;
            UUID uuid2 = g.i.a.c.w.g.f5761b;
            BluetoothGattCharacteristic characteristic2 = bluetoothGattService4.getCharacteristic(uuid2);
            this.F = characteristic2;
            if (characteristic2 == null) {
                i.w0("OTA_DEVICE_MAC_CHARACTERISTIC_UUID not found");
            } else {
                g.a.a.a.a.i0("find OTA_DEVICE_MAC_CHARACTERISTIC_UUID = ", uuid2);
                g.a.a.a.a.V(this.F);
            }
            BluetoothGattCharacteristic characteristic3 = this.f5613n.getCharacteristic(g.i.a.c.w.g.f5762c);
            this.G = characteristic3;
            if (characteristic3 == null) {
                i.w0("OTA_DEVICE_INFO_CHARACTERISTIC_UUID not found");
            }
            int i2 = 65472;
            while (true) {
                if (i2 > 65487) {
                    break;
                }
                UUID uuidA = g.i.a.b.e.i.a.a(i2);
                BluetoothGattCharacteristic characteristic4 = this.f5613n.getCharacteristic(uuidA);
                if (characteristic4 == null) {
                    g.a.a.a.a.t0(uuidA, g.a.a.a.a.F("not found debug characteristic:"));
                    break;
                } else {
                    g.a.a.a.a.v0(uuidA, g.a.a.a.a.F("find debug characteristic: "), true);
                    this.f5617r.add(characteristic4);
                    i2++;
                }
            }
            int i3 = 65504;
            while (true) {
                if (i3 > 65519) {
                    break;
                }
                UUID uuidA2 = g.i.a.b.e.i.a.a(i3);
                BluetoothGattCharacteristic characteristic5 = this.f5613n.getCharacteristic(uuidA2);
                if (characteristic5 == null) {
                    g.a.a.a.a.v0(uuidA2, g.a.a.a.a.F("not found image version characteristic:"), false);
                    break;
                } else {
                    g.a.a.a.a.v0(uuidA2, g.a.a.a.a.F("find image version characteristic: "), false);
                    this.f5617r.add(characteristic5);
                    i3++;
                }
            }
            int i4 = 65524;
            while (true) {
                if (i4 > 65526) {
                    break;
                }
                UUID uuidA3 = g.i.a.b.e.i.a.a(i4);
                BluetoothGattCharacteristic characteristic6 = this.f5613n.getCharacteristic(uuidA3);
                if (characteristic6 == null) {
                    StringBuilder sbF = g.a.a.a.a.F("not found image session size characteristic:");
                    sbF.append(uuidA3.toString());
                    i.V3(false, sbF.toString());
                    break;
                } else {
                    StringBuilder sbF2 = g.a.a.a.a.F("find image session size characteristic: ");
                    sbF2.append(uuidA3.toString());
                    i.V3(false, sbF2.toString());
                    this.f5617r.add(characteristic6);
                    i4++;
                }
            }
        }
        if (this.f5614o != null) {
            g.a.a.a.a.T(16, this.f5619t);
        }
        if (this.E != null) {
            g.a.a.a.a.T(0, this.f5619t);
        }
    }

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