package no.nordicsemi.android.dfu;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Intent;
import g.a.a.a.a;
import java.io.IOException;
import java.util.UUID;
import java.util.zip.CRC32;
import no.nordicsemi.android.dfu.BaseDfuImpl;
import no.nordicsemi.android.dfu.internal.exception.DeviceDisconnectedException;
import no.nordicsemi.android.dfu.internal.exception.DfuException;
import no.nordicsemi.android.dfu.internal.exception.HexFileValidationException;
import no.nordicsemi.android.dfu.internal.exception.UploadAbortedException;

/* JADX INFO: loaded from: classes2.dex */
@SuppressLint({"MissingPermission"})
public abstract class BaseCustomDfuImpl extends BaseDfuImpl {
    public boolean mFirmwareUploadInProgress;
    private boolean mInitPacketInProgress;
    public int mPacketsBeforeNotification;
    private int mPacketsSentSinceNotification;
    public boolean mRemoteErrorOccurred;

    public class BaseCustomBluetoothCallback extends BaseDfuImpl.BaseBluetoothGattCallback {
        public BaseCustomBluetoothCallback() {
            super();
        }

        public void handleNotification(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
            DfuBaseService dfuBaseService = BaseCustomDfuImpl.this.mService;
            StringBuilder sbF = a.F("Notification received from ");
            sbF.append(bluetoothGattCharacteristic.getUuid());
            sbF.append(", value (0x): ");
            sbF.append(parse(bluetoothGattCharacteristic));
            dfuBaseService.sendLogBroadcast(5, sbF.toString());
            BaseCustomDfuImpl.this.mReceivedData = bluetoothGattCharacteristic.getValue();
            BaseCustomDfuImpl.this.mFirmwareUploadInProgress = false;
        }

        public void handlePacketReceiptNotification(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
            BaseCustomDfuImpl baseCustomDfuImpl;
            int i2;
            BaseCustomDfuImpl baseCustomDfuImpl2 = BaseCustomDfuImpl.this;
            if (!baseCustomDfuImpl2.mFirmwareUploadInProgress) {
                handleNotification(bluetoothGatt, bluetoothGattCharacteristic);
                return;
            }
            BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(baseCustomDfuImpl2.getDfuServiceUUID()).getCharacteristic(BaseCustomDfuImpl.this.getPacketCharacteristicUUID());
            try {
                BaseCustomDfuImpl.this.mPacketsSentSinceNotification = 0;
                BaseCustomDfuImpl.this.waitIfPaused();
                BaseCustomDfuImpl baseCustomDfuImpl3 = BaseCustomDfuImpl.this;
                if (!baseCustomDfuImpl3.mAborted && baseCustomDfuImpl3.mError == 0 && !baseCustomDfuImpl3.mRemoteErrorOccurred && !baseCustomDfuImpl3.mResetRequestSent) {
                    boolean zIsComplete = baseCustomDfuImpl3.mProgressInfo.isComplete();
                    boolean zIsObjectComplete = BaseCustomDfuImpl.this.mProgressInfo.isObjectComplete();
                    if (!zIsComplete && !zIsObjectComplete) {
                        int availableObjectSizeIsBytes = BaseCustomDfuImpl.this.mProgressInfo.getAvailableObjectSizeIsBytes();
                        BaseCustomDfuImpl baseCustomDfuImpl4 = BaseCustomDfuImpl.this;
                        byte[] bArr = baseCustomDfuImpl4.mBuffer;
                        if (availableObjectSizeIsBytes < bArr.length) {
                            bArr = new byte[availableObjectSizeIsBytes];
                        }
                        BaseCustomDfuImpl.this.writePacket(bluetoothGatt, characteristic, bArr, baseCustomDfuImpl4.mFirmwareStream.read(bArr));
                        return;
                    }
                    BaseCustomDfuImpl baseCustomDfuImpl5 = BaseCustomDfuImpl.this;
                    baseCustomDfuImpl5.mFirmwareUploadInProgress = false;
                    baseCustomDfuImpl5.notifyLock();
                    return;
                }
                baseCustomDfuImpl3.mFirmwareUploadInProgress = false;
                baseCustomDfuImpl3.mService.sendLogBroadcast(15, "Upload terminated");
            } catch (HexFileValidationException unused) {
                BaseCustomDfuImpl.this.loge("Invalid HEX file");
                baseCustomDfuImpl = BaseCustomDfuImpl.this;
                i2 = 4099;
                baseCustomDfuImpl.mError = i2;
            } catch (IOException e2) {
                BaseCustomDfuImpl.this.loge("Error while reading the input stream", e2);
                baseCustomDfuImpl = BaseCustomDfuImpl.this;
                i2 = 4100;
                baseCustomDfuImpl.mError = i2;
            }
        }

