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,13 @@
package com.ubtrobot.jimu.bluetooth.base;
/* compiled from: DeviceProcessThread.java */
/* loaded from: classes2.dex */
class BUFFER_DATA {
public byte[] a;
public int b;
public long c;
public int d;
BUFFER_DATA() {
}
}

View File

@@ -0,0 +1,177 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
import android.util.Log;
import com.ijm.dataencryption.de.DataDecryptTool;
import com.ubtrobot.jimu.bluetooth.base.DeviceProcessThread;
import com.ubtrobot.jimu.bluetooth.utils.ByteHexHelper;
import com.ubtrobot.log.ALog;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/* loaded from: classes2.dex */
public class BlueToothClientHandler extends Thread implements DeviceProcessThread.DeviceProcessThreadCallBack {
private final String a;
private final BluetoothSocket b;
private final InputStream c;
private final OutputStream d;
private final ClentCallBack e;
private ProtocolPacket g;
private DeviceProcessThread k;
private int l;
private int m;
private boolean f = true;
private boolean j = true;
private long h = SystemClock.uptimeMillis();
private long i = this.h;
public interface ClentCallBack {
void a(String str);
void a(String str, byte b, byte[] bArr, int i);
}
public BlueToothClientHandler(String str, BluetoothSocket bluetoothSocket, ClentCallBack clentCallBack) {
InputStream inputStream;
this.l = 0;
this.m = 0;
this.a = str;
this.b = bluetoothSocket;
this.e = clentCallBack;
OutputStream outputStream = null;
try {
inputStream = bluetoothSocket.getInputStream();
try {
outputStream = bluetoothSocket.getOutputStream();
} catch (IOException e) {
e = e;
Log.e("BlueToothClientHandler", "temp sockets not created", e);
this.c = inputStream;
this.d = outputStream;
this.l = 0;
this.m = 0;
this.g = new ProtocolPacket();
this.k = new DeviceProcessThread(this);
this.k.start();
}
} catch (IOException e2) {
e = e2;
inputStream = null;
}
this.c = inputStream;
this.d = outputStream;
this.l = 0;
this.m = 0;
this.g = new ProtocolPacket();
this.k = new DeviceProcessThread(this);
this.k.start();
}
public String a() {
return this.a;
}
public void b(byte[] bArr, int i) {
this.k.a(bArr, i);
}
public void c(byte[] bArr, int i) {
if (SystemClock.uptimeMillis() - this.i < 3000) {
return;
}
if (!this.j) {
this.h = SystemClock.uptimeMillis();
} else {
a(bArr, i);
this.l++;
}
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
byte[] bArr = new byte[DataDecryptTool.DECRYPT_SP_FILE];
while (this.f) {
try {
int read = this.c.read(bArr);
if (read > 0) {
byte[] bArr2 = new byte[read];
System.arraycopy(bArr, 0, bArr2, 0, read);
ALog.a("DV_READSTATUS").d("Receive: param=" + ByteHexHelper.a(bArr2));
for (int i = 0; i < read; i++) {
if (this.g.b(bArr[i])) {
if (this.e != null) {
this.g.a(this.g.g().length);
this.e.a(this.a, this.g.f(), this.g.g(), this.g.a());
}
this.l = 0;
this.m = 0;
this.h = SystemClock.uptimeMillis();
this.k.a(this.g.f());
}
}
}
} catch (IOException e) {
Log.e("BlueToothClientHandler", "read form bt socket fail", e);
return;
} catch (Exception unused) {
this.f = false;
return;
}
}
}
public void a(boolean z) {
this.j = z;
}
public void b() {
synchronized (this) {
try {
this.l = 0;
this.m = 0;
this.f = false;
if (this.k != null) {
this.k.a();
}
if (this.c != null) {
this.c.close();
}
if (this.d != null) {
this.d.close();
}
if (this.b != null) {
this.b.close();
}
if (this.e != null) {
this.e.a(this.a);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override // com.ubtrobot.jimu.bluetooth.base.DeviceProcessThread.DeviceProcessThreadCallBack
public synchronized void a(byte[] bArr, int i) {
try {
try {
ALog.a("DV_READSTATUS").d("SendData=" + ByteHexHelper.a(bArr));
this.d.write(bArr, 0, i);
this.i = SystemClock.uptimeMillis();
this.m = this.m + 1;
} catch (Exception e) {
ALog.a("BlueToothClientHandler").d("Send bluetooth data to socket fail! Close socket!", e);
b();
}
} catch (IOException e2) {
ALog.a("BlueToothClientHandler").d("Send bluetooth data to socket fail! Close socket!", e2);
b();
}
}
public boolean c() {
return (this.f && isAlive() && (!(this.l > 3 || this.m > 6) || !this.j)) ? false : true;
}
}

View File

@@ -0,0 +1,168 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.os.SystemClock;
import com.ubtrobot.jimu.bluetooth.base.BlueToothClientHandler;
import com.ubtrobot.jimu.bluetooth.base.BluetoothUtil;
import com.ubtrobot.jimu.bluetooth.proxy.Callback;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes2.dex */
public class BlueToothManager extends Thread implements BlueToothClientHandler.ClentCallBack, BluetoothUtil.BluetoothUtilCallBack {
private Callback d;
private BluetoothUtil e;
private boolean a = false;
private boolean c = true;
private List<BlueToothClientHandler> b = new ArrayList();
public BlueToothManager(Context context, Callback callback) {
this.d = callback;
this.e = new BluetoothUtil(context, this);
SystemClock.uptimeMillis();
}
public void a(BluetoothDevice bluetoothDevice) {
b();
this.e.a(bluetoothDevice);
}
@Override // com.ubtrobot.jimu.bluetooth.base.BluetoothUtil.BluetoothUtilCallBack
public void a(String str, int i) {
}
public synchronized BlueToothClientHandler b(String str) {
BlueToothClientHandler blueToothClientHandler;
blueToothClientHandler = null;
Iterator<BlueToothClientHandler> it = this.b.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
BlueToothClientHandler next = it.next();
if (next.a().equals(str)) {
blueToothClientHandler = next;
break;
}
}
return blueToothClientHandler;
}
public void c() {
this.c = true;
this.e.a(this.a);
start();
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
BlueToothClientHandler blueToothClientHandler;
while (this.c) {
synchronized (this) {
Iterator<BlueToothClientHandler> it = this.b.iterator();
while (true) {
if (!it.hasNext()) {
blueToothClientHandler = null;
break;
}
blueToothClientHandler = it.next();
if (blueToothClientHandler.c()) {
break;
}
ProtocolPacket protocolPacket = new ProtocolPacket();
protocolPacket.a((byte) 3);
protocolPacket.a((byte[]) null);
protocolPacket.a(0);
byte[] b = protocolPacket.b();
blueToothClientHandler.c(b, b.length);
}
if (blueToothClientHandler != null) {
String a = blueToothClientHandler.a();
blueToothClientHandler.b();
this.b.remove(blueToothClientHandler);
if (this.d != null) {
this.d.b(a);
}
} else {
try {
Thread.sleep(300L);
} catch (InterruptedException unused) {
this.c = false;
Thread.currentThread().interrupt();
return;
}
}
}
}
}
public void a(String str, boolean z) {
BlueToothClientHandler b = b(str);
if (b != null) {
b.a(z);
}
}
public synchronized void b(String str, BluetoothSocket bluetoothSocket) {
if (b(str) != null) {
return;
}
BlueToothClientHandler blueToothClientHandler = new BlueToothClientHandler(str, bluetoothSocket, this);
this.b.add(blueToothClientHandler);
blueToothClientHandler.start();
}
@Override // com.ubtrobot.jimu.bluetooth.base.BlueToothClientHandler.ClentCallBack
public synchronized void a(String str, byte b, byte[] bArr, int i) {
if (this.d != null) {
this.d.b(str, b, bArr, i);
}
}
@Override // com.ubtrobot.jimu.bluetooth.base.BlueToothClientHandler.ClentCallBack
public synchronized void a(String str) {
if (this.d != null) {
this.d.b(str);
}
}
public synchronized void b() {
if (this.b != null) {
Iterator<BlueToothClientHandler> it = this.b.iterator();
while (it.hasNext()) {
it.next().b();
}
this.b.clear();
}
}
@Override // com.ubtrobot.jimu.bluetooth.base.BluetoothUtil.BluetoothUtilCallBack
public synchronized void a(String str, BluetoothSocket bluetoothSocket) {
b(str, bluetoothSocket);
if (this.d != null) {
this.d.a(true, str);
}
}
@Override // com.ubtrobot.jimu.bluetooth.base.BluetoothUtil.BluetoothUtilCallBack
public synchronized void a() {
if (this.d != null) {
this.d.a(false, null);
}
}
public synchronized void b(String str, byte b, byte[] bArr, int i) {
ProtocolPacket protocolPacket = new ProtocolPacket();
protocolPacket.a(b);
protocolPacket.a(bArr);
protocolPacket.a(i);
byte[] b2 = protocolPacket.b();
BlueToothClientHandler b3 = b(str);
if (b3 != null) {
b3.b(b2, b2.length);
}
}
}

View File

@@ -0,0 +1,231 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.Cancellable;
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
import com.ubtrobot.jimu.bluetooth.proxy.Callback;
import com.ubtrobot.jimu.bluetooth.proxy.Device;
import com.ubtrobot.jimu.bluetooth.proxy.DeviceListener;
import com.ubtrobot.jimu.bluetooth.proxy.Proxy;
import com.ubtrobot.log.ALog;
import java.util.ArrayList;
/* loaded from: classes2.dex */
public class BluetoothLib extends Callback implements Proxy {
private static final String k = "BluetoothLib";
public static BluetoothLib l;
public static BlueToothManager m;
private BluetoothAdapter b;
private Context c;
private ArrayList<String> d = new ArrayList<>();
private Boolean e;
private DeviceListener f;
private ScannedHubEmitter g;
private Handler h;
private Cancellable i;
private final BroadcastReceiver j;
public BluetoothLib() {
new ArrayList();
this.e = false;
new Runnable(this) { // from class: com.ubtrobot.jimu.bluetooth.base.BluetoothLib.1
@Override // java.lang.Runnable
public void run() {
}
};
this.i = new Cancellable() { // from class: com.ubtrobot.jimu.bluetooth.base.BluetoothLib.3
@Override // com.ubtrobot.jimu.bluetooth.Cancellable
public boolean cancel() {
BluetoothLib.this.c();
BluetoothLib.this.h.removeCallbacksAndMessages(null);
return BluetoothLib.this.b != null && BluetoothLib.this.b.isDiscovering();
}
@Override // com.ubtrobot.jimu.bluetooth.Cancellable
public boolean isCancelled() {
return BluetoothLib.this.b != null && BluetoothLib.this.b.isDiscovering();
}
};
this.j = new BroadcastReceiver() { // from class: com.ubtrobot.jimu.bluetooth.base.BluetoothLib.4
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (!"android.bluetooth.device.action.FOUND".equals(action)) {
"android.bluetooth.adapter.action.DISCOVERY_FINISHED".equals(action);
return;
}
BluetoothDevice bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
if (bluetoothDevice == null || intent.getExtras() == null) {
return;
}
short s = intent.getExtras().getShort("android.bluetooth.device.extra.RSSI");
String replace = TextUtils.isEmpty(bluetoothDevice.getName()) ? "" : bluetoothDevice.getName().replace("\n", "").replace("\\n", "");
String str = replace + "\n" + bluetoothDevice.getAddress() + "\n" + ((int) s);
if (BluetoothLib.this.c(str)) {
return;
}
BluetoothLib.this.d.add(str);
BluetoothLib.this.f.b(str);
Proxy.a.add(new Device(bluetoothDevice.getAddress(), replace));
if (!TextUtils.isEmpty(bluetoothDevice.getName()) && bluetoothDevice.getName().toLowerCase().contains("jimu")) {
ScanResult scanResult = new ScanResult(bluetoothDevice, s);
if (BluetoothLib.this.g != null) {
BluetoothLib.this.g.a(scanResult);
}
}
}
};
}
public static synchronized BluetoothLib d() {
BluetoothLib bluetoothLib;
synchronized (BluetoothLib.class) {
if (l == null) {
synchronized (BluetoothLib.class) {
if (l == null) {
l = new BluetoothLib();
}
}
}
bluetoothLib = l;
}
return bluetoothLib;
}
private void e() {
if (this.e.booleanValue()) {
return;
}
this.c.registerReceiver(this.j, new IntentFilter("android.bluetooth.device.action.FOUND"));
this.c.registerReceiver(this.j, new IntentFilter("android.bluetooth.adapter.action.DISCOVERY_FINISHED"));
this.e = true;
}
public void b() {
ALog.a(k).d("startScan");
BluetoothAdapter bluetoothAdapter = this.b;
if (bluetoothAdapter == null) {
return;
}
try {
if (bluetoothAdapter.isDiscovering()) {
this.b.cancelDiscovery();
}
this.d.clear();
this.b.startDiscovery();
} catch (Exception e) {
Log.e(k, "Start scan fail", e);
}
}
public void c() {
BluetoothAdapter bluetoothAdapter = this.b;
if (bluetoothAdapter == null || !bluetoothAdapter.isDiscovering()) {
return;
}
this.b.cancelDiscovery();
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public boolean a(Context context, DeviceListener deviceListener) {
this.c = context;
this.f = deviceListener;
if (m == null) {
m = new BlueToothManager(context, this);
m.c();
}
this.b = BluetoothAdapter.getDefaultAdapter();
if (this.b == null) {
return false;
}
e();
Log.i(k, "BluetoothLib-init");
this.h = new Handler(context.getMainLooper());
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public boolean c(String str) {
for (int i = 0; i < this.d.size(); i++) {
if (this.d.get(i).equals(str)) {
return true;
}
}
return false;
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Callback
public void b(String str, byte b, byte[] bArr, int i) {
this.f.a(str, b, bArr, i);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Callback
public void b(String str) {
this.f.disconnect(str);
}
public Cancellable a(final ScannedHubEmitter scannedHubEmitter, int i) {
BluetoothAdapter bluetoothAdapter = this.b;
if (bluetoothAdapter == null) {
scannedHubEmitter.a(-2, "Device not support bluetooth!");
return null;
}
if (bluetoothAdapter.getState() != 12) {
scannedHubEmitter.a(-3, "Bluetooth is not turn on!");
return null;
}
this.g = scannedHubEmitter;
b();
this.h.postDelayed(new Runnable() { // from class: com.ubtrobot.jimu.bluetooth.base.BluetoothLib.2
@Override // java.lang.Runnable
public void run() {
BluetoothLib.this.c();
scannedHubEmitter.a();
}
}, i);
return this.i;
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str) {
BluetoothAdapter bluetoothAdapter = this.b;
if (bluetoothAdapter == null) {
return;
}
if (bluetoothAdapter.isDiscovering()) {
this.b.cancelDiscovery();
}
BluetoothDevice remoteDevice = this.b.getRemoteDevice(str);
m.b();
m.a(remoteDevice);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a() {
m.b();
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str, byte b, byte[] bArr, int i) {
m.b(str, b, bArr, i);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str, boolean z) {
m.a(str, z);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Callback
public void a(boolean z, String str) {
this.f.onConnectState(z, str);
}
}

View File

@@ -0,0 +1,245 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.util.Log;
import com.ubtrobot.log.ALog;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
/* loaded from: classes2.dex */
public class BluetoothUtil {
private static final UUID i = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private AcceptThread b;
private ConnectThread c;
private String e;
private final BluetoothUtilCallBack g;
private BluetoothDevice h;
private boolean f = false;
private final BluetoothAdapter a = BluetoothAdapter.getDefaultAdapter();
private int d = 0;
private class AcceptThread extends Thread {
private final BluetoothServerSocket a;
private boolean b = true;
public AcceptThread() {
BluetoothServerSocket bluetoothServerSocket;
try {
bluetoothServerSocket = BluetoothUtil.this.a.listenUsingRfcommWithServiceRecord("BluetoothChat", BluetoothUtil.i);
} catch (IOException e) {
Log.e("BluetoothChatService", "listen() failed", e);
bluetoothServerSocket = null;
}
this.a = bluetoothServerSocket;
}
public void cancel() {
ALog.a("BluetoothChatService").d("cancel " + this);
try {
this.b = false;
this.a.close();
} catch (IOException e) {
ALog.a("BluetoothChatService").d("close() of server failed", e);
}
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
ALog.a("BluetoothChatService").d("BEGIN mAcceptThread" + this);
setName("AcceptThread");
while (this.b) {
try {
BluetoothSocket accept = this.a.accept();
if (accept != null) {
BluetoothUtil.this.a(accept, accept.getRemoteDevice());
}
} catch (IOException e) {
Log.e("BluetoothChatService", "accept() failed", e);
}
}
Log.i("BluetoothChatService", "END mAcceptThread");
}
}
class BluetoothThread extends Thread {
BluetoothThread() {
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
if (BluetoothUtil.this.c != null) {
BluetoothUtil.this.c.cancel();
BluetoothUtil.this.c = null;
try {
Thread.sleep(500L);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
BluetoothUtil bluetoothUtil = BluetoothUtil.this;
bluetoothUtil.c = bluetoothUtil.new ConnectThread(bluetoothUtil.h);
BluetoothUtil.this.c.start();
BluetoothUtil.this.a(2);
}
}
public interface BluetoothUtilCallBack {
void a();
void a(String str, int i);
void a(String str, BluetoothSocket bluetoothSocket);
}
private class ConnectThread extends Thread {
private BluetoothSocket a;
private final BluetoothDevice b;
@SuppressLint({"NewApi"})
public ConnectThread(BluetoothDevice bluetoothDevice) {
this.b = bluetoothDevice;
BluetoothSocket bluetoothSocket = null;
try {
if (DeviceDependency.a()) {
try {
try {
bluetoothSocket = (BluetoothSocket) bluetoothDevice.getClass().getMethod("createInsecureRfcommSocket", Integer.TYPE).invoke(bluetoothDevice, 6);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e2) {
e2.printStackTrace();
} catch (InvocationTargetException e3) {
e3.printStackTrace();
}
} catch (IllegalArgumentException e4) {
e4.printStackTrace();
} catch (NoSuchMethodException e5) {
e5.printStackTrace();
}
} else if (DeviceDependency.b()) {
bluetoothSocket = this.b.createRfcommSocketToServiceRecord(BluetoothUtil.i);
} else {
bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(BluetoothUtil.i);
Log.v("BluetoothChatService", "createInsecureRfcommSocketToServiceRecord");
}
} catch (IOException e6) {
Log.e("BluetoothChatService", "create() failed", e6);
}
this.a = bluetoothSocket;
}
public void cancel() {
try {
Log.e("zdy", "socket.close()");
if (this.a != null) {
this.a.close();
}
} catch (IOException e) {
Log.e("BluetoothChatService", "close() of connect socket failed", e);
}
}
@Override // java.lang.Thread, java.lang.Runnable
@SuppressLint({"NewApi"})
public void run() {
Log.i("BluetoothChatService", "BEGIN mConnectThread");
setName("ConnectThread");
if (this.a == null) {
Log.w("BluetoothChatService", "get BluetoothSocket fail! Stop connect!");
return;
}
BluetoothUtil.this.a.cancelDiscovery();
try {
Log.e("zdy", "socket.run()");
this.a.connect();
synchronized (BluetoothUtil.this) {
BluetoothUtil.this.c = null;
}
BluetoothUtil.this.a(this.a, this.b);
} catch (Exception e) {
e.printStackTrace();
Log.e("zdy", "IOException", e);
BluetoothUtil.this.b();
try {
this.a.close();
} catch (IOException e2) {
Log.e("BluetoothChatService", "unable to close() socket during connection failure", e2);
} catch (Exception unused) {
Log.e("BluetoothChatService", "unable close socket during connection failure.");
}
}
}
}
public BluetoothUtil(Context context, BluetoothUtilCallBack bluetoothUtilCallBack) {
this.g = bluetoothUtilCallBack;
}
/* JADX INFO: Access modifiers changed from: private */
public void b() {
a(1);
BluetoothUtilCallBack bluetoothUtilCallBack = this.g;
if (bluetoothUtilCallBack != null) {
bluetoothUtilCallBack.a();
}
}
/* JADX INFO: Access modifiers changed from: private */
public synchronized void a(int i2) {
ALog.a("BluetoothChatService").d("setState() " + this.d + " -> " + i2);
this.d = i2;
if (i2 != 3) {
this.e = null;
}
if (this.g != null) {
this.g.a(this.e, i2);
}
}
public synchronized void a(boolean z) {
ALog.a("BluetoothChatService").d("start");
this.f = z;
if (this.c != null) {
this.c.cancel();
this.c = null;
}
if (this.b != null) {
this.b.cancel();
this.b = null;
}
if (this.f) {
this.b = new AcceptThread();
this.b.start();
}
a(1);
}
public synchronized void a(BluetoothDevice bluetoothDevice) {
this.h = bluetoothDevice;
new BluetoothThread().start();
}
public synchronized void a(BluetoothSocket bluetoothSocket, BluetoothDevice bluetoothDevice) {
ALog.a("BluetoothChatService").d("connected");
if (this.c != null) {
this.c.cancel();
this.c = null;
}
if (this.b != null) {
this.b.cancel();
this.b = null;
}
this.e = bluetoothDevice.getAddress();
a(3);
if (this.g != null) {
this.g.a(bluetoothDevice.getAddress(), bluetoothSocket);
}
}
}

View File

@@ -0,0 +1,25 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.os.Build;
import com.baidu.cloud.media.player.BDCloudMediaPlayer;
import com.ubt.jimu.blockly.feature.audio.AndroidManufacturer;
/* loaded from: classes2.dex */
public class DeviceDependency {
public static boolean a() {
if (Build.VERSION.RELEASE.startsWith("4.0.") && (Build.MANUFACTURER.equals("samsung") || Build.MANUFACTURER.equals("HTC"))) {
return true;
}
if (Build.VERSION.RELEASE.startsWith("4.1.") && Build.MANUFACTURER.equals("samsung")) {
return true;
}
return Build.MANUFACTURER.equals(AndroidManufacturer.XIAO_MI) && Build.VERSION.RELEASE.equals(BDCloudMediaPlayer.SDK_VERSION);
}
public static boolean b() {
if (Build.MANUFACTURER.equals(AndroidManufacturer.XIAO_MI) && Build.MODEL.equals("2013022") && Build.VERSION.RELEASE.equals("4.2.1")) {
return true;
}
return Build.MODEL.equals("Lenovo A820");
}
}

View File

@@ -0,0 +1,111 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.os.SystemClock;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/* loaded from: classes2.dex */
public class DeviceProcessThread extends Thread {
private DeviceProcessThreadCallBack a;
private List<BUFFER_DATA> b;
private boolean c = true;
public interface DeviceProcessThreadCallBack {
void a(byte[] bArr, int i);
}
public DeviceProcessThread(DeviceProcessThreadCallBack deviceProcessThreadCallBack) {
this.a = deviceProcessThreadCallBack;
new ProtocolPacket();
this.b = new CopyOnWriteArrayList();
}
public void a(byte[] bArr, int i) {
synchronized (this) {
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.b.add(buffer_data);
if (this.a != null) {
this.a.a(bArr, i);
}
}
}
public void b(byte[] bArr, int i) {
synchronized (this) {
if (this.a != null) {
this.a.a(bArr, i);
}
}
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
while (this.c) {
synchronized (this) {
BUFFER_DATA buffer_data = null;
Iterator<BUFFER_DATA> it = this.b.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.b.remove(buffer_data);
} else {
try {
Thread.sleep(100L);
} catch (InterruptedException unused) {
this.c = false;
Thread.currentThread().interrupt();
return;
}
}
}
}
}
public void a() {
synchronized (this) {
this.c = false;
this.b.clear();
}
}
public void a(byte b) {
synchronized (this) {
ProtocolPacket protocolPacket = new ProtocolPacket();
BUFFER_DATA buffer_data = null;
Iterator<BUFFER_DATA> it = this.b.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.b.remove(buffer_data);
}
}
}
}

View File

@@ -0,0 +1,12 @@
package com.ubtrobot.jimu.bluetooth.base;
/* loaded from: classes2.dex */
public interface IPacket extends Cloneable {
byte f();
byte[] g();
int getId();
boolean isValid();
}

View File

@@ -0,0 +1,13 @@
package com.ubtrobot.jimu.bluetooth.base;
/* compiled from: ProtocolPacket.java */
/* loaded from: classes2.dex */
enum PROTOCOL_STATE {
HEADER1,
HEADER2,
LENGHT,
CMD,
PARAM,
CHECKSUM,
END
}

View File

@@ -0,0 +1,253 @@
package com.ubtrobot.jimu.bluetooth.base;
import android.util.Log;
import com.ijm.dataencryption.de.DataDecryptTool;
import java.nio.ByteBuffer;
/* loaded from: classes2.dex */
public class ProtocolPacket implements IPacket {
private byte[] a;
private int b;
private byte c;
private byte[] d;
private int e;
private PROTOCOL_STATE f = PROTOCOL_STATE.HEADER1;
private ByteBuffer g = ByteBuffer.allocate(DataDecryptTool.DECRYPT_SP_FILE);
/* renamed from: com.ubtrobot.jimu.bluetooth.base.ProtocolPacket$1, reason: invalid class name */
static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] a = new int[PROTOCOL_STATE.values().length];
static {
try {
a[PROTOCOL_STATE.HEADER1.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[PROTOCOL_STATE.HEADER2.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
a[PROTOCOL_STATE.LENGHT.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
a[PROTOCOL_STATE.CMD.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
a[PROTOCOL_STATE.PARAM.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
try {
a[PROTOCOL_STATE.CHECKSUM.ordinal()] = 6;
} catch (NoSuchFieldError unused6) {
}
try {
a[PROTOCOL_STATE.END.ordinal()] = 7;
} catch (NoSuchFieldError unused7) {
}
}
}
public ProtocolPacket() {
this.g.clear();
}
public byte a(byte[] bArr, int i, int i2) {
byte b = 0;
while (i <= i2) {
b = (byte) (b + bArr[i]);
i++;
}
return b;
}
public void a(String str) {
}
public void b(byte[] bArr) {
this.a = new byte[2];
System.arraycopy(bArr, 0, this.a, 0, 2);
this.b = bArr[2] & 255;
this.c = bArr[3];
int i = this.b;
int i2 = 4;
if (i - 5 > 0) {
this.d = new byte[i - 5];
System.arraycopy(bArr, 4, this.d, 0, i - 5);
int i3 = this.b;
i2 = 4 + (i3 - 5);
this.e = i3 - 5;
}
byte b = bArr[i2];
byte b2 = bArr[i2 + 1];
}
public Object clone() {
try {
return (ProtocolPacket) super.clone();
} catch (CloneNotSupportedException e) {
Log.e("ContentValues", "Clone BleProtocolPacket fail!", e);
return null;
}
}
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
public byte f() {
return this.c;
}
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
public byte[] g() {
return this.d;
}
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
public int getId() {
return this.c;
}
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
public boolean isValid() {
return true;
}
public void a(byte b) {
this.c = b;
}
public void a(byte[] bArr) {
this.d = bArr;
if (bArr == null) {
this.e = 0;
} else {
this.e = bArr.length;
}
}
public ProtocolPacket(int i, byte[] bArr) {
this.g.clear();
a((byte) i);
a(bArr);
}
public int a() {
return this.e;
}
public void a(int i) {
this.e = i;
}
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
public boolean b(byte b) {
try {
int i = 0;
switch (AnonymousClass1.a[this.f.ordinal()]) {
case 1:
if (b != -5) {
Log.v("error_blue", "1");
} else {
this.g.clear();
this.g.put(b);
this.f = PROTOCOL_STATE.HEADER2;
}
return false;
case 2:
if (b != -65) {
this.f = PROTOCOL_STATE.HEADER1;
Log.v("error_blue", "2");
if (b == -5) {
b(b);
}
} else {
this.g.put(b);
this.f = PROTOCOL_STATE.LENGHT;
}
return false;
case 3:
this.b = b & 255;
this.g.put(b);
this.f = PROTOCOL_STATE.CMD;
return false;
case 4:
this.c = b;
this.g.put(b);
this.f = PROTOCOL_STATE.PARAM;
this.e = this.b - 5;
this.d = new byte[this.e];
return false;
case 5:
this.g.put(b);
this.e--;
if (this.e == 0) {
this.f = PROTOCOL_STATE.CHECKSUM;
}
return false;
case 6:
if (a(this.g.array(), 2, this.g.position() - 1) != b) {
this.f = PROTOCOL_STATE.HEADER1;
Log.v("error_blue", "3");
if (b == -5) {
b(b);
}
} else {
this.g.put(b);
this.f = PROTOCOL_STATE.END;
}
return false;
case 7:
if (b != -19) {
this.f = PROTOCOL_STATE.HEADER1;
Log.v("error_blue", "4");
if (b == -5) {
b(b);
}
return false;
}
this.g.put(b);
this.f = PROTOCOL_STATE.HEADER1;
int i2 = 0;
while (i < this.b - 5) {
this.d[i2] = this.g.get(i + 4);
i++;
i2++;
}
return true;
default:
return false;
}
} catch (Exception e) {
e.getMessage();
return true;
}
}
public byte[] b() {
int i;
int i2 = this.e;
int i3 = (short) (i2 == 0 ? 7 : i2 + 6);
byte[] bArr = new byte[i3];
int i4 = 0;
bArr[0] = -5;
bArr[1] = -65;
bArr[2] = (byte) ((i3 - 1) & 255);
bArr[3] = this.c;
if (this.e == 0) {
i = 5;
bArr[4] = 0;
} else {
i = 4;
while (i4 < this.e) {
bArr[i] = this.d[i4];
i4++;
i++;
}
}
int i5 = i + 1;
bArr[i] = a(bArr, 2, i5);
bArr[i5] = -19;
return bArr;
}
}

View File

@@ -0,0 +1,164 @@
package com.ubtrobot.jimu.bluetooth.base.discover;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.Cancellable;
import com.ubtrobot.log.ALog;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes2.dex */
public class BleDeviceScanner {
private BluetoothAdapter b;
private Handler d;
private ScannedHubEmitter e;
private int a = 5000;
private List<BluetoothDevice> c = new ArrayList();
private BluetoothAdapter.LeScanCallback f = new BluetoothAdapter.LeScanCallback() { // from class: com.ubtrobot.jimu.bluetooth.base.discover.BleDeviceScanner.1
@Override // android.bluetooth.BluetoothAdapter.LeScanCallback
public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bArr) {
if (BleDeviceScanner.this.c.contains(bluetoothDevice)) {
return;
}
BleDeviceScanner.this.c.add(bluetoothDevice);
BleDeviceScanner.this.e.a(new ScanResult(bluetoothDevice, i));
}
};
private ScanCallback g = new ScanCallback() { // from class: com.ubtrobot.jimu.bluetooth.base.discover.BleDeviceScanner.2
@Override // android.bluetooth.le.ScanCallback
public void onBatchScanResults(List<android.bluetooth.le.ScanResult> list) {
super.onBatchScanResults(list);
}
@Override // android.bluetooth.le.ScanCallback
public void onScanFailed(int i) {
Log.e("ContentValues", "Scan ble fail! errorCode:" + i);
super.onScanFailed(i);
BleDeviceScanner.this.e.a(i, "Scan ble device fail! Detail define refer to ScanCallback.SCAN_FAILED_*");
}
@Override // android.bluetooth.le.ScanCallback
@TargetApi(21)
public void onScanResult(int i, android.bluetooth.le.ScanResult scanResult) {
BluetoothDevice device = scanResult.getDevice();
if (BleDeviceScanner.this.c.contains(device)) {
return;
}
BleDeviceScanner.this.c.add(device);
BleDeviceScanner.this.e.a(new ScanResult(device, scanResult.getRssi()));
}
};
private class DiscoverCancelable implements Cancellable, Runnable {
private final Handler a;
private final ScannedHubEmitter b;
private boolean c;
private boolean d;
public DiscoverCancelable(Handler handler, ScannedHubEmitter scannedHubEmitter, int i) {
this.a = handler;
this.a.postDelayed(this, i);
this.b = scannedHubEmitter;
}
@Override // com.ubtrobot.jimu.bluetooth.Cancellable
public synchronized boolean cancel() {
if (!this.d && !this.c) {
this.a.removeCallbacks(this);
BleDeviceScanner.this.b();
this.d = true;
return true;
}
return false;
}
@Override // com.ubtrobot.jimu.bluetooth.Cancellable
public synchronized boolean isCancelled() {
return this.d;
}
@Override // java.lang.Runnable
public synchronized void run() {
if (!this.d) {
this.c = true;
BleDeviceScanner.this.b();
this.b.a();
}
}
}
public BleDeviceScanner(Context context) {
this.d = new Handler(context.getMainLooper());
this.b = ((BluetoothManager) context.getSystemService("bluetooth")).getAdapter();
}
/* JADX INFO: Access modifiers changed from: private */
public void b() {
BluetoothAdapter bluetoothAdapter = this.b;
if (bluetoothAdapter == null) {
return;
}
if (Build.VERSION.SDK_INT < 21) {
bluetoothAdapter.stopLeScan(this.f);
return;
}
BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
if (bluetoothLeScanner == null) {
return;
}
bluetoothLeScanner.stopScan(this.g);
ALog.a("ContentValues").d("call BluetoothLeScanner.stopScan by new api after Android LOLLIPOP");
}
public Cancellable a(ScannedHubEmitter scannedHubEmitter, int i) {
BluetoothAdapter bluetoothAdapter = this.b;
if (bluetoothAdapter == null) {
Log.e("ContentValues", "Bluetooth is not support!");
this.e.a(4, "Scan fail as bluetooth is not support");
return null;
}
if (bluetoothAdapter.getState() != 12) {
scannedHubEmitter.a(-3, "Bluetooth is not turn on!");
return null;
}
if (i < 5000) {
Log.e("ContentValues", "Duration must greater than 5000");
this.a = 5000;
} else {
this.a = i;
}
DiscoverCancelable discoverCancelable = new DiscoverCancelable(this.d, scannedHubEmitter, this.a);
this.e = scannedHubEmitter;
try {
a();
} catch (Exception e) {
Log.e("ContentValues", "Start scan fail", e);
}
return discoverCancelable;
}
private void a() {
if (this.b == null) {
return;
}
this.c.clear();
if (Build.VERSION.SDK_INT >= 21) {
BluetoothLeScanner bluetoothLeScanner = this.b.getBluetoothLeScanner();
if (bluetoothLeScanner == null) {
return;
}
bluetoothLeScanner.startScan(this.g);
ALog.a("ContentValues").d("call BluetoothLeScanner.startScan by new api after Android LOLLIPOP");
return;
}
this.b.startLeScan(this.f);
}
}

View File

@@ -0,0 +1,22 @@
package com.ubtrobot.jimu.bluetooth.base.discover;
import android.bluetooth.BluetoothDevice;
/* loaded from: classes2.dex */
public class ScanResult {
private BluetoothDevice a;
private int b;
public ScanResult(BluetoothDevice bluetoothDevice, int i) {
this.a = bluetoothDevice;
this.b = i;
}
public BluetoothDevice a() {
return this.a;
}
public int b() {
return this.b;
}
}

View File

@@ -0,0 +1,10 @@
package com.ubtrobot.jimu.bluetooth.base.discover;
/* loaded from: classes2.dex */
public interface ScannedHubEmitter {
void a();
void a(int i, String str);
void a(ScanResult scanResult);
}