Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import com.afunx.ble.blelitelib.log.BleLiteLog;
/* loaded from: classes.dex */
public class BleCloseOperation extends BleOperationAbs {
private static final String TAG = "BleCloseOperation";
private final BluetoothGatt mBluetoothGatt;
private boolean mIsClosed = false;
private BleCloseOperation(BluetoothGatt bluetoothGatt) {
this.mBluetoothGatt = bluetoothGatt;
}
public static BleCloseOperation createInstance(BluetoothGatt bluetoothGatt) {
return new BleCloseOperation(bluetoothGatt);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 2;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
if (this.mIsClosed) {
BleLiteLog.w(TAG, "it is closed already");
return;
}
this.mIsClosed = true;
BluetoothGatt bluetoothGatt = this.mBluetoothGatt;
if (bluetoothGatt != null) {
bluetoothGatt.close();
}
}
}

View File

@@ -0,0 +1,44 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCallback;
import android.content.Context;
import com.afunx.ble.blelitelib.connector.BleConnector;
import com.afunx.ble.blelitelib.utils.BleUtils;
/* loaded from: classes.dex */
public class BleConnectOperation extends BleOperationAbs {
private final Context mAppContext;
private final String mBleAddr;
private final BluetoothGattCallback mBluetoothGattCallback;
private BleConnectOperation(Context context, String str, BluetoothGattCallback bluetoothGattCallback) {
this.mAppContext = context.getApplicationContext();
this.mBleAddr = str;
this.mBluetoothGattCallback = bluetoothGattCallback;
}
public static BleConnectOperation createInstance(Context context, String str, BluetoothGattCallback bluetoothGattCallback) {
return new BleConnectOperation(context, str, bluetoothGattCallback);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 1;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
BluetoothDevice remoteDevice = BleUtils.getRemoteDevice(this.mBleAddr);
BleConnector connector = getConnector();
if (connector == null) {
connector = new BleConnector.Builder().build(this.mAppContext, remoteDevice).setGattCallback(this.mBluetoothGattCallback).create();
setConnector(connector);
}
connector.connect();
}
}

View File

@@ -0,0 +1,30 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
/* loaded from: classes.dex */
public class BleDiscoverServiceOperation extends BleOperationAbs {
private final BluetoothGatt mBluetoothGatt;
private BleDiscoverServiceOperation(BluetoothGatt bluetoothGatt) {
this.mBluetoothGatt = bluetoothGatt;
}
public static BleDiscoverServiceOperation createInstance(BluetoothGatt bluetoothGatt) {
return new BleDiscoverServiceOperation(bluetoothGatt);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 3;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mBluetoothGatt.discoverServices();
}
}

View File

@@ -0,0 +1,5 @@
package com.afunx.ble.blelitelib.operation;
/* loaded from: classes.dex */
public interface BleInterruptable {
}

View File

@@ -0,0 +1,22 @@
package com.afunx.ble.blelitelib.operation;
/* loaded from: classes.dex */
public interface BleOperation extends Runnable {
public static final int BLE_CLOSE = 2;
public static final int BLE_CONNECT = 1;
public static final int BLE_DISCOVER_SERVICE = 3;
public static final int BLE_READ_CHARACTERISTIC = 4;
public static final int BLE_REQUEST_MTU = 5;
public static final int BLE_WRITE_CHARACTERISITC_NO_RESPONSE_PACKET = 10;
public static final int BLE_WRITE_CHARACTERISITC_NO_RESPONSE_PACKET2 = 11;
public static final int BLE_WRITE_CHARACTERISTIC = 6;
public static final int BLE_WRITE_CHARACTERISTIC_NO_RESPONSE = 8;
public static final int BLE_WRITE_CHARACTERISTIC_NO_RESPONSE_20 = 9;
public static final int BLE_WRITE_CHARACTERISTIC_NO_RESPONSE_INTERRUPT = 12;
public static final int BLE_WRITE_DESCRIPTOR = 7;
int getOperatcionCode();
@Override // java.lang.Runnable
void run();
}

View File

