package com.ubtrobot.jimu.bluetooth.ble; import android.os.SystemClock; import android.util.Log; import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /* loaded from: classes2.dex */ public class BleDeviceProcessThread extends Thread { private static final String d = BleDeviceProcessThread.class.getSimpleName(); private List a; private boolean b = true; private Callback c; public interface Callback { void a(byte[] bArr, int i); } public BleDeviceProcessThread(Callback callback) { this.c = callback; new ProtocolPacket(); this.a = new ArrayList(); } public void a(byte[] bArr, int i) { synchronized (this) { Log.i(d, "sendData"); BUFFER_DATA buffer_data = new BUFFER_DATA(); buffer_data.a = bArr; buffer_data.b = i; buffer_data.c = SystemClock.uptimeMillis(); buffer_data.d = 0; this.a.add(buffer_data); if (this.c != null) { this.c.a(bArr, i); } } } public void b(byte[] bArr, int i) { synchronized (this) { if (this.c != null) { this.c.a(bArr, i); } } } @Override // java.lang.Thread, java.lang.Runnable public void run() { while (this.b) { synchronized (this) { BUFFER_DATA buffer_data = null; Iterator it = this.a.iterator(); while (true) { if (!it.hasNext()) { break; } BUFFER_DATA next = it.next(); if (SystemClock.uptimeMillis() - next.c >= 10000) { if (next.d >= 2) { buffer_data = next; break; } else { b(next.a, next.b); next.c = SystemClock.uptimeMillis(); next.d++; } } } if (buffer_data != null) { this.a.remove(buffer_data); } else { try { Thread.sleep(100L); } catch (InterruptedException unused) { this.b = false; Thread.currentThread().interrupt(); return; } } } } } public void a() { synchronized (this) { this.b = false; this.a.clear(); } } public void a(byte b) { synchronized (this) { ProtocolPacket protocolPacket = new ProtocolPacket(); BUFFER_DATA buffer_data = null; Iterator it = this.a.iterator(); while (true) { if (!it.hasNext()) { break; } BUFFER_DATA next = it.next(); protocolPacket.b(next.a); if (protocolPacket.f() == b) { buffer_data = next; break; } } if (buffer_data != null) { this.a.remove(buffer_data); } } } }