Skip to content

Commit

Permalink
Implement IDynamicLinksService.getDynamicLink() for compatibility wit…
Browse files Browse the repository at this point in the history
…h react native firebase email link auth (#2297)

Co-authored-by: Marvin W <git@larma.de>
  • Loading branch information
derMart and mar-v-in committed Apr 29, 2024
1 parent cf65b1a commit ca833fe
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 45 deletions.
15 changes: 12 additions & 3 deletions firebase-dynamic-links/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-FileCopyrightText: 2019, e Foundation
* SPDX-FileCopyrightText: 2020, microG Project Team
* SPDX-FileCopyrightText: 2019 e Foundation
* SPDX-FileCopyrightText: 2020 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -31,8 +31,17 @@ android {
}

dependencies {
// Dependencies from firebase-dynamic-links:21.2.0
api 'androidx.annotation:annotation:1.2.0'
api project(':play-services-base')
api project(':play-services-basement')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
api project(':play-services-tasks')
// api project(':firebase-auth-interop')
// api project(':firebase-measurement-connector')
// api project(':firebase-common')
// api project(':firebase-common-ktx')
// api project(':firebase-components')
api 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
}

apply from: '../gradle/publish-android.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import com.google.firebase.dynamiclinks.internal.IDynamicLinksCallbacks;
import android.os.Bundle;

interface IDynamicLinksService {
void getInitialLink(IDynamicLinksCallbacks callback, String link) = 0;
void getDynamicLink(IDynamicLinksCallbacks callback, String link) = 0;
void createShortDynamicLink(IDynamicLinksCallbacks callback, in Bundle extras) = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

package com.google.firebase.dynamiclinks.internal;

import org.microg.safeparcel.AutoSafeParcelable;
import org.microg.safeparcel.SafeParceled;
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.SafeParcelableCreatorAndWriter;

import android.os.Bundle;
import android.net.Uri;

public class DynamicLinkData extends AutoSafeParcelable {
public class DynamicLinkData extends AbstractSafeParcelable {
@Field(1)
public final String dynamicLink;

Expand All @@ -32,14 +34,19 @@ public class DynamicLinkData extends AutoSafeParcelable {
@Field(6)
public final Uri redirectUrl;

public DynamicLinkData() {
dynamicLink = "";
deepLink = "";
minVersion = 0;
clickTimestamp = 0;
extensionBundle = new Bundle();
redirectUrl = Uri.EMPTY;
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;
this.minVersion = minVersion;
this.clickTimestamp = clickTimestamp;
this.extensionBundle = extensionBundle;
this.redirectUrl = redirectUrl;
}

public static final Creator<DynamicLinkData> CREATOR = new AutoCreator<DynamicLinkData>(DynamicLinkData.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<DynamicLinkData> CREATOR = findCreator(DynamicLinkData.class);
}
21 changes: 8 additions & 13 deletions play-services-appinvite/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
* Copyright 2019 e Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-FileCopyrightText: 2019 e Foundation
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

apply plugin: 'com.android.library'
Expand Down Expand Up @@ -41,5 +31,10 @@ android {
}

dependencies {
// Dependencies from play-services-appinvite:18.0.0
api project(':play-services-base')
api project(':play-services-basement')
api project(':play-services-tasks')
// api project(':firebase-analytics')
api project(':firebase-dynamic-links')
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AppInviteActivity : AppCompatActivity() {
language = Locale.getDefault().language
),
link = LinkInfo(
empty = "",
invitationId = "",
uri = intent.data.toString()
),
system = SystemInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message ClientIdInfo {
}

message LinkInfo {
optional string empty = 1; // e.g. ""
optional string invitationId = 1; // e.g. ""
optional string uri = 2;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
/*
* Copyright (C) 2019 e Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-FileCopyrightText: 2019 e Foundation
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package org.microg.gms.firebase.dynamiclinks;

import android.net.Uri;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.Bundle;
Expand All @@ -33,13 +24,40 @@
public class DynamicLinksServiceImpl extends IDynamicLinksService.Stub {
private static final String TAG = "GmsDynamicLinksServImpl";

private String packageName;

public DynamicLinksServiceImpl(Context context, String packageName, Bundle extras) {
this.packageName = packageName;
}


@Override
public void getInitialLink(IDynamicLinksCallbacks callback, String link) throws RemoteException {
callback.onStatusDynamicLinkData(Status.SUCCESS, null);
public void getDynamicLink(IDynamicLinksCallbacks callback, String link) throws RemoteException {
if (link != null) {
Uri linkUri = Uri.parse(link);
String packageName = linkUri.getQueryParameter("apn");
String amvParameter = linkUri.getQueryParameter("amv");
if (packageName == null) {
throw new RuntimeException("Missing package name");
} else if (!this.packageName.equals(packageName)) {
throw new RuntimeException("Registered package name:" + this.packageName + " does not match link package name: " + packageName);
}
int amv = 0;
if (amvParameter != null && amvParameter != "") {
amv = Integer.parseInt(amvParameter);
}
DynamicLinkData data = new DynamicLinkData(
null,
linkUri.getQueryParameter("link"),
amv,
0,
null,
null
);
callback.onStatusDynamicLinkData(Status.SUCCESS, data);
} else {
callback.onStatusDynamicLinkData(Status.SUCCESS, null);
}
}


Expand Down

0 comments on commit ca833fe

Please sign in to comment.