diff --git a/app/src/main/java/com/geeksville/mesh/DataPacket.kt b/app/src/main/java/com/geeksville/mesh/DataPacket.kt index 6e991aab4..24d380c04 100644 --- a/app/src/main/java/com/geeksville/mesh/DataPacket.kt +++ b/app/src/main/java/com/geeksville/mesh/DataPacket.kt @@ -2,10 +2,21 @@ package com.geeksville.mesh import android.os.Parcel import android.os.Parcelable -import com.geeksville.mesh.util.readParcelableCompat import kotlinx.parcelize.Parcelize import kotlinx.serialization.Serializable +/** + * Generic [Parcel.readParcelable] Android 13 compatibility extension. + */ +private inline fun Parcel.readParcelableCompat(loader: ClassLoader?): T? { + return if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU) { + @Suppress("DEPRECATION") + readParcelable(loader) + } else { + readParcelable(loader, T::class.java) + } +} + @Parcelize enum class MessageStatus : Parcelable { UNKNOWN, // Not set for this message diff --git a/app/src/main/java/com/geeksville/mesh/NodeInfo.kt b/app/src/main/java/com/geeksville/mesh/NodeInfo.kt index 7c222e5b0..51f39af35 100644 --- a/app/src/main/java/com/geeksville/mesh/NodeInfo.kt +++ b/app/src/main/java/com/geeksville/mesh/NodeInfo.kt @@ -5,7 +5,6 @@ import android.os.Parcelable import androidx.room.Embedded import androidx.room.Entity import androidx.room.PrimaryKey -import com.geeksville.mesh.MeshProtos.User import com.geeksville.mesh.util.GPSFormat import com.geeksville.mesh.util.bearing import com.geeksville.mesh.util.latLongToMeter @@ -13,8 +12,9 @@ import com.geeksville.mesh.util.anonymize import kotlinx.parcelize.Parcelize /** - * Room [Embedded], [Entity] and [PrimaryKey] annotations and imports can be removed when only using the API. - * For details check the AIDL interface in [com.geeksville.mesh.IMeshService] + * Room [Embedded], [Entity] and [PrimaryKey] annotations and imports, as well as any protobuf + * reference [MeshProtos], [TelemetryProtos], [ConfigProtos] can be removed when only using the API. + * For details check the AIDL interface in [com.geeksville.mesh.IMeshService] */ // @@ -34,8 +34,24 @@ data class MeshUser( return "MeshUser(id=${id.anonymize}, longName=${longName.anonymize}, shortName=${shortName.anonymize}, hwModel=${hwModelString}, isLicensed=${isLicensed})" } - fun toProto(): User = User.newBuilder().setId(id).setLongName(longName).setShortName(shortName) - .setHwModel(hwModel).setIsLicensed(isLicensed).build() + /** Create our model object from a protobuf. + */ + constructor(p: MeshProtos.User) : this( + p.id, + p.longName, + p.shortName, + p.hwModel, + p.isLicensed, + ) + + fun toProto(): MeshProtos.User = + MeshProtos.User.newBuilder() + .setId(id) + .setLongName(longName) + .setShortName(shortName) + .setHwModel(hwModel) + .setIsLicensed(isLicensed) + .build() /** a string version of the hardware model, converted into pretty lowercase and changing _ to -, and p to dot * or null if unset diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 121d7d8b8..c3a4002f3 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -1225,15 +1225,9 @@ class MeshService : Service(), Logging { private fun installNodeInfo(info: MeshProtos.NodeInfo) { // Just replace/add any entry updateNodeInfo(info.num) { - if (info.hasUser()) - it.user = - MeshUser( - info.user.id, - info.user.longName, - info.user.shortName, - info.user.hwModel, - info.user.isLicensed - ) + if (info.hasUser()) { + it.user = MeshUser(info.user) + } if (info.hasPosition()) { // For the local node, it might not be able to update its times because it doesn't have a valid GPS reading yet