diff --git a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt index f0bbdcb81..0a4a15d94 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt @@ -18,8 +18,6 @@ package com.geeksville.mesh.repository.radio import android.app.Application -import android.content.SharedPreferences -import androidx.core.content.edit import androidx.lifecycle.Lifecycle import androidx.lifecycle.coroutineScope import com.geeksville.mesh.BuildConfig @@ -29,6 +27,7 @@ import com.geeksville.mesh.android.BinaryLogFile import com.geeksville.mesh.android.BuildUtils import com.geeksville.mesh.android.GeeksvilleApplication import com.geeksville.mesh.android.Logging +import com.geeksville.mesh.android.prefs.RadioPrefs import com.geeksville.mesh.concurrent.handledLaunch import com.geeksville.mesh.repository.bluetooth.BluetoothRepository import com.geeksville.mesh.repository.network.NetworkRepository @@ -61,6 +60,7 @@ import javax.inject.Singleton * Note - this class intentionally dumb. It doesn't understand protobuf framing etc... It is designed to be simple so it * can be stubbed out with a simulated version as needed. */ +@Suppress("LongParameterList") @Singleton class RadioInterfaceService @Inject @@ -70,7 +70,7 @@ constructor( private val bluetoothRepository: BluetoothRepository, private val networkRepository: NetworkRepository, private val processLifecycle: Lifecycle, - @RadioRepositoryQualifier private val prefs: SharedPreferences, + private val radioPrefs: RadioPrefs, private val interfaceFactory: InterfaceFactory, ) : Logging { @@ -81,7 +81,7 @@ constructor( val receivedData: SharedFlow = _receivedData // Thread-safe StateFlow for tracking device address changes - private val _currentDeviceAddressFlow = MutableStateFlow(prefs.getString(DEVADDR_KEY, null)) + private val _currentDeviceAddressFlow = MutableStateFlow(radioPrefs.devAddr) val currentDeviceAddressFlow: StateFlow = _currentDeviceAddressFlow.asStateFlow() private val logSends = false @@ -129,7 +129,6 @@ constructor( } companion object { - const val DEVADDR_KEY = "devAddr2" // the new name for devaddr private const val HEARTBEAT_INTERVAL_MILLIS = 5 * 60 * 1000L } @@ -167,7 +166,7 @@ constructor( */ fun getDeviceAddress(): String? { // If the user has unpaired our device, treat things as if we don't have one - var address = prefs.getString(DEVADDR_KEY, null) + var address = radioPrefs.devAddr // If we are running on the emulator we default to the mock interface, so we can have some data to show to the // user @@ -309,13 +308,8 @@ constructor( debug("Setting bonded device to ${address.anonymize}") - prefs.edit { - if (address == null) { - this.remove(DEVADDR_KEY) - } else { - putString(DEVADDR_KEY, address) - } - } + // Stores the address if non-null, otherwise removes the pref + radioPrefs.devAddr = address _currentDeviceAddressFlow.value = address // Force the service to reconnect diff --git a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt index ed22b7ab4..d333d79fa 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt @@ -17,12 +17,8 @@ package com.geeksville.mesh.repository.radio -import android.app.Application -import android.content.Context -import android.content.SharedPreferences import dagger.Binds import dagger.Module -import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import dagger.multibindings.IntoMap @@ -49,11 +45,4 @@ abstract class RadioRepositoryModule { @[Binds IntoMap InterfaceMapKey(InterfaceId.TCP)] abstract fun bindTCPInterfaceSpec(spec: TCPInterfaceSpec): @JvmSuppressWildcards InterfaceSpec<*> - - companion object { - @Provides - @RadioRepositoryQualifier - fun provideSharedPreferences(application: Application): SharedPreferences = - application.getSharedPreferences("radio-prefs", Context.MODE_PRIVATE) - } } diff --git a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryQualifier.kt b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryQualifier.kt deleted file mode 100644 index f7365200f..000000000 --- a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryQualifier.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2025 Meshtastic LLC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.geeksville.mesh.repository.radio - -import javax.inject.Qualifier - -/** - * Qualifier to distinguish radio repository- specific object instances. - */ -@Qualifier -annotation class RadioRepositoryQualifier