Modularize more models/utils (#3182)

This commit is contained in:
Phil Oliver 2025-09-24 11:43:46 -04:00 committed by GitHub
parent 5bb3f73e0d
commit 4eba3e9daf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 656 additions and 629 deletions

View file

@ -21,7 +21,7 @@ import android.app.Application
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import org.meshtastic.core.network.model.NetworkDeviceHardware
import org.meshtastic.core.model.NetworkDeviceHardware
import javax.inject.Inject
class DeviceHardwareJsonDataSource @Inject constructor(private val application: Application) {

View file

@ -22,7 +22,7 @@ import com.geeksville.mesh.database.entity.DeviceHardwareEntity
import com.geeksville.mesh.database.entity.asEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.meshtastic.core.network.model.NetworkDeviceHardware
import org.meshtastic.core.model.NetworkDeviceHardware
import javax.inject.Inject
class DeviceHardwareLocalDataSource

View file

@ -21,7 +21,7 @@ import android.app.Application
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import org.meshtastic.core.network.model.NetworkFirmwareReleases
import org.meshtastic.core.model.NetworkFirmwareReleases
import javax.inject.Inject
class FirmwareReleaseJsonDataSource @Inject constructor(private val application: Application) {

View file

@ -25,7 +25,7 @@ import com.geeksville.mesh.database.entity.asEntity
import dagger.Lazy
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.meshtastic.core.network.model.NetworkFirmwareRelease
import org.meshtastic.core.model.NetworkFirmwareRelease
import javax.inject.Inject
class FirmwareReleaseLocalDataSource @Inject constructor(private val firmwareReleaseDaoLazy: Lazy<FirmwareReleaseDao>) {

View file

@ -18,19 +18,19 @@
package com.geeksville.mesh.repository.bluetooth
import android.bluetooth.BluetoothDevice
import com.geeksville.mesh.util.anonymize
import org.meshtastic.core.model.util.anonymize
/**
* A snapshot in time of the state of the bluetooth subsystem.
*/
/** A snapshot in time of the state of the bluetooth subsystem. */
data class BluetoothState(
/** Whether we have adequate permissions to query bluetooth state */
val hasPermissions: Boolean = false,
/** If we have adequate permissions and bluetooth is enabled */
val enabled: Boolean = false,
/** If enabled, a list of the currently bonded devices */
val bondedDevices: List<BluetoothDevice> = emptyList()
val bondedDevices: List<BluetoothDevice> = emptyList(),
) {
override fun toString(): String =
"BluetoothState(hasPermissions=$hasPermissions, enabled=$enabled, bondedDevices=${bondedDevices.map { it.anonymize }})"
"BluetoothState(hasPermissions=$hasPermissions, enabled=$enabled, bondedDevices=${bondedDevices.map {
it.anonymize
}})"
}

View file

@ -29,7 +29,6 @@ import com.geeksville.mesh.service.BLEConnectionClosing
import com.geeksville.mesh.service.BLEException
import com.geeksville.mesh.service.RadioNotConnectedException
import com.geeksville.mesh.service.SafeBluetooth
import com.geeksville.mesh.util.anonymize
import com.geeksville.mesh.util.exceptionReporter
import com.geeksville.mesh.util.ignoreException
import dagger.assisted.Assisted
@ -37,6 +36,7 @@ import dagger.assisted.AssistedInject
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import org.meshtastic.core.model.util.anonymize
import java.lang.reflect.Method
import java.util.UUID

View file

@ -19,24 +19,22 @@ package com.geeksville.mesh.repository.radio
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
import com.geeksville.mesh.util.anonymize
import org.meshtastic.core.model.util.anonymize
import javax.inject.Inject
/**
* Bluetooth backend implementation.
*/
class BluetoothInterfaceSpec @Inject constructor(
/** Bluetooth backend implementation. */
class BluetoothInterfaceSpec
@Inject
constructor(
private val factory: BluetoothInterfaceFactory,
private val bluetoothRepository: BluetoothRepository,
) : InterfaceSpec<BluetoothInterface>, Logging {
override fun createInterface(rest: String): BluetoothInterface {
return factory.create(rest)
}
) : InterfaceSpec<BluetoothInterface>,
Logging {
override fun createInterface(rest: String): BluetoothInterface = factory.create(rest)
/** Return true if this address is still acceptable. For BLE that means, still bonded */
override fun addressValid(rest: String): Boolean {
val allPaired = bluetoothRepository.state.value.bondedDevices
.map { it.address }.toSet()
val allPaired = bluetoothRepository.state.value.bondedDevices.map { it.address }.toSet()
return if (!allPaired.contains(rest)) {
warn("Ignoring stale bond to ${rest.anonymize}")
false

View file

@ -21,10 +21,8 @@ import com.geeksville.mesh.AdminProtos
import com.geeksville.mesh.ChannelProtos
import com.geeksville.mesh.ConfigKt
import com.geeksville.mesh.ConfigProtos
import com.geeksville.mesh.DataPacket
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.Portnums
import com.geeksville.mesh.Position
import com.geeksville.mesh.TelemetryProtos
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.channel
@ -39,6 +37,8 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.delay
import org.meshtastic.core.model.Channel
import org.meshtastic.core.model.DataPacket
import org.meshtastic.core.model.Position
import kotlin.random.Random
private val defaultLoRaConfig =

View file

@ -31,7 +31,6 @@ import com.geeksville.mesh.concurrent.handledLaunch
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
import com.geeksville.mesh.repository.network.NetworkRepository
import com.geeksville.mesh.service.ConnectionState
import com.geeksville.mesh.util.anonymize
import com.geeksville.mesh.util.ignoreException
import com.geeksville.mesh.util.toRemoteExceptions
import kotlinx.coroutines.CoroutineScope
@ -48,6 +47,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.meshtastic.core.model.util.anonymize
import org.meshtastic.core.prefs.radio.RadioPrefs
import javax.inject.Inject
import javax.inject.Singleton