        @Override // android.bluetooth.BluetoothGattCallback
        public void onCharacteristicWrite(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i2) {
            BaseCustomDfuImpl baseCustomDfuImpl;
            BaseCustomDfuImpl baseCustomDfuImpl2;
            int i3;
            BaseCustomDfuImpl baseCustomDfuImpl3;
            if (i2 != 0) {
                baseCustomDfuImpl = BaseCustomDfuImpl.this;
                if (!baseCustomDfuImpl.mResetRequestSent) {
                    baseCustomDfuImpl.loge("Characteristic write error: " + i2);
                    baseCustomDfuImpl2 = BaseCustomDfuImpl.this;
                    i3 = i2 | 16384;
                    baseCustomDfuImpl2.mError = i3;
                }
                baseCustomDfuImpl.mRequestCompleted = true;
            } else if (!bluetoothGattCharacteristic.getUuid().equals(BaseCustomDfuImpl.this.getPacketCharacteristicUUID())) {
                DfuBaseService dfuBaseService = BaseCustomDfuImpl.this.mService;
                StringBuilder sbF = a.F("Data written to ");
                sbF.append(bluetoothGattCharacteristic.getUuid());
                sbF.append(", value (0x): ");
                sbF.append(parse(bluetoothGattCharacteristic));
                dfuBaseService.sendLogBroadcast(5, sbF.toString());
                baseCustomDfuImpl = BaseCustomDfuImpl.this;
                baseCustomDfuImpl.mRequestCompleted = true;
            } else if (BaseCustomDfuImpl.this.mInitPacketInProgress) {
                DfuBaseService dfuBaseService2 = BaseCustomDfuImpl.this.mService;
                StringBuilder sbF2 = a.F("Data written to ");
                sbF2.append(bluetoothGattCharacteristic.getUuid());
                sbF2.append(", value (0x): ");
                sbF2.append(parse(bluetoothGattCharacteristic));
                dfuBaseService2.sendLogBroadcast(5, sbF2.toString());
                BaseCustomDfuImpl.this.mInitPacketInProgress = false;
            } else {
                BaseCustomDfuImpl baseCustomDfuImpl4 = BaseCustomDfuImpl.this;
                if (baseCustomDfuImpl4.mFirmwareUploadInProgress) {
                    baseCustomDfuImpl4.mProgressInfo.addBytesSent(bluetoothGattCharacteristic.getValue().length);
                    BaseCustomDfuImpl.access$108(BaseCustomDfuImpl.this);
                    BaseCustomDfuImpl baseCustomDfuImpl5 = BaseCustomDfuImpl.this;
                    boolean z2 = baseCustomDfuImpl5.mPacketsBeforeNotification > 0 && baseCustomDfuImpl5.mPacketsSentSinceNotification >= BaseCustomDfuImpl.this.mPacketsBeforeNotification;
                    boolean zIsComplete = BaseCustomDfuImpl.this.mProgressInfo.isComplete();
                    boolean zIsObjectComplete = BaseCustomDfuImpl.this.mProgressInfo.isObjectComplete();
                    if (z2) {
                        return;
                    }
                    if (zIsComplete || zIsObjectComplete) {
                        baseCustomDfuImpl3 = BaseCustomDfuImpl.this;
                        baseCustomDfuImpl3.mFirmwareUploadInProgress = false;
                        baseCustomDfuImpl3.notifyLock();
                    }
                    try {
                        BaseCustomDfuImpl.this.waitIfPaused();
                        BaseCustomDfuImpl baseCustomDfuImpl6 = BaseCustomDfuImpl.this;
                        if (!baseCustomDfuImpl6.mAborted && baseCustomDfuImpl6.mError == 0 && !baseCustomDfuImpl6.mRemoteErrorOccurred && !baseCustomDfuImpl6.mResetRequestSent) {
                            int availableObjectSizeIsBytes = baseCustomDfuImpl6.mProgressInfo.getAvailableObjectSizeIsBytes();
                            BaseCustomDfuImpl baseCustomDfuImpl7 = BaseCustomDfuImpl.this;
                            byte[] bArr = baseCustomDfuImpl7.mBuffer;
                            if (availableObjectSizeIsBytes < bArr.length) {
                                bArr = new byte[availableObjectSizeIsBytes];
                            }
                            BaseCustomDfuImpl.this.writePacket(bluetoothGatt, bluetoothGattCharacteristic, bArr, baseCustomDfuImpl7.mFirmwareStream.read(bArr));
                            return;
                        }
                        baseCustomDfuImpl6.mFirmwareUploadInProgress = false;
                        baseCustomDfuImpl6.mService.sendLogBroadcast(15, "Upload terminated");
                        BaseCustomDfuImpl.this.notifyLock();
                        return;
                    } catch (HexFileValidationException unused) {
                        BaseCustomDfuImpl.this.loge("Invalid HEX file");
                        baseCustomDfuImpl2 = BaseCustomDfuImpl.this;
                        i3 = 4099;
                    } catch (IOException e2) {
                        BaseCustomDfuImpl.this.loge("Error while reading the input stream", e2);
                        baseCustomDfuImpl2 = BaseCustomDfuImpl.this;
                        i3 = 4100;
                    }
                } else {
                    onPacketCharacteristicWrite(bluetoothGatt, bluetoothGattCharacteristic, i2);
                }
            }
            baseCustomDfuImpl3 = BaseCustomDfuImpl.this;
            baseCustomDfuImpl3.notifyLock();
        }

