Skip to content

Commit

Permalink
Add deeplink fallback for flipper scheme uri (#983)
Browse files Browse the repository at this point in the history
**Background**

Right now we have bug with deeplink handling on some bad devices

**Changes**

- Add in deeplink parse fallback query segment apply
- Improve logging for deeplink parse

**Test plan**

Try open link from browser. For example,
https://flpr.app/sf/#path=nfc/Volna_11.nfc&key=-9iAwAho85pFALQKZEc2Bg&id=ReRwXA
  • Loading branch information
LionZXY authored Nov 1, 2024
1 parent c3ae42c commit f60966e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Attention: don't forget to add the flag for F-Droid before release
- [FIX] Fix remote-controls duplication ir files
- [FIX] Fix infrared remotes card beta text color
- [FIX] Fix disappeared file manager
- [FIX] Add deeplink fallback for flipper scheme uri
- [FIX] Change description of remotes library card
- [CI] Fix merge-queue files diff
- [CI] Add https://github.com/LionZXY/detekt-decompose-rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.flipperdevices.bridge.dao.api.model.FlipperFilePath
import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.core.ktx.jre.FlipperDispatchers
import com.flipperdevices.core.log.LogTagProvider
import com.flipperdevices.core.log.info
import com.flipperdevices.deeplink.api.DeepLinkParserDelegate
import com.flipperdevices.deeplink.impl.utils.Constants
import com.flipperdevices.deeplink.model.DeepLinkParserDelegatePriority
Expand Down Expand Up @@ -44,13 +45,18 @@ class DeepLinkFlipperFormatSharing @Inject constructor(

override suspend fun fromIntent(context: Context, intent: Intent): Deeplink? {
var pureUri = intent.data ?: return null
info { "Try parse uri $pureUri. ${pureUri.query}${pureUri.fragment}" }

if (pureUri.scheme == SCHEME_FLIPPERKEY) {
val query = pureUri.query
var query = "${pureUri.query}"
if (pureUri.fragment.isNullOrBlank().not()) {
query += "#${pureUri.fragment}"
}
val decodedQuery = withContext(FlipperDispatchers.workStealingDispatcher) {
URLDecoder.decode(query, "UTF-8")
}
pureUri = Uri.parse(decodedQuery)
info { "Found flipper scheme, new uri is $pureUri" }
}

return getUrlDeeplink(pureUri) ?: getCryptoFileDeeplink(pureUri)
Expand All @@ -66,7 +72,11 @@ class DeepLinkFlipperFormatSharing @Inject constructor(
}

private fun getCryptoFileDeeplink(uri: Uri): Deeplink? {
val flipperKeyCrypto = parser.parseUriToCryptoKeyData(uri) ?: return null
val flipperKeyCrypto = parser.parseUriToCryptoKeyData(uri)
if (flipperKeyCrypto == null) {
info { "Failed parse $uri because flipperKeyCrypto is null" }
return null
}

val path = flipperKeyCrypto.pathToKey
val flipperFilePath = FlipperFilePath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.flipperdevices.core.data.PredefinedEnumMap
import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.core.ktx.jre.FlipperDispatchers
import com.flipperdevices.core.log.LogTagProvider
import com.flipperdevices.core.log.info
import com.flipperdevices.core.log.warn
import com.flipperdevices.keyparser.api.KeyParser
import com.flipperdevices.keyparser.api.model.FlipperKeyParsed
Expand Down Expand Up @@ -108,23 +109,29 @@ class KeyParserImpl @Inject constructor() : KeyParser, LogTagProvider {
}

override fun parseUriToCryptoKeyData(uri: Uri): FlipperKeyCrypto? {
val fragment = uri.encodedFragment ?: return null
val fragment = uri.encodedFragment
if (fragment == null) {
info { "Failed parse $uri because fragment is null" }
return null
}
val parsedFragment = urlDecoder.decodeQuery(fragment)

val path = parsedFragment
.firstOrNull { it.first == QUERY_KEY_PATH }
?.second
?: return null

val key = parsedFragment
.firstOrNull { it.first == QUERY_KEY }
?.second
?: return null

val fileId = parsedFragment
.firstOrNull { it.first == QUERY_ID }
?.second
?: return null

if (path == null || key == null || fileId == null) {
info { "Failed parse uri $uri because path, key or fileId is null ($path,$key,$fileId)" }
return null
}

return FlipperKeyCrypto(
fileId = fileId,
Expand Down

0 comments on commit f60966e

Please sign in to comment.