@@ -0,0 +1,156 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGattCallback;
import android.os.Looper;
import android.util.LongSparseArray;
import android.util.SparseArray;
import com.afunx.ble.blelitelib.connector.BleConnector;
import com.afunx.ble.blelitelib.log.BleLiteLog;
import com.afunx.ble.blelitelib.proxy.BleGattClientProxy;
import com.afunx.ble.blelitelib.threadpool.BleThreadpool;
import java.util.concurrent.Future;
/* loaded from: classes.dex */
public abstract class BleOperationAbs<T> implements BleOperation {
private static final String TAG = "BleOperationAbs";
private BluetoothGattCallback mBluetoothGattCallback;
private BleConnector mConnector;
private BleGattClientProxy mOwner;
private T mResult;
private static final BleThreadpool sThreadpool = BleThreadpool.getInstance();
private static final SparseArray<Future<?>> mInterruptableTasks = new SparseArray<>();
private final LongSparseArray<Runnable> mRunnables = new LongSparseArray<>();
private final BleOperationLock mLock = new BleOperationLock();
private void clearBleOperationAbs() {
this.mRunnables.clear();
this.mResult = null;
this.mOwner = null;
this.mConnector = null;
this.mBluetoothGattCallback = null;
}
private Runnable getRunnable(long j, boolean z) {
Runnable runnable;
synchronized (this.mRunnables) {
runnable = this.mRunnables.get(j);
if (z) {
this.mRunnables.remove(j);
}
}
return runnable;
}
public final void clear() {
BleLiteLog.v(TAG, "clear() called by " + this);
clearConcurrentOperation();
clearBleOperationAbs();
}
protected abstract void clearConcurrentOperation();
public final void doRunnableAsync(long j, boolean z) {
Runnable runnable = getRunnable(j, z);
if (runnable != null) {
sThreadpool.submit(runnable);
}
}
public final void doRunnableSelfAsync(boolean z) {
if (!z) {
sThreadpool.submit(this);
} else {
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IllegalStateException("It can't be called in UI Main Thread.");
}
sThreadpool.submitInMain(this);
}
}
public final void doRunnableSelfAsyncInterruptable(int i) {
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IllegalStateException("It can't be called in UI Main Thread.");
}
if (!(this instanceof BleInterruptable)) {
throw new IllegalArgumentException("Only BleInterruptable could call the method.");
}
synchronized (mInterruptableTasks) {
Future<?> future = mInterruptableTasks.get(i);
if (future != null) {
future.cancel(true);
}
mInterruptableTasks.put(i, sThreadpool.submit(this));
}
}
public final void doRunnableUIAsync(long j, boolean z) {
Runnable runnable = getRunnable(j, z);
if (runnable != null) {
sThreadpool.submitInMain(runnable);
}
}
public final BluetoothGattCallback getBluetoothGattCallback() {
return this.mBluetoothGattCallback;
}
public final BleConnector getConnector() {
return this.mConnector;
}
public final BleGattClientProxy getOwner() {
return this.mOwner;
}
public final T getResult() {
return this.mResult;
}
public final boolean isNotified() {
return this.mLock.isNotified();
}
public final void notifyLock() {
this.mLock.notifyLock();
}
public final void putRunnable(long j, Runnable runnable) {
synchronized (this.mRunnables) {
this.mRunnables.put(j, runnable);
}
}
public final void removeRunnable(long j) {
synchronized (this.mRunnables) {
this.mRunnables.remove(j);
}
}
public final void setBluetoothGattCallback(BluetoothGattCallback bluetoothGattCallback) {
this.mBluetoothGattCallback = bluetoothGattCallback;
}
public final void setConnector(BleConnector bleConnector) {
this.mConnector = bleConnector;
}
public final void setOwner(BleGattClientProxy bleGattClientProxy) {
this.mOwner = bleGattClientProxy;
}
public final void setResult(T t) {
this.mResult = t;
}
public String toString() {
return String.format("[%s-%d-%04x]", getClass().getSimpleName(), Integer.valueOf(hashCode()), Long.valueOf(getOperatcionCode()));
}
public final void waitLock(long j) {
this.mLock.waitLock(j);
}
public final Runnable getRunnable(long j) {
return getRunnable(j, false);
}
}

View File

