Skip to content

Commit 8f8c55e

Browse files
committed
Treat the tox:-intent data as a uri
1 parent 3e8af02 commit 8f8c55e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

atox/src/main/kotlin/MainActivity.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// SPDX-FileCopyrightText: 2019-2024 Robin Lindén <dev@robinlinden.eu>
1+
// SPDX-FileCopyrightText: 2019-2025 Robin Lindén <dev@robinlinden.eu>
22
//
33
// SPDX-License-Identifier: GPL-3.0-only
44

55
package ltd.evilcorp.atox
66

77
import android.content.Intent
8+
import android.net.Uri
89
import android.os.Build
910
import android.os.Bundle
1011
import android.util.Log
@@ -20,9 +21,10 @@ import ltd.evilcorp.atox.settings.Settings
2021
import ltd.evilcorp.atox.ui.contactlist.ARG_SHARE
2122

2223
private const val TAG = "MainActivity"
23-
private const val SCHEME = "tox:"
2424
private const val TOX_ID_LENGTH = 76
2525

26+
private fun isToxUri(uri: Uri) = uri.isOpaque && uri.scheme == "tox" && uri.schemeSpecificPart.length == TOX_ID_LENGTH
27+
2628
class MainActivity : AppCompatActivity() {
2729
@Inject
2830
lateinit var vmFactory: ViewModelFactory
@@ -81,16 +83,16 @@ class MainActivity : AppCompatActivity() {
8183
}
8284

8385
private fun handleToxLinkIntent(intent: Intent) {
84-
val data = intent.dataString ?: ""
86+
val data = intent.data
8587
Log.i(TAG, "Got uri with data: $data")
86-
if (!data.startsWith(SCHEME) || data.length != SCHEME.length + TOX_ID_LENGTH) {
88+
if (data == null || !isToxUri(data)) {
8789
Log.e(TAG, "Got malformed uri: $data")
8890
return
8991
}
9092

9193
supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.findNavController()?.navigate(
9294
R.id.addContactFragment,
93-
bundleOf("toxId" to data.drop(SCHEME.length)),
95+
bundleOf("toxId" to data.schemeSpecificPart),
9496
)
9597
}
9698

0 commit comments

Comments
 (0)