Skip to content

Commit

Permalink
Update Fdl Code with tests from piper (#2749)
Browse files Browse the repository at this point in the history
* Project import generated by Copybara.

FolderOrigin-RevId: /google/src/cloud/vguthal/move_stuff/.

changes

update Hide

update

update everything

update

update

update

* update

* update

* update

* update

* update

* update

Co-authored-by: Googler <noreply@google.com>
  • Loading branch information
VinayGuthal and Googler committed Jun 21, 2021
1 parent c7d8a80 commit 91681dd
Show file tree
Hide file tree
Showing 23 changed files with 473 additions and 87 deletions.
29 changes: 16 additions & 13 deletions firebase-dynamic-links/firebase-dynamic-links.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
compileSdkVersion project.targetSdkVersion
defaultConfig {
targetSdkVersion project.targetSdkVersion
minSdkVersion project.minSdkVersion
minSdkVersion 16
versionName version
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -51,31 +51,34 @@ dependencies {
implementation project(':firebase-common')
implementation project(':firebase-components')

implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.annotation:annotation:1.2.0'

implementation 'com.google.android.gms:play-services-basement:17.0.0'
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
implementation 'com.google.android.gms:play-services-basement:17.6.0'
implementation 'com.google.android.gms:play-services-tasks:17.2.1'
implementation 'com.google.android.gms:play-services-base:17.6.0'

implementation('com.google.firebase:firebase-auth-interop:18.0.0') {
implementation('com.google.firebase:firebase-auth-interop:20.0.0') {
exclude group: "com.google.firebase", module: "firebase-common"
}
implementation('com.google.firebase:firebase-measurement-connector:18.0.0') {
implementation('com.google.firebase:firebase-measurement-connector:19.0.0') {
exclude group: 'com.google.firebase', module: 'firebase-common'
}
testCompileOnly 'com.google.auto.value:auto-value-annotations:1.6.3'
testAnnotationProcessor "com.google.auto.value:auto-value:1.6.3"

javadocClasspath 'com.google.auto.value:auto-value-annotations:1.6.6'

javadocClasspath 'com.google.code.findbugs:jsr305:3.0.2'

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'com.android.support.test:runner:1.0.1'
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test:core:1.3.0'
testImplementation 'com.android.support.test:runner:1.0.2'
testImplementation 'org.mockito:mockito-core:3.3.3'
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "com.google.truth:truth:$googleTruthVersion"
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.10.2'
testImplementation 'com.google.guava:guava-testlib:12.0-rc2'
testImplementation('com.google.android.gms:play-services-appinvite:16.0.0') {
testImplementation('com.google.android.gms:play-services-appinvite:18.0.0') {
exclude group: 'com.google.firebase', module: 'firebase-common'
exclude group: 'com.google.firebase', module: 'firebase-dynamic-links'
}
Expand Down
3 changes: 1 addition & 2 deletions firebase-dynamic-links/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

<application>
<service android:name="com.google.firebase.components.ComponentDiscoveryService"
android:exported="false">
android:exported="false">
<meta-data
android:name="com.google.firebase.components:com.google.firebase.dynamiclinks.internal.FirebaseDynamicLinkRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,10 +94,8 @@ public static final class Builder {
public Builder(FirebaseDynamicLinksImpl firebaseDynamicLinks) {
firebaseDynamicLinksImpl = firebaseDynamicLinks;
builderParameters = new Bundle();
if (FirebaseApp.getInstance() != null) {
builderParameters.putString(
KEY_API_KEY, FirebaseApp.getInstance().getOptions().getApiKey());
}
builderParameters.putString(
KEY_API_KEY, firebaseDynamicLinks.getFirebaseApp().getOptions().getApiKey());
fdlParameters = new Bundle();
builderParameters.putBundle(KEY_DYNAMIC_LINK_PARAMETERS, fdlParameters);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,23 +21,25 @@
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.annotation.KeepForSdk;
import com.google.android.gms.common.util.DefaultClock;
import com.google.android.gms.common.util.VisibleForTesting;
import com.google.firebase.dynamiclinks.internal.DynamicLinkData;
import com.google.firebase.dynamiclinks.internal.DynamicLinkUTMParams;

/** Provides accessor methods to dynamic links data. */
public class PendingDynamicLinkData {

private final DynamicLinkData dynamicLinkData;
@Nullable private final DynamicLinkUTMParams dynamicLinkUTMParams;
@Nullable private final DynamicLinkData dynamicLinkData;

/**
* Create a dynamic link from parameters.
*
* @hide
*/
@KeepForSdk
@VisibleForTesting
public PendingDynamicLinkData(DynamicLinkData dynamicLinkData) {
if (dynamicLinkData == null) {
Expand Down Expand Up @@ -77,6 +79,7 @@ protected PendingDynamicLinkData(
* @return A bundle will all extension data.
* @hide
*/
@KeepForSdk
@Nullable
public Bundle getExtensions() {
if (dynamicLinkData == null) {
Expand Down Expand Up @@ -114,7 +117,7 @@ public Uri getLink() {
@NonNull
public Bundle getUtmParameters() {
if (dynamicLinkUTMParams == null) {
return Bundle.EMPTY;
return new Bundle();
}

return dynamicLinkUTMParams.asBundle();
Expand Down Expand Up @@ -156,6 +159,7 @@ public long getClickTimestamp() {
* @hide
*/
@VisibleForTesting
@Nullable
public Uri getRedirectUrl() {
if (dynamicLinkData == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import androidx.annotation.Nullable;
import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable;
import com.google.android.gms.common.internal.safeparcel.SafeParcelable;

Expand All @@ -25,9 +26,11 @@
public class DynamicLinkData extends AbstractSafeParcelable {

@SafeParcelable.Field(id = 1, getter = "getDynamicLink")
@Nullable
private String dynamicLink;

@SafeParcelable.Field(id = 2, getter = "getDeepLink")
@Nullable
private String deepLink;

@SafeParcelable.Field(id = 3, getter = "getMinVersion")
Expand All @@ -37,11 +40,14 @@ public class DynamicLinkData extends AbstractSafeParcelable {
private long clickTimestamp = 0L;

@SafeParcelable.Field(id = 5, getter = "getExtensionBundle")
@Nullable
private Bundle extensionBundle = null;

@SafeParcelable.Field(id = 6, getter = "getRedirectUrl")
@Nullable
private Uri redirectUrl;

@Nullable
public String getDynamicLink() {
return dynamicLink;
}
Expand All @@ -50,6 +56,7 @@ public void setDynamicLink(String dynamicLink) {
this.dynamicLink = dynamicLink;
}

@Nullable
public String getDeepLink() {
return deepLink;
}
Expand Down Expand Up @@ -82,6 +89,7 @@ public void setRedirectUrl(Uri redirectUrl) {
this.redirectUrl = redirectUrl;
}

@Nullable
public Uri getRedirectUrl() {
return redirectUrl;
}
Expand All @@ -101,12 +109,12 @@ public void setExtensionData(Bundle bundle) {

@SafeParcelable.Constructor
public DynamicLinkData(
@Param(id = 1) String dynamicLink,
@Param(id = 2) String deepLink,
@Nullable @Param(id = 1) String dynamicLink,
@Nullable @Param(id = 2) String deepLink,
@Param(id = 3) int minVersion,
@Param(id = 4) long clickTimestamp,
@Param(id = 5) Bundle extensions,
@Param(id = 6) Uri redirectUrl) {
@Nullable @Param(id = 5) Bundle extensions,
@Nullable @Param(id = 6) Uri redirectUrl) {
this.dynamicLink = dynamicLink;
this.deepLink = deepLink;
this.minVersion = minVersion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,44 @@ public class DynamicLinkUTMParams {

public DynamicLinkUTMParams(DynamicLinkData dynamicLinkData) {
this.dynamicLinkData = dynamicLinkData;
this.utmParamsBundle = initUTMParamsBundle();
this.utmParamsBundle = initUTMParamsBundle(dynamicLinkData);
}

@NonNull
public Bundle asBundle() {
return new Bundle(utmParamsBundle);
}

private Bundle initUTMParamsBundle() {
@NonNull
private static Bundle initUTMParamsBundle(DynamicLinkData dynamicLinkData) {
Bundle bundle = new Bundle();
if (dynamicLinkData == null || dynamicLinkData.getExtensionBundle() == null) {
return Bundle.EMPTY;
return bundle;
}

Bundle scionBundle = dynamicLinkData.getExtensionBundle().getBundle(KEY_SCION_DATA_BUNDLE);

if (scionBundle == null) {
return Bundle.EMPTY;
return bundle;
}

Bundle campaignBundle = scionBundle.getBundle(KEY_CAMPAIGN_BUNDLE);
if (campaignBundle == null) {
return Bundle.EMPTY;
return bundle;
}

Bundle bundle = new Bundle();
checkAndAdd(KEY_MEDIUM, KEY_UTM_MEDIUM, campaignBundle, bundle);
checkAndAdd(KEY_SOURCE, KEY_UTM_SOURCE, campaignBundle, bundle);
checkAndAdd(KEY_CAMPAIGN, KEY_UTM_CAMPAIGN, campaignBundle, bundle);

return bundle;
}

/*
* Checks and adds the value from source bundle to the destination bundle based on the source
* key and destination key.
*/
private void checkAndAdd(
private static void checkAndAdd(
@NonNull String sourceKey,
@NonNull String destKey,
@NonNull Bundle source,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,14 @@
import android.content.Context;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.Api.ApiOptions;
import com.google.android.gms.common.api.Api.ApiOptions.NoOptions;
import com.google.android.gms.common.api.GoogleApi;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.internal.ClientSettings;
import com.google.android.gms.common.util.VisibleForTesting;

public class DynamicLinksApi extends GoogleApi<NoOptions> {

Expand Down Expand Up @@ -63,6 +64,6 @@ public DynamicLinksClient buildClient(
*/
@VisibleForTesting
public DynamicLinksApi(@NonNull Context context) {
super(context, API, null /* options */, Settings.DEFAULT_SETTINGS);
super(context, API, ApiOptions.NO_OPTIONS /* options */, Settings.DEFAULT_SETTINGS);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,8 @@ public class DynamicLinksClient extends GmsClient<IDynamicLinksService> {
"com.google.firebase.dynamiclinks.service.START";
public static final String SERVICE_DESCRIPTOR =
"com.google.firebase.dynamiclinks.internal.IDynamicLinksService";
private static final int DYNAMIC_LINKS_API_VALUE = 131;
private static final int V17 = 12451000;

public DynamicLinksClient(
Context context,
Expand All @@ -42,8 +44,7 @@ public DynamicLinksClient(
super(
context,
looper,
// ServiceId.DYNAMIC_LINKS_API_VALUE,
131,
DYNAMIC_LINKS_API_VALUE,
clientSettings,
connectedListener,
connectionFailedListener);
Expand All @@ -67,7 +68,7 @@ protected IDynamicLinksService createServiceInterface(IBinder binder) {
return IDynamicLinksService.Stub.asInterface(binder);
}

void getDynamicLink(IDynamicLinksCallbacks.Stub callback, String dynamicLink) {
void getDynamicLink(IDynamicLinksCallbacks.Stub callback, @Nullable String dynamicLink) {
try {
getService().getDynamicLink(callback, dynamicLink);
} catch (RemoteException e) {
Expand All @@ -89,7 +90,11 @@ public int getMinApkVersion() {
// or an older version is now supported. Do _not_ use JAR_BUILD_VERSION_CODE as long as this
// code is shipped in the 3P SDK (which ships ~from head / dev and would not work with the head
// version of the .apk)..
// return BuildConstants.BaseApkVersion.V17;
return 12451000;
return V17;
}

@Override
public boolean usesClientTelemetry() {
return true;
}
}
Loading

0 comments on commit 91681dd

Please sign in to comment.