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