From 336d283c8226c34a0c41be15a2845af17681260a Mon Sep 17 00:00:00 2001 From: Ludovic Goix Date: Thu, 1 Oct 2020 16:59:34 -0400 Subject: [PATCH] fix packet display in debug panel make the test work with any non US default Locale remove java-lite usage fix a test --- app/build.gradle | 10 +- app/proguard-rules.pro | 11 +- .../java/com/geeksville/mesh/ChannelTest.kt | 4 - .../geeksville/mesh/service/MeshService.kt | 35 ++++- .../main/res/layout/adapter_packet_layout.xml | 128 ++++++++++-------- app/src/main/res/layout/debug_fragment.xml | 5 +- .../java/com/geeksville/mesh/NodeInfoTest.kt | 17 +++ 7 files changed, 134 insertions(+), 76 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8b36f7912..d15185658 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -92,14 +92,15 @@ androidExtensions { // per protobuf-gradle-plugin docs, this is recommended for android protobuf { protoc { - artifact = 'com.google.protobuf:protoc:3.9.0' + artifact = 'com.google.protobuf:protoc:3.13.0' } generateProtoTasks { all().each { task -> task.builtins { java { + // turned off for now so I can use json printing in debug panel // use the smaller android version of the library - option "lite" + //option "lite" } } } @@ -145,11 +146,8 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" - // You need to depend on the lite runtime library, not protobuf-java // For now I'm not using javalite, because I want JSON printing - //implementation 'com.google.protobuf:protobuf-java:3.11.1' - //implementation 'com.google.protobuf:protobuf-java-util:3.11.1' - implementation 'com.google.protobuf:protobuf-javalite:3.13.0' + implementation ('com.google.protobuf:protobuf-java:3.13.0') // For UART access // implementation 'com.google.android.things:androidthings:1.0' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 6ffefad0c..abd97ff52 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -26,18 +26,21 @@ -keepclassmembernames class kotlinx.** { volatile ; } # Needed for protobufs +-keepclassmembers class * extends com.google.protobuf.GeneratedMessageV3 { ; } +-keep class com.geeksville.mesh.**{*;} -keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite { ; } # for kotlinx.serialization -keepattributes *Annotation*, InnerClasses -dontnote kotlinx.serialization.SerializationKt --keep,includedescriptorclasses class com.yourcompany.yourpackage.**$$serializer { *; } # <-- change package name to your app's --keepclassmembers class com.geeksville.mesh.** { # <-- change package name to your app's +-keep,includedescriptorclasses class com.geeksville.mesh.**$$serializer { *; } +-keepclassmembers class com.geeksville.mesh.** { *** Companion; } --keepclasseswithmembers class com.geeksville.mesh.** { # <-- change package name to your app's +-keepclasseswithmembers class com.geeksville.mesh.** { kotlinx.serialization.KSerializer serializer(...); } # Our app is opensource no need to obsfucate --dontobfuscate \ No newline at end of file +-dontobfuscate +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable \ No newline at end of file diff --git a/app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt b/app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt index 02e3cf459..adb8e32c2 100644 --- a/app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt +++ b/app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt @@ -1,7 +1,5 @@ package com.geeksville.mesh - -import androidx.compose.frames.open import androidx.test.ext.junit.runners.AndroidJUnit4 import com.geeksville.mesh.model.Channel import org.junit.Assert @@ -12,11 +10,9 @@ import org.junit.runner.RunWith class ChannelTest { @Test fun channelUrlGood() { - open() // Needed to make Compose think we are inside a Frame val ch = Channel.emulated Assert.assertTrue(ch.getChannelUrl().toString().startsWith(Channel.prefix)) Assert.assertEquals(Channel(ch.getChannelUrl()), ch) } - } \ No newline at end of file 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 2e1cd5eb7..79c14e2d3 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -972,7 +972,12 @@ class MeshService : Service(), Logging { // debug("Recieved: $packet") val p = packet.decoded - val packetToSave = Packet(UUID.randomUUID().toString(), "packet", System.currentTimeMillis(), packet.toString()) + val packetToSave = Packet( + UUID.randomUUID().toString(), + "packet", + System.currentTimeMillis(), + packet.toString() + ) insertPacket(packetToSave) // If the rxTime was not set by the device (because device software was old), guess at a time val rxTime = if (packet.rxTime != 0) packet.rxTime else currentSecond() @@ -1246,7 +1251,12 @@ class MeshService : Service(), Logging { private fun handleRadioConfig(radio: MeshProtos.RadioConfig) { - val packetToSave = Packet(UUID.randomUUID().toString(), "RadioConfig", System.currentTimeMillis(), radio.toString()) + val packetToSave = Packet( + UUID.randomUUID().toString(), + "RadioConfig", + System.currentTimeMillis(), + radio.toString() + ) insertPacket(packetToSave) radioConfig = radio } @@ -1276,7 +1286,12 @@ class MeshService : Service(), Logging { private fun handleNodeInfo(info: MeshProtos.NodeInfo) { debug("Received nodeinfo num=${info.num}, hasUser=${info.hasUser()}, hasPosition=${info.hasPosition()}") - val packetToSave = Packet(UUID.randomUUID().toString(), "NodeInfo", System.currentTimeMillis(), info.toString()) + val packetToSave = Packet( + UUID.randomUUID().toString(), + "NodeInfo", + System.currentTimeMillis(), + info.toString() + ) insertPacket(packetToSave) logAssert(newNodes.size <= 256) // Sanity check to make sure a device bug can't fill this list forever @@ -1288,7 +1303,12 @@ class MeshService : Service(), Logging { * Update the nodeinfo (called from either new API version or the old one) */ private fun handleMyInfo(myInfo: MeshProtos.MyNodeInfo) { - val packetToSave = Packet(UUID.randomUUID().toString(), "MyNodeInfo", System.currentTimeMillis(), myInfo.toString()) + val packetToSave = Packet( + UUID.randomUUID().toString(), + "MyNodeInfo", + System.currentTimeMillis(), + myInfo.toString() + ) insertPacket(packetToSave) setFirmwareUpdateFilename(myInfo) @@ -1338,7 +1358,12 @@ class MeshService : Service(), Logging { private fun handleConfigComplete(configCompleteId: Int) { if (configCompleteId == configNonce) { - val packetToSave = Packet(UUID.randomUUID().toString(), "ConfigComplete", System.currentTimeMillis(), configCompleteId.toString()) + val packetToSave = Packet( + UUID.randomUUID().toString(), + "ConfigComplete", + System.currentTimeMillis(), + configCompleteId.toString() + ) insertPacket(packetToSave) // This was our config request diff --git a/app/src/main/res/layout/adapter_packet_layout.xml b/app/src/main/res/layout/adapter_packet_layout.xml index f1e8beda1..e3f51da40 100644 --- a/app/src/main/res/layout/adapter_packet_layout.xml +++ b/app/src/main/res/layout/adapter_packet_layout.xml @@ -1,68 +1,84 @@ - + android:layout_margin="4dp"> - + android:layout_height="wrap_content"> - + + + + + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" + android:fontFamily="monospace" + android:singleLine="false" + android:textAppearance="@style/TextAppearance.AppCompat.Small" + android:textIsSelectable="true" + android:textSize="8sp" + android:typeface="monospace" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/cloudDownloadIcon" + app:layout_constraintVertical_weight="1" + tools:text="# com.geeksville.mesh.MeshProtos$MeshPacket@1b1ea594\n + decoded {\n + position {\n + altitude: 60\n + battery_level: 81\n + latitude_i: 411111136\n + longitude_i: -711111805\n + time: 1600390966\n + }\n + }\n + from: -1409794164\n + hop_limit: 3\n + id: 1737414295\n + rx_snr: 9.5\n + rx_time: 316400569\n + to: -1409790708" /> - + - + + - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/debug_fragment.xml b/app/src/main/res/layout/debug_fragment.xml index 6aef5a358..9374ae282 100644 --- a/app/src/main/res/layout/debug_fragment.xml +++ b/app/src/main/res/layout/debug_fragment.xml @@ -11,11 +11,14 @@ android:layout_width="0dp" android:layout_height="0dp" android:layout_marginTop="8dp" + android:scrollbarAlwaysDrawVerticalTrack="true" android:scrollbars="vertical" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/clearButton" /> + app:layout_constraintTop_toBottomOf="@+id/clearButton" + tools:itemCount="8" + tools:listitem="@layout/adapter_packet_layout" />