diff --git a/firebase-dynamic-links/build.gradle b/firebase-dynamic-links/build.gradle index 76f298c8e6..7e10a722e7 100644 --- a/firebase-dynamic-links/build.gradle +++ b/firebase-dynamic-links/build.gradle @@ -42,6 +42,7 @@ dependencies { // api project(':firebase-common-ktx') // api project(':firebase-components') api 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10' + annotationProcessor project(':safe-parcel-processor') } apply from: '../gradle/publish-android.gradle' diff --git a/firebase-dynamic-links/src/main/java/com/google/firebase/dynamiclinks/internal/DynamicLinkData.java b/firebase-dynamic-links/src/main/java/com/google/firebase/dynamiclinks/internal/DynamicLinkData.java index 8ae5d431f6..a2b0e42dbf 100644 --- a/firebase-dynamic-links/src/main/java/com/google/firebase/dynamiclinks/internal/DynamicLinkData.java +++ b/firebase-dynamic-links/src/main/java/com/google/firebase/dynamiclinks/internal/DynamicLinkData.java @@ -10,12 +10,14 @@ import android.os.Parcel; import androidx.annotation.NonNull; import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import android.os.Bundle; import android.net.Uri; import org.microg.gms.utils.ToStringHelper; +@SafeParcelable.Class public class DynamicLinkData extends AbstractSafeParcelable { @Field(1) public final String dynamicLink; @@ -35,6 +37,7 @@ public class DynamicLinkData extends AbstractSafeParcelable { @Field(6) public final Uri redirectUrl; + @Constructor public DynamicLinkData(@Param(1) String dynamicLink, @Param(2) String deepLink, @Param(3) int minVersion, @Param(4) long clickTimestamp, @Param(5) Bundle extensionBundle, @Param(6) Uri redirectUrl) { this.dynamicLink = dynamicLink; this.deepLink = deepLink; diff --git a/play-services-appinvite/core/src/main/kotlin/org/microg/gms/appinivite/AppInviteActivity.kt b/play-services-appinvite/core/src/main/kotlin/org/microg/gms/appinivite/AppInviteActivity.kt index 86b3f86f4e..074a891262 100644 --- a/play-services-appinvite/core/src/main/kotlin/org/microg/gms/appinivite/AppInviteActivity.kt +++ b/play-services-appinvite/core/src/main/kotlin/org/microg/gms/appinivite/AppInviteActivity.kt @@ -21,6 +21,8 @@ import androidx.core.view.setPadding import androidx.lifecycle.lifecycleScope import com.android.volley.* import com.android.volley.toolbox.Volley +import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer +import com.google.firebase.dynamiclinks.internal.DynamicLinkData import com.squareup.wire.Message import com.squareup.wire.ProtoAdapter import kotlinx.coroutines.CompletableDeferred @@ -28,7 +30,6 @@ import okio.ByteString.Companion.decodeHex import org.microg.gms.appinvite.* import org.microg.gms.common.Constants import org.microg.gms.utils.singleInstanceOf -import org.microg.gms.utils.toBase64 import java.util.* private const val TAG = "AppInviteActivity" @@ -37,6 +38,7 @@ private const val APPINVITE_DEEP_LINK = "com.google.android.gms.appinvite.DEEP_L private const val APPINVITE_INVITATION_ID = "com.google.android.gms.appinvite.INVITATION_ID" private const val APPINVITE_OPENED_FROM_PLAY_STORE = "com.google.android.gms.appinvite.OPENED_FROM_PLAY_STORE" private const val APPINVITE_REFERRAL_BUNDLE = "com.google.android.gms.appinvite.REFERRAL_BUNDLE" +private const val DYNAMIC_LINK_DATA = "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA" class AppInviteActivity : AppCompatActivity() { private val queue by lazy { singleInstanceOf { Volley.newRequestQueue(applicationContext) } } @@ -71,6 +73,8 @@ class AppInviteActivity : AppCompatActivity() { } private fun open(appInviteLink: MutateAppInviteLinkResponse) { + val dynamicLinkData = DynamicLinkData(appInviteLink.metadata?.info?.url, appInviteLink.data_?.intentData, + (appInviteLink.data_?.app?.minAppVersion ?: 0).toInt(), System.currentTimeMillis(), null, null) val intent = Intent(Intent.ACTION_VIEW).apply { addCategory(Intent.CATEGORY_DEFAULT) data = appInviteLink.data_?.intentData?.let { Uri.parse(it) } @@ -83,17 +87,31 @@ class AppInviteActivity : AppCompatActivity() { APPINVITE_OPENED_FROM_PLAY_STORE to false ) ) + putExtra(DYNAMIC_LINK_DATA, SafeParcelableSerializer.serializeToBytes(dynamicLinkData)) } val fallbackIntent = Intent(Intent.ACTION_VIEW).apply { addCategory(Intent.CATEGORY_DEFAULT) data = appInviteLink.data_?.fallbackUrl?.let { Uri.parse(it) } } val installedVersionCode = runCatching { - intent.resolveActivity(packageManager)?.let { - PackageInfoCompat.getLongVersionCode(packageManager.getPackageInfo(it.packageName, 0)) + if (appInviteLink.data_?.packageName != null) { + PackageInfoCompat.getLongVersionCode(packageManager.getPackageInfo(appInviteLink.data_.packageName, 0)) + } else { + null } }.getOrNull() if (installedVersionCode != null && (appInviteLink.data_?.app?.minAppVersion == null || installedVersionCode >= appInviteLink.data_.app.minAppVersion)) { + val componentName = intent.resolveActivity(packageManager) + if (componentName == null) { + Log.w(TAG, "open resolve activity is null") + if (appInviteLink.data_?.packageName != null) { + val intentLaunch = + packageManager.getLaunchIntentForPackage(appInviteLink.data_.packageName) + if (intentLaunch != null) { + intent.setComponent(intentLaunch.component) + } + } + } startActivity(intent) finish() } else {