package com.afunx.ble.blelitelib.operation; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import com.afunx.ble.blelitelib.log.BleLiteLog; import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; /* loaded from: classes.dex */ public class BleWriteCharacteristicNoResponseInterruptOperation extends BleOperationAbs implements BleInterruptable { private static final int PACKET_SIZE = 20; private static final String TAG = "BleWriteCharacteristicNoResponseInterruptOperation"; private final BluetoothGatt mBluetoothGatt; private final BluetoothGattCharacteristic mCharacteristic; private final byte[] mMsg; private static int[] PACKET_INTERVALS = {5, 5, 5, 35}; private static final AtomicInteger mAutoId = new AtomicInteger(0); private static volatile long lastTimestamp = 0; private static final Map mBufferMap = new HashMap(); private BleWriteCharacteristicNoResponseInterruptOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) { this.mBluetoothGatt = bluetoothGatt; this.mCharacteristic = bluetoothGattCharacteristic; this.mMsg = bArr; } public static BleWriteCharacteristicNoResponseInterruptOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) { return new BleWriteCharacteristicNoResponseInterruptOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr); } private static byte[][] getBuffer20(UUID uuid, int i) { byte[][] bArr = mBufferMap.get(uuid); if (bArr == null) { bArr = new byte[i][]; int i2 = 0; while (i2 < bArr.length) { int i3 = i2 + 1; bArr[i2] = new byte[i3]; i2 = i3; } mBufferMap.put(uuid, bArr); } return bArr; } private static byte[] getSendMessage(UUID uuid, int i, byte[] bArr, int i2, int i3) { byte[][] buffer20 = getBuffer20(uuid, i); int i4 = i3 - 1; System.arraycopy(bArr, i2, buffer20[i4], 0, i3); return buffer20[i4]; } private static boolean sleep() { synchronized (BleWriteCharacteristicNoResponseInterruptOperation.class) { int currentTimeMillis = PACKET_INTERVALS[mAutoId.getAndAdd(1) % PACKET_INTERVALS.length] - ((int) (System.currentTimeMillis() - lastTimestamp)); if (currentTimeMillis <= 0) { return Thread.interrupted(); } try { BleWriteCharacteristicNoResponseInterruptOperation.class.wait(currentTimeMillis); return false; } catch (InterruptedException unused) { BleLiteLog.e(TAG, "sleep() is interrupted, return true"); Thread.currentThread().interrupt(); return true; } } } private static synchronized void updateLastTimestamp() { synchronized (BleWriteCharacteristicNoResponseInterruptOperation.class) { lastTimestamp = System.currentTimeMillis(); } } @Override // com.afunx.ble.blelitelib.operation.BleOperationAbs protected void clearConcurrentOperation() { } @Override // com.afunx.ble.blelitelib.operation.BleOperation public int getOperatcionCode() { return 12; } /* JADX WARN: Code restructure failed: missing block: B:34:0x0019, code lost: com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId.wait(50); */ @Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void run() { /* r12 = this; byte[] r0 = r12.mMsg int r0 = r0.length java.util.concurrent.atomic.AtomicInteger r1 = com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId monitor-enter(r1) android.bluetooth.BluetoothGattCharacteristic r2 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4 r3 = 1 r2.setWriteType(r3) // Catch: java.lang.Throwable -> La4 r2 = 0 r4 = 0 r5 = 0 Lf: if (r4 >= r0) goto La2 boolean r6 = sleep() // Catch: java.lang.Throwable -> La4 r7 = 50 if (r6 == 0) goto L2e java.util.concurrent.atomic.AtomicInteger r0 = com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId // Catch: java.lang.InterruptedException -> L1f java.lang.Throwable -> La4 r0.wait(r7) // Catch: java.lang.InterruptedException -> L1f java.lang.Throwable -> La4 goto L2a L1f: r0 = move-exception r0.printStackTrace() // Catch: java.lang.Throwable -> La4 java.lang.Thread r0 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> La4 r0.interrupt() // Catch: java.lang.Throwable -> La4 L2a: updateLastTimestamp() // Catch: java.lang.Throwable -> La4 goto La2 L2e: int r6 = r4 + 20 r9 = 20 if (r6 > r0) goto L37 r6 = 20 goto L39 L37: int r6 = r0 - r4 L39: android.bluetooth.BluetoothGattCharacteristic r10 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4 java.util.UUID r10 = r10.getUuid() // Catch: java.lang.Throwable -> La4 byte[] r11 = r12.mMsg // Catch: java.lang.Throwable -> La4 byte[] r9 = getSendMessage(r10, r9, r11, r4, r6) // Catch: java.lang.Throwable -> La4 android.bluetooth.BluetoothGattCharacteristic r10 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4 r10.setValue(r9) // Catch: java.lang.Throwable -> La4 android.bluetooth.BluetoothGatt r10 = r12.mBluetoothGatt // Catch: java.lang.Throwable -> La4 android.bluetooth.BluetoothGattCharacteristic r11 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4 boolean r10 = r10.writeCharacteristic(r11) // Catch: java.lang.Throwable -> La4 if (r10 == 0) goto L56 r5 = 0 goto L69 L56: int r5 = r5 + r3 r11 = 3 if (r5 <= r11) goto L63 java.lang.String r0 = "BleWriteCharacteristicNoResponseInterruptOperation" java.lang.String r2 = "writeCharacteristic() fail" com.afunx.ble.blelitelib.log.BleLiteLog.e(r0, r2) // Catch: java.lang.Throwable -> La4 monitor-exit(r1) // Catch: java.lang.Throwable -> La4 return L63: int r4 = r4 - r6 java.util.concurrent.atomic.AtomicInteger r11 = com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId // Catch: java.lang.InterruptedException -> L91 java.lang.Throwable -> La4 r11.wait(r7) // Catch: java.lang.InterruptedException -> L91 java.lang.Throwable -> La4 L69: java.lang.String r7 = "BleWriteCharacteristicNoResponseInterruptOperation" java.lang.StringBuilder r8 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> La4 r8.() // Catch: java.lang.Throwable -> La4 java.lang.String r11 = "writeCharacteristic() " r8.append(r11) // Catch: java.lang.Throwable -> La4 java.lang.String r9 = com.afunx.ble.blelitelib.utils.HexUtils.bytes2HexStringWithSpace(r9, r2, r6) // Catch: java.lang.Throwable -> La4 r8.append(r9) // Catch: java.lang.Throwable -> La4 java.lang.String r9 = ", isWriteSuc: " r8.append(r9) // Catch: java.lang.Throwable -> La4 r8.append(r10) // Catch: java.lang.Throwable -> La4 java.lang.String r8 = r8.toString() // Catch: java.lang.Throwable -> La4 com.afunx.ble.blelitelib.log.BleLiteLog.i(r7, r8) // Catch: java.lang.Throwable -> La4 updateLastTimestamp() // Catch: java.lang.Throwable -> La4 int r4 = r4 + r6 goto Lf L91: java.lang.String r0 = "BleWriteCharacteristicNoResponseInterruptOperation" java.lang.String r2 = "sleep() is interrupted, break" com.afunx.ble.blelitelib.log.BleLiteLog.e(r0, r2) // Catch: java.lang.Throwable -> La4 updateLastTimestamp() // Catch: java.lang.Throwable -> La4 java.lang.Thread r0 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> La4 r0.interrupt() // Catch: java.lang.Throwable -> La4 La2: monitor-exit(r1) // Catch: java.lang.Throwable -> La4 return La4: r0 = move-exception monitor-exit(r1) // Catch: java.lang.Throwable -> La4 throw r0 */ throw new UnsupportedOperationException("Method not decompiled: com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.run():void"); } }