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,42 @@
package com.ubtrobot.jimu;
/* loaded from: classes2.dex */
public class Firmware {
private String a;
private String b;
private String c;
private int d;
private boolean e;
public Firmware(int i, String str, String str2, String str3, int i2, boolean z) {
this.e = false;
this.d = i;
this.a = str;
this.b = str2;
this.c = str3;
this.e = z;
}
public String a() {
return this.c;
}
public void a(int i) {
}
public String b() {
return this.b;
}
public int c() {
return this.d;
}
public String d() {
return this.a;
}
public boolean e() {
return this.e;
}
}

View File

@@ -0,0 +1,8 @@
package com.ubtrobot.jimu.bluetooth;
/* loaded from: classes2.dex */
public interface Cancellable {
boolean cancel();
boolean isCancelled();
}

View File

@@ -0,0 +1,8 @@
package com.ubtrobot.jimu.bluetooth;
/* loaded from: classes2.dex */
public interface ConnectCallback {
void a(int i, String str);
void onSuccess();
}

View File

@@ -0,0 +1,9 @@
package com.ubtrobot.jimu.bluetooth;
/* loaded from: classes2.dex */
public enum ConnectionState {
STATE_CONNECTING,
STATE_CONNECTED,
STATE_DISCONNECTING,
STATE_DISCONNECTED
}

View File

@@ -0,0 +1,6 @@
package com.ubtrobot.jimu.bluetooth;
/* loaded from: classes2.dex */
public interface ConnectionStateListener {
void onConnectionStateChange(String str, ConnectionState connectionState);
}

View File

@@ -0,0 +1,6 @@
package com.ubtrobot.jimu.bluetooth;
/* loaded from: classes2.dex */
public interface DataReceiveListener {
void onDataAvailable(String str, byte b, byte[] bArr);
}

View File