        public void onPacketCharacteristicWrite(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i2) {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0024 A[PHI: r4
      0x0024: PHI (r4v3 int) = (r4v1 int), (r4v4 int) binds: [B:19:0x0046, B:9:0x0021] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public BaseCustomDfuImpl(android.content.Intent r6, no.nordicsemi.android.dfu.DfuBaseService r7) {
        /*
            r5 = this;
            r5.<init>(r6, r7)
            java.lang.String r0 = "no.nordicsemi.android.dfu.extra.EXTRA_PRN_ENABLED"
            boolean r1 = r6.hasExtra(r0)
            r2 = 65535(0xffff, float:9.1834E-41)
            r3 = 0
            r4 = 12
            if (r1 == 0) goto L28
            boolean r7 = r6.getBooleanExtra(r0, r3)
            java.lang.String r0 = "no.nordicsemi.android.dfu.extra.EXTRA_PRN_VALUE"
            int r6 = r6.getIntExtra(r0, r4)
            if (r6 < 0) goto L21
            if (r6 <= r2) goto L20
            goto L21
        L20:
            r4 = r6
        L21:
            if (r7 != 0) goto L24
            goto L25
        L24:
            r3 = r4
        L25:
            r5.mPacketsBeforeNotification = r3
            goto L49
        L28:
            android.content.SharedPreferences r6 = android.preference.PreferenceManager.getDefaultSharedPreferences(r7)
            java.lang.String r7 = "settings_packet_receipt_notification_enabled"
            boolean r7 = r6.getBoolean(r7, r3)
            java.lang.String r0 = java.lang.String.valueOf(r4)
            java.lang.String r1 = "settings_number_of_packets"
            java.lang.String r6 = r6.getString(r1, r0)
            int r6 = java.lang.Integer.parseInt(r6)     // Catch: java.lang.NumberFormatException -> L46
            if (r6 < 0) goto L46
            if (r6 <= r2) goto L45
            goto L46
        L45:
            r4 = r6
        L46:
            if (r7 != 0) goto L24
            goto L25
        L49:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: no.nordicsemi.android.dfu.BaseCustomDfuImpl.<init>(android.content.Intent, no.nordicsemi.android.dfu.DfuBaseService):void");
    }

    public static /* synthetic */ int access$108(BaseCustomDfuImpl baseCustomDfuImpl) {
        int i2 = baseCustomDfuImpl.mPacketsSentSinceNotification;
        baseCustomDfuImpl.mPacketsSentSinceNotification = i2 + 1;
        return i2;
    }

    private void writeInitPacket(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i2) throws UploadAbortedException, DfuException, DeviceDisconnectedException {
        if (this.mAborted) {
            throw new UploadAbortedException();
        }
        if (bArr.length != i2) {
            byte[] bArr2 = new byte[i2];
            System.arraycopy(bArr, 0, bArr2, 0, i2);
            bArr = bArr2;
        }
        this.mReceivedData = null;
        this.mError = 0;
        this.mInitPacketInProgress = true;
        bluetoothGattCharacteristic.setWriteType(1);
        bluetoothGattCharacteristic.setValue(bArr);
        logi("Sending init packet (Value = " + parse(bArr) + ")");
        DfuBaseService dfuBaseService = this.mService;
        StringBuilder sbF = a.F("Writing to characteristic ");
        sbF.append(bluetoothGattCharacteristic.getUuid());
        dfuBaseService.sendLogBroadcast(1, sbF.toString());
        DfuBaseService dfuBaseService2 = this.mService;
        StringBuilder sbF2 = a.F("gatt.writeCharacteristic(");
        sbF2.append(bluetoothGattCharacteristic.getUuid());
        sbF2.append(")");
        dfuBaseService2.sendLogBroadcast(0, sbF2.toString());
        this.mGatt.writeCharacteristic(bluetoothGattCharacteristic);
        try {
            synchronized (this.mLock) {
                while (true) {
                    if ((!this.mInitPacketInProgress || !this.mConnected || this.mError != 0) && !this.mPaused) {
                        break;
                    } else {
                        this.mLock.wait();
                    }
                }
            }
        } catch (InterruptedException e2) {
            loge("Sleeping interrupted", e2);
        }
        if (!this.mConnected) {
            throw new DeviceDisconnectedException("Unable to write Init DFU Parameters: device disconnected");
        }
        if (this.mError != 0) {
            throw new DfuException("Unable to write Init DFU Parameters", this.mError);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void writePacket(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i2) {
        if (i2 <= 0) {
            return;
        }
        if (bArr.length != i2) {
            byte[] bArr2 = new byte[i2];
            System.arraycopy(bArr, 0, bArr2, 0, i2);
            bArr = bArr2;
        }
        bluetoothGattCharacteristic.setWriteType(1);
        bluetoothGattCharacteristic.setValue(bArr);
        bluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic);
    }

    public void finalize(Intent intent, boolean z2) {
        boolean booleanExtra = intent.getBooleanExtra(DfuBaseService.EXTRA_KEEP_BOND, false);
        this.mService.refreshDeviceCache(this.mGatt, z2 || !booleanExtra);
        this.mService.close(this.mGatt);
        if (this.mGatt.getDevice().getBondState() == 12) {
            boolean booleanExtra2 = intent.getBooleanExtra(DfuBaseService.EXTRA_RESTORE_BOND, false);
            if (booleanExtra2 || !booleanExtra) {
                removeBond();
                this.mService.waitFor(2000L);
            }
            if (booleanExtra2 && (this.mFileType & 4) > 0 && !createBond()) {
                logw("Creating bond failed");
            }
        }
        if (this.mProgressInfo.isLastPart()) {
            this.mProgressInfo.setProgress(-6);
            return;
        }
        logi("Starting service that will upload application");
        Intent intent2 = new Intent();
        intent2.fillIn(intent, 24);
        intent2.putExtra(DfuBaseService.EXTRA_FILE_MIME_TYPE, DfuBaseService.MIME_TYPE_ZIP);
        intent2.putExtra(DfuBaseService.EXTRA_FILE_TYPE, 4);
        intent2.putExtra(DfuBaseService.EXTRA_PART_CURRENT, this.mProgressInfo.getCurrentPart() + 1);
        intent2.putExtra(DfuBaseService.EXTRA_PARTS_TOTAL, this.mProgressInfo.getTotalParts());
        restartService(intent2, true);
    }

    public abstract UUID getControlPointCharacteristicUUID();

    public abstract UUID getDfuServiceUUID();

    public abstract UUID getPacketCharacteristicUUID();

    /* JADX WARN: Removed duplicated region for block: B:31:0x0072  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0081  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void uploadFirmwareImage(android.bluetooth.BluetoothGattCharacteristic r7) {
        /*
            r6 = this;
            boolean r0 = r6.mAborted
            if (r0 != 0) goto L9d
            r0 = 0
            r6.mReceivedData = r0
            r0 = 0
            r6.mError = r0
            r1 = 1
            r6.mFirmwareUploadInProgress = r1
            r6.mPacketsSentSinceNotification = r0
            no.nordicsemi.android.dfu.DfuProgressInfo r0 = r6.mProgressInfo     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            int r0 = r0.getAvailableObjectSizeIsBytes()     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            byte[] r2 = r6.mBuffer     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            int r3 = r2.length     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            if (r0 >= r3) goto L1c
            byte[] r2 = new byte[r0]     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
        L1c:
            java.io.InputStream r0 = r6.mFirmwareStream     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            int r0 = r0.read(r2)     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            no.nordicsemi.android.dfu.DfuBaseService r3 = r6.mService     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            java.lang.StringBuilder r4 = new java.lang.StringBuilder     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            r4.<init>()     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            java.lang.String r5 = "Sending firmware to characteristic "
            r4.append(r5)     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            java.util.UUID r5 = r7.getUuid()     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            r4.append(r5)     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            java.lang.String r5 = "..."
            r4.append(r5)     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            java.lang.String r4 = r4.toString()     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            r3.sendLogBroadcast(r1, r4)     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            android.bluetooth.BluetoothGatt r1 = r6.mGatt     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            r6.writePacket(r1, r7, r2, r0)     // Catch: java.io.IOException -> L89 no.nordicsemi.android.dfu.internal.exception.HexFileValidationException -> L93
            java.lang.Object r7 = r6.mLock     // Catch: java.lang.InterruptedException -> L68
            monitor-enter(r7)     // Catch: java.lang.InterruptedException -> L68
        L49:
            boolean r0 = r6.mFirmwareUploadInProgress     // Catch: java.lang.Throwable -> L65
            if (r0 == 0) goto L59
            byte[] r0 = r6.mReceivedData     // Catch: java.lang.Throwable -> L65
            if (r0 != 0) goto L59
            boolean r0 = r6.mConnected     // Catch: java.lang.Throwable -> L65
            if (r0 == 0) goto L59
            int r0 = r6.mError     // Catch: java.lang.Throwable -> L65
            if (r0 == 0) goto L5d
        L59:
            boolean r0 = r6.mPaused     // Catch: java.lang.Throwable -> L65
            if (r0 == 0) goto L63
        L5d:
            java.lang.Object r0 = r6.mLock     // Catch: java.lang.Throwable -> L65
            r0.wait()     // Catch: java.lang.Throwable -> L65
            goto L49
        L63:
            monitor-exit(r7)     // Catch: java.lang.Throwable -> L65
            goto L6e
        L65:
            r0 = move-exception
            monitor-exit(r7)     // Catch: java.lang.Throwable -> L65
            throw r0     // Catch: java.lang.InterruptedException -> L68
        L68:
            r7 = move-exception
            java.lang.String r0 = "Sleeping interrupted"
            r6.loge(r0, r7)
        L6e:
            boolean r7 = r6.mConnected
            if (r7 == 0) goto L81
            int r7 = r6.mError
            if (r7 != 0) goto L77
            return
        L77:
            no.nordicsemi.android.dfu.internal.exception.DfuException r7 = new no.nordicsemi.android.dfu.internal.exception.DfuException
            java.lang.String r0 = "Uploading Firmware Image failed"
            int r1 = r6.mError
            r7.<init>(r0, r1)
            throw r7
        L81:
            no.nordicsemi.android.dfu.internal.exception.DeviceDisconnectedException r7 = new no.nordicsemi.android.dfu.internal.exception.DeviceDisconnectedException
            java.lang.String r0 = "Uploading Firmware Image failed: device disconnected"
            r7.<init>(r0)
            throw r7
        L89:
            no.nordicsemi.android.dfu.internal.exception.DfuException r7 = new no.nordicsemi.android.dfu.internal.exception.DfuException
            java.lang.String r0 = "Error while reading file"
            r1 = 4100(0x1004, float:5.745E-42)
            r7.<init>(r0, r1)
            throw r7
        L93:
            no.nordicsemi.android.dfu.internal.exception.DfuException r7 = new no.nordicsemi.android.dfu.internal.exception.DfuException
            java.lang.String r0 = "HEX file not valid"
            r1 = 4099(0x1003, float:5.744E-42)
            r7.<init>(r0, r1)
            throw r7
        L9d:
            no.nordicsemi.android.dfu.internal.exception.UploadAbortedException r7 = new no.nordicsemi.android.dfu.internal.exception.UploadAbortedException
            r7.<init>()
            throw r7
        */
        throw new UnsupportedOperationException("Method not decompiled: no.nordicsemi.android.dfu.BaseCustomDfuImpl.uploadFirmwareImage(android.bluetooth.BluetoothGattCharacteristic):void");
    }

    public void writeInitData(BluetoothGattCharacteristic bluetoothGattCharacteristic, CRC32 crc32) {
        try {
            byte[] bArr = this.mBuffer;
            while (true) {
                int i2 = this.mInitPacketStream.read(bArr, 0, bArr.length);
                if (i2 == -1) {
                    return;
                }
                writeInitPacket(bluetoothGattCharacteristic, bArr, i2);
                if (crc32 != null) {
                    crc32.update(bArr, 0, i2);
                }
            }
        } catch (IOException e2) {
            loge("Error while reading Init packet file", e2);
            throw new DfuException("Error while reading Init packet file", 4098);
        }
    }
}
