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

Adds App Store payment support on Calendar App #8043

Open
wants to merge 3 commits into
base: dev-calendar
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ 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
import androidx.core.app.ActivityCompat.startActivityForResult
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.FileProvider
import androidx.fragment.app.FragmentActivity
Expand All @@ -21,6 +23,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 All @@ -33,6 +36,8 @@ class AndroidMobileSystemFacade(
companion object {
private const val TAG = "SystemFacade"
const val APP_LOCK_METHOD = "AppLockMethod"
const val TUTA_INTENT_ACTION = "TUTA_INTEROP"
const val TUTA_INTENT_INTEROP_DATA = "TUTA_INTEROP_DATA"
}

override suspend fun openLink(uri: String): Boolean {
Expand Down Expand Up @@ -168,4 +173,35 @@ class AndroidMobileSystemFacade(
override suspend fun openMailApp(query: String) {
Log.e(TAG, "Trying to open Tuta Mail from Tuta Mail")
}

private fun tryToLaunchStore() {
try {
val packageId = activity.getString(R.string.package_name).replace("tutanota", "calendar")
startActivity(
activity,
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageId")),
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 targetPackageId = activity.getString(R.string.package_name).replace("calendar", "tutanota")

val intent = Intent()
intent.setPackage(targetPackageId)
intent.setAction(Intent.ACTION_EDIT)
intent.putExtra(TUTA_INTENT_ACTION, "interop")
intent.setData(Uri.parse("tutacalendar://interop?$decodedQuery"))

try {
startActivityForResult(activity, intent, 0, null)
} catch (e: Exception) {
Log.d(TAG, e.toString())
tryToLaunchStore()
}
}
}
11 changes: 10 additions & 1 deletion app-android/app/src/main/java/de/tutao/tutanota/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.ComponentName
import android.content.Intent
import android.content.Intent.ACTION_EDIT
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Color
Expand Down Expand Up @@ -453,7 +454,13 @@ class MainActivity : FragmentActivity() {
return@launch
}

if (data != null && data.toString().startsWith("tutamail://") && data.host == "interop") {
val isInteropCall = intent.action == ACTION_EDIT && intent.getStringExtra(TUTA_INTENT_ACTION) == "interop"
val isTrustedCaller = callingPackage == BuildConfig.APPLICATION_ID.replace(
"tutanota",
"calendar"
)

if (data != null && isInteropCall && isTrustedCaller) {
openContactEditor(data)
}

Expand Down Expand Up @@ -804,6 +811,8 @@ class MainActivity : FragmentActivity() {
const val OPEN_CONTACT_EDITOR_CONTACT_ID = "contactId"
const val OPEN_USER_MAILBOX_MAILID_KEY = "mailId"
const val ALREADY_HANDLED_INTENT = "alreadyHandledIntent"
const val TUTA_INTENT_ACTION = "TUTA_INTEROP"

private const val TAG = "MainActivity"
private var requestId = 0

Expand Down
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 @@ -10,6 +10,7 @@ import android.util.Base64
import android.util.Log
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
import androidx.core.app.ActivityCompat.startActivityForResult
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.FileProvider
import androidx.fragment.app.FragmentActivity
Expand All @@ -31,12 +32,13 @@ class AndroidMobileSystemFacade(
private val activity: MainActivity,
private val db: AppDatabase,
) : MobileSystemFacade {

private val authenticationPrompt = AuthenticationPrompt()

companion object {
private const val TAG = "SystemFacade"
const val APP_LOCK_METHOD = "AppLockMethod"
const val TUTA_INTENT_ACTION = "TUTA_INTEROP"
const val TUTA_INTENT_INTEROP_DATA = "TUTA_INTEROP_DATA"
}

override suspend fun openLink(uri: String): Boolean {
Expand Down Expand Up @@ -169,11 +171,12 @@ class AndroidMobileSystemFacade(
}
}

fun tryToLaunchStore() {
private fun tryToLaunchStore() {
try {
val packageId = activity.getString(R.string.package_name).replace("calendar", "tutanota")
startActivity(
activity,
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=de.tutao.tutanota")),
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageId")),
null
)
} catch (e: Exception) {
Expand All @@ -183,16 +186,23 @@ class AndroidMobileSystemFacade(

override suspend fun openMailApp(query: String) {
val decodedQuery = Base64.decode(query.toByteArray(), Base64.DEFAULT).toString(Charset.defaultCharset())
val targetPackageId = activity.getString(R.string.package_name).replace("calendar", "tutanota")

val intent = Intent()
intent.setPackage(targetPackageId)
intent.setAction(Intent.ACTION_EDIT)
intent.setData(Uri.parse("tutamail://interop?${decodedQuery}"))
intent.putExtra(TUTA_INTENT_ACTION, "interop")
intent.setData(Uri.parse("tutamail://interop?$decodedQuery"))

try {
startActivity(activity, intent, null)
startActivityForResult(activity, intent, 0, null)
} catch (e: Exception) {
Log.d(TAG, e.toString())
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
Loading