@@ -0,0 +1,28 @@
package com.afunx.ble.blelitelib.operation;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
/* loaded from: classes.dex */
public class BleOperationLock {
private final Semaphore mSemaphore = new Semaphore(0);
private volatile boolean mIsNotified = false;
boolean isNotified() {
return this.mIsNotified;
}
void notifyLock() {
this.mIsNotified = true;
this.mSemaphore.release();
}
void waitLock(long j) {
try {
this.mSemaphore.tryAcquire(1, j, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
}

View File

@@ -0,0 +1,33 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
/* loaded from: classes.dex */
public class BleReadCharacteristicOperation extends BleOperationAbs<byte[]> {
private final BluetoothGatt mBluetoothGatt;
private final BluetoothGattCharacteristic mGattCharacteristic;
private BleReadCharacteristicOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
this.mBluetoothGatt = bluetoothGatt;
this.mGattCharacteristic = bluetoothGattCharacteristic;
}
public static BleReadCharacteristicOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
return new BleReadCharacteristicOperation(bluetoothGatt, bluetoothGattCharacteristic);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 4;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mBluetoothGatt.readCharacteristic(this.mGattCharacteristic);
}
}

View File

@@ -0,0 +1,34 @@
package com.afunx.ble.blelitelib.operation;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothGatt;
/* loaded from: classes.dex */
public class BleRequestMtuOperation extends BleOperationAbs {
private final BluetoothGatt mBluetoothGatt;
private final int mMTU;
private BleRequestMtuOperation(BluetoothGatt bluetoothGatt, int i) {
this.mBluetoothGatt = bluetoothGatt;
this.mMTU = i;
}
public static BleRequestMtuOperation createInstance(BluetoothGatt bluetoothGatt, int i) {
return new BleRequestMtuOperation(bluetoothGatt, i);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 5;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
@TargetApi(21)
public void run() {
this.mBluetoothGatt.requestMtu(this.mMTU);
}
}

View File

@@ -0,0 +1,64 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import com.afunx.ble.blelitelib.log.BleLiteLog;
import com.afunx.ble.blelitelib.utils.HexUtils;
import java.util.Arrays;
/* loaded from: classes.dex */
public class BleWriteCharacterisitcNoResponsePacketOperation extends BleOperationAbs {
private static final String TAG = "BleWriteCharacterisitcNoResponsePacketOperation";
private final BluetoothGatt mBluetoothGatt;
private final BluetoothGattCharacteristic mCharacteristic;
private final byte[] mMsg;
private final int mPacketInterval;
private final int mPacketSize;
private BleWriteCharacterisitcNoResponsePacketOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2) {
this.mBluetoothGatt = bluetoothGatt;
this.mCharacteristic = bluetoothGattCharacteristic;
this.mMsg = bArr;
this.mPacketSize = i;
this.mPacketInterval = i2;
}
public static BleWriteCharacterisitcNoResponsePacketOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2) {
return new BleWriteCharacterisitcNoResponsePacketOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr, i, i2);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 10;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mCharacteristic.setWriteType(1);
int i = this.mPacketSize;
int i2 = this.mPacketInterval;
int length = this.mMsg.length;
int i3 = 0;
while (i3 < length) {
int i4 = i3 + i;
int i5 = i4 <= length ? i : length - i3;
byte[] copyOfRange = Arrays.copyOfRange(this.mMsg, i3, i3 + i5);
this.mCharacteristic.setValue(copyOfRange);
this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
BleLiteLog.i(TAG, "writeCharacteristic() " + HexUtils.bytes2HexStringWithSpace(copyOfRange, 0, i5));
if (i2 > 0) {
try {
Thread.sleep(i2);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
return;
}
}
i3 = i4;
}
}
}

View File

@@ -0,0 +1,102 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import com.afunx.ble.blelitelib.log.BleLiteLog;
import com.afunx.ble.blelitelib.utils.HexUtils;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
public class BleWriteCharacterisitcNoResponsePacketOperation2 extends BleOperationAbs {
private static final int PACKET_SIZE = 20;
private static final String TAG = "BleWriteCharacterisitcNoResponsePacketOperation2";
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 BleWriteCharacterisitcNoResponsePacketOperation2(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
this.mBluetoothGatt = bluetoothGatt;
this.mCharacteristic = bluetoothGattCharacteristic;
this.mMsg = bArr;
}
public static BleWriteCharacterisitcNoResponsePacketOperation2 createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
return new BleWriteCharacterisitcNoResponsePacketOperation2(bluetoothGatt, bluetoothGattCharacteristic, bArr);
}
public static void setPacketIntervals(int[] iArr) {
PACKET_INTERVALS = iArr;
}
private static void sleep() {
int currentTimeMillis;
synchronized (BleWriteCharacterisitcNoResponsePacketOperation2.class) {
int andAdd = mAutoId.getAndAdd(1) % PACKET_INTERVALS.length;
if (lastTimestamp == 0) {
currentTimeMillis = 0;
} else {
currentTimeMillis = PACKET_INTERVALS[andAdd] - ((int) (System.currentTimeMillis() - lastTimestamp));
}
if (currentTimeMillis > 0) {
try {
BleWriteCharacterisitcNoResponsePacketOperation2.class.wait(currentTimeMillis);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
}
}
}
}
private static synchronized void updateLastTimestamp() {
synchronized (BleWriteCharacterisitcNoResponsePacketOperation2.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 11;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
int length = this.mMsg.length;
this.mCharacteristic.setWriteType(1);
int i = 0;
int i2 = 0;
while (i < length) {
sleep();
int i3 = i + 20 <= length ? 20 : length - i;
byte[] copyOfRange = Arrays.copyOfRange(this.mMsg, i, i + i3);
this.mCharacteristic.setValue(copyOfRange);
boolean writeCharacteristic = this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
if (writeCharacteristic) {
i2 = 0;
} else {
i2++;
if (i2 > 3) {
BleLiteLog.e(TAG, "writeCharacteristic() fail");
return;
}
i -= i3;
try {
Thread.sleep(50L);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
BleLiteLog.i(TAG, "writeCharacteristic() " + HexUtils.bytes2HexStringWithSpace(copyOfRange, 0, i3) + ", isWriteSuc: " + writeCharacteristic);
updateLastTimestamp();
i += i3;
}
}
}

View File

@@ -0,0 +1,59 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import com.afunx.ble.blelitelib.log.BleLiteLog;
import com.afunx.ble.blelitelib.utils.HexUtils;
import java.util.Arrays;
/* loaded from: classes.dex */
public class BleWriteCharacteristicNoResponse20Operation extends BleOperationAbs {
private static final String TAG = "BleWriteCharacteristicNoResponse20Operation";
private static final int TWEENTY = 20;
private final BluetoothGatt mBluetoothGatt;
private final BluetoothGattCharacteristic mCharacteristic;
private final byte[] mMsg;
private BleWriteCharacteristicNoResponse20Operation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
this.mBluetoothGatt = bluetoothGatt;
this.mCharacteristic = bluetoothGattCharacteristic;
this.mMsg = bArr;
Log.e("NoResponse20Operation", "msg: " + HexUtils.bytes2HexStringWithSpace(bArr));
}
public static BleWriteCharacteristicNoResponse20Operation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
return new BleWriteCharacteristicNoResponse20Operation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 9;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mCharacteristic.setWriteType(1);
int length = this.mMsg.length;
int i = 0;
while (i < length) {
int i2 = i + 20;
int i3 = i2 <= length ? 20 : length - i;
byte[] copyOfRange = Arrays.copyOfRange(this.mMsg, i, i + i3);
this.mCharacteristic.setValue(copyOfRange);
this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
BleLiteLog.i(TAG, "writeCharacteristic() " + HexUtils.bytes2HexStringWithSpace(copyOfRange, 0, i3));
try {
Thread.sleep(2L);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
i = i2;
}
}
}

View File

@@ -0,0 +1,192 @@
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<UUID, byte[][]> 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.<init>() // 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");
}
}

