kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix: replace BluetoothAdapter with repository methods
rodzic
23966b173b
commit
79b98c84b2
|
@ -8,7 +8,6 @@ import android.bluetooth.BluetoothManager
|
|||
import android.companion.CompanionDeviceManager
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.location.LocationManager
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -26,8 +25,6 @@ val Context.companionDeviceManager: CompanionDeviceManager?
|
|||
@SuppressLint("NewApi")
|
||||
get() = getSystemService(Context.COMPANION_DEVICE_SERVICE).takeIf { hasCompanionDeviceApi() } as? CompanionDeviceManager?
|
||||
|
||||
val Context.usbManager: UsbManager get() = requireNotNull(getSystemService(Context.USB_SERVICE) as? UsbManager?) { "USB_SERVICE is not available"}
|
||||
|
||||
val Context.notificationManager: NotificationManager get() = requireNotNull(getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager?)
|
||||
|
||||
val Context.locationManager: LocationManager get() = requireNotNull(getSystemService(Context.LOCATION_SERVICE) as? LocationManager?)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.geeksville.mesh.repository.radio
|
||||
|
||||
import android.app.Application
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.bluetooth.BluetoothGattService
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.concurrent.handledLaunch
|
||||
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
|
||||
import com.geeksville.mesh.service.*
|
||||
import com.geeksville.mesh.util.anonymize
|
||||
import com.geeksville.mesh.util.exceptionReporter
|
||||
|
@ -79,7 +79,7 @@ A variable keepAllPackets, if set to true will suppress this behavior and instea
|
|||
*/
|
||||
class BluetoothInterface @AssistedInject constructor(
|
||||
context: Application,
|
||||
bluetoothAdapter: dagger.Lazy<BluetoothAdapter?>,
|
||||
bluetoothRepository: BluetoothRepository,
|
||||
private val service: RadioInterfaceService,
|
||||
@Assisted val address: String,
|
||||
) : IRadioInterface, Logging {
|
||||
|
@ -136,7 +136,7 @@ class BluetoothInterface @AssistedInject constructor(
|
|||
init {
|
||||
// Note: this call does no comms, it just creates the device object (even if the
|
||||
// device is off/not connected)
|
||||
val device = bluetoothAdapter.get()?.getRemoteDevice(address)
|
||||
val device = bluetoothRepository.getRemoteDevice(address)
|
||||
if (device != null) {
|
||||
info("Creating radio interface service. device=${address.anonymize}")
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.geeksville.mesh.repository.radio
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
|
||||
import com.geeksville.mesh.util.anonymize
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -11,17 +10,15 @@ import javax.inject.Inject
|
|||
*/
|
||||
class BluetoothInterfaceSpec @Inject constructor(
|
||||
private val factory: BluetoothInterfaceFactory,
|
||||
private val bluetoothAdapter: dagger.Lazy<BluetoothAdapter?>
|
||||
|
||||
private val bluetoothRepository: BluetoothRepository,
|
||||
): InterfaceSpec<BluetoothInterface>, Logging {
|
||||
override fun createInterface(rest: String): BluetoothInterface {
|
||||
return factory.create(rest)
|
||||
}
|
||||
|
||||
/** Return true if this address is still acceptable. For BLE that means, still bonded */
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun addressValid(rest: String): Boolean {
|
||||
val allPaired = bluetoothAdapter.get()?.bondedDevices.orEmpty()
|
||||
val allPaired = bluetoothRepository.state.value.bondedDevices
|
||||
.map { it.address }.toSet()
|
||||
return if (!allPaired.contains(rest)) {
|
||||
warn("Ignoring stale bond to ${rest.anonymize}")
|
||||
|
|
Ładowanie…
Reference in New Issue