@@ -0,0 +1,257 @@
package com.ubtrobot.jimu.bluetooth;
import android.content.Context;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
import com.ubtrobot.jimu.bluetooth.proxy.BluetoothProxy;
import com.ubtrobot.jimu.bluetooth.proxy.DeviceListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes2.dex */
public class JimuBluetoothManager {
private static final String k = "JimuBluetoothManager";
/* renamed from: a */
private Context context;
/* renamed from: b */
private BluetoothProxy bluetoothProxy;
/* renamed from: c */
private List<ConnectionStateListener> connectionStateListeners;
/* renamed from: d */
private List<DataReceiveListener> dataReceiveListeners;
/* renamed from: e */
private HashMap<String, ConnectCallback> connectionCallbacks;
/* renamed from: f */
private HashMap<String, ConnectionState> connectionStates;
/* renamed from: g */
private boolean supportsBluetooth;
/* renamed from: h */
private String macAddress;
private String i;
/* renamed from: j */
private DeviceListener deviceListener;
private static class Holder {
private static final JimuBluetoothManager a = new JimuBluetoothManager();
}
private JimuBluetoothManager() {
this.connectionStateListeners = new ArrayList();
this.dataReceiveListeners = new ArrayList();
this.connectionCallbacks = new HashMap<>();
this.connectionStates = new HashMap<>();
this.supportsBluetooth = false;
this.macAddress = null;
this.i = null;
this.deviceListener = new DeviceListener() { // from class: com.ubtrobot.jimu.bluetooth.JimuBluetoothManager.1
@Override // com.ubtrobot.jimu.bluetooth.proxy.DeviceListener
/* renamed from: a */
public void onConnectState(boolean isSuccess, String macAddress) {
ConnectionState connectionState;
Log.d(JimuBluetoothManager.k, "onConnectState isSuccess:" + isSuccess + " mac:" + macAddress);
if (macAddress == null) {
Log.e(JimuBluetoothManager.k, "onConnectState isSuccess:" + isSuccess + " mac:" + macAddress);
if (JimuBluetoothManager.this.i == null) {
return;
} else {
macAddress = JimuBluetoothManager.this.i;
}
}
if (isSuccess) {
connectionState = ConnectionState.STATE_CONNECTED;
JimuBluetoothManager.this.macAddress = macAddress;
} else {
connectionState = ConnectionState.STATE_DISCONNECTED;
if (macAddress.equals(JimuBluetoothManager.this.macAddress)) {
JimuBluetoothManager.this.macAddress = null;
}
}
JimuBluetoothManager.this.a(macAddress, connectionState);
ConnectCallback connectCallback = (ConnectCallback) JimuBluetoothManager.this.connectionCallbacks.get(macAddress);
if (connectCallback != null) {
if (isSuccess) {
connectCallback.onSuccess();
} else {
connectCallback.a(-1, "connect fail!");
}
}
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.DeviceListener
public String b(String str) {
return null;
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.DeviceListener
public void a(String str, byte b, byte[] bArr, int i) {
Iterator it = JimuBluetoothManager.this.dataReceiveListeners.iterator();
while (it.hasNext()) {
((DataReceiveListener) it.next()).onDataAvailable(str, b, bArr);
}
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.DeviceListener
/* renamed from: a */
public void disconnect(String macAddress) {
JimuBluetoothManager.this.a(macAddress, ConnectionState.STATE_DISCONNECTED);
if (macAddress.equals(JimuBluetoothManager.this.macAddress)) {
JimuBluetoothManager.this.macAddress = null;
}
}
};
this.bluetoothProxy = BluetoothProxy.c();
}
public static JimuBluetoothManager d() {
return Holder.a;
}
public void b(ConnectionStateListener connectionStateListener) {
synchronized (this.connectionStateListeners) {
this.connectionStateListeners.remove(connectionStateListener);
}
}
/* JADX INFO: Access modifiers changed from: private */
public void a(String macAddress, ConnectionState connectionState) {
synchronized (this.connectionStateListeners) {
Iterator<ConnectionStateListener> it = this.connectionStateListeners.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
ConnectionStateListener next = it.next();
ConnectionState connectionState2 = this.connectionStates.get(macAddress);
if (connectionState2 == null) {
connectionState2 = ConnectionState.STATE_DISCONNECTED;
}
if (connectionState2 == connectionState) {
Log.w(k, "new connection state is same to old state, not notify connectionstate change.");
break;
}
next.onConnectionStateChange(macAddress, connectionState);
}
this.connectionStates.put(macAddress, connectionState);
}
}
/* renamed from: b */
public void removeDataReceiveListener(DataReceiveListener dataReceiveListener) {
this.dataReceiveListeners.remove(dataReceiveListener);
}
/* JADX INFO: Access modifiers changed from: private */
/* renamed from: b */
public boolean isJimu(String str) {
String lowerCase = str.toLowerCase();
if (lowerCase.startsWith("My_Jimu_".toLowerCase())) {
return true;
}
return lowerCase.startsWith("Jimu".toLowerCase()) && !lowerCase.startsWith("Jimuspk".toLowerCase());
}
public String b() {
return this.macAddress;
}
/* renamed from: a */
public boolean supportsBluetooth(Context context) {
this.context = context.getApplicationContext();
this.supportsBluetooth = this.bluetoothProxy.a(this.context, this.deviceListener);
boolean supportsBluetooth = this.supportsBluetooth;
if (supportsBluetooth) {
return supportsBluetooth;
}
Log.e(k, "Device not support bluetooth or not bluetooth related permissions");
return false;
}
/* renamed from: a */
public void connectWithCallback(String macAddress, ConnectCallback connectCallback) {
this.i = macAddress;
this.connectionStates.get(macAddress);
this.connectionCallbacks.put(macAddress, connectCallback);
this.connectionStates.put(macAddress, ConnectionState.STATE_CONNECTING);
this.bluetoothProxy.a(macAddress);
}
/* renamed from: a */
public void disconnect() {
Log.i(k, "Disconnect buletooth.");
this.macAddress = null;
this.bluetoothProxy.a();
this.connectionStates.clear();
}
public void a(ConnectionStateListener connectionStateListener) {
synchronized (this.connectionStateListeners) {
if (!this.connectionStateListeners.contains(connectionStateListener)) {
this.connectionStateListeners.add(connectionStateListener);
}
}
}
/* renamed from: a */
public ConnectionState getConnectionState(String macAddress) {
if (macAddress == null) {
return ConnectionState.STATE_DISCONNECTED;
}
ConnectionState connectionState = this.connectionStates.get(macAddress);
return connectionState == null ? ConnectionState.STATE_DISCONNECTED : connectionState;
}
public synchronized void a(String str, int i, byte[] bArr) {
this.bluetoothProxy.a(str, (byte) i, bArr, bArr.length);
}
public void a(DataReceiveListener dataReceiveListener) {
if (this.dataReceiveListeners.contains(dataReceiveListener)) {
return;
}
this.dataReceiveListeners.add(dataReceiveListener);
}
public Cancellable a(final ScannedHubEmitter scannedHubEmitter, int i) {
if (!this.supportsBluetooth) {
Log.e(k, "Bluetooth is not support!");
scannedHubEmitter.a(4, "Scan fail as bluetooth is not support");
return null;
}
return this.bluetoothProxy.a(new ScannedHubEmitter() { // from class: com.ubtrobot.jimu.bluetooth.JimuBluetoothManager.2
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(ScanResult scanResult) {
String name;
if (scanResult == null || scanResult.a() == null || (name = scanResult.a().getName()) == null || !JimuBluetoothManager.this.isJimu(name)) {
return;
}
scannedHubEmitter.a(scanResult);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(int i2, String str) {
scannedHubEmitter.a(i2, str);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a() {
scannedHubEmitter.a();
}
}, i);
}
public void a(String str, boolean z) {
this.bluetoothProxy.a(str, z);
}
}

View File

@@ -0,0 +1,18 @@
package com.ubtrobot.jimu.bluetooth;
/* loaded from: classes2.dex */
public enum RobotWalkingType {
DOUBLE_FEET("doubleFeet"),
FOUR_FEET("fourFeet"),
WHEEL_MODE("wheelMode");
private String type;
RobotWalkingType(String str) {
this.type = str;
}
public String getType() {
return this.type;
}
}

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);
}

View File

@@ -0,0 +1,13 @@
package com.ubtrobot.jimu.bluetooth.ble;
/* compiled from: BleDeviceProcessThread.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,197 @@
package com.ubtrobot.jimu.bluetooth.ble;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.os.SystemClock;
import android.util.Log;
import com.afunx.ble.blelitelib.log.BleLiteLog;
import com.afunx.ble.blelitelib.proxy.BleGattClientProxy;
import com.afunx.ble.blelitelib.utils.BleUuidUtils;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.bluetooth.ble.BleDeviceProcessThread;
import com.ubtrobot.jimu.bluetooth.utils.ByteHexHelper;
/* loaded from: classes2.dex */
public class BleClientHandler extends Thread implements BleDeviceProcessThread.Callback {
private static final String p = BleClientHandler.class.getSimpleName();
private String a;
private BleGattClientProxy b;
private BluetoothGattService c;
private BluetoothGattCharacteristic d;
private BluetoothGattCharacteristic e;
private int l;
private int m;
private ClientCallback n;
private boolean h = true;
private boolean k = true;
private BleGattClientProxy.OnCharacteristicNotificationListener o = new BleGattClientProxy.OnCharacteristicNotificationListener() { // from class: com.ubtrobot.jimu.bluetooth.ble.BleClientHandler.1
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy.OnCharacteristicNotificationListener
public synchronized void onCharacteristicNotification(byte[] bArr) {
if (bArr != null) {
if (bArr.length != 0) {
try {
Log.i(BleClientHandler.p, "onReceive:msg :" + ByteHexHelper.a(bArr));
for (byte b : bArr) {
if (BleClientHandler.this.f.b(b)) {
if (BleClientHandler.this.n != null) {
BleClientHandler.this.f.a(BleClientHandler.this.f.g().length);
BleClientHandler.this.n.a(BleClientHandler.this.a, BleClientHandler.this.f.f(), BleClientHandler.this.f.g(), BleClientHandler.this.f.a());
}
BleClientHandler.this.l = 0;
BleClientHandler.this.m = 0;
BleClientHandler.this.i = SystemClock.uptimeMillis();
BleClientHandler.this.g.a(BleClientHandler.this.f.f());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
};
private ProtocolPacket f = new ProtocolPacket();
private long i = SystemClock.uptimeMillis();
private long j = this.i;
private BleDeviceProcessThread g = new BleDeviceProcessThread(this);
public interface ClientCallback {
void a(String str);
void a(String str, byte b, byte[] bArr, int i);
}
public BleClientHandler(String str, BleGattClientProxy bleGattClientProxy, ClientCallback clientCallback) {
this.l = 0;
this.m = 0;
this.a = str;
this.b = bleGattClientProxy;
this.n = clientCallback;
this.l = 0;
this.m = 0;
this.g.start();
b();
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
while (this.h) {
try {
if (this.c == null) {
this.c = this.b.discoverService(BleUuidUtils.str2uuid("49535343-fe7d-4ae5-8fa9-9fafd205e455"), 5000L);
}
if (this.d == null) {
this.d = this.b.discoverCharacteristic(this.c, BleUuidUtils.str2uuid("49535343-1e4d-4bd9-ba61-23c647249616"));
}
if (this.e == null) {
this.e = this.b.discoverCharacteristic(this.c, BleUuidUtils.str2uuid("49535343-8841-43f4-a8d4-ecbe34729bb3"));
}
} catch (Exception unused) {
this.h = false;
return;
}
}
}
public void c(byte[] bArr, int i) {
if (SystemClock.uptimeMillis() - this.j < 3000) {
return;
}
if (!this.k) {
this.i = SystemClock.uptimeMillis();
} else {
a(bArr, i);
this.l++;
}
}
public boolean d() {
return (this.h && isAlive() && (!(this.l > 3 || this.m > 6) || !this.k)) ? false : true;
}
public void b(byte[] bArr, int i) {
this.g.a(bArr, i);
}
public String a() {
return this.a;
}
public void b() {
if (this.c == null) {
BleGattClientProxy bleGattClientProxy = this.b;
if (bleGattClientProxy == null) {
return;
} else {
this.c = bleGattClientProxy.discoverService(BleUuidUtils.str2uuid("49535343-fe7d-4ae5-8fa9-9fafd205e455"), 5000L);
}
}
BluetoothGattService bluetoothGattService = this.c;
if (bluetoothGattService == null) {
Log.e(p, "gattWriteService is null");
return;
}
if (this.d == null) {
BleGattClientProxy bleGattClientProxy2 = this.b;
if (bleGattClientProxy2 == null || bluetoothGattService == null) {
return;
} else {
this.d = bleGattClientProxy2.discoverCharacteristic(bluetoothGattService, BleUuidUtils.str2uuid("49535343-1e4d-4bd9-ba61-23c647249616"));
}
}
BleGattClientProxy bleGattClientProxy3 = this.b;
if (bleGattClientProxy3 == null) {
return;
}
BluetoothGattCharacteristic bluetoothGattCharacteristic = this.d;
if (bluetoothGattCharacteristic == null) {
BleLiteLog.e(p, "registerCharacteristicNotification fail! Because gattNotifyCharacteristic is null! ");
} else {
bleGattClientProxy3.registerCharacteristicNotification(bluetoothGattCharacteristic, this.o);
}
}
public void a(boolean z) {
this.k = z;
}
@Override // com.ubtrobot.jimu.bluetooth.ble.BleDeviceProcessThread.Callback
public synchronized void a(byte[] bArr, int i) {
try {
Log.i("Handler-", "onSendData");
if (this.c == null) {
this.c = this.b.discoverService(BleUuidUtils.str2uuid("49535343-fe7d-4ae5-8fa9-9fafd205e455"), 5000L);
}
if (this.e == null) {
this.e = this.b.discoverCharacteristic(this.c, BleUuidUtils.str2uuid("49535343-8841-43f4-a8d4-ecbe34729bb3"));
}
Log.i(p, "onSend:" + ByteHexHelper.a(bArr));
boolean writeCharacterisitcNoResponse2 = this.b.writeCharacterisitcNoResponse2(this.e, bArr);
this.j = SystemClock.uptimeMillis();
this.m = this.m + 1;
Log.i(p, "sendNormalCount: " + this.m + " writeSucc: " + writeCharacterisitcNoResponse2);
} catch (Exception e) {
e.printStackTrace();
c();
}
}
public void c() {
synchronized (this) {
try {
this.l = 0;
this.m = 0;
this.h = false;
if (this.g != null) {
this.g.a();
}
if (this.n != null) {
this.n.a(this.a);
}
this.b.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,115 @@
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<BUFFER_DATA> 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<BUFFER_DATA> 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<BUFFER_DATA> 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);
}
}
}
}

View File

@@ -0,0 +1,199 @@
package com.ubtrobot.jimu.bluetooth.ble;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.Cancellable;
import com.ubtrobot.jimu.bluetooth.base.discover.BleDeviceScanner;
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.jimu.bluetooth.utils.ByteHexHelper;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes2.dex */
public class BleLib extends Callback implements Proxy {
private static BleLib e;
private static BleManager f;
private ArrayList<String> b = new ArrayList<>();
private DeviceListener c;
private BleDeviceScanner d;
private BleLib() {
new ArrayList();
new Handler(Looper.getMainLooper());
new BluetoothAdapter.LeScanCallback() { // from class: com.ubtrobot.jimu.bluetooth.ble.BleLib.2
@Override // android.bluetooth.BluetoothAdapter.LeScanCallback
public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bArr) {
String replace = TextUtils.isEmpty(bluetoothDevice.getName()) ? "" : bluetoothDevice.getName().replace("\n", "").replace("\\n", "");
String str = replace + "\n" + bluetoothDevice.getAddress() + "\n" + i;
Log.i("BleLib", str);
if (BleLib.this.c(str)) {
return;
}
BleLib.this.b.add(str);
BleLib.this.c.b(str);
Proxy.a.add(new Device(bluetoothDevice.getAddress(), replace));
}
};
new ScanCallback() { // from class: com.ubtrobot.jimu.bluetooth.ble.BleLib.4
@Override // android.bluetooth.le.ScanCallback
public void onBatchScanResults(List<ScanResult> list) {
super.onBatchScanResults(list);
}
@Override // android.bluetooth.le.ScanCallback
public void onScanFailed(int i) {
Log.e("BleLib", "Scan ble fail! errorCode:" + i);
super.onScanFailed(i);
}
@Override // android.bluetooth.le.ScanCallback
@TargetApi(21)
public void onScanResult(int i, ScanResult scanResult) {
Log.d("BleLib", "onScanResult " + scanResult.getDevice().getName());
BluetoothDevice device = scanResult.getDevice();
String replace = TextUtils.isEmpty(device.getName()) ? "" : device.getName().replace("\n", "").replace("\\n", "");
String str = replace + "\n" + device.getAddress() + "\n" + scanResult.getRssi();
Log.i("BleLib", str);
if (BleLib.this.c(str)) {
return;
}
BleLib.this.b.add(str);
BleLib.this.c.b(str);
Proxy.a.add(new Device(device.getAddress(), replace));
}
};
}
/* JADX INFO: Access modifiers changed from: private */
public boolean c(String str) {
for (int i = 0; i < this.b.size(); i++) {
if (this.b.get(i).equals(str)) {
return true;
}
}
return false;
}
public static synchronized BleLib b() {
BleLib bleLib;
synchronized (BleLib.class) {
if (e == null) {
synchronized (BleLib.class) {
if (e == null) {
e = new BleLib();
}
}
}
bleLib = e;
}
return bleLib;
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public boolean a(Context context, DeviceListener deviceListener) {
this.c = deviceListener;
if (f == null) {
f = new BleManager(context, this);
f.b();
}
if (this.d == null) {
this.d = new BleDeviceScanner(context);
}
return BluetoothAdapter.getDefaultAdapter() != null;
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Callback
public void b(String str, byte b, byte[] bArr, int i) {
DeviceListener deviceListener = this.c;
if (deviceListener != null) {
deviceListener.a(str, b, bArr, i);
}
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Callback
public void b(String str) {
DeviceListener deviceListener = this.c;
if (deviceListener != null) {
deviceListener.disconnect(str);
}
}
public Cancellable a(final ScannedHubEmitter scannedHubEmitter, int i) {
return this.d.a(new ScannedHubEmitter() { // from class: com.ubtrobot.jimu.bluetooth.ble.BleLib.1
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(com.ubtrobot.jimu.bluetooth.base.discover.ScanResult scanResult) {
if (scanResult.a() == null || scanResult.a().getName() == null || !scanResult.a().getName().toLowerCase().contains("jimu")) {
return;
}
scannedHubEmitter.a(scanResult);
BluetoothDevice a = scanResult.a();
int b = scanResult.b();
String replace = TextUtils.isEmpty(a.getName()) ? "" : a.getName().replace("\n", "").replace("\\n", "");
String str = replace + "\n" + a.getAddress() + "\n" + b;
Log.v("BleLib", str);
if (BleLib.this.c(str)) {
return;
}
BleLib.this.b.add(str);
BleLib.this.c.b(str);
Proxy.a.add(new Device(a.getAddress(), replace));
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(int i2, String str) {
scannedHubEmitter.a(i2, str);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a() {
scannedHubEmitter.a();
}
}, i);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str) {
if (TextUtils.isEmpty(str)) {
return;
}
Log.i("BleLib", "connect: mac: " + str);
f.d(str);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a() {
f.a();
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str, boolean z) {
f.a(str, z);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public synchronized void a(String str, byte b, byte[] bArr, int i) {
Log.i("BleLib", "sendData:" + ByteHexHelper.a(bArr) + " cmd:" + ((int) b));
f.b(str, b, bArr, i);
Log.i("BleLib", "after-sendData");
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Callback
public void a(boolean z, String str) {
DeviceListener deviceListener = this.c;
if (deviceListener != null) {
deviceListener.onConnectState(z, str);
}
}
}

View File

@@ -0,0 +1,174 @@
package com.ubtrobot.jimu.bluetooth.ble;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import com.afunx.ble.blelitelib.proxy.BleGattClientProxy;
import com.afunx.ble.blelitelib.proxy.BleGattClientProxyImpl;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.bluetooth.ble.BleClientHandler;
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 BleManager extends Thread implements BleClientHandler.ClientCallback {
private static final String f = BleManager.class.getSimpleName();
private boolean a = true;
private BleGattClientProxy b;
private Callback c;
private List<BleClientHandler> d;
private Handler e;
public BleManager(Context context, Callback callback) {
new ArrayList();
new ArrayList();
this.d = new ArrayList();
this.e = new Handler(Looper.getMainLooper());
this.b = new BleGattClientProxyImpl(context.getApplicationContext());
this.c = callback;
}
public synchronized void d(final String str) {
if (TextUtils.isEmpty(str)) {
return;
}
Log.i(f, "connect: mac: " + str);
new Thread(new Runnable() { // from class: com.ubtrobot.jimu.bluetooth.ble.BleManager.1
@Override // java.lang.Runnable
public void run() {
final boolean connect = BleManager.this.b.connect(str, 30000L);
BleManager.this.b(str);
BleManager.this.e.post(new Runnable() { // from class: com.ubtrobot.jimu.bluetooth.ble.BleManager.1.1
@Override // java.lang.Runnable
public void run() {
BleManager.this.c.a(connect, str);
}
});
}
}).start();
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
BleClientHandler bleClientHandler;
while (this.a) {
synchronized (this) {
Iterator<BleClientHandler> it = this.d.iterator();
while (true) {
if (!it.hasNext()) {
bleClientHandler = null;
break;
}
bleClientHandler = it.next();
if (bleClientHandler.d()) {
Log.i(f, "tryToReleaseConnection");
break;
}
ProtocolPacket protocolPacket = new ProtocolPacket();
protocolPacket.a((byte) 3);
protocolPacket.a((byte[]) null);
protocolPacket.a(0);
byte[] b = protocolPacket.b();
bleClientHandler.c(b, b.length);
}
if (bleClientHandler != null) {
String a = bleClientHandler.a();
bleClientHandler.c();
this.d.remove(bleClientHandler);
if (this.c != null) {
this.c.b(a);
}
} else {
try {
Thread.sleep(300L);
} catch (InterruptedException unused) {
this.a = false;
Thread.currentThread().interrupt();
return;
}
}
}
}
}
public synchronized void a() {
if (this.d != null) {
Iterator<BleClientHandler> it = this.d.iterator();
while (it.hasNext()) {
it.next().c();
}
this.d.clear();
}
}
public void b() {
this.a = true;
start();
}
public synchronized BleClientHandler c(String str) {
BleClientHandler bleClientHandler;
bleClientHandler = null;
Iterator<BleClientHandler> it = this.d.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
BleClientHandler next = it.next();
if (next.a().equals(str)) {
bleClientHandler = next;
break;
}
}
return bleClientHandler;
}
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();
BleClientHandler c = c(str);
if (c != null) {
c.b(b2, b2.length);
}
}
public void a(String str, boolean z) {
BleClientHandler c = c(str);
if (c != null) {
c.a(z);
}
}
@Override // com.ubtrobot.jimu.bluetooth.ble.BleClientHandler.ClientCallback
public synchronized void a(String str, byte b, byte[] bArr, int i) {
if (this.c != null) {
this.c.b(str, b, bArr, i);
}
}
@Override // com.ubtrobot.jimu.bluetooth.ble.BleClientHandler.ClientCallback
public synchronized void a(String str) {
if (this.c != null) {
this.c.b(str);
}
}
public synchronized void b(String str) {
if (c(str) != null) {
return;
}
if (this.b == null) {
return;
}
BleClientHandler bleClientHandler = new BleClientHandler(str, this.b, this);
this.d.add(bleClientHandler);
bleClientHandler.start();
}
}

View File

@@ -0,0 +1,162 @@
package com.ubtrobot.jimu.bluetooth.proxy;
import android.content.Context;
import android.util.Log;
import com.ubtech.jimu.storage.UbtPrefs;
import com.ubtrobot.jimu.bluetooth.Cancellable;
import com.ubtrobot.jimu.bluetooth.base.BluetoothLib;
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
import com.ubtrobot.jimu.bluetooth.ble.BleLib;
import com.ubtrobot.log.ALog;
import java.util.ArrayList;
import java.util.Iterator;
/* loaded from: classes2.dex */
public class BluetoothProxy implements Proxy {
private static final String i = "BluetoothProxy";
private static BluetoothProxy j;
private Context c;
private DeviceListener d;
private UbtPrefs e;
private Cancellable g;
private Cancellable h;
private Proxy b = BleLib.b();
private ArrayList<String> f = new ArrayList<>();
private BluetoothProxy() {
this.f.add("lemobile");
this.f.add("meizu");
this.f.add("vivo");
this.f.add("oneplus");
this.f.add("oppo");
this.f.add("lenove");
}
public static synchronized BluetoothProxy c() {
BluetoothProxy bluetoothProxy;
synchronized (BluetoothProxy.class) {
if (j == null) {
j = new BluetoothProxy();
}
bluetoothProxy = j;
}
return bluetoothProxy;
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public boolean a(Context context, DeviceListener deviceListener) {
this.c = context;
this.d = deviceListener;
this.e = new UbtPrefs(context);
Log.i(i, "init ble");
BluetoothLib.d().a(context, deviceListener);
return BleLib.b().a(context, deviceListener);
}
public Cancellable a(final ScannedHubEmitter scannedHubEmitter, final int i2) {
if (this.e.a("sp_key_is_last_connect_ble", (Boolean) true).booleanValue()) {
this.g = BleLib.b().a(new ScannedHubEmitter(this) { // from class: com.ubtrobot.jimu.bluetooth.proxy.BluetoothProxy.1
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(ScanResult scanResult) {
scannedHubEmitter.a(scanResult);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(int i3, String str) {
scannedHubEmitter.a(i3, str);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a() {
ALog.a(BluetoothProxy.i).d("Ble scan end, start classical bluetooth scan");
BluetoothLib.d().a(scannedHubEmitter, i2 / 2);
}
}, i2 / 2);
} else {
this.h = BluetoothLib.d().a(new ScannedHubEmitter(this) { // from class: com.ubtrobot.jimu.bluetooth.proxy.BluetoothProxy.2
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(ScanResult scanResult) {
scannedHubEmitter.a(scanResult);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(int i3, String str) {
scannedHubEmitter.a(i3, str);
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a() {
ALog.a(BluetoothProxy.i).d("Classical Bluetooth scan end, start ble scan");
BleLib.b().a(scannedHubEmitter, i2 / 2);
}
}, i2 / 2);
}
return new Cancellable() { // from class: com.ubtrobot.jimu.bluetooth.proxy.BluetoothProxy.3
@Override // com.ubtrobot.jimu.bluetooth.Cancellable
public boolean cancel() {
if (BluetoothProxy.this.g != null) {
BluetoothProxy.this.g.cancel();
}
if (BluetoothProxy.this.h == null) {
return true;
}
BluetoothProxy.this.h.cancel();
return true;
}
@Override // com.ubtrobot.jimu.bluetooth.Cancellable
public boolean isCancelled() {
return false;
}
};
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str) {
boolean z;
Iterator<Device> it = Proxy.a.iterator();
while (true) {
if (!it.hasNext()) {
z = false;
break;
}
Device next = it.next();
String mac = next.getMac();
String name = next.getName();
if (mac.equals(str) && name.startsWith("My_")) {
z = true;
break;
}
}
if (!z) {
Log.i(i, "reinit-classify bluetooth");
this.e.a("sp_key_is_last_connect_ble", (Object) false);
this.b = null;
this.b = BluetoothLib.d();
this.b.a(this.c, this.d);
this.b.a(str);
return;
}
Log.i(i, "reinit-ble");
this.e.a("sp_key_is_last_connect_ble", (Object) true);
this.b = BleLib.b();
this.b.a(this.c, this.d);
this.b.a(str);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a() {
this.b.a();
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str, boolean z) {
this.b.a(str, z);
}
@Override // com.ubtrobot.jimu.bluetooth.proxy.Proxy
public void a(String str, byte b, byte[] bArr, int i2) {
this.b.a(str, b, bArr, i2);
}
}

View File

@@ -0,0 +1,10 @@
package com.ubtrobot.jimu.bluetooth.proxy;
/* loaded from: classes2.dex */
public abstract class Callback {
public abstract void a(boolean z, String str);
public abstract void b(String str);
public abstract void b(String str, byte b, byte[] bArr, int i);
}

View File

@@ -0,0 +1,30 @@
package com.ubtrobot.jimu.bluetooth.proxy;
import java.io.Serializable;
/* loaded from: classes2.dex */
public class Device implements Serializable {
private String mac;
private String name;
public Device(String str, String str2) {
this.mac = str;
this.name = str2;
}
public String getMac() {
return this.mac;
}
public String getName() {
return this.name;
}
public void setMac(String str) {
this.mac = str;
}
public void setName(String str) {
this.name = str;
}
}

View File

@@ -0,0 +1,14 @@
package com.ubtrobot.jimu.bluetooth.proxy;
/* loaded from: classes2.dex */
public interface DeviceListener {
/* renamed from: a */
void disconnect(String str);
void a(String str, byte b, byte[] bArr, int i);
/* renamed from: a */
void onConnectState(boolean z, String str);
String b(String str);
}

View File

@@ -0,0 +1,20 @@
package com.ubtrobot.jimu.bluetooth.proxy;
import android.content.Context;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes2.dex */
public interface Proxy {
public static final List<Device> a = new ArrayList();
void a();
void a(String str);
void a(String str, byte b, byte[] bArr, int i);
void a(String str, boolean z);
boolean a(Context context, DeviceListener deviceListener);
}

View File

@@ -0,0 +1,20 @@
package com.ubtrobot.jimu.bluetooth.utils;
/* loaded from: classes2.dex */
public class ByteHexHelper {
public static String a(byte[] bArr) {
StringBuilder sb = new StringBuilder("");
if (bArr == null || bArr.length <= 0) {
return "";
}
for (byte b : bArr) {
String hexString = Integer.toHexString(b & 255);
if (hexString.length() < 2) {
sb.append(0);
}
sb.append(hexString);
sb.append(" ");
}
return sb.toString();
}
}

View File

@@ -0,0 +1,121 @@
package com.ubtrobot.jimu.bluetooth.view;
import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.ConnectionState;
import com.ubtrobot.jimu.bluetooth.ConnectionStateListener;
import com.ubtrobot.jimu.bluetooth.JimuBluetoothManager;
import com.ubtrobot.jimu.bluetooth.base.BluetoothLib;
import com.ubtrobot.log.ALog;
import java.util.Timer;
import java.util.TimerTask;
/* loaded from: classes2.dex */
public class BluetoothActivity extends Activity {
private static final String e = BluetoothActivity.class.getSimpleName();
private Timer a = new Timer();
private String b = null;
private ConnectionStateListener c = new ConnectionStateListener() { // from class: com.ubtrobot.jimu.bluetooth.view.BluetoothActivity.2
@Override // com.ubtrobot.jimu.bluetooth.ConnectionStateListener
public void onConnectionStateChange(String str, ConnectionState connectionState) {
ALog.a(BluetoothActivity.e).d(str + "Bluetooth state changed, new ConnectionState:" + connectionState);
if (str == null) {
return;
}
if (connectionState == ConnectionState.STATE_CONNECTED || connectionState == ConnectionState.STATE_DISCONNECTED) {
BluetoothActivity.this.finish();
}
}
};
private final BroadcastReceiver d = new BroadcastReceiver() { // from class: com.ubtrobot.jimu.bluetooth.view.BluetoothActivity.3
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
char c;
String action = intent.getAction();
ALog.a(BluetoothActivity.e).d("Receive bluetooth broadcast action: " + action);
int hashCode = action.hashCode();
if (hashCode != -223687943) {
if (hashCode == 2116862345 && action.equals("android.bluetooth.device.action.BOND_STATE_CHANGED")) {
c = 0;
}
c = 65535;
} else {
if (action.equals("android.bluetooth.device.action.PAIRING_REQUEST")) {
c = 1;
}
c = 65535;
}
if (c != 0) {
return;
}
BluetoothDevice bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
Log.w(BluetoothActivity.e, "蓝牙设备的状态" + bluetoothDevice.getBondState());
switch (bluetoothDevice.getBondState()) {
case 10:
Log.w(BluetoothActivity.e, "取消配对");
BluetoothActivity.this.finish();
break;
case 11:
Log.w(BluetoothActivity.e, "正在配对......");
break;
case 12:
Log.w(BluetoothActivity.e, "完成配对");
BluetoothActivity.this.finish();
break;
}
}
};
@Override // android.app.Activity
public void onCreate(Bundle bundle) {
ALog.a(e).d("===== onCreate ======= ");
super.onCreate(bundle);
String stringExtra = getIntent().getStringExtra("MacAddr");
if (stringExtra != null) {
ALog.a(e).d("Bluetooth connect " + stringExtra);
BluetoothLib.d().a(stringExtra);
this.b = stringExtra;
JimuBluetoothManager.d().a(this.c);
this.a.schedule(new TimerTask() { // from class: com.ubtrobot.jimu.bluetooth.view.BluetoothActivity.1
@Override // java.util.TimerTask, java.lang.Runnable
public void run() {
Log.i(BluetoothActivity.e, "Timeout and finish BluetoothActivity!");
BluetoothActivity.this.finish();
}
}, 15000L);
} else {
finish();
}
IntentFilter intentFilter = new IntentFilter("android.bluetooth.device.action.PAIRING_REQUEST");
intentFilter.addAction("android.bluetooth.device.action.BOND_STATE_CHANGED");
intentFilter.addAction("android.bluetooth.device.action.ACL_CONNECTED");
intentFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED");
intentFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECTED");
intentFilter.addAction("android.bluetooth.adapter.action.STATE_CHANGED");
intentFilter.addAction("android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED");
registerReceiver(this.d, intentFilter);
}
@Override // android.app.Activity
public void onDestroy() {
ALog.a(e).d("======= onDestroy ========");
if (this.b != null) {
JimuBluetoothManager.d().b(this.c);
}
unregisterReceiver(this.d);
this.a.cancel();
super.onDestroy();
}
@Override // android.app.Activity
public void onResume() {
ALog.a(e).d("===== onResume ======= ");
super.onResume();
}
}

View File

@@ -0,0 +1,8 @@
package com.ubtrobot.jimu.connection;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
/* loaded from: classes2.dex */
public interface PacketsReceiveListener {
void a(String str, IPacket iPacket);
}

View File

@@ -0,0 +1,24 @@
package com.ubtrobot.jimu.connection;
/* loaded from: classes2.dex */
public class RequestException extends Exception {
public static final int ERR_CODE_BT_NOT_CONNECTED = -1;
public static final int ERR_CODE_CMD_INVALID = -4;
public static final int ERR_CODE_TIMEOUT = -3;
public static final String ERR_MSG_CMD_TIMEOUT = "Send command timeout";
public static final String ERR_MSG_NOT_CONNECT = "Bluetooth not connected";
private final int mCode;
public RequestException(int i, String str) {
this(i, str, null);
}
public int getCode() {
return this.mCode;
}
public RequestException(int i, String str, Throwable th) {
super(str, th);
this.mCode = i;
}
}

View File

@@ -0,0 +1,10 @@
package com.ubtrobot.jimu.connection;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
/* loaded from: classes2.dex */
public interface ResponseCallback {
void a(IPacket iPacket, IPacket iPacket2);
void a(IPacket iPacket, RequestException requestException);
}

View File

@@ -0,0 +1,8 @@
package com.ubtrobot.jimu.connection;
/* loaded from: classes2.dex */
public interface ResultCallback {
void a(int i, String str);
void onSuccess();
}

View File

@@ -0,0 +1,392 @@
package com.ubtrobot.jimu.connection;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.ubtrobot.jimu.bluetooth.ConnectCallback;
import com.ubtrobot.jimu.bluetooth.ConnectionState;
import com.ubtrobot.jimu.bluetooth.ConnectionStateListener;
import com.ubtrobot.jimu.bluetooth.DataReceiveListener;
import com.ubtrobot.jimu.bluetooth.JimuBluetoothManager;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.log.ALog;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/* loaded from: classes2.dex */
public class RobotConnection {
private static final String p = "RobotConnection";
private Context a;
private JimuBluetoothManager b;
private Handler d;
private String g;
private IPacket h;
protected Handler l;
private final ArrayDeque<IPacket> e = new ArrayDeque<>();
private ExecutorService f = Executors.newSingleThreadExecutor();
private Object i = new Object();
private DataReceiveListener j = new DataReceiveListener() { // from class: com.ubtrobot.jimu.connection.RobotConnection.1
@Override // com.ubtrobot.jimu.bluetooth.DataReceiveListener
public void onDataAvailable(String str, byte b, byte[] bArr) {
ProtocolPacket protocolPacket = new ProtocolPacket();
protocolPacket.a(b);
protocolPacket.a(bArr);
protocolPacket.a(str);
if (protocolPacket.isValid()) {
RobotConnection.this.a(str, protocolPacket);
} else {
Log.e(RobotConnection.p, "Receive an invalid length byte array.");
}
}
};
protected final HashMap<Integer, WrapperResponseCallback> k = new HashMap<>();
private volatile boolean m = false;
private Runnable n = new Runnable() { // from class: com.ubtrobot.jimu.connection.RobotConnection.4
@Override // java.lang.Runnable
public void run() {
RobotConnection.this.e();
}
};
private List<PacketsReceiveListener> o = new ArrayList();
private HandlerThread c = new HandlerThread("BtSendDataThread");
public class WrapperResponseCallback implements ResponseCallback {
private final IPacket a;
private final ResponseCallback b;
private final Runnable c;
private int d = 1;
private volatile boolean e;
WrapperResponseCallback(ResponseCallback responseCallback, IPacket iPacket, Handler handler) {
this.b = responseCallback;
this.a = iPacket;
RobotConnection.this.d = handler;
this.c = new Runnable(RobotConnection.this) { // from class: com.ubtrobot.jimu.connection.RobotConnection.WrapperResponseCallback.1
@Override // java.lang.Runnable
public void run() {
ALog.a(RobotConnection.p).d("response timeout! packet:" + WrapperResponseCallback.this.a.getId());
WrapperResponseCallback.this.e = true;
RobotConnection.this.m = false;
RobotConnection.this.f.execute(RobotConnection.this.n);
WrapperResponseCallback wrapperResponseCallback = WrapperResponseCallback.this;
wrapperResponseCallback.a(wrapperResponseCallback.a, new RequestException(-3, "Timeout."));
}
};
}
static /* synthetic */ int e(WrapperResponseCallback wrapperResponseCallback) {
int i = wrapperResponseCallback.d;
wrapperResponseCallback.d = i - 1;
return i;
}
public void a(int i) {
if (i < 1) {
i = 1;
}
this.d = i;
}
void a() {
byte f = this.a.f();
RobotConnection.this.d.postDelayed(this.c, f != 8 ? (f == 26 || f == 35 || f == 128) ? 3000L : 2000L : 6000L);
}
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket, final IPacket iPacket2) {
RobotConnection.this.d.post(new Runnable() { // from class: com.ubtrobot.jimu.connection.RobotConnection.WrapperResponseCallback.2
@Override // java.lang.Runnable
public void run() {
synchronized (RobotConnection.this.k) {
WrapperResponseCallback.e(WrapperResponseCallback.this);
if (WrapperResponseCallback.this.d <= 0) {
RobotConnection.this.k.remove(Integer.valueOf(WrapperResponseCallback.this.a.getId()));
}
}
WrapperResponseCallback.this.b.a(WrapperResponseCallback.this.a, iPacket2);
RobotConnection.this.d.removeCallbacks(WrapperResponseCallback.this.c);
}
});
}
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket, final RequestException requestException) {
RobotConnection.this.d.post(new Runnable() { // from class: com.ubtrobot.jimu.connection.RobotConnection.WrapperResponseCallback.3
@Override // java.lang.Runnable
public void run() {
synchronized (RobotConnection.this.k) {
WrapperResponseCallback.this.d = 0;
RobotConnection.this.k.remove(Integer.valueOf(WrapperResponseCallback.this.a.getId()));
}
WrapperResponseCallback.this.b.a(WrapperResponseCallback.this.a, requestException);
RobotConnection.this.d.removeCallbacks(WrapperResponseCallback.this.c);
}
});
}
}
public RobotConnection(Context context) {
this.c.start();
this.d = new Handler(this.c.getLooper());
this.a = context.getApplicationContext();
this.l = new Handler(context.getMainLooper());
this.b = JimuBluetoothManager.d();
if (!this.b.supportsBluetooth(this.a)) {
Log.e(p, "Initialize Bluetooth fail!");
} else if (((BluetoothManager) this.a.getSystemService("bluetooth")).getAdapter() == null) {
Toast.makeText(this.a, "请检测设备是否支持蓝牙", 0).show();
} else {
this.b.a(this.j);
}
}
/* JADX INFO: Access modifiers changed from: private */
public void e() {
IPacket poll;
if (ConnectionState.STATE_CONNECTED != a(this.g)) {
Log.w(p, "Robot not connect");
return;
}
if (this.m) {
ALog.a(p).d("is Sending, send nothing and return");
return;
}
synchronized (this.e) {
poll = this.e.poll();
}
if (poll == null) {
return;
}
synchronized (this.i) {
this.h = poll;
}
synchronized (this.k) {
WrapperResponseCallback wrapperResponseCallback = this.k.get(Integer.valueOf(poll.getId()));
if (wrapperResponseCallback == null) {
Log.e(p, "No responseCallback");
return;
}
wrapperResponseCallback.a();
this.m = true;
this.b.a(b(), poll.f(), poll.g());
}
}
private void d() {
if (Looper.myLooper() == Looper.getMainLooper()) {
throw new SyncCallOnMainThreadException();
}
}
public String b() {
return this.g;
}
public void b(ConnectionStateListener connectionStateListener) {
this.b.b(connectionStateListener);
}
private void b(IPacket iPacket, ResponseCallback responseCallback, int i) {
if (iPacket != null && iPacket.isValid()) {
if (ConnectionState.STATE_CONNECTED != a(this.g)) {
responseCallback.a(iPacket, new RequestException(-1, "ERR_CODE_BT_NOT_CONNECTED"));
return;
}
WrapperResponseCallback wrapperResponseCallback = new WrapperResponseCallback(responseCallback, iPacket, this.l);
wrapperResponseCallback.a(i);
synchronized (this.k) {
this.k.put(Integer.valueOf(iPacket.getId()), wrapperResponseCallback);
}
b(iPacket);
return;
}
responseCallback.a(iPacket, new RequestException(-4, "ERR_CODE_CMD_INVALID"));
}
public void a(String str, ConnectCallback connectCallback) {
this.g = str;
this.b.connectWithCallback(str, connectCallback);
}
public void a() {
this.b.disconnect();
}
public synchronized ConnectionState a(String str) {
return this.b.getConnectionState(str);
}
public void a(ConnectionStateListener connectionStateListener) {
this.b.a(connectionStateListener);
}
public void a(IPacket iPacket, final ResponseCallback responseCallback, int i) {
d();
final boolean[] zArr = new boolean[1];
final boolean[] zArr2 = new boolean[1];
final ProtocolPacket[] protocolPacketArr = new ProtocolPacket[1];
final RequestException[] requestExceptionArr = new RequestException[1];
b(iPacket, new ResponseCallback(this) { // from class: com.ubtrobot.jimu.connection.RobotConnection.2
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket2, IPacket iPacket3) {
synchronized (zArr) {
zArr2[0] = true;
protocolPacketArr[0] = iPacket3;
responseCallback.a(iPacket2, iPacket3);
zArr[0] = true;
ALog.a(RobotConnection.p).d("responded notify");
zArr.notifyAll();
}
}
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket2, RequestException requestException) {
synchronized (zArr) {
requestExceptionArr[0] = requestException;
zArr[0] = true;
ALog.a(RobotConnection.p).d("responded notify");
zArr.notifyAll();
}
}
}, i);
synchronized (zArr) {
while (!zArr[0]) {
try {
ALog.a(p).d("responded wait");
zArr.wait();
break;
} catch (InterruptedException e) {
ALog.a(p).c("Interrupted by someone when sync doRequest. req=" + iPacket + "Ignore it.", e);
Thread.currentThread().interrupt();
}
}
if (requestExceptionArr[0] != null) {
responseCallback.a(iPacket, requestExceptionArr[0]);
}
}
}
private void b(IPacket iPacket) {
synchronized (this.e) {
this.e.add(iPacket);
}
this.f.execute(this.n);
}
public void b(PacketsReceiveListener packetsReceiveListener) {
this.o.remove(packetsReceiveListener);
}
public IPacket a(IPacket iPacket) throws RequestException {
ProtocolPacket protocolPacket;
d();
final boolean[] zArr = new boolean[1];
final boolean[] zArr2 = new boolean[1];
final ProtocolPacket[] protocolPacketArr = new ProtocolPacket[1];
final RequestException[] requestExceptionArr = new RequestException[1];
a(iPacket, new ResponseCallback(this) { // from class: com.ubtrobot.jimu.connection.RobotConnection.3
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket2, IPacket iPacket3) {
synchronized (zArr) {
zArr2[0] = true;
protocolPacketArr[0] = iPacket3;
zArr[0] = true;
ALog.a(RobotConnection.p).d("responded notify");
zArr.notifyAll();
}
}
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket2, RequestException requestException) {
synchronized (zArr) {
requestExceptionArr[0] = requestException;
zArr[0] = true;
ALog.a(RobotConnection.p).d("responded notify");
zArr.notifyAll();
}
}
});
synchronized (zArr) {
while (!zArr[0]) {
try {
ALog.a(p).d("responded wait");
zArr.wait();
break;
} catch (InterruptedException e) {
ALog.a(p).c("Interrupted by someone when sync doRequest. req=" + iPacket + "Ignore it.", e);
Thread.currentThread().interrupt();
}
}
if (requestExceptionArr[0] == null) {
protocolPacket = protocolPacketArr[0];
} else {
throw requestExceptionArr[0];
}
}
return protocolPacket;
}
private void a(IPacket iPacket, ResponseCallback responseCallback) {
b(iPacket, responseCallback, 1);
}
/* JADX INFO: Access modifiers changed from: private */
public void a(String str, ProtocolPacket protocolPacket) {
if (protocolPacket.isValid()) {
if (protocolPacket.f() == 3) {
return;
}
if (protocolPacket.getId() == this.h.getId()) {
this.m = false;
this.f.execute(this.n);
synchronized (this.i) {
if (protocolPacket.getId() != this.h.getId()) {
Log.w(p, "Error response! cmd:" + protocolPacket + " res:" + protocolPacket);
} else {
ProtocolPacket protocolPacket2 = (ProtocolPacket) protocolPacket.clone();
synchronized (this.k) {
WrapperResponseCallback wrapperResponseCallback = this.k.get(Integer.valueOf(protocolPacket.getId()));
if (wrapperResponseCallback == null) {
Log.e(p, "No responseCallback");
} else {
wrapperResponseCallback.a(this.h, protocolPacket2);
}
}
}
}
}
Iterator<PacketsReceiveListener> it = this.o.iterator();
while (it.hasNext()) {
it.next().a(str, protocolPacket);
}
return;
}
Log.i(p, "Receive an packet of not response. packet:" + protocolPacket);
}
public void a(PacketsReceiveListener packetsReceiveListener) {
if (this.o.contains(packetsReceiveListener)) {
return;
}
this.o.add(packetsReceiveListener);
}
public void a(boolean z) {
String str = this.g;
if (str == null) {
Log.e(p, "enableHeartbeat fail, connected device is null");
} else {
this.b.a(str, z);
}
}
}

View File

@@ -0,0 +1,8 @@
package com.ubtrobot.jimu.connection;
/* loaded from: classes2.dex */
public class SyncCallOnMainThreadException extends RuntimeException {
public SyncCallOnMainThreadException() {
super("Sync call on main thread is forbidden.");
}
}

View File

@@ -0,0 +1,31 @@
package com.ubtrobot.jimu.exception;
import android.content.Context;
import com.ubtrobot.jimu.robotapi.R$string;
/* loaded from: classes2.dex */
public class BatteryException extends RobotActiveException {
public static final int CODE_VOLTAGE_HIGH = 1;
public static final int CODE_VOLTAGE_LOW = 0;
private int power;
public BatteryException(int i, int i2, String str) {
super(i, str);
this.power = i2;
}
public String getErrorMessage(Context context) {
int i = this.power;
if (i == 0) {
return context.getResources().getString(R$string.batter_low);
}
if (i == 1) {
return context.getResources().getString(R$string.batter_high);
}
return null;
}
public int getPowerCode() {
return this.power;
}
}

View File

@@ -0,0 +1,121 @@
package com.ubtrobot.jimu.exception;
import android.content.Context;
import com.ubtrobot.jimu.robotapi.R$string;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public class EngineProtectException extends RobotActiveException {
public static final int CODE_ELECTRICITY = 2;
public static final int CODE_FUSE_ENCRYPT = 64;
public static final int CODE_LOCK = 1;
public static final int CODE_OTHERS = 32;
public static final int CODE_OVER_VOLTAGE = 8;
public static final int CODE_TEMPERATURE = 4;
public static final int CODE_UNDER_VOLTAGE = 16;
private int engineType;
private Map<Integer, List<Integer>> errorMap;
public EngineProtectException(int i, String str, int i2, Map<Integer, List<Integer>> map) {
super(i, str);
this.engineType = i2;
this.errorMap = map;
}
private String getIdString(List<Integer> list) {
if (list == null || list.size() <= 0) {
return "";
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
if (i < list.size() - 1) {
sb.append(",");
}
}
return sb.toString();
}
public boolean canUnlock() {
return (getHigherExceptionCode() & 1) > 0;
}
public int getEngineType() {
return this.engineType;
}
public Map<Integer, List<Integer>> getErrorMap() {
return this.errorMap;
}
public List<Integer> getErrorMapByCode(int i) {
Map<Integer, List<Integer>> map = this.errorMap;
if (map == null || map.size() <= 0) {
return null;
}
return this.errorMap.get(Integer.valueOf(i));
}
public String getErrorMessage(Context context, int i, List<Integer> list) {
if (list == null || list.size() <= 0) {
return null;
}
String idString = getIdString(list);
int i2 = this.engineType;
if (i2 != 128) {
if (i2 != 10) {
return null;
}
if (i == 1) {
return String.format(context.getResources().getString(R$string.engine_protect_motor_lock), idString);
}
if (i != 32) {
return null;
}
return String.format(context.getResources().getString(R$string.engine_protect_motor_other), idString);
}
if (i == 1) {
return String.format(context.getResources().getString(R$string.engine_protect_lock), idString);
}
if (i != 2) {
if (i == 4) {
return String.format(context.getResources().getString(R$string.engine_protect_temp), idString);
}
if (i != 8 && i != 16) {
if (i == 32) {
return String.format(context.getResources().getString(R$string.engine_protect_other), idString);
}
if (i != 64) {
return null;
}
return String.format(context.getResources().getString(R$string.engine_protect_encrypt), idString);
}
}
return String.format(context.getResources().getString(R$string.engine_protect_electricity), idString);
}
public int getHigherExceptionCode() {
Map<Integer, List<Integer>> map = this.errorMap;
if (map == null || map.size() <= 0) {
return 0;
}
ArrayList arrayList = new ArrayList(this.errorMap.entrySet());
Collections.sort(arrayList, new Comparator() { // from class: com.ubtrobot.jimu.exception.a
@Override // java.util.Comparator
public final int compare(Object obj, Object obj2) {
int compareTo;
compareTo = ((Integer) ((Map.Entry) obj).getKey()).compareTo((Integer) ((Map.Entry) obj2).getKey());
return compareTo;
}
});
return ((Integer) ((Map.Entry) arrayList.get(0)).getKey()).intValue();
}
public boolean needHandUp() {
return getHigherExceptionCode() == 32 || getHigherExceptionCode() == 64;
}
}

View File

@@ -0,0 +1,21 @@
package com.ubtrobot.jimu.exception;
/* loaded from: classes2.dex */
public class EngineVersionException extends RobotActiveException {
private int mEngineType;
private int mInconformityId;
public EngineVersionException(int i, String str, int i2, int i3) {
super(i, str);
this.mInconformityId = i3;
this.mEngineType = i2;
}
public int getEngineType() {
return this.mEngineType;
}
public int getInconformityIds() {
return this.mInconformityId;
}
}

View File

@@ -0,0 +1,15 @@
package com.ubtrobot.jimu.exception;
/* loaded from: classes2.dex */
public class RobotActiveException extends Exception {
private int errorCode;
public RobotActiveException(int i, String str) {
super(str);
this.errorCode = i;
}
public int getErrorCode() {
return this.errorCode;
}
}

View File

@@ -0,0 +1,38 @@
package com.ubtrobot.jimu.robotapi;
/* loaded from: classes2.dex */
public class BatteryInfo {
private float a;
private float b;
private boolean c;
private boolean d;
public BatteryInfo(float f, float f2, boolean z, boolean z2) {
this.c = false;
this.d = false;
this.a = f;
this.b = f2 <= 100.0f ? f2 : 100.0f;
this.d = z;
this.c = z2;
}
public float a() {
return this.b;
}
public float b() {
return this.a;
}
public boolean c() {
return this.c;
}
public boolean d() {
return this.d;
}
public String toString() {
return "Battery voltage:" + this.a + " percentage:" + this.b + "% isPluginCharger:" + this.d + " isChargingCompleted:" + this.c;
}
}

View File

@@ -0,0 +1,20 @@
package com.ubtrobot.jimu.robotapi;
/* loaded from: classes2.dex */
public class BluetoothSpeakerInfo {
private String a;
private String b;
public BluetoothSpeakerInfo(String str, String str2) {
this.a = str;
this.b = str2;
}
public String a() {
return this.b;
}
public String toString() {
return "name:" + this.b + " mac:" + this.a;
}
}

View File

@@ -0,0 +1,276 @@
package com.ubtrobot.jimu.robotapi;
import com.afunx.ble.blelitelib.utils.HexUtils;
import com.ubtech.utils.XLog;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public class BoardInfo {
private String a;
private float c;
private String f;
private byte[] i;
private int b = 0;
private List<Integer> d = new ArrayList();
private List<Integer> e = new ArrayList();
private List<Integer> g = new ArrayList();
private HashMap<Integer, SensorBoardInfo> h = new HashMap<>();
public class SensorBoardInfo {
private List<Integer> a;
private List<Integer> b;
private String c;
private List<Integer> d;
public SensorBoardInfo(BoardInfo boardInfo) {
}
public List<Integer> d() {
return this.d;
}
public List<Integer> b() {
return this.a;
}
public String c() {
return this.c;
}
public List<Integer> a() {
return this.b;
}
}
private boolean a(int i, int i2) {
return ((i >> i2) & 1) > 0;
}
public List<Integer> a() {
return this.e;
}
public float b() {
return this.c;
}
public int c() {
return this.b;
}
public String d() {
return this.a;
}
public int e() {
return (this.a.startsWith("Jimu_p") || this.a.startsWith("JIMU") || !this.a.startsWith("Jimu_b")) ? 112 : 113;
}
public byte[] f() {
return this.i;
}
public Map<Integer, Integer> g() {
List<Integer> b;
HashMap<Integer, SensorBoardInfo> hashMap = this.h;
if (hashMap == null || hashMap.size() <= 0) {
return null;
}
HashMap hashMap2 = new HashMap(this.h.size());
Iterator<Integer> it = this.h.keySet().iterator();
while (it.hasNext()) {
int intValue = it.next().intValue();
SensorBoardInfo sensorBoardInfo = this.h.get(Integer.valueOf(intValue));
if (sensorBoardInfo != null && (b = sensorBoardInfo.b()) != null && b.size() > 0) {
hashMap2.put(Integer.valueOf(intValue), Integer.valueOf(b.size()));
}
}
return hashMap2;
}
public HashMap<Integer, SensorBoardInfo> h() {
return this.h;
}
public List<Integer> i() {
return this.d;
}
public String j() {
return this.f;
}
public List<Integer> k() {
return this.g;
}
public boolean l() {
if (a().size() != 0) {
return true;
}
Iterator<Map.Entry<Integer, SensorBoardInfo>> it = h().entrySet().iterator();
while (it.hasNext()) {
if (it.next().getValue().a().size() != 0) {
return true;
}
}
return false;
}
private List<Integer> b(byte[] bArr) {
ArrayList arrayList = new ArrayList();
int i = (bArr[3] & 255) | ((bArr[0] & 255) << 24) | ((bArr[1] & 255) << 16) | ((bArr[2] & 255) << 8);
for (int i2 = 0; i2 < 32; i2++) {
if (a(i, i2)) {
arrayList.add(Integer.valueOf(i2 + 1));
}
}
return arrayList;
}
public int a(byte[] bArr) {
int i;
this.i = bArr;
int length = bArr.length;
if (length == 1) {
int i2 = bArr[0] & 255;
if (i2 == 1) {
XLog.d("BoardInfo", "Read board info fail!", new Object[0]);
} else if (i2 == 238) {
XLog.d("BoardInfo", "Read board info fail for board is initing", new Object[0]);
}
return -1;
}
if (length < 10) {
XLog.b("BoardInfo", "Invalid param");
return -1;
}
byte[] bArr2 = new byte[10];
System.arraycopy(bArr, 0, bArr2, 0, bArr2.length);
try {
this.a = new String(bArr2, "UTF-8");
} catch (UnsupportedEncodingException unused) {
XLog.b("BoardInfo", "Unsupported encoding board version name");
}
int i3 = length - 10;
if (i3 < 1) {
XLog.b("BoardInfo", "Board info(0x08 cmd response) not any battery info");
return 0;
}
if (a(bArr[10], 7)) {
this.b = 1;
} else {
this.b = 0;
}
this.c = (r6 & Byte.MAX_VALUE) / 10.0f;
int i4 = i3 - 1;
if (i4 < 16) {
XLog.b("BoardInfo", "Board info(0x08 cmd response) not any servo info");
return 0;
}
byte[] bArr3 = new byte[4];
System.arraycopy(bArr, 11, bArr3, 0, bArr3.length);
int length2 = 11 + bArr3.length;
this.d = b(bArr3);
System.arraycopy(bArr, length2, bArr3, 0, bArr3.length);
int length3 = length2 + bArr3.length;
this.e = b(bArr3);
this.f = HexUtils.bytes2HexString(bArr, length3, 4);
int i5 = length3 + 4;
System.arraycopy(bArr, i5, bArr3, 0, bArr3.length);
int length4 = i5 + bArr3.length;
this.g = b(bArr3);
int i6 = i4 - 16;
if (i6 < 1) {
XLog.b("BoardInfo", "Board info(0x08 cmd response) not any Flash size info");
return 0;
}
int i7 = length4 + 1;
byte b = bArr[length4];
int i8 = (i6 - 1) / 7;
for (int i9 = 1; i9 <= i8; i9++) {
int a = a(i9);
SensorBoardInfo sensorBoardInfo = new SensorBoardInfo(this);
sensorBoardInfo.c = "";
int i10 = i7 + 1;
sensorBoardInfo.a = a(bArr[i7]);
int i11 = i10 + 1;
sensorBoardInfo.b = a(bArr[i10]);
if (a == 10) {
sensorBoardInfo.c = HexUtils.bytes2HexString(bArr, i11, 4);
i = i11 + 4;
} else {
int i12 = i11;
int i13 = 0;
while (i13 < 4) {
int i14 = i12 + 1;
String valueOf = String.valueOf((int) bArr[i12]);
if (valueOf.length() == 1) {
valueOf = "0" + valueOf;
}
sensorBoardInfo.c += valueOf;
i13++;
i12 = i14;
}
i = i12;
}
sensorBoardInfo.d = a(bArr[i]);
i7 = i + 1;
this.h.put(Integer.valueOf(a), sensorBoardInfo);
}
return 0;
}
private List<Integer> a(byte b) {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < 8; i++) {
if (a(b, i)) {
arrayList.add(Integer.valueOf(i + 1));
}
}
return arrayList;
}
private int a(int i) {
switch (i) {
case 1:
return 1;
case 2:
return 3;
case 3:
return 2;
case 4:
return 4;
case 5:
return 5;
case 6:
return 6;
case 7:
return 7;
case 8:
return 8;
case 9:
return 12;
case 10:
return 97;
case 11:
return 96;
case 12:
return 11;
case 13:
return 9;
case 14:
return 10;
case 15:
return 14;
default:
XLog.b("BoardInfo", "INVALID SENSOR INDEX");
return -1;
}
}
}

View File

@@ -0,0 +1,160 @@
package com.ubtrobot.jimu.robotapi;
import android.util.Log;
import com.afunx.ble.blelitelib.utils.HexUtils;
import com.ubtech.utils.XLog;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.RobotConnection;
import java.io.UnsupportedEncodingException;
/* loaded from: classes2.dex */
public class DeviceManager {
private RobotConnection a;
public DeviceManager(RobotConnection robotConnection) {
this.a = robotConnection;
}
public void a(boolean z) throws JimuException {
try {
byte[] g = this.a.a(new ProtocolPacket(5, z ? new byte[]{0} : new byte[]{1})).g();
if (g[0] == 0) {
return;
}
throw new JimuException(-21, "read robot battery info fail! ErrCode:" + ((int) g[0]));
} catch (RequestException e) {
throw new JimuException(e.getCode(), e.getMessage());
}
}
public String b() throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(44, new byte[]{0});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g[0] != 0) {
XLog.b("DeviceManager", "read McuId fail!");
throw new JimuException(-21, "read McuId fail!");
}
byte[] bArr = new byte[g.length - 1];
System.arraycopy(g, 1, bArr, 0, bArr.length);
String bytes2HexString = HexUtils.bytes2HexString(bArr);
Log.d("DeviceManager", "McuId:" + bytes2HexString);
return bytes2HexString;
} catch (RequestException e) {
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public String c() throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(54, new byte[]{0});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length <= 1) {
return "";
}
if (g.length == 1 && g[0] != 0) {
XLog.b("DeviceManager", "read device type(cmd:0x36) fail! errResult:" + ((int) g[0]));
throw new JimuException(-21, "read device type(cmd:0x36) fail! errResult:" + ((int) g[0]));
}
byte[] bArr = new byte[g.length - 1];
System.arraycopy(g, 1, bArr, 0, bArr.length);
try {
String str = new String(bArr, "UTF-8");
XLog.a("DeviceManager", "productName:" + str);
return str;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return String.valueOf(bArr);
}
} catch (RequestException e2) {
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e2);
throw new JimuException(e2.getCode(), e2.getMessage());
}
}
public BatteryInfo d() throws JimuException {
boolean z = true;
ProtocolPacket protocolPacket = new ProtocolPacket(39, new byte[]{0});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length != 1) {
boolean z2 = g[0] != 0;
if (g[1] != 1) {
z = false;
}
return new BatteryInfo(g[2], g[3], z2, z);
}
throw new JimuException(-21, "read robot battery info fail! ErrCode:" + ((int) g[0]));
} catch (RequestException e) {
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public BoardInfo e() throws JimuException {
String str;
try {
byte[] g = this.a.a(new ProtocolPacket(8, new byte[]{0})).g();
if (g.length != 1) {
BoardInfo boardInfo = new BoardInfo();
boardInfo.a(g);
return boardInfo;
}
int i = g[0] & 255;
if (i == 1) {
str = "Read board info fail!";
XLog.d("DeviceManager", "Read board info fail!", new Object[0]);
} else if (i != 238) {
str = "Read board info fail for invalid error code!";
XLog.d("DeviceManager", "Read board info fail for invalid error code!", new Object[0]);
} else {
str = "Read board info fail for board is initing!";
XLog.d("DeviceManager", "Read board info fail for board is initing!", new Object[0]);
}
throw new JimuException(g[0] & 255, str);
} catch (RequestException e) {
Log.e("DeviceManager", "Read board info fail", e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public String f() throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(43, new byte[]{7});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g[0] != 0) {
XLog.b("DeviceManager", "read SN fail!");
throw new JimuException(-21, "excuse cmd fail!");
}
byte[] bArr = new byte[g.length - 1];
System.arraycopy(g, 1, bArr, 0, bArr.length);
String str = new String(bArr);
Log.d("DeviceManager", "SN:" + str);
return str;
} catch (RequestException e) {
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public int g() throws RequestException {
try {
IPacket a = this.a.a(new ProtocolPacket(1, new byte[]{0}));
if (a.g().length == 1) {
return a.g()[0] == 0 ? 0 : -1;
}
return -1;
} catch (RequestException e) {
throw e;
}
}
public boolean a() throws JimuException {
String c = c();
Log.d("DeviceManager", "Product type:" + c);
return "".equals(c) || c.startsWith("JIMU") || c.startsWith("Jimu") || c.startsWith("S1JIMU");
}
}

View File

@@ -0,0 +1,129 @@
package com.ubtrobot.jimu.robotapi;
import android.content.Context;
import android.text.TextUtils;
import com.ubtech.utils.XLog;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
import com.ubtrobot.jimu.exception.BatteryException;
import com.ubtrobot.jimu.exception.EngineProtectException;
import com.ubtrobot.jimu.exception.EngineVersionException;
import com.ubtrobot.jimu.exception.RobotActiveException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public class GlobalExceptionUtil {
public interface ExceptionCallback {
void a(String str, RobotActiveException robotActiveException, List<Integer> list);
}
private boolean a(int i, int i2) {
return ((i >> i2) & 1) > 0;
}
public RobotActiveException a(IPacket iPacket, String str) {
byte[] g = iPacket.g();
int i = g[0] & 255;
XLog.a("woo", "errorCode: %d", Integer.valueOf(i));
if (i == 0) {
return null;
}
if (i == 1) {
return new BatteryException(i, g[1] & 255, "Battery Error");
}
if (i == 2) {
Map<Integer, List<Integer>> a = a(g);
if (a == null || a.size() <= 0) {
return null;
}
return new EngineProtectException(i, "Servo is protected", PeripheralType.SERVO, a);
}
if (i == 3) {
return new EngineVersionException(i, "The Servo version is inconformity", PeripheralType.SERVO, g[1] & 255);
}
if (i != 4) {
return i != 5 ? new RobotActiveException(i, "Unknown Exception") : new EngineVersionException(i, "The Motor version is inconformity", 10, g[1] & 255);
}
Map<Integer, List<Integer>> a2 = a(g);
if (a2 == null || a2.size() <= 0) {
return null;
}
return new EngineProtectException(i, "Motor is protected", 10, a2);
}
private Map<Integer, List<Integer>> a(byte[] bArr) {
HashMap hashMap = new HashMap();
List<Integer> a = a(a(bArr, 1));
if (a != null && a.size() > 0) {
hashMap.put(1, a);
}
List<Integer> a2 = a(a(bArr, 5));
if (a2 != null && a2.size() > 0) {
hashMap.put(2, a2);
}
List<Integer> a3 = a(a(bArr, 9));
if (a3 != null && a3.size() > 0) {
hashMap.put(4, a3);
}
List<Integer> a4 = a(a(bArr, 13));
if (a4 != null && a4.size() > 0) {
hashMap.put(8, a4);
}
List<Integer> a5 = a(a(bArr, 17));
if (a5 != null && a5.size() > 0) {
hashMap.put(16, a5);
}
List<Integer> a6 = a(a(bArr, 21));
if (a6 != null && a6.size() > 0) {
hashMap.put(32, a6);
}
List<Integer> a7 = a(a(bArr, 25));
if (a7 != null && a7.size() > 0) {
hashMap.put(64, a7);
}
return hashMap;
}
private List<Integer> a(int i) {
ArrayList arrayList = null;
for (int i2 = 0; i2 < 32; i2++) {
if (a(i, i2)) {
if (arrayList == null) {
arrayList = new ArrayList();
}
arrayList.add(Integer.valueOf(i2 + 1));
}
}
return arrayList;
}
private int a(byte[] bArr, int i) {
return bArr[i + 3] | (bArr[i] << 24) | (bArr[i + 1] << 16) | (bArr[i + 2] << 8);
}
public static void a(Context context, RobotActiveException robotActiveException, ExceptionCallback exceptionCallback) {
int errorCode = robotActiveException.getErrorCode();
if ((errorCode == 2 || errorCode == 4) && (robotActiveException instanceof EngineProtectException)) {
EngineProtectException engineProtectException = (EngineProtectException) robotActiveException;
int higherExceptionCode = engineProtectException.getHigherExceptionCode();
List<Integer> errorMapByCode = engineProtectException.getErrorMapByCode(higherExceptionCode);
String errorMessage = engineProtectException.getErrorMessage(context, higherExceptionCode, errorMapByCode);
if (TextUtils.isEmpty(errorMessage) || exceptionCallback == null) {
return;
}
exceptionCallback.a(errorMessage, engineProtectException, errorMapByCode);
return;
}
if (errorCode == 1 && (robotActiveException instanceof BatteryException)) {
BatteryException batteryException = (BatteryException) robotActiveException;
String errorMessage2 = batteryException.getErrorMessage(context);
if (TextUtils.isEmpty(errorMessage2) || exceptionCallback == null) {
return;
}
exceptionCallback.a(errorMessage2, batteryException, null);
}
}
}

View File

@@ -0,0 +1,183 @@
package com.ubtrobot.jimu.robotapi;
import com.ubtrobot.jimu.bluetooth.ConnectionState;
import com.ubtrobot.jimu.bluetooth.ConnectionStateListener;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
import com.ubtrobot.jimu.connection.PacketsReceiveListener;
import com.ubtrobot.jimu.connection.RobotConnection;
import com.ubtrobot.jimu.exception.RobotActiveException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
/* loaded from: classes2.dex */
public class GlobalManager implements PacketsReceiveListener, ConnectionStateListener {
private Timer a;
private RobotConnection b;
private DeviceManager c;
private Vector<IPowerStateListener> d;
private Vector<IGlobalExceptionListener> e;
private BatteryInfo f;
private volatile boolean g;
public GlobalManager(RobotConnection robotConnection, DeviceManager deviceManager) {
this.b = robotConnection;
this.c = deviceManager;
this.b.a((PacketsReceiveListener) this);
this.b.a((ConnectionStateListener) this);
}
public void c() {
Timer timer = this.a;
if (timer != null) {
try {
timer.cancel();
this.a = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override // com.ubtrobot.jimu.bluetooth.ConnectionStateListener
public void onConnectionStateChange(String str, ConnectionState connectionState) {
Vector<IPowerStateListener> vector;
Object[] array;
if (connectionState == null || (vector = this.d) == null || vector.size() == 0) {
return;
}
synchronized (this) {
array = this.d.toArray();
}
for (int length = array.length - 1; length >= 0; length--) {
((IPowerStateListener) array[length]).onConnectionStateChange(str, connectionState);
}
}
@Override // com.ubtrobot.jimu.connection.PacketsReceiveListener
public void a(String str, IPacket iPacket) {
if (iPacket == null) {
return;
}
int f = iPacket.f() & 255;
if (f == 5) {
b(str, iPacket);
} else {
if (f != 39) {
return;
}
a(iPacket);
}
}
public void b() {
Timer timer = this.a;
if (timer != null) {
try {
timer.cancel();
} catch (Exception e) {
e.printStackTrace();
}
}
this.a = new Timer();
this.a.schedule(new TimerTask() { // from class: com.ubtrobot.jimu.robotapi.GlobalManager.1
@Override // java.util.TimerTask, java.lang.Runnable
public void run() {
try {
if (GlobalManager.this.g) {
return;
}
GlobalManager.this.c.d();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}, 5000L, 30000L);
}
public void a(boolean z) {
this.g = z;
}
public synchronized BatteryInfo a(IPowerStateListener iPowerStateListener) {
if (this.d == null) {
this.d = new Vector<>();
}
if (!this.d.contains(iPowerStateListener)) {
this.d.add(iPowerStateListener);
}
return this.f;
}
public void b(IPowerStateListener iPowerStateListener) {
Vector<IPowerStateListener> vector = this.d;
if (vector != null) {
vector.removeElement(iPowerStateListener);
}
}
public void b(IGlobalExceptionListener iGlobalExceptionListener) {
Vector<IGlobalExceptionListener> vector = this.e;
if (vector != null) {
vector.removeElement(iGlobalExceptionListener);
}
}
private void b(String str, IPacket iPacket) {
Vector<IGlobalExceptionListener> vector;
RobotActiveException a;
Object[] array;
if (iPacket == null || (vector = this.e) == null || vector.size() == 0 || (a = new GlobalExceptionUtil().a(iPacket, str)) == null) {
return;
}
synchronized (this) {
array = this.e.toArray();
}
if (array == null || array.length == 0) {
return;
}
for (int length = array.length - 1; length >= 0; length--) {
((IGlobalExceptionListener) array[length]).onGlobalException(a);
}
}
public synchronized void a(IGlobalExceptionListener iGlobalExceptionListener) {
if (this.e == null) {
this.e = new Vector<>();
}
if (!this.e.contains(iGlobalExceptionListener)) {
this.e.add(iGlobalExceptionListener);
}
}
public BatteryInfo a() {
return this.f;
}
private void a(IPacket iPacket) {
Object[] array;
if (iPacket == null) {
return;
}
byte[] g = iPacket.g();
if (g.length == 1) {
return;
}
BatteryInfo batteryInfo = new BatteryInfo(g[2], g[3], g[0] != 0, g[1] == 1);
BatteryInfo batteryInfo2 = this.f;
if (batteryInfo2 != null && batteryInfo2.c() == batteryInfo.c() && this.f.d() == batteryInfo.d() && this.f.a() == batteryInfo.a() && this.f.b() == batteryInfo.b()) {
return;
}
this.f = batteryInfo;
Vector<IPowerStateListener> vector = this.d;
if (vector == null || vector.size() == 0) {
return;
}
synchronized (this) {
array = this.d.toArray();
}
for (int length = array.length - 1; length >= 0; length--) {
((IPowerStateListener) array[length]).onPowerStateChanged(batteryInfo);
}
}
}

View File

@@ -0,0 +1,8 @@
package com.ubtrobot.jimu.robotapi;
import com.ubtrobot.jimu.exception.RobotActiveException;
/* loaded from: classes2.dex */
public interface IGlobalExceptionListener {
void onGlobalException(RobotActiveException robotActiveException);
}

View File

@@ -0,0 +1,10 @@
package com.ubtrobot.jimu.robotapi;
import com.ubtrobot.jimu.bluetooth.ConnectionState;
/* loaded from: classes2.dex */
public interface IPowerStateListener {
void onConnectionStateChange(String str, ConnectionState connectionState);
void onPowerStateChanged(BatteryInfo batteryInfo);
}

View File

@@ -0,0 +1,19 @@
package com.ubtrobot.jimu.robotapi;
import com.ubtrobot.jimu.connection.RequestException;
/* loaded from: classes2.dex */
public class JimuException extends RequestException {
public static final int ERR_CODE_ARGUMENT_INVALID = -20;
public static final int ERR_CODE_RESULT_FAIL = -21;
public static final int ERR_CODE_RES_INVALID = -22;
public static final String ERR_MSG_ARGUMENT_INVALID = "Argument is illegal!";
public JimuException(int i, String str) {
this(i, str, null);
}
public JimuException(int i, String str, Throwable th) {
super(i, str, th);
}
}

View File

@@ -0,0 +1,191 @@
package com.ubtrobot.jimu.robotapi;
import android.content.Context;
import com.ubtrobot.jimu.Firmware;
import com.ubtrobot.jimu.bluetooth.ConnectCallback;
import com.ubtrobot.jimu.bluetooth.ConnectionState;
import com.ubtrobot.jimu.bluetooth.ConnectionStateListener;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.RobotConnection;
import com.ubtrobot.jimu.robotapi.UpdateManager;
import java.util.List;
/* loaded from: classes2.dex */
public class JimuManager {
private ServoManager a;
private MotorManager b;
private DeviceManager c;
private SensorManager d;
private UpdateManager e;
private GlobalManager f;
private RobotConnection g;
private String h;
public JimuManager(Context context) {
this.g = new RobotConnection(context);
this.a = new ServoManager(this.g);
this.b = new MotorManager(this.g);
new LedManager(this.g);
this.c = new DeviceManager(this.g);
this.d = new SensorManager(this.g);
this.e = new UpdateManager(context, this.g);
this.f = new GlobalManager(this.g, this.c);
}
public void a(String str, ConnectCallback connectCallback) {
this.g.a(str, connectCallback);
}
public void b(ConnectionStateListener connectionStateListener) {
this.g.b(connectionStateListener);
}
public void c() {
this.g.a();
}
public String d() {
return this.g.b();
}
public String e() {
return this.h;
}
public BatteryInfo f() {
return this.f.a();
}
public boolean g() {
String d = d();
return d != null && a(d) == ConnectionState.STATE_CONNECTED;
}
public boolean h() throws JimuException {
return this.c.a();
}
public void i() throws JimuException {
this.a.b();
}
public String j() throws JimuException {
return this.c.b();
}
public BatteryInfo k() throws JimuException {
return this.c.d();
}
public BoardInfo l() throws JimuException {
return this.c.e();
}
public String m() throws JimuException {
return this.c.f();
}
public int n() throws RequestException {
return this.c.g();
}
public void o() {
this.f.b();
}
public void p() {
this.f.c();
}
public void q() throws JimuException {
this.b.a();
}
public void r() throws JimuException {
this.a.a();
}
public ConnectionState a(String str) {
return this.g.a(str);
}
public ConnectionState b(String str) {
return (!g() || str == null) ? ConnectionState.STATE_DISCONNECTED : !str.equals(e()) ? ConnectionState.STATE_DISCONNECTED : ConnectionState.STATE_CONNECTED;
}
public void c(String str) {
this.h = str;
}
public void a(ConnectionStateListener connectionStateListener) {
this.g.a(connectionStateListener);
}
public boolean a(BoardInfo boardInfo, List<Firmware> list, UpdateManager.UpdateProgressListener updateProgressListener) {
return this.e.a(boardInfo, list, updateProgressListener);
}
public void a() {
this.e.a();
}
public void a(boolean z) throws JimuException {
this.c.a(z);
}
public BatteryInfo a(IPowerStateListener iPowerStateListener) {
return this.f.a(iPowerStateListener);
}
public void a(IGlobalExceptionListener iGlobalExceptionListener) {
this.f.a(iGlobalExceptionListener);
}
public int b() throws JimuException {
return this.e.b();
}
public void a(int[] iArr, float[] fArr, int i, int i2) throws MotorException {
this.a.a(iArr, fArr, i, i2);
}
public void b(IPowerStateListener iPowerStateListener) {
this.f.b(iPowerStateListener);
}
public void a(int[] iArr, int i) throws MotorException {
this.a.a(iArr, i);
}
public void b(IGlobalExceptionListener iGlobalExceptionListener) {
this.f.b(iGlobalExceptionListener);
}
public List<ServoAngleReadInfo> a(int i, boolean z) throws JimuException {
return this.a.a(i, z);
}
public void b(boolean z) {
this.f.a(z);
}
public void a(int[] iArr, int[] iArr2, int[] iArr3) throws MotorException {
this.b.a(iArr, iArr2, iArr3);
}
public ServoAngleReadInfo b(int i, boolean z) throws JimuException {
return this.a.b(i, z);
}
public int a(int i, int i2) throws JimuException {
return this.b.a(i, i2);
}
public int a(int i, List<Integer> list, boolean z) throws JimuException {
return this.d.a(i, list, z);
}
public BluetoothSpeakerInfo a(int i) throws JimuException {
return this.d.a(i);
}
}

View File

@@ -0,0 +1,17 @@
package com.ubtrobot.jimu.robotapi;
import android.content.Context;
import com.ubtrobot.jimu.bluetooth.Cancellable;
import com.ubtrobot.jimu.bluetooth.JimuBluetoothManager;
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
/* loaded from: classes2.dex */
public class JimuScanner {
public JimuScanner(Context context) {
JimuBluetoothManager.d().supportsBluetooth(context);
}
public Cancellable a(ScannedHubEmitter scannedHubEmitter, int i) {
return JimuBluetoothManager.d().a(scannedHubEmitter, i);
}
}

View File

@@ -0,0 +1,9 @@
package com.ubtrobot.jimu.robotapi;
import com.ubtrobot.jimu.connection.RobotConnection;
/* loaded from: classes2.dex */
public class LedManager {
public LedManager(RobotConnection robotConnection) {
}
}

View File

@@ -0,0 +1,34 @@
package com.ubtrobot.jimu.robotapi;
import java.util.ArrayList;
/* loaded from: classes2.dex */
public class MotorException extends JimuException {
private ArrayList<Integer> failIds;
private int subErrorId;
public MotorException(int i, String str) {
super(i, str);
}
public ArrayList<Integer> getFailIds() {
return this.failIds;
}
public int getSubErrorId() {
return this.subErrorId;
}
public void setFailIds(ArrayList<Integer> arrayList) {
this.failIds = arrayList;
}
public void setSubErrorId(int i) {
this.subErrorId = i;
}
public MotorException(int i, String str, ArrayList<Integer> arrayList) {
super(i, str);
this.failIds = arrayList;
}
}

View File

@@ -0,0 +1,151 @@
package com.ubtrobot.jimu.robotapi;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.RobotConnection;
import java.util.ArrayList;
import java.util.Arrays;
/* loaded from: classes2.dex */
public class MotorManager {
protected RobotConnection a;
public MotorManager(RobotConnection robotConnection) {
this.a = robotConnection;
}
private static byte[] b(int[] iArr, int[] iArr2, int[] iArr3) {
if (iArr.length != iArr2.length || iArr2.length != iArr3.length) {
Log.e("MotorManager", "Invalid arguments!");
return null;
}
int length = iArr.length;
byte[] a = a(iArr);
byte[] bArr = new byte[a.length + (length * 4)];
System.arraycopy(a, 0, bArr, 0, a.length);
int length2 = a.length + 0;
for (int i = 1; i <= length; i++) {
int i2 = length - i;
int i3 = iArr2[i2];
int i4 = length2 + 1;
bArr[length2] = (byte) ((i3 >> 8) & 255);
int i5 = i4 + 1;
bArr[i4] = (byte) (i3 & 255);
int i6 = iArr3[i2];
int i7 = i5 + 1;
bArr[i5] = (byte) ((i6 >> 8) & 255);
length2 = i7 + 1;
bArr[i7] = (byte) (i6 & 255);
}
return bArr;
}
public void a(int[] iArr, int[] iArr2, int[] iArr3) throws MotorException {
int[] iArr4 = new int[iArr3.length];
for (int i = 0; i < iArr3.length; i++) {
iArr4[i] = iArr3[i] / 100;
}
try {
byte[] g = this.a.a(new ProtocolPacket(144, b(iArr, iArr2, iArr4))).g();
if (g[0] == 0) {
return;
}
throw new MotorException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]), a(Arrays.copyOfRange(g, 1, g.length)));
} catch (RequestException e) {
throw new MotorException(e.getCode(), e.getMessage());
}
}
public int a(int i, int i2) throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(116, new byte[]{10, (byte) i, (byte) i2});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length == 3) {
return g[2] & 255;
}
throw new JimuException(-22, "res argument is err!");
} catch (RequestException e) {
Log.e("MotorManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public void a() throws JimuException {
try {
byte[] g = this.a.a(new ProtocolPacket(146, new byte[0])).g();
if (g[0] == 0) {
return;
}
throw new JimuException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]));
} catch (RequestException e) {
throw new JimuException(e.getCode(), e.getMessage());
}
}
private static byte[] a(int[] iArr) {
int i;
byte[] bArr = new byte[8];
int i2 = 0;
byte b = 0;
while (true) {
i = 1;
if (i2 >= iArr.length) {
break;
}
if (iArr[i2] > 64 || iArr[i2] < 1) {
Log.e("MotorManager", "Unsupport id! The support motor id range is 1~64");
}
int i3 = (iArr[i2] - 1) / 8;
b = (byte) (b | (1 << i3));
bArr[i3] = (byte) (((byte) (1 << ((iArr[i2] - 1) % 8))) | bArr[i3]);
i2++;
}
int i4 = 0;
for (byte b2 : bArr) {
if (b2 != 0) {
i4++;
}
}
byte[] bArr2 = new byte[i4 + 1];
bArr2[0] = b;
for (int length = bArr.length - 1; length >= 0; length--) {
if (bArr[length] != 0) {
bArr2[i] = bArr[length];
i++;
}
}
return bArr2;
}
private static ArrayList<Integer> a(byte[] bArr) {
ArrayList<Integer> arrayList = new ArrayList<>();
int i = 0;
byte b = bArr[0];
ArrayList arrayList2 = new ArrayList();
for (int i2 = 7; i2 >= 0; i2--) {
if (((1 << i2) & b & 255) != 0) {
arrayList2.add(Integer.valueOf(i2));
}
}
if (arrayList2.size() != bArr.length - 1) {
return arrayList;
}
while (i < arrayList2.size()) {
int intValue = ((Integer) arrayList2.get(i)).intValue();
i++;
arrayList.addAll(a(bArr[i], intValue * 8));
}
return arrayList;
}
private static ArrayList<Integer> a(byte b, int i) {
ArrayList<Integer> arrayList = new ArrayList<>();
for (int i2 = 0; i2 < 8; i2++) {
if ((b & 255 & (1 << i2)) != 0) {
arrayList.add(Integer.valueOf(i2 + 1 + i));
}
}
return arrayList;
}
}

View File

@@ -0,0 +1,25 @@
package com.ubtrobot.jimu.robotapi;
/* loaded from: classes2.dex */
public interface PeripheralType {
public static final int ATMOSPHERIC_PRESSURE = 97;
public static final int COLOR = 9;
public static final int COMPASS = 96;
public static final int DIGITALTUBE = 7;
public static final int EN_LIGHT_SENSOR = 12;
public static final int FIREBOT_HEAD_LED = 101;
public static final int GRAVITY = 5;
public static final int GYRO = 3;
public static final int INFRARED = 1;
public static final int INVALID_PERIPHERAL_TYPE = -1;
public static final int LED = 4;
public static final int MOTOR = 10;
public static final int New_MAIN_BOARD = 113;
public static final int OLD_MAIN_BOARD = 112;
public static final int RGB_LED = 14;
public static final int SERVO = 128;
public static final int SPEAKER = 8;
public static final int TEMP = 11;
public static final int TOUCH = 2;
public static final int ULTRASOUND = 6;
}

View File

@@ -0,0 +1,130 @@
package com.ubtrobot.jimu.robotapi;
/* loaded from: classes2.dex */
public final class R$string {
public static final int abc_action_bar_home_description = 2131820553;
public static final int abc_action_bar_up_description = 2131820554;
public static final int abc_action_menu_overflow_description = 2131820555;
public static final int abc_action_mode_done = 2131820556;
public static final int abc_activity_chooser_view_see_all = 2131820557;
public static final int abc_activitychooserview_choose_application = 2131820558;
public static final int abc_capital_off = 2131820559;
public static final int abc_capital_on = 2131820560;
public static final int abc_font_family_body_1_material = 2131820561;
public static final int abc_font_family_body_2_material = 2131820562;
public static final int abc_font_family_button_material = 2131820563;
public static final int abc_font_family_caption_material = 2131820564;
public static final int abc_font_family_display_1_material = 2131820565;
public static final int abc_font_family_display_2_material = 2131820566;
public static final int abc_font_family_display_3_material = 2131820567;
public static final int abc_font_family_display_4_material = 2131820568;
public static final int abc_font_family_headline_material = 2131820569;
public static final int abc_font_family_menu_material = 2131820570;
public static final int abc_font_family_subhead_material = 2131820571;
public static final int abc_font_family_title_material = 2131820572;
public static final int abc_menu_alt_shortcut_label = 2131820573;
public static final int abc_menu_ctrl_shortcut_label = 2131820574;
public static final int abc_menu_delete_shortcut_label = 2131820575;
public static final int abc_menu_enter_shortcut_label = 2131820576;
public static final int abc_menu_function_shortcut_label = 2131820577;
public static final int abc_menu_meta_shortcut_label = 2131820578;
public static final int abc_menu_shift_shortcut_label = 2131820579;
public static final int abc_menu_space_shortcut_label = 2131820580;
public static final int abc_menu_sym_shortcut_label = 2131820581;
public static final int abc_prepend_shortcut_label = 2131820582;
public static final int abc_search_hint = 2131820583;
public static final int abc_searchview_description_clear = 2131820584;
public static final int abc_searchview_description_query = 2131820585;
public static final int abc_searchview_description_search = 2131820586;
public static final int abc_searchview_description_submit = 2131820587;
public static final int abc_searchview_description_voice = 2131820588;
public static final int abc_shareactionprovider_share_with = 2131820589;
public static final int abc_shareactionprovider_share_with_application = 2131820590;
public static final int abc_toolbar_collapse_description = 2131820591;
public static final int app_name = 2131820649;
public static final int batter_high = 2131820668;
public static final int batter_low = 2131820669;
public static final int com_crashlytics_android_build_id = 2131820749;
public static final int com_facebook_device_auth_instructions = 2131820750;
public static final int com_facebook_image_download_unknown_error = 2131820751;
public static final int com_facebook_internet_permission_error_message = 2131820752;
public static final int com_facebook_internet_permission_error_title = 2131820753;
public static final int com_facebook_like_button_liked = 2131820754;
public static final int com_facebook_like_button_not_liked = 2131820755;
public static final int com_facebook_loading = 2131820756;
public static final int com_facebook_loginview_cancel_action = 2131820757;
public static final int com_facebook_loginview_log_in_button = 2131820758;
public static final int com_facebook_loginview_log_in_button_continue = 2131820759;
public static final int com_facebook_loginview_log_in_button_long = 2131820762;
public static final int com_facebook_loginview_log_out_action = 2131820763;
public static final int com_facebook_loginview_log_out_button = 2131820766;
public static final int com_facebook_loginview_logged_in_as = 2131820769;
public static final int com_facebook_loginview_logged_in_using_facebook = 2131820772;
public static final int com_facebook_send_button_text = 2131820775;
public static final int com_facebook_share_button_text = 2131820778;
public static final int com_facebook_smart_device_instructions = 2131820781;
public static final int com_facebook_smart_device_instructions_or = 2131820782;
public static final int com_facebook_smart_login_confirmation_cancel = 2131820783;
public static final int com_facebook_smart_login_confirmation_continue_as = 2131820786;
public static final int com_facebook_smart_login_confirmation_title = 2131820789;
public static final int com_facebook_tooltip_default = 2131820792;
public static final int comm_cancel = 2131820797;
public static final int comm_ok = 2131820798;
public static final int common_google_play_services_enable_button = 2131820814;
public static final int common_google_play_services_enable_text = 2131820815;
public static final int common_google_play_services_enable_title = 2131820816;
public static final int common_google_play_services_install_button = 2131820817;
public static final int common_google_play_services_install_text = 2131820818;
public static final int common_google_play_services_install_title = 2131820819;
public static final int common_google_play_services_notification_channel_name = 2131820820;
public static final int common_google_play_services_notification_ticker = 2131820821;
public static final int common_google_play_services_unknown_issue = 2131820822;
public static final int common_google_play_services_unsupported_text = 2131820823;
public static final int common_google_play_services_update_button = 2131820824;
public static final int common_google_play_services_update_text = 2131820825;
public static final int common_google_play_services_update_title = 2131820826;
public static final int common_google_play_services_updating_text = 2131820827;
public static final int common_google_play_services_wear_update_text = 2131820828;
public static final int common_open_on_phone = 2131820829;
public static final int common_signin_button_text = 2131820830;
public static final int common_signin_button_text_long = 2131820831;
public static final int engine_protect_electricity = 2131820978;
public static final int engine_protect_encrypt = 2131820979;
public static final int engine_protect_lock = 2131820980;
public static final int engine_protect_motor_lock = 2131820981;
public static final int engine_protect_motor_other = 2131820982;
public static final int engine_protect_other = 2131820983;
public static final int engine_protect_temp = 2131820984;
public static final int jg_channel_name_p_default = 2131821170;
public static final int jg_channel_name_p_high = 2131821171;
public static final int jg_channel_name_p_low = 2131821172;
public static final int jg_channel_name_p_min = 2131821173;
public static final int kit_name = 2131821184;
public static final int messenger_send_button_text = 2131821253;
public static final int search_menu_title = 2131821508;
public static final int status_bar_notification_info_overflow = 2131821607;
public static final int tw__allow_btn_txt = 2131821703;
public static final int tw__composer_hint = 2131821704;
public static final int tw__install = 2131821705;
public static final int tw__like_tweet = 2131821706;
public static final int tw__liked_tweet = 2131821707;
public static final int tw__loading_tweet = 2131821708;
public static final int tw__login_btn_txt = 2131821709;
public static final int tw__max_tweet_chars = 2131821710;
public static final int tw__not_now_btn_txt = 2131821711;
public static final int tw__pause = 2131821712;
public static final int tw__play = 2131821713;
public static final int tw__play_store = 2131821714;
public static final int tw__post_tweet = 2131821715;
public static final int tw__relative_date_format_long = 2131821716;
public static final int tw__relative_date_format_short = 2131821717;
public static final int tw__replay = 2131821718;
public static final int tw__retweeted_by_format = 2131821719;
public static final int tw__share_content_format = 2131821720;
public static final int tw__share_email_desc = 2131821721;
public static final int tw__share_email_title = 2131821722;
public static final int tw__share_subject_format = 2131821723;
public static final int tw__share_tweet = 2131821724;
public static final int tw__tweet_content_description = 2131821725;
public static final int tw__tweet_media = 2131821726;
}

View File

@@ -0,0 +1,77 @@
package com.ubtrobot.jimu.robotapi;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.RobotConnection;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes2.dex */
public class SensorManager {
private RobotConnection a;
public SensorManager(RobotConnection robotConnection) {
this.a = robotConnection;
}
public int a(int i, List<Integer> list, boolean z) throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(113, new byte[]{(byte) (i & 255), a(list), !z ? 1 : 0});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length == 3) {
return g[2] & 255;
}
throw new JimuException(-22, "res argument is err!");
} catch (RequestException e) {
Log.e("SensorManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public byte a(List<Integer> list) {
Iterator<Integer> it = list.iterator();
byte b = 0;
while (it.hasNext()) {
b = (byte) (b | (1 << (it.next().intValue() - 1)));
}
return b;
}
public BluetoothSpeakerInfo a(int i) throws JimuException {
if (i >= 1 && i <= 8) {
ProtocolPacket protocolPacket = new ProtocolPacket(114, new byte[]{8, (byte) (1 << (i - 1))});
try {
byte[] g = this.a.a(protocolPacket).g();
int i2 = 3;
if (g.length > 3) {
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
int i3 = 0;
while (i2 < g.length) {
if (i3 < 6) {
sb2.append(String.format("%02x:", Byte.valueOf(g[i2])));
} else {
sb.append((char) g[i2]);
}
i2++;
i3++;
}
if (sb2.length() == 0) {
Log.e("SensorManager", "Read speaker info fail! Mac is null!");
return null;
}
sb2.deleteCharAt(sb2.length() - 1);
return new BluetoothSpeakerInfo(sb2.toString(), sb.toString());
}
Log.e("SensorManager", "Read speaker info fail!");
throw new JimuException(-21, "Read speaker info fail!");
} catch (RequestException e) {
Log.e("SensorManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
Log.e("SensorManager", "Invalid id");
throw new JimuException(-20, JimuException.ERR_MSG_ARGUMENT_INVALID);
}
}

View File

@@ -0,0 +1,40 @@
package com.ubtrobot.jimu.robotapi;
/* loaded from: classes2.dex */
public class ServoAngleReadInfo {
private int a;
private float b;
private boolean c;
private float d;
public ServoAngleReadInfo(int i, boolean z, float f, float f2) {
this.a = i;
this.c = z;
this.d = f;
this.b = f2;
}
public float a() {
return this.b;
}
public int b() {
return this.a;
}
public float c() {
return this.d;
}
public String toString() {
return "ServoAngleReadInfo{id=" + this.a + ", actualAngle=" + this.b + ", isReciveSuccess=" + this.c + ", targetAngle=" + this.d + '}';
}
public void a(float f) {
this.b = f;
}
public void b(float f) {
this.d = f;
}
}

View File

@@ -0,0 +1,242 @@
package com.ubtrobot.jimu.robotapi;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.ResponseCallback;
import com.ubtrobot.jimu.connection.RobotConnection;
import com.ubtrobot.log.ALog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/* loaded from: classes2.dex */
public class ServoManager extends MotorManager {
public ServoManager(RobotConnection robotConnection) {
super(robotConnection);
}
public void a(int[] iArr, float[] fArr, int i, int i2) throws MotorException {
int length = fArr.length;
byte[] bArr = new byte[length + 4 + 1 + 2];
byte[] a = a(iArr);
byte[] bArr2 = new byte[length];
for (int i3 = 0; i3 < length; i3++) {
bArr2[i3] = (byte) fArr[i3];
}
System.arraycopy(a, 0, bArr, 0, a.length);
int length2 = a.length + 0;
System.arraycopy(bArr2, 0, bArr, length2, bArr2.length);
int length3 = length2 + bArr2.length;
bArr[length3] = (byte) (i / 20);
int i4 = length3 + 1;
int i5 = i + i2;
bArr[i4] = (byte) ((65280 & i5) >> 8);
bArr[i4 + 1] = (byte) (i5 & 255);
try {
byte[] g = this.a.a(new ProtocolPacket(9, bArr)).g();
if (g.length == 1 && g[0] == 0) {
return;
}
if (g.length != 5) {
throw new MotorException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]));
}
throw new MotorException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]), a(Arrays.copyOfRange(g, 1, g.length)));
} catch (RequestException e) {
throw new MotorException(e.getCode(), e.getMessage());
}
}
public void b() throws JimuException {
b(0, false);
}
public ServoAngleReadInfo b(int i, boolean z) throws JimuException {
new ArrayList();
byte[] bArr = new byte[2];
bArr[0] = (byte) i;
boolean z2 = true;
if (z) {
bArr[1] = 1;
} else {
bArr[1] = 0;
}
ProtocolPacket protocolPacket = new ProtocolPacket(11, bArr);
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length == 1 || g.length != 6) {
throw new JimuException(-22, "Control fail!");
}
int i2 = g[0] & 255;
if ((g[1] & 255) != 170) {
z2 = false;
}
return new ServoAngleReadInfo(i2, z2, ((g[2] & 255) << 8) | (g[3] & 255), (g[5] & 255) | ((g[4] & 255) << 8));
} catch (RequestException e) {
Log.e("ServoManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public void a(int[] iArr, int i) throws MotorException {
int length = iArr.length;
byte[] bArr = new byte[length + 4];
bArr[0] = (byte) (length & 255);
int i2 = 0;
while (i2 < length) {
int i3 = i2 + 1;
bArr[i3] = (byte) iArr[i2];
i2 = i3;
}
if (i > 0) {
bArr[length + 1] = 1;
} else if (i < 0) {
bArr[length + 1] = 2;
} else {
bArr[length + 1] = 0;
}
int abs = Math.abs(i);
bArr[length + 2] = (byte) ((65280 & abs) >> 8);
bArr[length + 3] = (byte) (abs & 255);
try {
byte[] g = this.a.a(new ProtocolPacket(7, bArr)).g();
if (g.length == 1 && g[0] == 0) {
return;
}
if (g.length == 5) {
throw new MotorException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]), a(Arrays.copyOfRange(g, 1, g.length)));
}
throw new MotorException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]));
} catch (RequestException e) {
throw new MotorException(e.getCode(), e.getMessage());
}
}
@Override // com.ubtrobot.jimu.robotapi.MotorManager
public void a() throws JimuException {
try {
byte[] g = this.a.a(new ProtocolPacket(59, new byte[0])).g();
if (g[0] == 0) {
return;
}
throw new JimuException(-21, "cmd result is fail! ErrCode:" + ((int) g[0]));
} catch (RequestException e) {
throw new JimuException(e.getCode(), e.getMessage());
}
}
public List<ServoAngleReadInfo> a(final int i, boolean z) throws JimuException {
final boolean[] zArr = new boolean[1];
final boolean[] zArr2 = new boolean[1];
final JimuException[] jimuExceptionArr = new JimuException[1];
final ArrayList arrayList = new ArrayList();
byte[] bArr = new byte[2];
bArr[0] = 0;
if (z) {
bArr[1] = 1;
} else {
bArr[1] = 0;
}
ProtocolPacket protocolPacket = new ProtocolPacket(11, bArr);
this.a.a(protocolPacket, new ResponseCallback(this) { // from class: com.ubtrobot.jimu.robotapi.ServoManager.1
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket, IPacket iPacket2) {
byte[] g = iPacket2.g();
if (g.length == 1 || g.length != 6) {
synchronized (zArr) {
jimuExceptionArr[0] = new JimuException(-22, "Control fail!");
zArr[0] = true;
ALog.a("ServoManager").d("responded notify");
zArr.notifyAll();
}
return;
}
ServoAngleReadInfo servoAngleReadInfo = new ServoAngleReadInfo(g[0] & 255, (g[1] & 255) == 170, ((g[2] & 255) << 8) | (g[3] & 255), (g[5] & 255) | ((g[4] & 255) << 8));
synchronized (zArr) {
arrayList.add(servoAngleReadInfo);
if (arrayList.size() == i) {
zArr2[0] = true;
zArr[0] = true;
Log.d("ServoManager", "responded notify");
zArr.notifyAll();
}
}
}
@Override // com.ubtrobot.jimu.connection.ResponseCallback
public void a(IPacket iPacket, RequestException requestException) {
synchronized (zArr) {
jimuExceptionArr[0] = new JimuException(requestException.getCode(), requestException.getMessage());
zArr[0] = true;
Log.d("ServoManager", "responded notify");
zArr.notifyAll();
}
}
}, i);
synchronized (zArr) {
while (!zArr[0]) {
try {
Log.d("ServoManager", "responded wait");
zArr.wait();
break;
} catch (InterruptedException e) {
Log.w("ServoManager", "Interrupted by someone when sync doRequest. req=" + protocolPacket + "Ignore it.", e);
Thread.currentThread().interrupt();
}
}
if (jimuExceptionArr[0] != null) {
throw jimuExceptionArr[0];
}
}
return arrayList;
}
@Override // com.ubtrobot.jimu.robotapi.MotorManager
public int a(int i, int i2) throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(12, new byte[]{(byte) i, (byte) i2});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length == 1) {
return g[0] & 255;
}
throw new JimuException(-22, "res argument is err!");
} catch (RequestException e) {
Log.e("ServoManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
private byte[] a(int[] iArr) {
byte[] bArr = new byte[4];
for (int i : iArr) {
if (i > 0 && i <= 8) {
bArr[3] = (byte) (bArr[3] + (1 << (i - 1)));
} else if (i > 8 && i <= 16) {
bArr[2] = (byte) (bArr[2] + (1 << ((i - 1) - 8)));
} else if (i > 16 && i <= 24) {
bArr[1] = (byte) (bArr[1] + (1 << ((i - 1) - 16)));
} else if (i >= 24 && i <= 32) {
bArr[0] = (byte) (bArr[0] + (1 << ((i - 1) - 24)));
}
}
return bArr;
}
private ArrayList<Integer> a(byte[] bArr) {
ArrayList<Integer> arrayList = new ArrayList<>();
if (bArr.length != 4) {
return arrayList;
}
for (int i = 0; i < bArr.length; i++) {
int i2 = 24 - (i * 8);
byte b = bArr[i];
for (int i3 = 0; i3 < 8; i3++) {
if ((b & 255 & (1 << i3)) != 0) {
arrayList.add(Integer.valueOf(i3 + 1 + i2));
}
}
}
return arrayList;
}
}

View File

@@ -0,0 +1,989 @@
package com.ubtrobot.jimu.robotapi;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import com.ijm.dataencryption.de.DataDecryptTool;
import com.ubtech.utils.FileHelper;
import com.ubtech.utils.XLog;
import com.ubtrobot.jimu.Firmware;
import com.ubtrobot.jimu.bluetooth.Cancellable;
import com.ubtrobot.jimu.bluetooth.ConnectCallback;
import com.ubtrobot.jimu.bluetooth.base.IPacket;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
import com.ubtrobot.jimu.connection.PacketsReceiveListener;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.RobotConnection;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Timer;
/* loaded from: classes2.dex */
public class UpdateManager implements PacketsReceiveListener, ConnectCallback {
private Timer a;
private volatile int b;
private RobotConnection c;
private DeviceManager d;
private JimuScanner e;
private Cancellable f;
private List<Firmware> g = new ArrayList();
private Queue<Firmware> h = new LinkedList();
private Firmware i;
private Firmware j;
private Firmware k;
private UpdateProgressListener l;
private int m;
private HandlerThread n;
private Handler o;
private volatile boolean p;
private int q;
private BoardInfo r;
public static class UpdateException extends RequestException {
public static final int ERR_CODE_DISCONNECTED = -99;
public static final int ERR_CODE_LOW_POWER = -102;
public static final int ERR_CODE_NO_FIRMWARE = -101;
public static final int ERR_CODE_STOP_UPDATE_BOARD_FAILED = -107;
public static final int ERR_CODE_UPDATE_BOARD_FAILED = -103;
public static final int ERR_CODE_UPDATE_CANCEL = -106;
public static final int ERR_CODE_UPDATE_FAILED = -100;
public static final int ERR_CODE_UPDATE_SENSOR_FAILED = -105;
public static final int ERR_CODE_UPDATE_SERVO_FAILED = -104;
private final IPacket response;
public UpdateException(int i, String str) {
this(i, str, null, null);
}
public IPacket getResponse() {
return this.response;
}
public UpdateException(int i, String str, IPacket iPacket) {
this(i, str, null, iPacket);
}
public UpdateException(int i, String str, Throwable th) {
this(i, str, th, null);
}
public UpdateException(int i, String str, Throwable th, IPacket iPacket) {
super(i, str, th);
this.response = iPacket;
}
}
public interface UpdateProgressListener {
void a(int i);
void a(int i, int i2);
void a(int i, Object obj);
void a(UpdateException updateException);
void g(BoardInfo boardInfo);
}
public UpdateManager(Context context, RobotConnection robotConnection) {
this.c = robotConnection;
this.d = new DeviceManager(robotConnection);
this.e = new JimuScanner(context.getApplicationContext());
}
private byte[] a(long j) {
return new byte[]{(byte) (j & 255), (byte) ((j >> 8) & 255), (byte) ((j >> 16) & 255), (byte) ((j >> 24) & 255)};
}
private byte[] b(int i) {
return new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255)};
}
@Override // com.ubtrobot.jimu.bluetooth.ConnectCallback
public void onSuccess() {
c(7);
}
private void d() {
XLog.a("UpdateManager", "quit update cancel=" + this.p);
try {
if (this.n != null) {
this.n.quit();
this.n = null;
this.o = null;
}
if (this.f == null || this.f.isCancelled()) {
return;
}
this.f.cancel();
this.f = null;
} catch (Exception e) {
e.printStackTrace();
}
}
private void e(String str, IPacket iPacket) {
byte[] g = iPacket.g();
if (g == null || g.length < 2) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SENSOR_FAILED, "83指令返回异常"));
return;
}
int i = g[1] & 255;
Log.d("UpdateManager", String.format("%s指令返回%s", "83", Integer.toHexString(i)));
if (i == 0) {
a(this.k.c(), 100);
return;
}
if (i == 170) {
this.c.a(true);
a(this.k.c(), (Object) null);
c(3);
} else {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SENSOR_FAILED, "83指令返回异常传感器升级失败:" + i, iPacket));
}
}
/* JADX INFO: Access modifiers changed from: private */
public void f() {
String b = this.c.b();
if (TextUtils.isEmpty(b)) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "新主板升级失败mac地址为null"));
} else {
this.c.a(b, this);
}
}
private int g() throws JimuException {
int a = a(new ProtocolPacket(130, new byte[]{0}));
XLog.a("UpdateManager", "取消传感器升级:" + a);
return a;
}
private int h() throws JimuException {
int a = a(new ProtocolPacket(37, new byte[]{0}));
XLog.a("UpdateManager", "取消舵机升级:" + a);
return a;
}
/* JADX INFO: Access modifiers changed from: private */
public void i() {
this.f = this.e.a(new ScannedHubEmitter() { // from class: com.ubtrobot.jimu.robotapi.UpdateManager.2
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a() {
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(int i, String str) {
}
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
public void a(ScanResult scanResult) {
if (scanResult == null || scanResult.a() == null || TextUtils.isEmpty(scanResult.a().getAddress()) || !scanResult.a().getAddress().equals(UpdateManager.this.c.b())) {
return;
}
XLog.a("UpdateManager", "新主板升级,扫描到设备,准备开始重连...");
UpdateManager.this.c(6);
UpdateManager.this.f.cancel();
}
}, 60000);
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Code restructure failed: missing block: B:30:0x007b, code lost:
android.util.Log.d("UpdateManager", "total:" + (java.lang.System.currentTimeMillis() - r13) + " sleep: " + r11);
*/
/* JADX WARN: Code restructure failed: missing block: B:31:0x009d, code lost:
if (r16 == false) goto L34;
*/
/* JADX WARN: Code restructure failed: missing block: B:32:0x009f, code lost:
a(new com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException(com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "主板升级失败指令1C失败"));
*/
/* JADX WARN: Code restructure failed: missing block: B:33:0x00a9, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:34:0x00aa, code lost:
b(20L);
*/
/* JADX WARN: Code restructure failed: missing block: B:35:0x00af, code lost:
if (r19.p == false) goto L37;
*/
/* JADX WARN: Code restructure failed: missing block: B:36:0x00b1, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:38:0x00b6, code lost:
if (a(r4, r7) == 0) goto L41;
*/
/* JADX WARN: Code restructure failed: missing block: B:39:0x00b8, code lost:
a(new com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException(com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException.ERR_CODE_STOP_UPDATE_BOARD_FAILED, "主板升级失败指令1B失败"));
*/
/* JADX WARN: Code restructure failed: missing block: B:40:0x00c4, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:42:0x00cd, code lost:
if (r19.i.c() != 113) goto L47;
*/
/* JADX WARN: Code restructure failed: missing block: B:43:0x00cf, code lost:
a(r19.i.c(), 100);
com.ubtech.utils.XLog.a("UpdateManager", "新主板升级文件传输完毕等待60秒重连");
r19.q = 0;
*/
/* JADX WARN: Code restructure failed: missing block: B:44:0x00e1, code lost:
if (r19.o == null) goto L46;
*/
/* JADX WARN: Code restructure failed: missing block: B:45:0x00e3, code lost:
r19.o.sendMessageDelayed(r19.o.obtainMessage(5), 50000);
*/
/* JADX WARN: Code restructure failed: missing block: B:46:?, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:47:0x00f3, code lost:
a(new com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException(com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "mHandler=null"));
*/
/* JADX WARN: Code restructure failed: missing block: B:48:?, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:49:0x00fe, code lost:
r19.c.a(false);
*/
/* JADX WARN: Code restructure failed: missing block: B:50:?, code lost:
return;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public void j() {
/*
Method dump skipped, instructions count: 272
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.ubtrobot.jimu.robotapi.UpdateManager.j():void");
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Code restructure failed: missing block: B:47:0x00d6, code lost:
if (r5 == false) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:48:0x00d8, code lost:
a(new com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException(com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException.ERR_CODE_UPDATE_SERVO_FAILED, "舵机升级失败指令24失败"));
*/
/* JADX WARN: Code restructure failed: missing block: B:49:0x00e2, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:50:0x00e3, code lost:
b(20L);
*/
/* JADX WARN: Code restructure failed: missing block: B:51:0x00e8, code lost:
if (r11.p == false) goto L51;
*/
/* JADX WARN: Code restructure failed: missing block: B:52:0x00ea, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:54:0x00ef, code lost:
if (b(r1, r2) == 0) goto L54;
*/
/* JADX WARN: Code restructure failed: missing block: B:55:0x00f1, code lost:
a(new com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException(com.ubtrobot.jimu.robotapi.UpdateManager.UpdateException.ERR_CODE_UPDATE_SERVO_FAILED, "舵机升级失败指令26失败"));
*/
/* JADX WARN: Code restructure failed: missing block: B:56:0x00fb, code lost:
r11.c.a(false);
*/
/* JADX WARN: Code restructure failed: missing block: B:57:?, code lost:
return;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public void k() {
/*
Method dump skipped, instructions count: 269
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.ubtrobot.jimu.robotapi.UpdateManager.k():void");
}
private void b(String str, IPacket iPacket) {
int i = iPacket.g()[0] & 255;
Log.d("UpdateManager", String.format("%s指令返回%s", "1E", Integer.toHexString(i)));
if (i == 0) {
a(this.i.c(), 100);
return;
}
if (i == 1) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "老主控开始升级失败"));
return;
}
if (i == 170) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "老主控开始还原主程序"));
} else if (i != 238) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "老主控开始升级失败"));
} else {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "老主控开始还原失败"));
}
}
/* JADX INFO: Access modifiers changed from: private */
public void c() {
XLog.a("UpdateManager", "cancel update");
this.c.b(this);
try {
try {
if (this.m == 3) {
g();
} else if (this.m == 2) {
h();
} else if (this.m == 1) {
b();
}
} catch (Exception e) {
e.printStackTrace();
}
} finally {
d();
}
}
public boolean a(BoardInfo boardInfo) {
return boardInfo == null || boardInfo.c() != 0 || boardInfo.b() >= 7.4f;
}
public boolean a(BoardInfo boardInfo, List<Firmware> list, UpdateProgressListener updateProgressListener) {
this.m = 0;
this.l = updateProgressListener;
if (list != null && list.size() != 0) {
if (!a(boardInfo)) {
this.p = true;
a(new UpdateException(UpdateException.ERR_CODE_LOW_POWER, "电量过低(电池电压低于7.4V)"));
return false;
}
this.r = boardInfo;
this.i = null;
this.j = null;
this.h.clear();
this.g.clear();
this.g.addAll(list);
for (Firmware firmware : list) {
if (112 != firmware.c() && 113 != firmware.c()) {
if (128 == firmware.c()) {
this.j = firmware;
} else {
this.h.add(firmware);
}
} else {
this.i = firmware;
}
}
this.c.a(this);
this.p = false;
this.n = new HandlerThread("jimu_firmware_update_thread");
this.n.start();
this.o = new Handler(this.n.getLooper()) { // from class: com.ubtrobot.jimu.robotapi.UpdateManager.1
@Override // android.os.Handler
public void handleMessage(Message message) {
super.handleMessage(message);
try {
switch (message.what) {
case 1:
UpdateManager.this.j();
break;
case 2:
UpdateManager.this.k();
break;
case 3:
UpdateManager.this.a(true);
break;
case 4:
UpdateManager.this.c();
break;
case 5:
UpdateManager.this.m = 5;
UpdateManager.this.i();
break;
case 6:
UpdateManager.this.m = 6;
UpdateManager.this.f();
break;
case 7:
UpdateManager.this.m = 7;
UpdateManager.this.e();
break;
}
} catch (Exception e) {
e.printStackTrace();
UpdateManager.this.a(new UpdateException(-100, "升级失败", e));
}
}
};
c(1);
return true;
}
a(new UpdateException(UpdateException.ERR_CODE_NO_FIRMWARE, "需要升级的固件列表为null"));
return false;
}
private int b(byte[] bArr, int i, int i2) throws JimuException {
return a(new ProtocolPacket(28, a(bArr, i, i2)));
}
private void d(String str, IPacket iPacket) {
int i = iPacket.g()[0] & 255;
Log.d("UpdateManager", String.format("%s指令返回%s", "26", Integer.toHexString(i)));
if (i == 0) {
a(PeripheralType.SERVO, 100);
return;
}
if (i == 2) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SERVO_FAILED, "舵机升级失败: " + iPacket.g(), iPacket));
return;
}
if (i != 170) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SERVO_FAILED, "舵机升级失败", iPacket));
} else {
this.c.a(true);
c(3);
}
}
/* JADX INFO: Access modifiers changed from: private */
public void e() {
try {
this.d.g();
b(20L);
BoardInfo e = this.d.e();
if (e == null) {
b(2000L);
e = this.d.e();
}
if (e != null && !TextUtils.isEmpty(e.d())) {
if (!e.d().equals(this.i.d())) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "新主板升级,重连后版本信息和要升级的不一致,升级失败"));
return;
}
Log.d("UpdateManager", "新主板升级成功,现在的版本名称为:" + e.d());
a(this.i.c(), e);
c(2);
this.r = e;
return;
}
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "新主板升级,重连后读取主板信息失败"));
} catch (Exception e2) {
e2.printStackTrace();
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "新主板升级,重连后读取主板信息失败"));
}
}
public int b() throws JimuException {
int a = a(new ProtocolPacket(29, new byte[]{0}));
XLog.a("UpdateManager", "取消主板升级:" + a);
return a;
}
private void c(String str, IPacket iPacket) {
int i = iPacket.g()[0] & 255;
Log.d("UpdateManager", String.format("%s指令返回%s", "1F", Integer.toHexString(i)));
if (i == 0) {
this.c.a(true);
c(2);
} else {
if (i == 1) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "主控结束升级失败"));
return;
}
if (i == 170) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "结束还原主程序成功"));
} else if (i != 238) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "主控结束升级失败"));
} else {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_BOARD_FAILED, "结束还原失败"));
}
}
}
private int b(byte[] bArr, int i) throws JimuException {
return a(new ProtocolPacket(38, a(bArr, i, i)));
}
private byte[] b(Firmware firmware) throws JimuException {
byte[] a;
if (firmware != null && (a = a(firmware.b(), firmware.a())) != null && a.length != 0) {
String a2 = FileHelper.a(firmware.b());
if (TextUtils.isEmpty(a2)) {
return null;
}
byte[] bytes = a2.replace(".bin", "").getBytes();
byte[] bArr = new byte[bytes.length + 5];
bArr[0] = (byte) (firmware.c() & 255);
bArr[1] = 0;
byte[] b = b(b(a));
bArr[2] = b[0];
bArr[3] = b[1];
bArr[4] = (byte) (bytes.length & 255);
System.arraycopy(bytes, 0, bArr, 5, bytes.length);
byte[] b2 = b(new ProtocolPacket(PeripheralType.SERVO, bArr));
if (b2 != null && b2.length >= 2 && firmware.c() == (b2[0] & 255) && (b2[1] & 255) == 0) {
return a;
}
}
return null;
}
private byte[] c(Firmware firmware) throws JimuException {
byte[] a;
if (firmware != null && (a = a(firmware.b(), firmware.a())) != null && a.length != 0) {
int length = a.length % 64;
if (length != 0) {
byte[] bArr = new byte[a.length + (64 - length)];
System.arraycopy(a, 0, bArr, 0, a.length);
a = bArr;
}
byte[] bArr2 = new byte[7];
bArr2[0] = 0;
System.arraycopy(b(b(a)), 0, bArr2, 1, 2);
System.arraycopy(a(a(a)), 0, bArr2, 3, 4);
if (a(new ProtocolPacket(35, bArr2)) == 0) {
return a;
}
}
return null;
}
public synchronized void a() {
if (!this.p && this.n != null) {
c(4);
a(this.m);
this.p = true;
}
}
private int c(byte[] bArr, int i, int i2) throws JimuException {
return a(new ProtocolPacket(36, a(bArr, i, i2)));
}
private byte[] b(int i, byte[] bArr, int i2, int i3) throws JimuException {
return b(new ProtocolPacket(129, a(i, bArr, i2, i3)));
}
/* JADX INFO: Access modifiers changed from: private */
public void c(int i) {
Handler handler = this.o;
if (handler == null) {
XLog.b("UpdateManager", "未知错误: mHandler==null");
d();
} else {
handler.sendEmptyMessage(i);
}
}
@Override // com.ubtrobot.jimu.connection.PacketsReceiveListener
public void a(String str, IPacket iPacket) {
if (iPacket == null) {
return;
}
try {
int f = iPacket.f() & 255;
if (f == 30) {
b(str, iPacket);
} else if (f == 31) {
c(str, iPacket);
} else if (f == 38) {
d(str, iPacket);
} else if (f == 131) {
e(str, iPacket);
}
} catch (Exception e) {
a(new UpdateException(-100, "升级失败", e));
}
}
private void b(BoardInfo boardInfo) {
this.c.b(this);
if (boardInfo != null) {
this.l.g(boardInfo);
return;
}
try {
try {
b(3000L);
this.d.g();
b(20L);
BoardInfo e = this.d.e();
if (e == null) {
b(2000L);
e = this.d.e();
}
if (e == null) {
a(new UpdateException(-100, "升级完成,但是读取主板信息失败"));
} else {
this.r = e;
this.l.g(e);
}
} catch (Exception e2) {
e2.printStackTrace();
}
d();
Timer timer = this.a;
if (timer != null) {
timer.cancel();
this.a = null;
}
} catch (Throwable th) {
d();
throw th;
}
}
@Override // com.ubtrobot.jimu.bluetooth.ConnectCallback
public void a(int i, String str) {
this.q++;
if (this.q > 3) {
a(new UpdateException(-99, "新主控升级失败重连3次失败"));
return;
}
Handler handler = this.o;
if (handler != null) {
handler.sendMessageDelayed(handler.obtainMessage(6), 3000L);
} else {
a(new UpdateException(-99, "新主控升级失败,重连失败"));
}
}
/* JADX INFO: Access modifiers changed from: private */
public void a(boolean z) {
boolean z2;
if (this.m == 2) {
if (z) {
try {
b(3000L);
this.d.g();
b(20L);
BoardInfo e = this.d.e();
if (e == null) {
b(2000L);
e = this.d.e();
}
if (e != null && !TextUtils.isEmpty(e.j()) && e.j().equals(this.j.d())) {
this.r = e;
a(PeripheralType.SERVO, e);
}
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SERVO_FAILED, "舵机升级完成,但是读取主板信息失败"));
return;
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (this.h == null || this.h.size() == 0) {
b(this.r);
return;
}
}
Firmware poll = this.h.poll();
if (poll == null) {
b((BoardInfo) null);
return;
}
Log.d("UpdateManager", "升级传感器:" + poll.c());
this.m = 3;
this.k = poll;
try {
b(20L);
if (this.p) {
return;
}
byte[] b = b(poll);
if (b != null && b.length != 0) {
int b2 = b(b);
int i = 0;
int i2 = 0;
while (i < b2 - 1) {
b(20L);
if (!this.p) {
int i3 = i + 1;
byte[] b3 = b(poll.c(), b, b2, i3);
if (poll.c() == (b3[0] & 255) && (b3[1] & 255) == 0) {
int i4 = (i * 100) / b2;
if (i2 != i4) {
a(poll.c(), i4);
i2 = i4;
}
i = i3;
}
z2 = true;
break;
}
return;
}
z2 = false;
if (z2) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SENSOR_FAILED, "传感器升级失败81指令调用失败"));
return;
}
b(20L);
if (this.p) {
return;
}
if ((a(poll.c(), b, b2)[1] & 255) != 0) {
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SENSOR_FAILED, "传感器升级失败83指令调用失败"));
}
this.c.a(false);
return;
}
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SENSOR_FAILED, "传感器升级失败80指令调用失败"));
} catch (Exception e3) {
e3.printStackTrace();
a(new UpdateException(UpdateException.ERR_CODE_UPDATE_SENSOR_FAILED, "传感器升级失败", e3));
}
}
private byte[] b(ProtocolPacket protocolPacket) throws JimuException {
try {
byte[] g = this.c.a(protocolPacket).g();
if (g != null && g.length != 0) {
return g;
}
throw new JimuException(-21, "指令操作失败:" + Integer.toHexString(protocolPacket.f()));
} catch (RequestException e) {
e.printStackTrace();
throw new JimuException(e.getCode(), e.getMessage());
}
}
private void b(long j) {
try {
Thread.sleep(j);
} catch (Exception e) {
e.printStackTrace();
}
}
private int b(byte[] bArr) {
int length = bArr.length;
int i = length / 100;
return length % 100 > 0 ? i + 1 : i;
}
private byte[] a(Firmware firmware) throws JimuException {
byte[] a = a(firmware.b(), firmware.a());
if (a == null) {
return null;
}
String a2 = FileHelper.a(firmware.b());
if (TextUtils.isEmpty(a2)) {
return null;
}
byte[] bytes = a2.getBytes();
byte[] bArr = new byte[bytes.length + 1 + 2];
bArr[0] = (byte) (bytes.length & 255);
System.arraycopy(bytes, 0, bArr, 1, bytes.length);
System.arraycopy(b(b(a)), 0, bArr, bytes.length + 1, 2);
int a3 = a(new ProtocolPacket(26, bArr));
if (a3 == 0) {
return a;
}
XLog.b("UpdateManager", "cmd 1A failed:" + a3);
return null;
}
private int a(byte[] bArr, int i) throws JimuException {
return a(new ProtocolPacket(27, a(bArr, i, i)));
}
private byte[] a(int i, byte[] bArr, int i2) throws JimuException {
return b(new ProtocolPacket(131, a(i, bArr, i2, i2)));
}
/* JADX WARN: Removed duplicated region for block: B:14:0x0020 A[Catch: all -> 0x0068, TryCatch #0 {, blocks: (B:4:0x0003, B:12:0x001b, B:14:0x0020, B:15:0x0028, B:18:0x003a, B:19:0x0066, B:25:0x0063), top: B:3:0x0003, inners: #1 }] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
private void a(final int r9, int r10) {
/*
r8 = this;
monitor-enter(r8)
int r10 = r10 * 9
int r10 = r10 / 10
r8.b = r10 // Catch: java.lang.Throwable -> L68
int r10 = r8.b // Catch: java.lang.Throwable -> L68
r0 = 90
if (r10 != r0) goto L3a
r10 = 113(0x71, float:1.58E-43)
if (r10 == r9) goto L19
r10 = 112(0x70, float:1.57E-43)
if (r10 != r9) goto L16
goto L19
L16:
r0 = 1000(0x3e8, double:4.94E-321)
goto L1b
L19:
r0 = 7000(0x1b58, double:3.4585E-320)
L1b:
r6 = r0
java.util.Timer r10 = r8.a // Catch: java.lang.Throwable -> L68
if (r10 == 0) goto L28
java.util.Timer r10 = r8.a // Catch: java.lang.Throwable -> L68
r10.cancel() // Catch: java.lang.Throwable -> L68
r10 = 0
r8.a = r10 // Catch: java.lang.Throwable -> L68
L28:
java.util.Timer r10 = new java.util.Timer // Catch: java.lang.Throwable -> L68
r10.<init>() // Catch: java.lang.Throwable -> L68
r8.a = r10 // Catch: java.lang.Throwable -> L68
java.util.Timer r2 = r8.a // Catch: java.lang.Throwable -> L68
com.ubtrobot.jimu.robotapi.UpdateManager$3 r3 = new com.ubtrobot.jimu.robotapi.UpdateManager$3 // Catch: java.lang.Throwable -> L68
r3.<init>() // Catch: java.lang.Throwable -> L68
r4 = r6
r2.scheduleAtFixedRate(r3, r4, r6) // Catch: java.lang.Throwable -> L68
L3a:
com.ubtrobot.jimu.robotapi.UpdateManager$UpdateProgressListener r10 = r8.l // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
int r0 = r8.b // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
r10.a(r9, r0) // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
java.lang.String r10 = "UpdateManager"
java.lang.StringBuilder r0 = new java.lang.StringBuilder // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
r0.<init>() // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
java.lang.String r1 = "updateProgress type:"
r0.append(r1) // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
r0.append(r9) // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
java.lang.String r9 = " progress:"
r0.append(r9) // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
int r9 = r8.b // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
r0.append(r9) // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
java.lang.String r9 = r0.toString() // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
android.util.Log.d(r10, r9) // Catch: java.lang.Exception -> L62 java.lang.Throwable -> L68
goto L66
L62:
r9 = move-exception
r9.printStackTrace() // Catch: java.lang.Throwable -> L68
L66:
monitor-exit(r8) // Catch: java.lang.Throwable -> L68
return
L68:
r9 = move-exception
monitor-exit(r8) // Catch: java.lang.Throwable -> L68
throw r9
*/
throw new UnsupportedOperationException("Method not decompiled: com.ubtrobot.jimu.robotapi.UpdateManager.a(int, int):void");
}
private void a(int i, Object obj) {
try {
this.l.a(i, obj);
} catch (Exception e) {
e.printStackTrace();
}
}
/* JADX INFO: Access modifiers changed from: private */
public void a(UpdateException updateException) {
try {
this.l.a(updateException);
this.c.b(this);
} catch (Exception e) {
e.printStackTrace();
}
try {
Log.e("UpdateManager", "updateFailed:" + updateException.getMessage());
c(4);
} catch (Exception e2) {
e2.printStackTrace();
d();
}
Timer timer = this.a;
if (timer != null) {
timer.cancel();
this.a = null;
}
}
private void a(int i) {
try {
this.l.a(i);
} catch (Exception e) {
e.printStackTrace();
}
}
private int a(ProtocolPacket protocolPacket) throws JimuException {
return b(protocolPacket)[0] & 255;
}
private byte[] a(byte[] bArr, int i, int i2) {
int i3 = (i2 - 1) * 100;
int length = (i2 == i ? bArr.length : i2 * 100) - i3;
byte[] bArr2 = new byte[length + 2];
System.arraycopy(b(i2), 0, bArr2, 0, 2);
System.arraycopy(bArr, i3, bArr2, 2, length);
return bArr2;
}
private byte[] a(int i, byte[] bArr, int i2, int i3) {
int i4 = (i3 - 1) * 100;
int length = (i3 == i2 ? bArr.length : i3 * 100) - i4;
byte[] bArr2 = new byte[length + 3];
bArr2[0] = (byte) (i & 255);
System.arraycopy(b(i3), 0, bArr2, 1, 2);
System.arraycopy(bArr, i4, bArr2, 3, length);
return bArr2;
}
private byte[] a(String str, String str2) {
File file = new File(str);
if (file.exists() && FileHelper.a(str2, str)) {
return FileHelper.b(file);
}
return null;
}
private long a(byte[] bArr) {
long[] jArr = new long[DataDecryptTool.DECRYPT_ALL_FILE];
for (long j = 0; j < 256; j++) {
long j2 = j;
for (long j3 = 0; j3 < 8; j3++) {
j2 = (j2 & 1) == 1 ? (j2 >> 1) ^ 3988292384L : j2 >> 1;
}
jArr[(int) j] = j2;
}
long j4 = 4294967295L;
for (byte b : bArr) {
j4 = (j4 >> 8) ^ jArr[(int) ((b ^ j4) & 255)];
}
return j4;
}
}