From 31665efafbdd5fcdd5390bb0631a7a74d354ff08 Mon Sep 17 00:00:00 2001 From: DaVinci9196 Date: Mon, 2 Sep 2024 16:24:26 +0800 Subject: [PATCH 1/3] app invite add dynamic link data --- firebase-dynamic-links/build.gradle | 1 + .../internal/DynamicLinkData.java | 11 ++++++++ .../gms/appinivite/AppInviteActivity.kt | 26 ++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) 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..cb23cfbf78 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; @@ -62,5 +65,13 @@ public void writeToParcel(@NonNull Parcel dest, int flags) { CREATOR.writeToParcel(this, dest, flags); } + public byte[] toByte() { + Parcel parcel = Parcel.obtain(); + writeToParcel(parcel, 0); + byte[] arr_b = parcel.marshall(); + parcel.recycle(); + return arr_b; + } + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(DynamicLinkData.class); } 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..8525c5dfde 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,7 @@ import androidx.core.view.setPadding import androidx.lifecycle.lifecycleScope import com.android.volley.* import com.android.volley.toolbox.Volley +import com.google.firebase.dynamiclinks.internal.DynamicLinkData import com.squareup.wire.Message import com.squareup.wire.ProtoAdapter import kotlinx.coroutines.CompletableDeferred @@ -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,8 +73,12 @@ class AppInviteActivity : AppCompatActivity() { } private fun open(appInviteLink: MutateAppInviteLinkResponse) { + Log.d(TAG, "open: $appInviteLink") + val dynamicLinkData = DynamicLinkData(appInviteLink.metadata?.info?.url, appInviteLink.data_?.intentData, + (appInviteLink.data_?.app?.minAppVersion ?: 0).toInt(), System.currentTimeMillis(), null, null) + Log.d(TAG, "open dynamicLinkData: $dynamicLinkData") val intent = Intent(Intent.ACTION_VIEW).apply { - addCategory(Intent.CATEGORY_DEFAULT) + addCategory(Intent.CATEGORY_LAUNCHER) data = appInviteLink.data_?.intentData?.let { Uri.parse(it) } `package` = appInviteLink.data_?.packageName flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP @@ -83,17 +89,31 @@ class AppInviteActivity : AppCompatActivity() { APPINVITE_OPENED_FROM_PLAY_STORE to false ) ) + putExtra(DYNAMIC_LINK_DATA, dynamicLinkData.toByte()) } 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.d(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 { From 4961012c9b3e9e728347137ebbffc3d49c957bb5 Mon Sep 17 00:00:00 2001 From: DaVinci9196 Date: Mon, 2 Sep 2024 17:15:27 +0800 Subject: [PATCH 2/3] Remove dead code --- .../kotlin/org/microg/gms/appinivite/AppInviteActivity.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 8525c5dfde..119053cc2d 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 @@ -29,7 +29,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" @@ -73,12 +72,10 @@ class AppInviteActivity : AppCompatActivity() { } private fun open(appInviteLink: MutateAppInviteLinkResponse) { - Log.d(TAG, "open: $appInviteLink") val dynamicLinkData = DynamicLinkData(appInviteLink.metadata?.info?.url, appInviteLink.data_?.intentData, (appInviteLink.data_?.app?.minAppVersion ?: 0).toInt(), System.currentTimeMillis(), null, null) - Log.d(TAG, "open dynamicLinkData: $dynamicLinkData") val intent = Intent(Intent.ACTION_VIEW).apply { - addCategory(Intent.CATEGORY_LAUNCHER) + addCategory(Intent.CATEGORY_DEFAULT) data = appInviteLink.data_?.intentData?.let { Uri.parse(it) } `package` = appInviteLink.data_?.packageName flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP @@ -105,7 +102,7 @@ class AppInviteActivity : AppCompatActivity() { if (installedVersionCode != null && (appInviteLink.data_?.app?.minAppVersion == null || installedVersionCode >= appInviteLink.data_.app.minAppVersion)) { val componentName = intent.resolveActivity(packageManager) if (componentName == null) { - Log.d(TAG, "open resolve activity is null") + Log.w(TAG, "open resolve activity is null") if (appInviteLink.data_?.packageName != null) { val intentLaunch = packageManager.getLaunchIntentForPackage(appInviteLink.data_.packageName) From d0f753a73661d9fdb76d682652eba325a5e910fc Mon Sep 17 00:00:00 2001 From: DaVinci9196 Date: Mon, 11 Nov 2024 09:57:24 +0800 Subject: [PATCH 3/3] use SafeParcelableSerializer.serializeToBytes instead of toByte --- .../firebase/dynamiclinks/internal/DynamicLinkData.java | 8 -------- .../kotlin/org/microg/gms/appinivite/AppInviteActivity.kt | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) 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 cb23cfbf78..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 @@ -65,13 +65,5 @@ public void writeToParcel(@NonNull Parcel dest, int flags) { CREATOR.writeToParcel(this, dest, flags); } - public byte[] toByte() { - Parcel parcel = Parcel.obtain(); - writeToParcel(parcel, 0); - byte[] arr_b = parcel.marshall(); - parcel.recycle(); - return arr_b; - } - public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(DynamicLinkData.class); } 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 119053cc2d..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,7 @@ 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 @@ -86,7 +87,7 @@ class AppInviteActivity : AppCompatActivity() { APPINVITE_OPENED_FROM_PLAY_STORE to false ) ) - putExtra(DYNAMIC_LINK_DATA, dynamicLinkData.toByte()) + putExtra(DYNAMIC_LINK_DATA, SafeParcelableSerializer.serializeToBytes(dynamicLinkData)) } val fallbackIntent = Intent(Intent.ACTION_VIEW).apply { addCategory(Intent.CATEGORY_DEFAULT)