diff --git a/firebase-installations-interop/firebase-installations-interop.gradle b/firebase-installations-interop/firebase-installations-interop.gradle new file mode 100644 index 00000000000..5acad3e1434 --- /dev/null +++ b/firebase-installations-interop/firebase-installations-interop.gradle @@ -0,0 +1,46 @@ +// Copyright 2018 Google LLC +// +// 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. + + +plugins { + id 'firebase-library' +} + +firebaseLibrary.publishJavadoc = false + +android { + compileSdkVersion project.targetSdkVersion + defaultConfig { + minSdkVersion project.minSdkVersion + targetSdkVersion project.targetSdkVersion + versionName version + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + testOptions { + unitTests { + includeAndroidResources = true + } + } +} + +dependencies { + implementation 'com.google.android.gms:play-services-tasks:17.0.0' + + compileOnly "com.google.auto.value:auto-value-annotations:1.6.5" + annotationProcessor "com.google.auto.value:auto-value:1.6.2" +} diff --git a/firebase-installations-interop/gradle.properties b/firebase-installations-interop/gradle.properties new file mode 100644 index 00000000000..752913a3eb5 --- /dev/null +++ b/firebase-installations-interop/gradle.properties @@ -0,0 +1 @@ +version=17.1.1 diff --git a/firebase-installations-interop/src/main/AndroidManifest.xml b/firebase-installations-interop/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..7ae18eafe43 --- /dev/null +++ b/firebase-installations-interop/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + diff --git a/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java b/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java new file mode 100644 index 00000000000..6947d7ec037 --- /dev/null +++ b/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java @@ -0,0 +1,42 @@ +// Copyright 2019 Google LLC +// +// 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. + +package com.google.firebase.installations; + +import com.google.android.gms.tasks.Task; + +/** + * This is an interface of {@code FirebaseInstallations} that is only exposed to 2p via component + * injection. + * + * @hide + */ +public interface FirebaseInstallationsApi { + + /** + * Async function that returns a globally unique identifier of this Firebase app installation. + * This is a url-safe base64 string of a 128-bit integer. + */ + Task getId(); + + /** Async function that returns a auth token(public key) of this Firebase app installation. */ + Task getAuthToken(boolean forceRefresh); + + /** + * Async function that deletes this Firebase app installation from Firebase backend. This call + * would possibly lead Firebase Notification, Firebase RemoteConfig, Firebase Predictions or + * Firebase In-App Messaging not function properly. + */ + Task delete(); +} diff --git a/firebase-installations-interop/src/main/java/com/google/firebase/installations/InstallationTokenResult.java b/firebase-installations-interop/src/main/java/com/google/firebase/installations/InstallationTokenResult.java new file mode 100644 index 00000000000..df04f26ca38 --- /dev/null +++ b/firebase-installations-interop/src/main/java/com/google/firebase/installations/InstallationTokenResult.java @@ -0,0 +1,38 @@ +// Copyright 2019 Google LLC +// +// 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. + +package com.google.firebase.installations; + +import androidx.annotation.NonNull; +import com.google.auto.value.AutoValue; + +/** This class represents a set of values describing a FIS Auth Token Result. */ +@AutoValue +public abstract class InstallationTokenResult { + + /** A new FIS Auth-Token, created for this firebase installation. */ + @NonNull + public abstract String getAuthToken(); + /** + * The amount of time, in milliseconds, before the auth-token expires for this firebase + * installation. + */ + public abstract long getTokenExpirationTimestampMillis(); + + @NonNull + public static InstallationTokenResult create( + @NonNull String authToken, long tokenExpirationTimestampMillis) { + return new AutoValue_InstallationTokenResult(authToken, tokenExpirationTimestampMillis); + } +} diff --git a/firebase-installations/firebase-installations.gradle b/firebase-installations/firebase-installations.gradle new file mode 100644 index 00000000000..45123f1c6ce --- /dev/null +++ b/firebase-installations/firebase-installations.gradle @@ -0,0 +1,54 @@ +// Copyright 2018 Google LLC +// +// 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. + + +plugins { + id 'firebase-library' +} + +android { + compileSdkVersion project.targetSdkVersion + defaultConfig { + minSdkVersion project.minSdkVersion + targetSdkVersion project.targetSdkVersion + multiDexEnabled true + versionName version + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + testOptions { + unitTests { + includeAndroidResources = true + } + } +} + +dependencies { + implementation project(':firebase-common') + implementation project(':firebase-installations-interop') + + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.multidex:multidex:2.0.1' + implementation 'com.google.android.gms:play-services-tasks:17.0.0' + + testImplementation 'androidx.test:core:1.2.0' + testImplementation 'junit:junit:4.12' + testImplementation "org.robolectric:robolectric:$robolectricVersion" + + androidTestImplementation 'androidx.test:runner:1.2.0' + implementation 'com.google.guava:guava:16.0.+' +} diff --git a/firebase-installations/gradle.properties b/firebase-installations/gradle.properties new file mode 100644 index 00000000000..752913a3eb5 --- /dev/null +++ b/firebase-installations/gradle.properties @@ -0,0 +1 @@ +version=17.1.1 diff --git a/firebase-installations/lint.xml b/firebase-installations/lint.xml new file mode 100644 index 00000000000..9b9bd90b534 --- /dev/null +++ b/firebase-installations/lint.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/firebase-installations/src/main/AndroidManifest.xml b/firebase-installations/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..08b562940aa --- /dev/null +++ b/firebase-installations/src/main/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java new file mode 100644 index 00000000000..f135aa2e197 --- /dev/null +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -0,0 +1,106 @@ +// Copyright 2019 Google LLC +// +// 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. + +package com.google.firebase.installations; + +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.Preconditions; +import com.google.android.gms.tasks.Task; +import com.google.android.gms.tasks.Tasks; +import com.google.common.annotations.VisibleForTesting; +import com.google.firebase.FirebaseApp; + +/** + * Entry point for Firebase Installations. + * + *

