From d2273b8d5b2ed0b4a14991a869fd70bb7d350f5f Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 29 Aug 2020 19:07:29 -0700 Subject: [PATCH] fix an autobug. Someone with a galaxy tab is trying to open the old version of the URL. Caused by java.net.MalformedURLException: Not a meshtastic URL at com.geeksville.mesh.model.Channel$Companion.urlToSettings(Channel.java:43) at com.geeksville.mesh.model.Channel$Companion.access$urlToSettings(Channel.java:19) at com.geeksville.mesh.model.Channel.(Channel.java:50) at com.geeksville.mesh.MainActivity.perhapsChangeChannel(MainActivity.java:631) at com.geeksville.mesh.MainActivity.handleIntent(MainActivity.java:467) at com.geeksville.mesh.MainActivity.onNewIntent(MainActivity.java:447) at android.app.Activity.performNewIntent(Activity.java:7971) at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1407) at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1420) at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:3838) at android.app.ActivityThread.handleNewIntent(ActivityThread.java:3850) at android.app.servertransaction.NewIntentItem.execute(NewIntentItem.java:53) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2261) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:8107) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) --- app/src/main/java/com/geeksville/mesh/model/Channel.kt | 10 +++++++--- geeksville-androidlib | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/model/Channel.kt b/app/src/main/java/com/geeksville/mesh/model/Channel.kt index cb8c5c1f8..a1e568d42 100644 --- a/app/src/main/java/com/geeksville/mesh/model/Channel.kt +++ b/app/src/main/java/com/geeksville/mesh/model/Channel.kt @@ -4,6 +4,7 @@ import android.graphics.Bitmap import android.net.Uri import android.util.Base64 import com.geeksville.mesh.MeshProtos +import com.geeksville.util.anonymize import com.google.zxing.BarcodeFormat import com.google.zxing.MultiFormatWriter import com.journeyapps.barcodescanner.BarcodeEncoder @@ -32,15 +33,18 @@ data class Channel( .setModemConfig(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128).build() ) - const val prefix = "https://www.meshtastic.org/c/#" + private const val prefixRoot = "https://www.meshtastic.org/c/" + const val prefix = "$prefixRoot#" private const val base64Flags = Base64.URL_SAFE + Base64.NO_WRAP private fun urlToSettings(url: Uri): MeshProtos.ChannelSettings { val urlStr = url.toString() - val pathRegex = Regex("$prefix(.*)") + + // Let the path optionally include the # character (or not) so we can work with old URLs generated by old versions of the app + val pathRegex = Regex("$prefixRoot#?(.*)") val (base64) = pathRegex.find(urlStr)?.destructured - ?: throw MalformedURLException("Not a meshtastic URL") + ?: throw MalformedURLException("Not a meshtastic URL: ${urlStr.anonymize(40)}") val bytes = Base64.decode(base64, base64Flags) return MeshProtos.ChannelSettings.parseFrom(bytes) diff --git a/geeksville-androidlib b/geeksville-androidlib index ce2485b63..80d207cb5 160000 --- a/geeksville-androidlib +++ b/geeksville-androidlib @@ -1 +1 @@ -Subproject commit ce2485b63b7fb09c9c506c9afa9531707ab829f3 +Subproject commit 80d207cb51c79601ceaf2b09bc369e5babf06495