View File

@@ -0,0 +1,54 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import com.afunx.ble.blelitelib.log.BleLiteLog;
/* loaded from: classes.dex */
public class BleWriteCharacteristicNoResponseOperation extends BleOperationAbs {
private static final String TAG = "BleWriteCharacteristicNoResponseOperation";
private final BluetoothGatt mBluetoothGatt;
private final BluetoothGattCharacteristic mCharacteristic;
private final byte[] mMsg;
private BleWriteCharacteristicNoResponseOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
this.mBluetoothGatt = bluetoothGatt;
this.mCharacteristic = bluetoothGattCharacteristic;
this.mMsg = bArr;
}
public static BleWriteCharacteristicNoResponseOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
return new BleWriteCharacteristicNoResponseOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 8;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mCharacteristic.setValue(this.mMsg);
this.mCharacteristic.setWriteType(1);
boolean z = false;
for (int i = 0; !z && i < 3; i++) {
if (i > 0) {
try {
Thread.sleep(50L);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
z = this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
}
if (z) {
return;
}
BleLiteLog.e(TAG, "writeCharacteristic() fail");
}
}

View File

@@ -0,0 +1,36 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
/* loaded from: classes.dex */
public class BleWriteCharacteristicOperation extends BleOperationAbs {
private final BluetoothGatt mBluetoothGatt;
private final BluetoothGattCharacteristic mCharacteristic;
private final byte[] mMsg;
private BleWriteCharacteristicOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
this.mBluetoothGatt = bluetoothGatt;
this.mCharacteristic = bluetoothGattCharacteristic;
this.mMsg = bArr;
}
public static BleWriteCharacteristicOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
return new BleWriteCharacteristicOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 6;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mCharacteristic.setValue(this.mMsg);
this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
}
}

View File

@@ -0,0 +1,36 @@
package com.afunx.ble.blelitelib.operation;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattDescriptor;
/* loaded from: classes.dex */
public class BleWriteDescriptorOperation extends BleOperationAbs {
private final BluetoothGatt mBluetoothGatt;
private final BluetoothGattDescriptor mDescriptor;
private final byte[] mMsg;
private BleWriteDescriptorOperation(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, byte[] bArr) {
this.mBluetoothGatt = bluetoothGatt;
this.mDescriptor = bluetoothGattDescriptor;
this.mMsg = bArr;
}
public static BleWriteDescriptorOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, byte[] bArr) {
return new BleWriteDescriptorOperation(bluetoothGatt, bluetoothGattDescriptor, bArr);
}
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
protected void clearConcurrentOperation() {
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation
public int getOperatcionCode() {
return 7;
}
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
public void run() {
this.mDescriptor.setValue(this.mMsg);
this.mBluetoothGatt.writeDescriptor(this.mDescriptor);
}
}