Firebase Installations does + * + *

    + *
  • provide unique identifier for a Firebase installation + *
  • provide auth token of a Firebase installation + *
  • provide a API to GDPR-delete a Firebase installation + *
+ */ +public class FirebaseInstallations implements FirebaseInstallationsApi { + + private final FirebaseApp firebaseApp; + + /** package private constructor. */ + FirebaseInstallations(FirebaseApp firebaseApp) { + this.firebaseApp = firebaseApp; + } + + /** + * Returns the {@link FirebaseInstallationsApi} initialized with the default {@link FirebaseApp}. + * + * @return a {@link FirebaseInstallationsApi} instance + */ + @NonNull + public static FirebaseInstallations getInstance() { + FirebaseApp defaultFirebaseApp = FirebaseApp.getInstance(); + return getInstance(defaultFirebaseApp); + } + + /** + * Returns the {@link FirebaseInstallations} initialized with a custom {@link FirebaseApp}. + * + * @param app a custom {@link FirebaseApp} + * @return a {@link FirebaseInstallations} instance + */ + @NonNull + public static FirebaseInstallations getInstance(@NonNull FirebaseApp app) { + Preconditions.checkArgument(app != null, "Null is not a valid value of FirebaseApp."); + return (FirebaseInstallations) app.get(FirebaseInstallationsApi.class); + } + + /** + * Returns a globally unique identifier of this Firebase app installation. This is a url-safe + * base64 string of a 128-bit integer. + */ + @NonNull + @Override + public Task getId() { + return Tasks.forResult("fid-is-better-than-iid"); + } + + /** Returns a auth token(public key) of this Firebase app installation. */ + @NonNull + @Override + public Task getAuthToken(boolean forceRefresh) { + return Tasks.forResult(InstallationTokenResult.create("dummy_auth_token", 1000l)); + } + + /** + * Call to delete this Firebase app installation from Firebase backend. This call would possibly + * lead Firebase Notification, Firebase RemoteConfig, Firebase Predictions or Firebase In-App + * Messaging not function properly. + */ + @NonNull + @Override + public Task delete() { + return Tasks.forResult(null); + } + + /** Returns the application id of the {@link FirebaseApp} of this {@link FirebaseInstallations} */ + @VisibleForTesting + String getApplicationId() { + return firebaseApp.getOptions().getApplicationId(); + } + + /** Returns the nick name of the {@link FirebaseApp} of this {@link FirebaseInstallations} */ + @VisibleForTesting + String getName() { + return firebaseApp.getName(); + } +} diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java new file mode 100644 index 00000000000..e84168ab4fb --- /dev/null +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java @@ -0,0 +1,39 @@ +// Copyright 2019 Google LLC +// +// 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. + +package com.google.firebase.installations; + +import androidx.annotation.Keep; +import com.google.firebase.FirebaseApp; +import com.google.firebase.components.Component; +import com.google.firebase.components.ComponentRegistrar; +import com.google.firebase.components.Dependency; +import com.google.firebase.platforminfo.LibraryVersionComponent; +import java.util.Arrays; +import java.util.List; + +/** @hide */ +@Keep +public class FirebaseInstallationsRegistrar implements ComponentRegistrar { + + @Override + public List> getComponents() { + return Arrays.asList( + Component.builder(FirebaseInstallationsApi.class) + .add(Dependency.required(FirebaseApp.class)) + .factory(c -> new FirebaseInstallations(c.get(FirebaseApp.class))) + .build(), + LibraryVersionComponent.create("fire-installations", BuildConfig.VERSION_NAME)); + } +} diff --git a/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java new file mode 100644 index 00000000000..5a7c505e9b6 --- /dev/null +++ b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java @@ -0,0 +1,18 @@ +// Copyright 2019 Google LLC +// +// 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. + +package com.google.firebase.installations; + +/** Tests for {@link FirebaseInstallationsRegistrar}. */ +public class FirebaseInstallationsRegistrarTest {} diff --git a/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java new file mode 100644 index 00000000000..fe64dcf06b8 --- /dev/null +++ b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java @@ -0,0 +1,18 @@ +// Copyright 2019 Google LLC +// +// 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. + +package com.google.firebase.installations; + +/** Tests for {@link FirebaseInstallations}. */ +public class FirebaseInstallationsTest {} diff --git a/subprojects.cfg b/subprojects.cfg index a80ebdb3c42..031fb302706 100644 --- a/subprojects.cfg +++ b/subprojects.cfg @@ -12,6 +12,8 @@ firebase-firestore firebase-firestore:ktx firebase-functions firebase-functions:ktx +firebase-installations-interop +firebase-installations firebase-inappmessaging-display firebase-storage firebase-storage:test-app