package qbsg.top.ble; public final class BleManager implements qbsg.top.ble.BleManagerFacade { public static final int $stable = 8; private final kotlinx.coroutines.flow.MutableStateFlow _activeDevice; private final kotlinx.coroutines.flow.MutableStateFlow _connections; private final kotlinx.coroutines.flow.MutableSharedFlow _disconnectEvents; private final kotlinx.coroutines.flow.MutableStateFlow _isBluetoothEnabled; private final kotlinx.coroutines.flow.MutableSharedFlow _messageEvents; private final kotlinx.coroutines.flow.MutableSharedFlow _rawScanResults; private final kotlinx.coroutines.flow.MutableStateFlow _scanState; private final kotlinx.coroutines.flow.MutableStateFlow _scannedDevices; private final kotlinx.coroutines.flow.MutableStateFlow _targetSessionMac; private final kotlinx.coroutines.flow.StateFlow activeDevice; private final android.bluetooth.BluetoothManager btManager; private final qbsg.top.ble.BleManager$btStateReceiver$1 btStateReceiver; private final kotlinx.coroutines.flow.StateFlow connections; private final android.content.Context context; private final java.util.LinkedList descriptorWriteQueue; private final java.util.concurrent.ConcurrentHashMap deviceInfoReadJobs; private final kotlinx.coroutines.flow.SharedFlow disconnectEvents; private final qbsg.top.ble.BleManager$gattCallback$1 gattCallback; private final java.util.concurrent.ConcurrentHashMap gatts; private final String id; private final kotlinx.coroutines.flow.StateFlow isBluetoothEnabled; private boolean isWritingDescriptor; private final kotlinx.coroutines.flow.SharedFlow messageEvents; private final java.util.concurrent.ConcurrentHashMap otaChannels; private a8.h otaManager; private final java.util.concurrent.ConcurrentHashMap pendingCccdCount; private final java.util.concurrent.ConcurrentHashMap pendingFirmware; private final kotlinx.coroutines.flow.SharedFlow rawScanResults; private final java.util.concurrent.ConcurrentHashMap readChannels; private final qbsg.top.ble.BleManager$scanCallback$1 scanCallback; private final kotlinx.coroutines.flow.StateFlow scanState; private final kotlinx.coroutines.flow.StateFlow scannedDevices; private final kotlinx.coroutines.CoroutineScope scope; private final kotlinx.coroutines.flow.StateFlow targetSessionMac; private final java.util.concurrent.ConcurrentHashMap$KeySetView userInitiatedDisconnections; public BleManager(android.content.Context p5) { String v2_13; kotlin.jvm.internal.s.f(p5, "context"); this.context = p5; this.id = w7.w.i(); this.scope = kotlinx.coroutines.CoroutineScopeKt.CoroutineScope(kotlinx.coroutines.SupervisorKt.SupervisorJob$default(0, 1, 0).plus(kotlinx.coroutines.Dispatchers.getIO())); qbsg.top.ble.BleManager$btStateReceiver$1 v0_9 = p5.getSystemService("bluetooth"); kotlin.jvm.internal.s.d(v0_9, "null cannot be cast to non-null type android.bluetooth.BluetoothManager"); this.btManager = ((android.bluetooth.BluetoothManager) v0_9); this.gatts = new java.util.concurrent.ConcurrentHashMap(); this.userInitiatedDisconnections = java.util.concurrent.ConcurrentHashMap.newKeySet(); this.otaChannels = new java.util.concurrent.ConcurrentHashMap(); this.descriptorWriteQueue = new java.util.LinkedList(); this.readChannels = new java.util.concurrent.ConcurrentHashMap(); this.pendingFirmware = new java.util.concurrent.ConcurrentHashMap(); this.deviceInfoReadJobs = new java.util.concurrent.ConcurrentHashMap(); this.pendingCccdCount = new java.util.concurrent.ConcurrentHashMap(); qbsg.top.ble.BleManager$btStateReceiver$1 v0_28 = kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow(q6.u.c); this._connections = v0_28; this.connections = kotlinx.coroutines.flow.FlowKt.asStateFlow(v0_28); qbsg.top.ble.BleManager$btStateReceiver$1 v0_30 = kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow(0); this._activeDevice = v0_30; this.activeDevice = kotlinx.coroutines.flow.FlowKt.asStateFlow(v0_30); qbsg.top.ble.BleManager$btStateReceiver$1 v0_32 = kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow(0); this._targetSessionMac = v0_32; this.targetSessionMac = kotlinx.coroutines.flow.FlowKt.asStateFlow(v0_32); qbsg.top.ble.BleManager$btStateReceiver$1 v0_36 = kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow(qbsg.top.ble.data.BleScanState.Idle); this._scanState = v0_36; this.scanState = kotlinx.coroutines.flow.FlowKt.asStateFlow(v0_36); qbsg.top.ble.BleManager$btStateReceiver$1 v0_39 = kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow(q6.t.c); this._scannedDevices = v0_39; this.scannedDevices = kotlinx.coroutines.flow.FlowKt.asStateFlow(v0_39); String v2_10 = kotlinx.coroutines.flow.SharedFlowKt.MutableSharedFlow$default(0, 16, 0, 5, 0); this._rawScanResults = v2_10; this.rawScanResults = kotlinx.coroutines.flow.FlowKt.asSharedFlow(v2_10); String v2_12 = this.getBtAdapter(); if (v2_12 == null) { v2_13 = 0; } else { v2_13 = v2_12.isEnabled(); } String v2_0 = kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow(Boolean.valueOf(v2_13)); this._isBluetoothEnabled = v2_0; this.isBluetoothEnabled = kotlinx.coroutines.flow.FlowKt.asStateFlow(v2_0); String v2_3 = kotlinx.coroutines.flow.SharedFlowKt.MutableSharedFlow$default(0, 8, 0, 5, 0); this._disconnectEvents = v2_3; this.disconnectEvents = kotlinx.coroutines.flow.FlowKt.asSharedFlow(v2_3); qbsg.top.ble.BleManager$btStateReceiver$1 v0_2 = kotlinx.coroutines.flow.SharedFlowKt.MutableSharedFlow$default(0, 64, 0, 5, 0); this._messageEvents = v0_2; this.messageEvents = kotlinx.coroutines.flow.FlowKt.asSharedFlow(v0_2); qbsg.top.ble.BleManager$btStateReceiver$1 v0_5 = new qbsg.top.ble.BleManager$btStateReceiver$1(this); this.btStateReceiver = v0_5; p5.registerReceiver(v0_5, new android.content.IntentFilter("android.bluetooth.adapter.action.STATE_CHANGED")); this.scanCallback = new qbsg.top.ble.BleManager$scanCallback$1(this); this.gattCallback = new qbsg.top.ble.BleManager$gattCallback$1(this); return; } public static synthetic boolean a(qbsg.top.ble.a p0, Object p1) { return qbsg.top.ble.BleManager.cleanupDevice$lambda$1(p0, p1); } public static final synthetic void access$cleanupDevice(qbsg.top.ble.BleManager p0, String p1, boolean p2, qbsg.top.ble.data.DisconnectReason p3) { p0.cleanupDevice(p1, p2, p3); return; } public static final synthetic boolean access$enqueueNotify(qbsg.top.ble.BleManager p0, android.bluetooth.BluetoothGatt p1, android.bluetooth.BluetoothGattCharacteristic p2) { return p0.enqueueNotify(p1, p2); } public static final synthetic java.util.LinkedList access$getDescriptorWriteQueue$p(qbsg.top.ble.BleManager p0) { return p0.descriptorWriteQueue; } public static final synthetic java.util.concurrent.ConcurrentHashMap access$getGatts$p(qbsg.top.ble.BleManager p0) { return p0.gatts; } public static final synthetic java.util.concurrent.ConcurrentHashMap access$getOtaChannels$p(qbsg.top.ble.BleManager p0) { return p0.otaChannels; } public static final synthetic java.util.concurrent.ConcurrentHashMap access$getPendingCccdCount$p(qbsg.top.ble.BleManager p0) { return p0.pendingCccdCount; } public static final synthetic java.util.concurrent.ConcurrentHashMap access$getPendingFirmware$p(qbsg.top.ble.BleManager p0) { return p0.pendingFirmware; } public static final synthetic java.util.concurrent.ConcurrentHashMap access$getReadChannels$p(qbsg.top.ble.BleManager p0) { return p0.readChannels; } public static final synthetic java.util.concurrent.ConcurrentHashMap$KeySetView access$getUserInitiatedDisconnections$p(qbsg.top.ble.BleManager p0) { return p0.userInitiatedDisconnections; } public static final synthetic kotlinx.coroutines.flow.MutableStateFlow access$get_activeDevice$p(qbsg.top.ble.BleManager p0) { return p0._activeDevice; } public static final synthetic kotlinx.coroutines.flow.MutableStateFlow access$get_connections$p(qbsg.top.ble.BleManager p0) { return p0._connections; } public static final synthetic kotlinx.coroutines.flow.MutableSharedFlow access$get_disconnectEvents$p(qbsg.top.ble.BleManager p0) { return p0._disconnectEvents; } public static final synthetic kotlinx.coroutines.flow.MutableStateFlow access$get_isBluetoothEnabled$p(qbsg.top.ble.BleManager p0) { return p0._isBluetoothEnabled; } public static final synthetic kotlinx.coroutines.flow.MutableSharedFlow access$get_messageEvents$p(qbsg.top.ble.BleManager p0) { return p0._messageEvents; } public static final synthetic kotlinx.coroutines.flow.MutableSharedFlow access$get_rawScanResults$p(qbsg.top.ble.BleManager p0) { return p0._rawScanResults; } public static final synthetic kotlinx.coroutines.flow.MutableStateFlow access$get_scanState$p(qbsg.top.ble.BleManager p0) { return p0._scanState; } public static final synthetic kotlinx.coroutines.flow.MutableStateFlow access$get_scannedDevices$p(qbsg.top.ble.BleManager p0) { return p0._scannedDevices; } public static final synthetic kotlinx.coroutines.flow.MutableStateFlow access$get_targetSessionMac$p(qbsg.top.ble.BleManager p0) { return p0._targetSessionMac; } public static final synthetic void access$processDescriptorQueue(qbsg.top.ble.BleManager p0) { p0.processDescriptorQueue(); return; } public static final synthetic Object access$readDeviceInfoString(qbsg.top.ble.BleManager p0, android.bluetooth.BluetoothGatt p1, String p2, java.util.UUID p3, kotlin.coroutines.Continuation p4) { return p0.readDeviceInfoString(p1, p2, p3, p4); } public static final synthetic void access$setWritingDescriptor$p(qbsg.top.ble.BleManager p0, boolean p1) { p0.isWritingDescriptor = p1; return; } public static final synthetic void access$startDeviceInfoRead(qbsg.top.ble.BleManager p0, android.bluetooth.BluetoothGatt p1) { p0.startDeviceInfoRead(p1); return; } public static final synthetic void access$updateDeviceInfo(qbsg.top.ble.BleManager p0, String p1, String p2) { p0.updateDeviceInfo(p1, p2); return; } public static synthetic boolean b(String p0, qbsg.top.ble.BleManager$DescriptorWriteRequest p1) { return qbsg.top.ble.BleManager.cleanupDevice$lambda$0(p0, p1); } private final void checkPrerequisitesOrThrow() { qbsg.top.ble.data.BleException$BluetoothDisabled v0_1; if (android.os.Build$VERSION.SDK_INT < 31) { v0_1 = k3.t.K("android.permission.ACCESS_FINE_LOCATION"); } else { v0_1 = q6.n.Y(new String[] {"android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT"})); } java.util.ArrayList v1_2 = new java.util.ArrayList(); qbsg.top.ble.data.BleException$BluetoothDisabled v0_2 = v0_1.iterator(); while (v0_2.hasNext()) { Object v2_1 = v0_2.next(); if (this.context.checkSelfPermission(((String) v2_1)) != 0) { v1_2.add(v2_1); } } if (!v1_2.isEmpty()) { throw new qbsg.top.ble.data.BleException$PermissionDenied(v1_2); } else { if (!this.getBtAdapter().isEnabled()) { throw new qbsg.top.ble.data.BleException$BluetoothDisabled(); } else { return; } } } private final void cleanupDevice(String p7, boolean p8, qbsg.top.ble.data.DisconnectReason p9) { this.userInitiatedDisconnections.remove(p7); kotlinx.coroutines.flow.MutableStateFlow v0_24 = ((kotlinx.coroutines.Job) this.deviceInfoReadJobs.remove(p7)); String v2 = 0; if (v0_24 != null) { kotlinx.coroutines.Job$DefaultImpls.cancel$default(v0_24, 0, 1, 0); } this.pendingFirmware.remove(p7); this.pendingCccdCount.remove(p7); kotlinx.coroutines.flow.MutableStateFlow v0_12 = ((kotlinx.coroutines.channels.Channel) this.readChannels.remove(p7)); if (v0_12 != null) { kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(v0_12, 0, 1, 0); } kotlinx.coroutines.flow.MutableStateFlow v0_16 = ((android.bluetooth.BluetoothGatt) this.gatts.get(p7)); if (v0_16 != null) { v0_16.close(); } this.gatts.remove(p7); this.descriptorWriteQueue.removeIf(new qbsg.top.ble.b(new qbsg.top.ble.a(p7))); if (this.descriptorWriteQueue.isEmpty()) { this.isWritingDescriptor = 0; } kotlinx.coroutines.flow.MutableStateFlow v0_23 = this._connections; do { int v3_3 = v0_23.getValue(); java.util.Map v4_3 = ((java.util.Map) v3_3); kotlin.jvm.internal.s.f(v4_3, ""); java.util.Map v4_4 = q6.y.c0(v4_3); v4_4.remove(p7); int v5_1 = v4_4.size(); if (v5_1 == 0) { v4_4 = q6.u.c; } else { if (v5_1 == 1) { v4_4 = q6.y.d0(v4_4); } } } while(!v0_23.compareAndSet(v3_3, v4_4)); kotlinx.coroutines.flow.MutableStateFlow v0_28; kotlinx.coroutines.flow.MutableStateFlow v0_27 = ((qbsg.top.ble.data.BleDeviceInfo) this._activeDevice.getValue()); if (v0_27 == null) { v0_28 = 0; } else { v0_28 = v0_27.getAddress(); } if (kotlin.jvm.internal.s.b(v0_28, p7)) { kotlinx.coroutines.flow.MutableStateFlow v0_35 = ((Iterable) ((java.util.Map) this._connections.getValue()).values()).iterator(); while (v0_35.hasNext()) { kotlinx.coroutines.flow.MutableStateFlow v1_7 = v0_35.next(); if ((((qbsg.top.ble.data.BleConnectionInfo) v1_7).getState() instanceof qbsg.top.ble.data.DeviceConnectionState$Connected)) { } kotlinx.coroutines.flow.MutableStateFlow v0_36; kotlinx.coroutines.flow.MutableStateFlow v1_8 = ((qbsg.top.ble.data.BleConnectionInfo) v1_7); if (v1_8 == null) { v0_36 = 0; } else { v0_36 = v1_8.getDevice(); } int v3_0; kotlinx.coroutines.flow.MutableStateFlow v1_9 = this._targetSessionMac; if (v0_36 == null) { v3_0 = 0; } else { v3_0 = v0_36.getAddress(); } v1_9.setValue(v3_0); this._activeDevice.setValue(v0_36); } v1_7 = 0; } if (kotlin.jvm.internal.s.b(this._targetSessionMac.getValue(), p7)) { int v7_7 = ((Iterable) ((java.util.Map) this._connections.getValue()).values()).iterator(); while (v7_7.hasNext()) { kotlinx.coroutines.flow.MutableStateFlow v0_6 = v7_7.next(); if ((((qbsg.top.ble.data.BleConnectionInfo) v0_6).getState() instanceof qbsg.top.ble.data.DeviceConnectionState$Connected)) { } int v7_8; kotlinx.coroutines.flow.MutableStateFlow v0_7 = ((qbsg.top.ble.data.BleConnectionInfo) v0_6); if (v0_7 == null) { v7_8 = 0; } else { v7_8 = v0_7.getDevice(); } kotlinx.coroutines.flow.MutableStateFlow v0_8 = this._targetSessionMac; if (v7_8 != 0) { v2 = v7_8.getAddress(); } v0_8.setValue(v2); this._activeDevice.setValue(v7_8); } v0_6 = 0; } if ((p8) && (p9 != null)) { this._disconnectEvents.tryEmit(p9); } return; } public static synthetic void cleanupDevice$default(qbsg.top.ble.BleManager p0, String p1, boolean p2, qbsg.top.ble.data.DisconnectReason p3, int p4, Object p5) { if ((p4 & 2) != 0) { p2 = 0; } if ((p4 & 4) != 0) { p3 = 0; } p0.cleanupDevice(p1, p2, p3); return; } private static final boolean cleanupDevice$lambda$0(String p0, qbsg.top.ble.BleManager$DescriptorWriteRequest p1) { return kotlin.jvm.internal.s.b(p1.getGatt().getDevice().getAddress(), p0); } private static final boolean cleanupDevice$lambda$1(a7.c p0, Object p1) { return ((Boolean) p0.invoke(p1)).booleanValue(); } private final boolean enqueueNotify(android.bluetooth.BluetoothGatt p5, android.bluetooth.BluetoothGattCharacteristic p6) { p5.setCharacteristicNotification(p6, 1); android.bluetooth.BluetoothGattDescriptor v1_1 = p6.getDescriptor(qbsg.top.ble.BleManagerKt.access$getCCCD_UUID$p()); if (v1_1 != null) { byte[] v6_1; if ((p6.getProperties() & 32) == 0) { v6_1 = android.bluetooth.BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE; } else { v6_1 = android.bluetooth.BluetoothGattDescriptor.ENABLE_INDICATION_VALUE; } java.util.LinkedList v2 = this.descriptorWriteQueue; kotlin.jvm.internal.s.c(v6_1); v2.add(new qbsg.top.ble.BleManager$DescriptorWriteRequest(p5, v1_1, v6_1)); this.processDescriptorQueue(); return 1; } else { return 0; } } private final android.bluetooth.BluetoothAdapter getBtAdapter() { return this.btManager.getAdapter(); } private final void processDescriptorQueue() { if ((!this.isWritingDescriptor) && (!this.descriptorWriteQueue.isEmpty())) { java.util.LinkedList v0_9 = ((qbsg.top.ble.BleManager$DescriptorWriteRequest) this.descriptorWriteQueue.peek()); if (v0_9 != null) { int v1_0 = 1; this.isWritingDescriptor = 1; if (android.os.Build$VERSION.SDK_INT < 33) { v0_9.getDesc().setValue(v0_9.getValue()); v1_0 = v0_9.getGatt().writeDescriptor(v0_9.getDesc()); } else { if (b.b.b(v0_9.getGatt(), v0_9.getDesc(), v0_9.getValue()) != 0) { v1_0 = 0; } } if (v1_0 == 0) { this.descriptorWriteQueue.poll(); this.isWritingDescriptor = 0; this.processDescriptorQueue(); } } } return; } private final Object readDeviceInfoString(android.bluetooth.BluetoothGatt p12, String p13, java.util.UUID p14, kotlin.coroutines.Continuation p15) { qbsg.top.ble.BleManager$readDeviceInfoString$1 v0_2; if (!(p15 instanceof qbsg.top.ble.BleManager$readDeviceInfoString$1)) { v0_2 = new qbsg.top.ble.BleManager$readDeviceInfoString$1(this, p15); } else { v0_2 = ((qbsg.top.ble.BleManager$readDeviceInfoString$1) p15); Object v1_2 = ((qbsg.top.ble.BleManager$readDeviceInfoString$1) p15).label; if ((v1_2 & -2147483648) == 0) { } else { ((qbsg.top.ble.BleManager$readDeviceInfoString$1) p15).label = (v1_2 - -2147483648); } } Object v12_16; android.bluetooth.BluetoothGattCharacteristic v8_1; Object v15_6; Object v13_10; int v14_2; long v6_3; Object v15_1 = v0_2.result; Object v1_1 = kotlin.coroutines.intrinsics.IntrinsicsKt.getCOROUTINE_SUSPENDED(); qbsg.top.ble.BleManager$readDeviceInfoString$result$1 v2_3 = v0_2.label; int v4 = 1; if (v2_3 == null) { q6.y.Y(v15_1); Object v15_3 = p12.getServices(); kotlin.jvm.internal.s.e(v15_3, "getServices(...)"); qbsg.top.ble.BleManager$readDeviceInfoString$result$1 v2_6 = new java.util.ArrayList(); Object v15_4 = v15_3.iterator(); while (v15_4.hasNext()) { long v6_6 = ((android.bluetooth.BluetoothGattService) v15_4.next()).getCharacteristics(); kotlin.jvm.internal.s.e(v6_6, "getCharacteristics(...)"); q6.o.f0(v2_6, v6_6); } Object v15_5 = v2_6.size(); v6_3 = 0; j7.d v7_0 = 0; while (v7_0 < v15_5) { android.bluetooth.BluetoothGattCharacteristic v8_0 = v2_6.get(v7_0); v7_0++; if (kotlin.jvm.internal.s.b(((android.bluetooth.BluetoothGattCharacteristic) v8_0).getUuid(), p14)) { } v8_1 = ((android.bluetooth.BluetoothGattCharacteristic) v8_0); if (v8_1 != null) { v15_6 = p14; v14_2 = p13; v13_10 = p12; v12_16 = 0; if (v12_16 >= 3) { v4 = v6_3; if (v4 != 0) { Object v12_3 = ((kotlinx.coroutines.channels.Channel) this.readChannels.get(v14_2)); if (v12_3 != null) { long v6_1 = j7.h.m(4, j7.d.f); qbsg.top.ble.BleManager$readDeviceInfoString$result$1 v2_2 = new qbsg.top.ble.BleManager$readDeviceInfoString$result$1(v12_3, v15_6, 0); v0_2.L$0 = kotlin.coroutines.jvm.internal.SpillingKt.nullOutSpilledVariable(v13_10); v0_2.L$1 = kotlin.coroutines.jvm.internal.SpillingKt.nullOutSpilledVariable(v14_2); v0_2.L$2 = kotlin.coroutines.jvm.internal.SpillingKt.nullOutSpilledVariable(v15_6); v0_2.L$3 = kotlin.coroutines.jvm.internal.SpillingKt.nullOutSpilledVariable(v8_1); v0_2.L$4 = kotlin.coroutines.jvm.internal.SpillingKt.nullOutSpilledVariable(v12_3); v0_2.I$0 = v4; v0_2.label = 2; v15_1 = kotlinx.coroutines.TimeoutKt.withTimeoutOrNull-KLykuaI(v6_1, v2_2, v0_2); if (v15_1 != v1_1) { Object v15_2 = ((p6.g) v15_1); if (v15_2 != null) { Object v12_13 = ((byte[]) v15_2.d); if (v12_13.length != 0) { Object v12_15 = i7.i.S0(new String(v12_13, i7.a.a)).toString(); if (v12_15.length() != 0) { return v12_15; } } } return 0; } } } } else { if (!v13_10.readCharacteristic(v8_1)) { long v9_4 = j7.h.m(120, j7.d.e); v0_2.L$0 = v13_10; v0_2.L$1 = v14_2; v0_2.L$2 = v15_6; v0_2.L$3 = v8_1; v0_2.I$0 = v6_3; v0_2.I$1 = v12_16; v0_2.label = 1; if (kotlinx.coroutines.DelayKt.delay-VtjQ1oo(v9_4, v0_2) == v1_1) { } } } return v1_1; } } v8_0 = 0; } else { if (v2_3 == 1) { v12_16 = v0_2.I$1; Object v13_11 = v0_2.I$0; int v14_4 = ((android.bluetooth.BluetoothGattCharacteristic) v0_2.L$3); qbsg.top.ble.BleManager$readDeviceInfoString$result$1 v2_9 = ((java.util.UUID) v0_2.L$2); long v6_8 = ((String) v0_2.L$1); j7.d v7_3 = ((android.bluetooth.BluetoothGatt) v0_2.L$0); q6.y.Y(v15_1); v8_1 = v14_4; v15_6 = v2_9; v14_2 = v6_8; v6_3 = v13_11; v13_10 = v7_3; do { v12_16++; } while(v4 != 0); } else { if (v2_3 != 2) { throw new IllegalStateException("call to \'resume\' before \'invoke\' with coroutine"); } else { p12 = ((android.bluetooth.BluetoothGattCharacteristic) v0_2.L$3); p12 = ((String) v0_2.L$1); q6.y.Y(v15_1); } } } return 0; } private final void startDeviceInfoRead(android.bluetooth.BluetoothGatt p9) { String v0_1 = p9.getDevice().getAddress(); java.util.concurrent.ConcurrentHashMap v1_4 = ((kotlinx.coroutines.Job) this.deviceInfoReadJobs.get(v0_1)); if ((v1_4 == null) || (v1_4.isActive() != 1)) { this.deviceInfoReadJobs.put(v0_1, kotlinx.coroutines.BuildersKt.launch$default(this.scope, 0, 0, new qbsg.top.ble.BleManager$startDeviceInfoRead$1(this, v0_1, p9, 0), 3, 0)); return; } else { return; } } private final void updateDeviceInfo(String p20, String p21) { kotlinx.coroutines.flow.MutableStateFlow v2 = this._connections; do { boolean v3_0 = v2.getValue(); java.util.Map v4_1 = ((java.util.Map) v3_0); qbsg.top.ble.data.BleConnectionInfo v5_2 = ((qbsg.top.ble.data.BleConnectionInfo) v4_1.get(p20)); if (v5_2 != null) { int v7_0; if (p21 != null) { v7_0 = p21; } else { v7_0 = "\u672a\u77e5"; } String v13; if (!v7_0.equals("\u672a\u77e5")) { v13 = v7_0; } else { v13 = 0; } int v7_4; p6.g v6_2 = qbsg.top.ble.data.BleDeviceInfo.copy$default(v5_2.getDevice(), 0, 0, 0, v13, 0, 0, 0, 119, 0); int v7_3 = ((qbsg.top.ble.data.BleDeviceInfo) this._activeDevice.getValue()); if (v7_3 == 0) { v7_4 = 0; } else { v7_4 = v7_3.getAddress(); } if (kotlin.jvm.internal.s.b(v7_4, p20)) { this._activeDevice.setValue(v6_2); } v4_1 = q6.y.L(v4_1, new p6.g(p20, qbsg.top.ble.data.BleConnectionInfo.copy$default(v5_2, v6_2, 0, 2, 0))); } } while(!v2.compareAndSet(v3_0, v4_1)); return; } public void closeOtaChannel(String p2) { kotlin.jvm.internal.s.f(p2, "address"); this.otaChannels.remove(p2); return; } public void connect(qbsg.top.ble.data.BleDeviceInfo p7) { kotlin.jvm.internal.s.f(p7, "device"); this.checkPrerequisitesOrThrow(); if (!this.gatts.containsKey(p7.getAddress())) { android.bluetooth.BluetoothGatt v0_6 = this._connections; do { java.util.concurrent.ConcurrentHashMap v1_0 = v0_6.getValue(); } while(!v0_6.compareAndSet(v1_0, q6.y.L(((java.util.Map) v1_0), new p6.g(p7.getAddress(), new qbsg.top.ble.data.BleConnectionInfo(p7, qbsg.top.ble.data.DeviceConnectionState$Connecting.INSTANCE))))); this.gatts.put(p7.getAddress(), this.getBtAdapter().getRemoteDevice(p7.getAddress()).connectGatt(this.context, 0, this.gattCallback, 2)); return; } else { return; } } public void destroy() { try { this.context.unregisterReceiver(this.btStateReceiver); } catch (Exception) { } java.util.Iterator v0_4 = this.gatts.keySet(); kotlin.jvm.internal.s.e(v0_4, "(...)"); java.util.Iterator v0_2 = q6.o.G0(((Iterable) v0_4)).iterator(); } public void disconnect(String p9) { kotlin.jvm.internal.s.f(p9, "address"); android.bluetooth.BluetoothGatt v0_3 = ((android.bluetooth.BluetoothGatt) this.gatts.get(p9)); if (v0_3 != null) { boolean v1_3; boolean v1_2 = ((qbsg.top.ble.data.BleConnectionInfo) ((java.util.Map) this._connections.getValue()).get(p9)); if (!v1_2) { v1_3 = 0; } else { v1_3 = v1_2.getState(); } if (!(v1_3 instanceof qbsg.top.ble.data.DeviceConnectionState$Connecting)) { this.userInitiatedDisconnections.add(p9); v0_3.disconnect(); return; } else { qbsg.top.ble.BleManager.cleanupDevice$default(this, p9, 0, 0, 4, 0); return; } } else { return; } } public kotlinx.coroutines.flow.StateFlow getActiveDevice() { return this.activeDevice; } public kotlinx.coroutines.flow.StateFlow getConnections() { return this.connections; } public kotlinx.coroutines.flow.SharedFlow getDisconnectEvents() { return this.disconnectEvents; } public String getId() { return this.id; } public kotlinx.coroutines.flow.SharedFlow getMessageEvents() { return this.messageEvents; } public a8.h getOtaManager() { return this.otaManager; } public kotlinx.coroutines.flow.SharedFlow getRawScanResults() { return this.rawScanResults; } public kotlinx.coroutines.flow.StateFlow getScanState() { return this.scanState; } public kotlinx.coroutines.flow.StateFlow getScannedDevices() { return this.scannedDevices; } public kotlinx.coroutines.flow.StateFlow getTargetSessionMac() { return this.targetSessionMac; } public kotlinx.coroutines.flow.StateFlow isBluetoothEnabled() { return this.isBluetoothEnabled; } public qbsg.top.ble.GattOtaChannel openOtaChannel(String p3) { kotlin.jvm.internal.s.f(p3, "address"); java.util.concurrent.ConcurrentHashMap v0_3 = ((android.bluetooth.BluetoothGatt) this.gatts.get(p3)); if (v0_3 != null) { qbsg.top.ble.BleManager$AndroidGattOtaChannel v1_1 = new qbsg.top.ble.BleManager$AndroidGattOtaChannel(this, v0_3); this.otaChannels.put(p3, v1_1); return v1_1; } else { return 0; } } public void setActiveFocus(qbsg.top.ble.data.BleDeviceInfo p3) { kotlin.jvm.internal.s.f(p3, "device"); qbsg.top.ble.data.BleDeviceInfo v0_1 = ((qbsg.top.ble.data.BleConnectionInfo) ((java.util.Map) this._connections.getValue()).get(p3.getAddress())); if ((v0_1 != null) && ((v0_1.getState() instanceof qbsg.top.ble.data.DeviceConnectionState$Connected))) { this._targetSessionMac.setValue(p3.getAddress()); this._activeDevice.setValue(v0_1.getDevice()); } return; } public boolean setBluetoothEnabled(boolean p2) { throw new p6.f("An operation is not implemented: Not yet implemented"); } public void setOtaManager(a8.h p1) { this.otaManager = p1; return; } public void startScan() { this.checkPrerequisitesOrThrow(); int v1_1 = qbsg.top.ble.data.BleScanState.Scanning; if (this._scanState.getValue() != v1_1) { this._scannedDevices.setValue(q6.t.c); this._scanState.setValue(v1_1); android.bluetooth.le.BluetoothLeScanner v0_2 = this.getBtAdapter().getBluetoothLeScanner(); if (v0_2 != null) { v0_2.startScan(0, new android.bluetooth.le.ScanSettings$Builder().setScanMode(2).build(), this.scanCallback); } kotlinx.coroutines.BuildersKt.launch$default(this.scope, 0, 0, new qbsg.top.ble.BleManager$startScan$1(this, 0), 3, 0); return; } else { return; } } public void stopScan() { if (this._scanState.getValue() == qbsg.top.ble.data.BleScanState.Scanning) { try { android.bluetooth.le.BluetoothLeScanner v0_5 = this.getBtAdapter(); } catch (Exception) { this._scanState.setValue(qbsg.top.ble.data.BleScanState.Idle); return; } if ((v0_5 == null) || (v0_5.isEnabled() != 1)) { this._scanState.setValue(qbsg.top.ble.data.BleScanState.Idle); return; } else { android.bluetooth.le.BluetoothLeScanner v0_2 = this.getBtAdapter().getBluetoothLeScanner(); if (v0_2 == null) { this._scanState.setValue(qbsg.top.ble.data.BleScanState.Idle); return; } else { v0_2.stopScan(this.scanCallback); this._scanState.setValue(qbsg.top.ble.data.BleScanState.Idle); return; } } } else { return; } } public void updateDeviceType(String p17, w7.y p18) { kotlin.jvm.internal.s.f(p17, "address"); kotlinx.coroutines.flow.MutableStateFlow v2_1 = this._connections; do { boolean v3_1 = v2_1.getValue(); java.util.Map v4_0 = ((java.util.Map) v3_1); qbsg.top.ble.data.BleConnectionInfo v5_1 = ((qbsg.top.ble.data.BleConnectionInfo) v4_0.get(p17)); if (v5_1 != null) { int v7_4; p6.g v6_1 = qbsg.top.ble.data.BleDeviceInfo.copy$default(v5_1.getDevice(), 0, 0, 0, 0, 0, p18, 0, 95, 0); int v7_3 = ((qbsg.top.ble.data.BleDeviceInfo) this._activeDevice.getValue()); if (v7_3 == 0) { v7_4 = 0; } else { v7_4 = v7_3.getAddress(); } if (kotlin.jvm.internal.s.b(v7_4, p17)) { this._activeDevice.setValue(v6_1); } v4_0 = q6.y.L(v4_0, new p6.g(p17, qbsg.top.ble.data.BleConnectionInfo.copy$default(v5_1, v6_1, 0, 2, 0))); } } while(!v2_1.compareAndSet(v3_1, v4_0)); return; } public void updateScreenSize(String p17, String p18) { kotlin.jvm.internal.s.f(p17, "address"); String v8 = p18; kotlin.jvm.internal.s.f(p18, "screenSize"); kotlinx.coroutines.flow.MutableStateFlow v2_2 = this._connections; while(true) { Object v13 = v2_2.getValue(); java.util.Map v14_1 = ((java.util.Map) v13); qbsg.top.ble.data.BleConnectionInfo v15_1 = ((qbsg.top.ble.data.BleConnectionInfo) v14_1.get(p17)); if (v15_1 != null) { p6.g v4_4; qbsg.top.ble.data.BleConnectionInfo v3_2 = qbsg.top.ble.data.BleDeviceInfo.copy$default(v15_1.getDevice(), 0, 0, 0, 0, v8, 0, 0, 111, 0); p6.g v4_3 = ((qbsg.top.ble.data.BleDeviceInfo) this._activeDevice.getValue()); if (v4_3 == null) { v4_4 = 0; } else { v4_4 = v4_3.getAddress(); } if (kotlin.jvm.internal.s.b(v4_4, p17)) { this._activeDevice.setValue(v3_2); } v14_1 = q6.y.L(v14_1, new p6.g(p17, qbsg.top.ble.data.BleConnectionInfo.copy$default(v15_1, v3_2, 0, 2, 0))); } if (v2_2.compareAndSet(v13, v14_1)) { break; } v8 = p18; } return; } public void updateSelectPhase(String p17, w7.x p18) { kotlin.jvm.internal.s.f(p17, "address"); w7.x v10 = p18; kotlin.jvm.internal.s.f(p18, "phase"); kotlinx.coroutines.flow.MutableStateFlow v2_2 = this._connections; while(true) { Object v13 = v2_2.getValue(); java.util.Map v14_1 = ((java.util.Map) v13); qbsg.top.ble.data.BleConnectionInfo v15_1 = ((qbsg.top.ble.data.BleConnectionInfo) v14_1.get(p17)); if (v15_1 != null) { p6.g v4_4; qbsg.top.ble.data.BleConnectionInfo v3_2 = qbsg.top.ble.data.BleDeviceInfo.copy$default(v15_1.getDevice(), 0, 0, 0, 0, 0, 0, v10, 63, 0); p6.g v4_3 = ((qbsg.top.ble.data.BleDeviceInfo) this._activeDevice.getValue()); if (v4_3 == null) { v4_4 = 0; } else { v4_4 = v4_3.getAddress(); } if (kotlin.jvm.internal.s.b(v4_4, p17)) { this._activeDevice.setValue(v3_2); } v14_1 = q6.y.L(v14_1, new p6.g(p17, qbsg.top.ble.data.BleConnectionInfo.copy$default(v15_1, v3_2, 0, 2, 0))); } if (v2_2.compareAndSet(v13, v14_1)) { break; } v10 = p18; } return; } }