Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deeplink fallback for flipper scheme uri #983

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading