|
@@ -1,4 +1,4 @@
|
|
|
-package com.luojigou.hardware.xiaodou
|
|
|
+package com.luojigou.product.xiaodou
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.app.Service
|
|
@@ -25,8 +25,9 @@ import androidx.core.app.NotificationChannelCompat
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
import androidx.core.app.NotificationManagerCompat
|
|
|
import androidx.core.content.ContextCompat
|
|
|
-import com.luojigou.hardware.xiaodou.ble.XDBLEUtils
|
|
|
-import com.luojigou.hardware.xiaodou.wifi.XDScanWifiInfo
|
|
|
+import com.luojigou.product.xiaodou.ble.XDBLEUtils
|
|
|
+import com.luojigou.product.xiaodou.ble.XDScanBLEDevice
|
|
|
+import com.luojigou.product.xiaodou.wifi.XDScanWifiInfo
|
|
|
import java.util.UUID
|
|
|
import kotlin.concurrent.thread
|
|
|
|
|
@@ -68,7 +69,7 @@ class XDConnectService : Service() {
|
|
|
private val bleChannelName = "BLE-CHANNEL"
|
|
|
}
|
|
|
|
|
|
- private val bluetoothDevices: MutableMap<com.luojigou.hardware.xiaodou.ble.XDScanBLEDevice, BluetoothDevice> = HashMap()
|
|
|
+ private val bluetoothDevices: MutableList<XDScanBLEDevice> = mutableListOf()
|
|
|
|
|
|
private lateinit var bluetoothManager: BluetoothManager
|
|
|
|
|
@@ -90,12 +91,10 @@ class XDConnectService : Service() {
|
|
|
val bleDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
intent.getParcelableExtra(
|
|
|
ACTION_SELECT_BLE_DEVICE_DATA,
|
|
|
- com.luojigou.hardware.xiaodou.ble.XDScanBLEDevice::class.java
|
|
|
+ XDScanBLEDevice::class.java
|
|
|
)
|
|
|
} else {
|
|
|
- intent.getParcelableExtra<com.luojigou.hardware.xiaodou.ble.XDScanBLEDevice>(
|
|
|
- ACTION_SELECT_BLE_DEVICE
|
|
|
- )
|
|
|
+ intent.getParcelableExtra(ACTION_SELECT_BLE_DEVICE)
|
|
|
}
|
|
|
|
|
|
bleDevice?.let { connectBLE(it) }
|
|
@@ -164,19 +163,19 @@ class XDConnectService : Service() {
|
|
|
|
|
|
if (!device.name.startsWith("XiaoDouAI")) return
|
|
|
|
|
|
- val device = com.luojigou.hardware.xiaodou.ble.XDScanBLEDevice(
|
|
|
+ val device = XDScanBLEDevice(
|
|
|
name = device.name ?: "unknown",
|
|
|
bondState = device.bondState.toString(),
|
|
|
rssi = rssi.toString(),
|
|
|
address = device.address,
|
|
|
addressType = device.type.toString(),
|
|
|
+ device = device
|
|
|
)
|
|
|
|
|
|
- if (!bluetoothDevices.contains(device)) {
|
|
|
- bluetoothDevices[device] = result.device
|
|
|
+ if (bluetoothDevices.firstOrNull { it.address == device.address } == null) {
|
|
|
+ bluetoothDevices.add(device)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -265,14 +264,15 @@ class XDConnectService : Service() {
|
|
|
private fun sendResult() {
|
|
|
val intent = Intent(ACTION_SCAN_RESULT)
|
|
|
intent.putParcelableArrayListExtra(
|
|
|
- ACTION_SCAN_RESULT_DATA, ArrayList(bluetoothDevices.keys)
|
|
|
+ ACTION_SCAN_RESULT_DATA, ArrayList(bluetoothDevices)
|
|
|
)
|
|
|
sendBroadcast(intent)
|
|
|
}
|
|
|
|
|
|
- private fun connectBLE(device: com.luojigou.hardware.xiaodou.ble.XDScanBLEDevice) {
|
|
|
+ private fun connectBLE(device: XDScanBLEDevice) {
|
|
|
broadcastUpdate(ACTION_CONNECT_BLE)
|
|
|
- val bleDevice = bluetoothDevices[device] ?: return
|
|
|
+ val bleDevice = bluetoothDevices.firstOrNull { it.address == device.address }?.device
|
|
|
+ ?: return
|
|
|
|
|
|
bluetoothGatt = bleDevice.connectGatt(
|
|
|
this,
|