Skip to content

Commit

Permalink
Adds App Store payment support on Calendar App
Browse files Browse the repository at this point in the history
Co-authored-by: André Dias <[email protected]>
  • Loading branch information
mup and andrehgdias committed Nov 28, 2024
1 parent a79aa85 commit 1d37295
Show file tree
Hide file tree
Showing 70 changed files with 1,559 additions and 866 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.ClipData
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.util.Base64
import android.util.Log
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
Expand All @@ -21,6 +22,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.IOException
import java.nio.charset.Charset

class AndroidMobileSystemFacade(
private val fileFacade: AndroidFileFacade,
Expand Down Expand Up @@ -168,4 +170,31 @@ class AndroidMobileSystemFacade(
override suspend fun openMailApp(query: String) {
Log.e(TAG, "Trying to open Tuta Mail from Tuta Mail")
}

private fun tryToLaunchStore() {
try {
startActivity(
activity,
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=de.tutao.calendar")),
null
)
} catch (e: Exception) {
Log.d(TAG, "Failed to launch store $e")
}
}

override suspend fun openCalendarApp(query: String) {
val decodedQuery = Base64.decode(query.toByteArray(), Base64.DEFAULT).toString(Charset.defaultCharset())

val intent = Intent()
intent.setAction(Intent.ACTION_EDIT)
intent.setData(Uri.parse("tutacalendar://interop?${decodedQuery}"))

try {
startActivity(activity, intent, null)
} catch (e: Exception) {
Log.d(TAG, e.toString())
tryToLaunchStore()
}
}
}
9 changes: 9 additions & 0 deletions app-android/calendar/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@

<action android:name="android.intent.action.VIEW"/>
</intent-filter>
<intent-filter>
<data
android:scheme="tutacalendar"
android:host="interop"/>
<action android:name="android.intent.action.EDIT"/>

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter>
<data
android:scheme="tutacalendar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class AndroidMobileSystemFacade(
}
}

fun tryToLaunchStore() {
private fun tryToLaunchStore() {
try {
startActivity(
activity,
Expand All @@ -195,4 +195,8 @@ class AndroidMobileSystemFacade(
tryToLaunchStore()
}
}

override suspend fun openCalendarApp(query: String) {
Log.e(TAG, "Trying to open Tuta Calendar from Tuta Calendar")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ interface CommonNativeFacade {
suspend fun handleFileImport(
filesUris: List<String>,
): Unit
/**
* Open a specified path inside settings
*/
suspend fun openSettings(
path: String,
): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,14 @@ class CommonNativeFacadeSendDispatcher (
this.transport.sendRequest("ipc", listOf(encodedFacade, encodedMethod) + args)
}

override suspend fun openSettings(
path: String,
): Unit
{
val encodedMethod = json.encodeToString("openSettings")
val args : MutableList<String> = mutableListOf()
args.add(json.encodeToString(path))
this.transport.sendRequest("ipc", listOf(encodedFacade, encodedMethod) + args)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ interface MobileSystemFacade {
suspend fun openMailApp(
query: String,
): Unit
suspend fun openCalendarApp(
query: String,
): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class MobileSystemFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}
"openCalendarApp" -> {
val query: String = json.decodeFromString(arg[0])
val result: Unit = this.facade.openCalendarApp(
query,
)
return json.encodeToString(result)
}
else -> throw Error("unknown method for MobileSystemFacade: $method")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@


@file:Suppress("NAME_SHADOWING")

package de.tutao.tutashared.ipc

import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.*
import kotlinx.serialization.json.*

class NativeCryptoFacadeReceiveDispatcher(
private val json: Json,
private val facade: NativeCryptoFacade,
) {

suspend fun dispatch(method: String, arg: List<String>): String {
when (method) {
"rsaEncrypt" -> {
Expand All @@ -26,7 +25,6 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

"rsaDecrypt" -> {
val privateKey: RsaPrivateKey = json.decodeFromString(arg[0])
val data: DataWrapper = json.decodeFromString(arg[1])
Expand All @@ -36,7 +34,6 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

"aesEncryptFile" -> {
val key: DataWrapper = json.decodeFromString(arg[0])
val fileUri: String = json.decodeFromString(arg[1])
Expand All @@ -48,7 +45,6 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

"aesDecryptFile" -> {
val key: DataWrapper = json.decodeFromString(arg[0])
val fileUri: String = json.decodeFromString(arg[1])
Expand All @@ -58,7 +54,6 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

"argon2idGeneratePassphraseKey" -> {
val passphrase: String = json.decodeFromString(arg[0])
val salt: DataWrapper = json.decodeFromString(arg[1])
Expand All @@ -68,15 +63,13 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

"generateKyberKeypair" -> {
val seed: DataWrapper = json.decodeFromString(arg[0])
val result: KyberKeyPair = this.facade.generateKyberKeypair(
seed,
)
return json.encodeToString(result)
}

"kyberEncapsulate" -> {
val publicKey: KyberPublicKey = json.decodeFromString(arg[0])
val seed: DataWrapper = json.decodeFromString(arg[1])
Expand All @@ -86,7 +79,6 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

"kyberDecapsulate" -> {
val privateKey: KyberPrivateKey = json.decodeFromString(arg[0])
val ciphertext: DataWrapper = json.decodeFromString(arg[1])
Expand All @@ -96,7 +88,6 @@ class NativeCryptoFacadeReceiveDispatcher(
)
return json.encodeToString(result)
}

else -> throw Error("unknown method for NativeCryptoFacade: $method")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

package de.tutao.tutashared.ipc

import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.json.*


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

package de.tutao.tutashared.ipc

import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.json.*


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ public protocol CommonNativeFacade {
func handleFileImport(
_ filesUris: [String]
) async throws -> Void
/**
* Open a specified path inside settings
*/
func openSettings(
_ path: String
) async throws -> Void
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ public class CommonNativeFacadeSendDispatcher : CommonNativeFacade {
let _ = try await self.transport.sendRequest(requestType: "ipc", args: [encodedFacadeName, encodedMethodName] + args)
}

public func openSettings(
_ path: String
) async throws -> Void
{
var args = [String]()
args.append(toJson(path))
let encodedFacadeName = toJson("CommonNativeFacade")
let encodedMethodName = toJson("openSettings")
let _ = try await self.transport.sendRequest(requestType: "ipc", args: [encodedFacadeName, encodedMethodName] + args)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ public protocol MobileSystemFacade {
func openMailApp(
_ query: String
) async throws -> Void
func openCalendarApp(
_ query: String
) async throws -> Void
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public class MobileSystemFacadeReceiveDispatcher {
query
)
return "null"
case "openCalendarApp":
let query = try! JSONDecoder().decode(String.self, from: arg[0].data(using: .utf8)!)
try await self.facade.openCalendarApp(
query
)
return "null"
default:
fatalError("licc messed up! \(method)")
}
Expand Down
1 change: 0 additions & 1 deletion app-ios/calendar-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ targets:
name: "build-calendar-app"
type: "folder"
buildPhase: "resources"
- path: "Plans.storekit"
settings:
base:
PRODUCT_MODULE_NAME: "calendar"
Expand Down
Loading

0 comments on commit 1d37295

Please sign in to comment.