Skip to content

Commit

Permalink
companion device debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Jun 10, 2024
1 parent a6767d3 commit c2be935
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package io.rebble.cobble.bluetooth

import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.companion.CompanionDeviceManager
import android.content.Context
import android.os.Build
import androidx.annotation.RequiresPermission
import io.rebble.cobble.BuildConfig
import io.rebble.cobble.bluetooth.ble.BlueLEDriver
Expand All @@ -17,6 +19,7 @@ import io.rebble.libpebblecommon.ProtocolHandler
import io.rebble.libpebblecommon.protocolhelpers.ProtocolEndpoint
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -40,6 +43,12 @@ class DeviceTransport @Inject constructor(
fun startSingleWatchConnection(macAddress: String): Flow<SingleConnectionStatus> {
bleScanner.stopScan()
classicScanner.stopScan()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val companionDeviceManager = context.getSystemService(CompanionDeviceManager::class.java)
Timber.d("Companion device associated: ${macAddress in companionDeviceManager.associations}, associations: ${companionDeviceManager.associations}")
}

val bluetoothDevice = if (BuildConfig.DEBUG && !macAddress.contains(":")) {
PebbleDevice(null, true, macAddress)
} else {
Expand All @@ -62,8 +71,11 @@ class DeviceTransport @Inject constructor(
incomingPacketsListener.receivedPackets
)
}
btDevice?.type == BluetoothDevice.DEVICE_TYPE_LE/* || btDevice?.type == BluetoothDevice.DEVICE_TYPE_DUAL */-> { // LE device
btDevice?.type == BluetoothDevice.DEVICE_TYPE_LE || btDevice?.type == BluetoothDevice.DEVICE_TYPE_UNKNOWN /* || btDevice?.type == BluetoothDevice.DEVICE_TYPE_DUAL */-> { // LE device
gattServerManager.initIfNeeded()
if (btDevice.type == BluetoothDevice.DEVICE_TYPE_UNKNOWN) {
Timber.w("Device $pebbleDevice has type unknown, assuming LE will work")
}
BlueLEDriver(
context = context,
protocolHandler = protocolHandler,
Expand All @@ -73,7 +85,7 @@ class DeviceTransport @Inject constructor(
flutterPreferences.shouldActivateWorkaround(it)
}
}
btDevice?.type != BluetoothDevice.DEVICE_TYPE_UNKNOWN -> { // Serial only device or serial/LE
btDevice?.type == BluetoothDevice.DEVICE_TYPE_LE || btDevice?.type == BluetoothDevice.DEVICE_TYPE_DUAL -> { // Serial only device or serial/LE
BlueSerialDriver(
protocolHandler,
incomingPacketsListener.receivedPackets
Expand Down

0 comments on commit c2be935

Please sign in to comment.