Skip to content

Commit 923624f

Browse files
authored
fix: further fixes for fdroid json fallbacks (#3847)
1 parent 5a413d0 commit 923624f

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

core/analytics/src/fdroid/kotlin/org/meshtastic/core/analytics/platform/FdroidPlatformAnalytics.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import javax.inject.Inject
3131
class FdroidPlatformAnalytics @Inject constructor() : PlatformAnalytics {
3232
init {
3333
// For F-Droid builds we don't initialize external analytics services.
34-
// In debug builds we attach a DebugTree for convenient local logging.
34+
// In debug builds we attach a DebugTree for convenient local logging, but
35+
// release builds rely on system logging only.
3536
if (BuildConfig.DEBUG) {
3637
Timber.plant(Timber.DebugTree())
3738
Timber.i("F-Droid platform no-op analytics initialized (DebugTree planted).")

core/data/src/main/kotlin/org/meshtastic/core/data/datasource/DeviceHardwareJsonDataSource.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ import org.meshtastic.core.model.NetworkDeviceHardware
2525
import javax.inject.Inject
2626

2727
class DeviceHardwareJsonDataSource @Inject constructor(private val application: Application) {
28+
29+
// Use a tolerant JSON parser so that additional fields in the bundled asset
30+
// (e.g., "key") do not break deserialization on older app versions.
2831
@OptIn(ExperimentalSerializationApi::class)
29-
fun loadDeviceHardwareFromJsonAsset(): List<NetworkDeviceHardware> {
30-
val inputStream = application.assets.open("device_hardware.json")
31-
return Json.decodeFromStream<List<NetworkDeviceHardware>>(inputStream)
32+
private val json = Json {
33+
ignoreUnknownKeys = true
34+
isLenient = true
3235
}
36+
37+
@OptIn(ExperimentalSerializationApi::class)
38+
fun loadDeviceHardwareFromJsonAsset(): List<NetworkDeviceHardware> =
39+
application.assets.open("device_hardware.json").use { inputStream ->
40+
json.decodeFromStream<List<NetworkDeviceHardware>>(inputStream)
41+
}
3342
}

core/data/src/main/kotlin/org/meshtastic/core/data/datasource/FirmwareReleaseJsonDataSource.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ import org.meshtastic.core.model.NetworkFirmwareReleases
2525
import javax.inject.Inject
2626

2727
class FirmwareReleaseJsonDataSource @Inject constructor(private val application: Application) {
28+
29+
// Match the network client behavior: be tolerant of unknown fields so that
30+
// older app versions can read newer snapshots of firmware_releases.json.
2831
@OptIn(ExperimentalSerializationApi::class)
29-
fun loadFirmwareReleaseFromJsonAsset(): NetworkFirmwareReleases {
30-
val inputStream = application.assets.open("firmware_releases.json")
31-
val result = inputStream.use { Json.decodeFromStream<NetworkFirmwareReleases>(inputStream) }
32-
return result
32+
private val json = Json {
33+
ignoreUnknownKeys = true
34+
isLenient = true
3335
}
36+
37+
@OptIn(ExperimentalSerializationApi::class)
38+
fun loadFirmwareReleaseFromJsonAsset(): NetworkFirmwareReleases =
39+
application.assets.open("firmware_releases.json").use { inputStream ->
40+
json.decodeFromStream<NetworkFirmwareReleases>(inputStream)
41+
}
3442
}

core/data/src/main/kotlin/org/meshtastic/core/data/repository/DeviceHardwareRepository.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ constructor(
123123
private suspend fun loadFromBundledJson(hwModel: Int): Result<DeviceHardware?> = runCatching {
124124
Timber.d("DeviceHardwareRepository: loading device hardware from bundled JSON for hwModel=%d", hwModel)
125125
val jsonHardware = jsonDataSource.loadDeviceHardwareFromJsonAsset()
126-
Timber.d("DeviceHardwareRepository: bundled JSON returned %d device hardware entries", jsonHardware.size)
126+
Timber.d(
127+
"DeviceHardwareRepository: bundled JSON returned %d device hardware entries",
128+
jsonHardware.size,
129+
)
127130

128131
localDataSource.insertAllDeviceHardware(jsonHardware)
129132
val fromDb = localDataSource.getByHwModel(hwModel)?.asExternalModel()
@@ -134,6 +137,15 @@ constructor(
134137
)
135138
fromDb
136139
}
140+
.also { result ->
141+
result.exceptionOrNull()?.let { e ->
142+
Timber.e(
143+
e,
144+
"DeviceHardwareRepository: failed to load device hardware from bundled JSON for hwModel=%d",
145+
hwModel,
146+
)
147+
}
148+
}
137149

138150
/** Returns true if the cached entity is missing important fields and should be refreshed. */
139151
private fun DeviceHardwareEntity.isIncomplete(): Boolean =

0 commit comments

Comments
 (0)