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

app invite add dynamic link data #2519

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions firebase-dynamic-links/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<DynamicLinkData> CREATOR = findCreator(DynamicLinkData.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ 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
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"
Expand All @@ -37,6 +37,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) } }
Expand Down Expand Up @@ -71,6 +72,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) }
Expand All @@ -83,17 +86,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.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 {
Expand Down