diff --git a/app-android/app/src/main/java/de/tutao/tutanota/AndroidMobileSystemFacade.kt b/app-android/app/src/main/java/de/tutao/tutanota/AndroidMobileSystemFacade.kt index a6b96f66e039..822165ca6f6a 100644 --- a/app-android/app/src/main/java/de/tutao/tutanota/AndroidMobileSystemFacade.kt +++ b/app-android/app/src/main/java/de/tutao/tutanota/AndroidMobileSystemFacade.kt @@ -4,9 +4,9 @@ import android.Manifest import android.content.ActivityNotFoundException import android.content.ClipData import android.content.Intent -import android.content.Intent.EXTRA_REFERRER import android.net.Uri import android.provider.Settings +import android.util.Base64 import android.util.Log import androidx.biometric.BiometricManager import androidx.biometric.BiometricPrompt @@ -15,6 +15,7 @@ import androidx.core.content.ContextCompat.startActivity import androidx.core.content.FileProvider import androidx.fragment.app.FragmentActivity import de.tutao.tutashared.CredentialAuthenticationException +import de.tutao.tutashared.SystemUtils import de.tutao.tutashared.atLeastTiramisu import de.tutao.tutashared.credentials.AuthenticationPrompt import de.tutao.tutashared.data.AppDatabase @@ -23,7 +24,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.File import java.io.IOException -import de.tutao.tutashared.SystemUtils +import java.nio.charset.Charset class AndroidMobileSystemFacade( @@ -37,6 +38,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 { @@ -188,11 +191,13 @@ class AndroidMobileSystemFacade( 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(EXTRA_REFERRER, BuildConfig.APPLICATION_ID) - intent.setData(Uri.parse("tutacalendar://interop?${decodedQuery}")) + intent.putExtra(TUTA_INTENT_ACTION, "interop") + intent.setData(Uri.parse("tutacalendar://interop?$decodedQuery")) try { startActivityForResult(activity, intent, 0, null) diff --git a/app-android/app/src/main/java/de/tutao/tutanota/MainActivity.kt b/app-android/app/src/main/java/de/tutao/tutanota/MainActivity.kt index 7102dd48d7df..4ddc9ed4424f 100644 --- a/app-android/app/src/main/java/de/tutao/tutanota/MainActivity.kt +++ b/app-android/app/src/main/java/de/tutao/tutanota/MainActivity.kt @@ -8,7 +8,7 @@ import android.content.ClipData import android.content.ClipboardManager import android.content.ComponentName import android.content.Intent -import android.content.Intent.EXTRA_REFERRER +import android.content.Intent.ACTION_EDIT import android.content.pm.PackageManager import android.content.res.Configuration import android.graphics.Color @@ -454,12 +454,14 @@ class MainActivity : FragmentActivity() { return@launch } - if (data != null && data.toString().startsWith("tutamail://") && data.host == "interop") { - val caller = intent.getStringExtra(EXTRA_REFERRER) + val isInteropCall = intent.action == ACTION_EDIT && intent.getStringExtra(TUTA_INTENT_ACTION) == "interop" + val isTrustedCaller = callingPackage == BuildConfig.APPLICATION_ID.replace( + "tutanota", + "calendar" + ) - if (caller?.startsWith("de.tutao") == true) { - openContactEditor(data) - } + if (data != null && isInteropCall && isTrustedCaller) { + openContactEditor(data) } if (intent.action != null && !intent.getBooleanExtra(ALREADY_HANDLED_INTENT, false)) { @@ -809,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 diff --git a/app-android/calendar/src/main/java/de/tutao/calendar/AndroidMobileSystemFacade.kt b/app-android/calendar/src/main/java/de/tutao/calendar/AndroidMobileSystemFacade.kt index d7401d4eb155..732d0f5b7590 100644 --- a/app-android/calendar/src/main/java/de/tutao/calendar/AndroidMobileSystemFacade.kt +++ b/app-android/calendar/src/main/java/de/tutao/calendar/AndroidMobileSystemFacade.kt @@ -4,7 +4,6 @@ import android.Manifest import android.content.ActivityNotFoundException import android.content.ClipData import android.content.Intent -import android.content.Intent.EXTRA_REFERRER import android.net.Uri import android.provider.Settings import android.util.Base64 @@ -34,12 +33,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 { @@ -187,11 +187,13 @@ 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.putExtra(EXTRA_REFERRER, BuildConfig.APPLICATION_ID) - intent.setData(Uri.parse("tutamail://interop?${decodedQuery}")) + intent.putExtra(TUTA_INTENT_ACTION, "interop") + intent.setData(Uri.parse("tutamail://interop?$decodedQuery")) try { startActivityForResult(activity, intent, 0, null)