From 553bf70c9287fb1fd72ba6821319a6a4e3012ef5 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 10:16:25 -0700 Subject: [PATCH 01/16] Adding an interface library for Firebase Installations SDK --- .../firebase-installations-interop.gradle | 43 +++++++++++++++++++ .../gradle.properties | 1 + .../src/main/AndroidManifest.xml | 17 ++++++++ .../FirebaseInstallationsApi.java | 42 ++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 firebase-installations-interop/firebase-installations-interop.gradle create mode 100644 firebase-installations-interop/gradle.properties create mode 100644 firebase-installations-interop/src/main/AndroidManifest.xml create mode 100644 firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java diff --git a/firebase-installations-interop/firebase-installations-interop.gradle b/firebase-installations-interop/firebase-installations-interop.gradle new file mode 100644 index 00000000000..1eec0386735 --- /dev/null +++ b/firebase-installations-interop/firebase-installations-interop.gradle @@ -0,0 +1,43 @@ +// 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' +} diff --git a/firebase-installations-interop/gradle.properties b/firebase-installations-interop/gradle.properties new file mode 100644 index 00000000000..33cda300b91 --- /dev/null +++ b/firebase-installations-interop/gradle.properties @@ -0,0 +1 @@ +version=17.1.1 \ No newline at end of file diff --git a/firebase-installations-interop/src/main/AndroidManifest.xml b/firebase-installations-interop/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..265d258f1b9 --- /dev/null +++ b/firebase-installations-interop/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + \ No newline at end of file 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..c02576a8efd --- /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(); + + /** + * 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(); +} \ No newline at end of file From 2ec4aeff1e96446ad4737e0b4f75e24fa63eba55 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 10:32:45 -0700 Subject: [PATCH 02/16] Adding Firebase Installations module --- .idea/copyright/Apache_2___Google.xml | 6 --- .idea/copyright/profiles_settings.xml | 10 ---- .../FirestoreProdIntegrationTest.xml | 21 -------- ...Integration_Tests__Firestore_Emulator_.xml | 51 ------------------- .../Firestore_Unit_Tests.xml | 24 --------- subprojects.cfg | 2 + 6 files changed, 2 insertions(+), 112 deletions(-) delete mode 100644 .idea/copyright/Apache_2___Google.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/runConfigurations/FirestoreProdIntegrationTest.xml delete mode 100644 .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml delete mode 100644 .idea/runConfigurations/Firestore_Unit_Tests.xml diff --git a/.idea/copyright/Apache_2___Google.xml b/.idea/copyright/Apache_2___Google.xml deleted file mode 100644 index a0bb219243a..00000000000 --- a/.idea/copyright/Apache_2___Google.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 0d00e324732..00000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml deleted file mode 100644 index fda38c03059..00000000000 --- a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml deleted file mode 100644 index 1c1053aa848..00000000000 --- a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Unit_Tests.xml b/.idea/runConfigurations/Firestore_Unit_Tests.xml deleted file mode 100644 index 5bfd8accf8a..00000000000 --- a/.idea/runConfigurations/Firestore_Unit_Tests.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/subprojects.cfg b/subprojects.cfg index a80ebdb3c42..fd8eb549e85 100644 --- a/subprojects.cfg +++ b/subprojects.cfg @@ -6,6 +6,8 @@ firebase-common:ktx firebase-config firebase-config:bandwagoner firebase-database +firebase-installations-interop +firebase-installations firebase-database-collection firebase-datatransport firebase-firestore From dca81d0787c8e9e5b58032c8501fefa58004cb23 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 10:38:41 -0700 Subject: [PATCH 03/16] Adding Firebase Installations module. --- .../firebase-installations.gradle | 97 +++++++++++ firebase-installations/gradle.properties | 1 + firebase-installations/lint.xml | 11 ++ firebase-installations/proguard-rules.pro | 21 +++ .../src/main/AndroidManifest.xml | 14 ++ .../installations/FirebaseInstallations.java | 110 ++++++++++++ .../FirebaseInstallationsRegistrar.java | 39 +++++ .../v1/firebase_installations_api.proto | 163 ++++++++++++++++++ .../src/main/res/values/strings.xml | 3 + .../FirebaseInstallationsRegistrarTest.java | 0 .../FirebaseInstallationsTest.java | 0 11 files changed, 459 insertions(+) create mode 100644 firebase-installations/firebase-installations.gradle create mode 100644 firebase-installations/gradle.properties create mode 100644 firebase-installations/lint.xml create mode 100644 firebase-installations/proguard-rules.pro create mode 100644 firebase-installations/src/main/AndroidManifest.xml create mode 100644 firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java create mode 100644 firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java create mode 100644 firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto create mode 100644 firebase-installations/src/main/res/values/strings.xml create mode 100644 firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java create mode 100644 firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java diff --git a/firebase-installations/firebase-installations.gradle b/firebase-installations/firebase-installations.gradle new file mode 100644 index 00000000000..1db5bb60d1c --- /dev/null +++ b/firebase-installations/firebase-installations.gradle @@ -0,0 +1,97 @@ +// 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' + id 'com.google.protobuf' +} + +protobuf { + // Configure the protoc executable + protoc { + // Download from repositories + artifact = 'com.google.protobuf:protoc:3.4.0' + } + plugins { + grpc { + artifact = 'io.grpc:protoc-gen-grpc-java:1.21.0' + } + javalite { + // The codegen for lite comes as a separate artifact + artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0' + } + } + generateProtoTasks { + all().each { task -> + task.builtins { + // In most cases you don't need the full Java output + // if you use the lite output. + remove java + } + task.plugins { + grpc { + option 'lite' + } + javalite {} + } + } + } +} + +android { + compileSdkVersion project.targetSdkVersion + defaultConfig { + minSdkVersion project.minSdkVersion + targetSdkVersion project.targetSdkVersion + multiDexEnabled true + versionName version + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + sourceSets { + main { + proto { + srcDir 'src/main/proto' + } + } + } + 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 project(':protolite-well-known-types') + + implementation 'io.grpc:grpc-stub:1.21.0' + implementation 'io.grpc:grpc-protobuf-lite:1.21.0' + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'com.squareup.okhttp3:okhttp:3.12.1' + 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' +} diff --git a/firebase-installations/gradle.properties b/firebase-installations/gradle.properties new file mode 100644 index 00000000000..33cda300b91 --- /dev/null +++ b/firebase-installations/gradle.properties @@ -0,0 +1 @@ +version=17.1.1 \ No newline at end of file diff --git a/firebase-installations/lint.xml b/firebase-installations/lint.xml new file mode 100644 index 00000000000..c478c9793de --- /dev/null +++ b/firebase-installations/lint.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/firebase-installations/proguard-rules.pro b/firebase-installations/proguard-rules.pro new file mode 100644 index 00000000000..481bb434814 --- /dev/null +++ b/firebase-installations/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/firebase-installations/src/main/AndroidManifest.xml b/firebase-installations/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..b7d77de60f9 --- /dev/null +++ b/firebase-installations/src/main/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file 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..99affb741a3 --- /dev/null +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -0,0 +1,110 @@ +// 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; +import okhttp3.OkHttpClient; + +/** + * 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 OkHttpClient httpClient; + + private final FirebaseApp firebaseApp; + + /** package private constructor. */ + FirebaseInstallations(FirebaseApp firebaseApp) { + this.firebaseApp = firebaseApp; + httpClient = new OkHttpClient(); + } + + /** + * 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() { + return Tasks.forResult("dummy_auth_token"); + } + + /** + * 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(); + } +} \ No newline at end of file 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..f36e8b3230a --- /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)); + } +} \ No newline at end of file diff --git a/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto b/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto new file mode 100644 index 00000000000..a73a74a3b27 --- /dev/null +++ b/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto @@ -0,0 +1,163 @@ +// 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. + +syntax = "proto3"; + +package google.firebase.installations.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; + +option java_multiple_files = true; +option java_package = "com.google.firebase.installations.v1"; + +// Firebase Installations API +// +// Firebase Installations API enables registration, management and deletion +// of Firebase installations: app instances, webapp instances, or IoT devices +// that use Firebase services. +service FirebaseInstallationsService { + // Deletes an Installation + rpc DeleteInstallation(DeleteInstallationRequest) + returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{name=projects/*/installations/*}" + }; + } + + // Creates (and registers) a new Firebase Installation, incl. its FID and + // Verification Key (used for authentication purposes) + // refer to https://cloud.google.com/apis/design/standard_methods + // for method definition formats. + rpc CreateInstallation(CreateInstallationRequest) returns (Installation) { + option (google.api.http) = { + post: "/v1/{parent=projects/*}/installations" + body: "installation" + }; + } + + // Creates a new short-lived FIS-Auth-Token (Bearer-Token for Installations) + rpc GenerateAuthToken(GenerateAuthTokenRequest) returns (AuthTokenInfo) { + option (google.api.http) = { + post: "/v1/{name=projects/*/installations/*}/authTokens:generate" + body: "*" + }; + } +} + +// The request to delete the data stored for a specific Installation and +// permanently disable its Firebase Installations ID and authentication +// credentials. This process triggers the Firebase GDPR delete-pipeline. +message DeleteInstallationRequest { + // Resource name of the installation. It must have the format of + // `projects/*/installations/*`. + string name = 1; +} + +// The request to register a new Installation. +message CreateInstallationRequest { + // The parent resource name. + // Identifies the Cloud Project owning this Installation. + // We accept both projectID and projectNumber. + string parent = 1; + + // The resource to create. + Installation installation = 2; +} + +// The request to register a new Installation. +message GenerateAuthTokenRequest { + // The Firebase Installation requesting for FIS-Auth-Token. + string name = 1; + + // Optional field that allows the Firebase Installation to update (some of) + // its attributes with FIS the server (ex: sdk_version) when it requests for a + // new FIS Auth-Token. + // (-- go/not-api-precedent: Updating the metadata has no relation to the + // generation of FIS Auth-Tokens. Ordinarily, generating a FIS Auth-Token and + // updating metadata should be handled by two separate endpoints. + // We decided to batch the requests in order to limit the number of necessary + // requests from the client, given that our users (Firebase Services) are + // targeting mobile applications and additional network requests increase the + // startup-time of applications which is undesirable for mobile platform. --) + Installation installation = 2; +} + +message AuthTokenInfo { + // A new FIS-Auth-Token, created for the Firebase Installation. + string token = 1; + + // The duration for which this auth_token will be valid. + // In a response's JSON format, the value is encoded as a string with the + // suffix "s" (indicating seconds), preceded by the number of seconds. + // Example: "604800s" + // (-- go/not-api-precedent: OnePlatform APIs usually do not use prepositions + // in field names, but we are doing so here to conform to the external OAuth + // terminology. --) + google.protobuf.Duration expires_in = 2; +} + +// next_id: 9 +message Installation { + // URI of the Firebase Installation with the following format: + // projects//installations/ + // Example: projects/35006771263/installations/eapzYQai_g8flVQyfKoGs7 + // This field is set only during response. + string name = 1; + + // Globally unique identifier of the Firebase Installation. + string fid = 2; + + // GMP App Id - Firebase Application identifier, generated by Firebase Console + string app_id = 3; + + // The current version of the used FIS client-SDK. + string sdk_version = 4; + + // The version of the Firebase Installations Internal Authentication scheme. + // This value is used as Authorization-Type of HTTP-header "Authorization". + // Compare: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication + // The internal client/server authentication of Firebase Installations may + // change in the future. Initial version is "FIS_v2". + // This field is optional. If not set the default version is assumed (FIS_v2). + string auth_version = 5; + + // A refresh token created for / assigned to the Firebase Installation by FIS. + // The Firebase Installation can use the refresh token to send requests to + // #GenerateAuthToken in order to request and generate new FIS Auth-Tokens. + // Used for FIS Internal Auth scheme FIS_v2. + // This field is set only during response. + string refresh_token = 6; + + // The verification-key (a.k.a. public-key) is used to authenticate the + // digital signatures sent by the Firebase Installation in requests to FIS. + // Used for FIS Internal Auth scheme FIS_v1. + // The public key is expected to be in X.509 format ("SubjectPublicKeyInfo"), + // compare RFC 5280 (https://tools.ietf.org/html/rfc5280#section-4.1). + string verification_key = 7; + + // The initial FIS Auth-Token, created for the Firebase Installation. + // This field is set only during response. + // (-- go/not-api-precedent: Ordinarily requesting a FIS Auth-Token should be + // achieved via a secondary request to endpoint #GenerateAuthToken. However + // the number of necessary requests has an impact on the startup time + // (particularly "cold-start") of mobile applications and FIS is used by + // Firebase Services that are targeting mobile applicatoins. Returning a FIS + // Auth-Token along with the created Installation resource allows us to reduce + // our client-server communication to 1 request during cold-start + // (i.e. 1st startup) of a newly installed app. This improves user experience + // as it reduces user-perceived latency. --) + AuthTokenInfo auth_token = 8; +} \ No newline at end of file diff --git a/firebase-installations/src/main/res/values/strings.xml b/firebase-installations/src/main/res/values/strings.xml new file mode 100644 index 00000000000..88c6d0b6d8f --- /dev/null +++ b/firebase-installations/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + FirebaseInstallations + 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..e69de29bb2d 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..e69de29bb2d From 7b4ebcf7accb28fc01ddd5e864fa3e9c0d46dba5 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 11:46:12 -0700 Subject: [PATCH 04/16] Readding .idea files that were deleted in previous commit --- .idea/copyright/Apache_2___Google.xml | 6 +++ .idea/copyright/profiles_settings.xml | 10 ++++ .../FirestoreProdIntegrationTest.xml | 21 ++++++++ ...Integration_Tests__Firestore_Emulator_.xml | 51 +++++++++++++++++++ .../Firestore_Unit_Tests.xml | 24 +++++++++ 5 files changed, 112 insertions(+) create mode 100644 .idea/copyright/Apache_2___Google.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/runConfigurations/FirestoreProdIntegrationTest.xml create mode 100644 .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml create mode 100644 .idea/runConfigurations/Firestore_Unit_Tests.xml diff --git a/.idea/copyright/Apache_2___Google.xml b/.idea/copyright/Apache_2___Google.xml new file mode 100644 index 00000000000..cba016dc880 --- /dev/null +++ b/.idea/copyright/Apache_2___Google.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000000..8c478598102 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml new file mode 100644 index 00000000000..6cc8a003a50 --- /dev/null +++ b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml new file mode 100644 index 00000000000..874d64e132f --- /dev/null +++ b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml @@ -0,0 +1,51 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Unit_Tests.xml b/.idea/runConfigurations/Firestore_Unit_Tests.xml new file mode 100644 index 00000000000..e8419c4a54d --- /dev/null +++ b/.idea/runConfigurations/Firestore_Unit_Tests.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file From a7696e77a251b953b8c3d06229c7beb5216e54bf Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:15:18 -0700 Subject: [PATCH 05/16] Revert "Adding Firebase Installations module" This reverts commit 2ec4aeff1e96446ad4737e0b4f75e24fa63eba55. --- subprojects.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/subprojects.cfg b/subprojects.cfg index fd8eb549e85..a80ebdb3c42 100644 --- a/subprojects.cfg +++ b/subprojects.cfg @@ -6,8 +6,6 @@ firebase-common:ktx firebase-config firebase-config:bandwagoner firebase-database -firebase-installations-interop -firebase-installations firebase-database-collection firebase-datatransport firebase-firestore From 1c502833d436babdc7acf2bb3891b5a5ccbe28de Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:16:04 -0700 Subject: [PATCH 06/16] Revert "Readding .idea files that were deleted in previous commit" This reverts commit 7b4ebcf7accb28fc01ddd5e864fa3e9c0d46dba5. --- .idea/copyright/Apache_2___Google.xml | 6 --- .idea/copyright/profiles_settings.xml | 10 ---- .../FirestoreProdIntegrationTest.xml | 21 -------- ...Integration_Tests__Firestore_Emulator_.xml | 51 ------------------- .../Firestore_Unit_Tests.xml | 24 --------- 5 files changed, 112 deletions(-) delete mode 100644 .idea/copyright/Apache_2___Google.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/runConfigurations/FirestoreProdIntegrationTest.xml delete mode 100644 .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml delete mode 100644 .idea/runConfigurations/Firestore_Unit_Tests.xml diff --git a/.idea/copyright/Apache_2___Google.xml b/.idea/copyright/Apache_2___Google.xml deleted file mode 100644 index cba016dc880..00000000000 --- a/.idea/copyright/Apache_2___Google.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 8c478598102..00000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml deleted file mode 100644 index 6cc8a003a50..00000000000 --- a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - diff --git a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml deleted file mode 100644 index 874d64e132f..00000000000 --- a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Unit_Tests.xml b/.idea/runConfigurations/Firestore_Unit_Tests.xml deleted file mode 100644 index e8419c4a54d..00000000000 --- a/.idea/runConfigurations/Firestore_Unit_Tests.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From c77acd2d335280834fc32622d7533af064576549 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:21:49 -0700 Subject: [PATCH 07/16] Add firebase installations project path --- subprojects.cfg | 2 ++ 1 file changed, 2 insertions(+) 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 From a32c3948ffe69323dead5b85d9ce6e715767f508 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 10:38:41 -0700 Subject: [PATCH 08/16] Adding Firebase Installations module. --- .../firebase-installations.gradle | 97 +++++++++++ firebase-installations/gradle.properties | 1 + firebase-installations/lint.xml | 11 ++ firebase-installations/proguard-rules.pro | 21 +++ .../src/main/AndroidManifest.xml | 14 ++ .../installations/FirebaseInstallations.java | 110 ++++++++++++ .../FirebaseInstallationsRegistrar.java | 39 +++++ .../v1/firebase_installations_api.proto | 163 ++++++++++++++++++ .../src/main/res/values/strings.xml | 3 + .../FirebaseInstallationsRegistrarTest.java | 20 +++ .../FirebaseInstallationsTest.java | 20 +++ 11 files changed, 499 insertions(+) create mode 100644 firebase-installations/firebase-installations.gradle create mode 100644 firebase-installations/gradle.properties create mode 100644 firebase-installations/lint.xml create mode 100644 firebase-installations/proguard-rules.pro create mode 100644 firebase-installations/src/main/AndroidManifest.xml create mode 100644 firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java create mode 100644 firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java create mode 100644 firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto create mode 100644 firebase-installations/src/main/res/values/strings.xml create mode 100644 firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java create mode 100644 firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java diff --git a/firebase-installations/firebase-installations.gradle b/firebase-installations/firebase-installations.gradle new file mode 100644 index 00000000000..1db5bb60d1c --- /dev/null +++ b/firebase-installations/firebase-installations.gradle @@ -0,0 +1,97 @@ +// 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' + id 'com.google.protobuf' +} + +protobuf { + // Configure the protoc executable + protoc { + // Download from repositories + artifact = 'com.google.protobuf:protoc:3.4.0' + } + plugins { + grpc { + artifact = 'io.grpc:protoc-gen-grpc-java:1.21.0' + } + javalite { + // The codegen for lite comes as a separate artifact + artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0' + } + } + generateProtoTasks { + all().each { task -> + task.builtins { + // In most cases you don't need the full Java output + // if you use the lite output. + remove java + } + task.plugins { + grpc { + option 'lite' + } + javalite {} + } + } + } +} + +android { + compileSdkVersion project.targetSdkVersion + defaultConfig { + minSdkVersion project.minSdkVersion + targetSdkVersion project.targetSdkVersion + multiDexEnabled true + versionName version + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + sourceSets { + main { + proto { + srcDir 'src/main/proto' + } + } + } + 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 project(':protolite-well-known-types') + + implementation 'io.grpc:grpc-stub:1.21.0' + implementation 'io.grpc:grpc-protobuf-lite:1.21.0' + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'com.squareup.okhttp3:okhttp:3.12.1' + 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' +} diff --git a/firebase-installations/gradle.properties b/firebase-installations/gradle.properties new file mode 100644 index 00000000000..33cda300b91 --- /dev/null +++ b/firebase-installations/gradle.properties @@ -0,0 +1 @@ +version=17.1.1 \ No newline at end of file diff --git a/firebase-installations/lint.xml b/firebase-installations/lint.xml new file mode 100644 index 00000000000..c478c9793de --- /dev/null +++ b/firebase-installations/lint.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/firebase-installations/proguard-rules.pro b/firebase-installations/proguard-rules.pro new file mode 100644 index 00000000000..481bb434814 --- /dev/null +++ b/firebase-installations/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/firebase-installations/src/main/AndroidManifest.xml b/firebase-installations/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..b7d77de60f9 --- /dev/null +++ b/firebase-installations/src/main/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file 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..99affb741a3 --- /dev/null +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -0,0 +1,110 @@ +// 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; +import okhttp3.OkHttpClient; + +/** + * 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 OkHttpClient httpClient; + + private final FirebaseApp firebaseApp; + + /** package private constructor. */ + FirebaseInstallations(FirebaseApp firebaseApp) { + this.firebaseApp = firebaseApp; + httpClient = new OkHttpClient(); + } + + /** + * 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() { + return Tasks.forResult("dummy_auth_token"); + } + + /** + * 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(); + } +} \ No newline at end of file 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..f36e8b3230a --- /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)); + } +} \ No newline at end of file diff --git a/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto b/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto new file mode 100644 index 00000000000..a73a74a3b27 --- /dev/null +++ b/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto @@ -0,0 +1,163 @@ +// 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. + +syntax = "proto3"; + +package google.firebase.installations.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; + +option java_multiple_files = true; +option java_package = "com.google.firebase.installations.v1"; + +// Firebase Installations API +// +// Firebase Installations API enables registration, management and deletion +// of Firebase installations: app instances, webapp instances, or IoT devices +// that use Firebase services. +service FirebaseInstallationsService { + // Deletes an Installation + rpc DeleteInstallation(DeleteInstallationRequest) + returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{name=projects/*/installations/*}" + }; + } + + // Creates (and registers) a new Firebase Installation, incl. its FID and + // Verification Key (used for authentication purposes) + // refer to https://cloud.google.com/apis/design/standard_methods + // for method definition formats. + rpc CreateInstallation(CreateInstallationRequest) returns (Installation) { + option (google.api.http) = { + post: "/v1/{parent=projects/*}/installations" + body: "installation" + }; + } + + // Creates a new short-lived FIS-Auth-Token (Bearer-Token for Installations) + rpc GenerateAuthToken(GenerateAuthTokenRequest) returns (AuthTokenInfo) { + option (google.api.http) = { + post: "/v1/{name=projects/*/installations/*}/authTokens:generate" + body: "*" + }; + } +} + +// The request to delete the data stored for a specific Installation and +// permanently disable its Firebase Installations ID and authentication +// credentials. This process triggers the Firebase GDPR delete-pipeline. +message DeleteInstallationRequest { + // Resource name of the installation. It must have the format of + // `projects/*/installations/*`. + string name = 1; +} + +// The request to register a new Installation. +message CreateInstallationRequest { + // The parent resource name. + // Identifies the Cloud Project owning this Installation. + // We accept both projectID and projectNumber. + string parent = 1; + + // The resource to create. + Installation installation = 2; +} + +// The request to register a new Installation. +message GenerateAuthTokenRequest { + // The Firebase Installation requesting for FIS-Auth-Token. + string name = 1; + + // Optional field that allows the Firebase Installation to update (some of) + // its attributes with FIS the server (ex: sdk_version) when it requests for a + // new FIS Auth-Token. + // (-- go/not-api-precedent: Updating the metadata has no relation to the + // generation of FIS Auth-Tokens. Ordinarily, generating a FIS Auth-Token and + // updating metadata should be handled by two separate endpoints. + // We decided to batch the requests in order to limit the number of necessary + // requests from the client, given that our users (Firebase Services) are + // targeting mobile applications and additional network requests increase the + // startup-time of applications which is undesirable for mobile platform. --) + Installation installation = 2; +} + +message AuthTokenInfo { + // A new FIS-Auth-Token, created for the Firebase Installation. + string token = 1; + + // The duration for which this auth_token will be valid. + // In a response's JSON format, the value is encoded as a string with the + // suffix "s" (indicating seconds), preceded by the number of seconds. + // Example: "604800s" + // (-- go/not-api-precedent: OnePlatform APIs usually do not use prepositions + // in field names, but we are doing so here to conform to the external OAuth + // terminology. --) + google.protobuf.Duration expires_in = 2; +} + +// next_id: 9 +message Installation { + // URI of the Firebase Installation with the following format: + // projects//installations/ + // Example: projects/35006771263/installations/eapzYQai_g8flVQyfKoGs7 + // This field is set only during response. + string name = 1; + + // Globally unique identifier of the Firebase Installation. + string fid = 2; + + // GMP App Id - Firebase Application identifier, generated by Firebase Console + string app_id = 3; + + // The current version of the used FIS client-SDK. + string sdk_version = 4; + + // The version of the Firebase Installations Internal Authentication scheme. + // This value is used as Authorization-Type of HTTP-header "Authorization". + // Compare: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication + // The internal client/server authentication of Firebase Installations may + // change in the future. Initial version is "FIS_v2". + // This field is optional. If not set the default version is assumed (FIS_v2). + string auth_version = 5; + + // A refresh token created for / assigned to the Firebase Installation by FIS. + // The Firebase Installation can use the refresh token to send requests to + // #GenerateAuthToken in order to request and generate new FIS Auth-Tokens. + // Used for FIS Internal Auth scheme FIS_v2. + // This field is set only during response. + string refresh_token = 6; + + // The verification-key (a.k.a. public-key) is used to authenticate the + // digital signatures sent by the Firebase Installation in requests to FIS. + // Used for FIS Internal Auth scheme FIS_v1. + // The public key is expected to be in X.509 format ("SubjectPublicKeyInfo"), + // compare RFC 5280 (https://tools.ietf.org/html/rfc5280#section-4.1). + string verification_key = 7; + + // The initial FIS Auth-Token, created for the Firebase Installation. + // This field is set only during response. + // (-- go/not-api-precedent: Ordinarily requesting a FIS Auth-Token should be + // achieved via a secondary request to endpoint #GenerateAuthToken. However + // the number of necessary requests has an impact on the startup time + // (particularly "cold-start") of mobile applications and FIS is used by + // Firebase Services that are targeting mobile applicatoins. Returning a FIS + // Auth-Token along with the created Installation resource allows us to reduce + // our client-server communication to 1 request during cold-start + // (i.e. 1st startup) of a newly installed app. This improves user experience + // as it reduces user-perceived latency. --) + AuthTokenInfo auth_token = 8; +} \ No newline at end of file diff --git a/firebase-installations/src/main/res/values/strings.xml b/firebase-installations/src/main/res/values/strings.xml new file mode 100644 index 00000000000..88c6d0b6d8f --- /dev/null +++ b/firebase-installations/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + FirebaseInstallations + 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..63e6eab827a --- /dev/null +++ b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java @@ -0,0 +1,20 @@ +// 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 { + +} \ No newline at end of file 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..96a33478d86 --- /dev/null +++ b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java @@ -0,0 +1,20 @@ +// 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 { + +} \ No newline at end of file From 73c9e39bb3421bc4b5ddb31d7123e2f65f4f5d16 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 11:46:12 -0700 Subject: [PATCH 09/16] Readding .idea files that were deleted in previous commit --- .idea/copyright/Apache_2___Google.xml | 6 +++ .idea/copyright/profiles_settings.xml | 10 ++++ .../FirestoreProdIntegrationTest.xml | 21 ++++++++ ...Integration_Tests__Firestore_Emulator_.xml | 51 +++++++++++++++++++ .../Firestore_Unit_Tests.xml | 24 +++++++++ 5 files changed, 112 insertions(+) create mode 100644 .idea/copyright/Apache_2___Google.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/runConfigurations/FirestoreProdIntegrationTest.xml create mode 100644 .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml create mode 100644 .idea/runConfigurations/Firestore_Unit_Tests.xml diff --git a/.idea/copyright/Apache_2___Google.xml b/.idea/copyright/Apache_2___Google.xml new file mode 100644 index 00000000000..cba016dc880 --- /dev/null +++ b/.idea/copyright/Apache_2___Google.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000000..8c478598102 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml new file mode 100644 index 00000000000..6cc8a003a50 --- /dev/null +++ b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml new file mode 100644 index 00000000000..874d64e132f --- /dev/null +++ b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml @@ -0,0 +1,51 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Unit_Tests.xml b/.idea/runConfigurations/Firestore_Unit_Tests.xml new file mode 100644 index 00000000000..e8419c4a54d --- /dev/null +++ b/.idea/runConfigurations/Firestore_Unit_Tests.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file From 0e8b2868102663e97ff80ebd9bda9aedbe53ead9 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:15:18 -0700 Subject: [PATCH 10/16] Revert "Adding Firebase Installations module" This reverts commit 2ec4aeff1e96446ad4737e0b4f75e24fa63eba55. --- subprojects.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/subprojects.cfg b/subprojects.cfg index fd8eb549e85..a80ebdb3c42 100644 --- a/subprojects.cfg +++ b/subprojects.cfg @@ -6,8 +6,6 @@ firebase-common:ktx firebase-config firebase-config:bandwagoner firebase-database -firebase-installations-interop -firebase-installations firebase-database-collection firebase-datatransport firebase-firestore From cf37ddeb598751db8149224bd6e719f38828da62 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:16:04 -0700 Subject: [PATCH 11/16] Revert "Readding .idea files that were deleted in previous commit" This reverts commit 7b4ebcf7accb28fc01ddd5e864fa3e9c0d46dba5. --- .idea/copyright/Apache_2___Google.xml | 6 --- .idea/copyright/profiles_settings.xml | 10 ---- .../FirestoreProdIntegrationTest.xml | 21 -------- ...Integration_Tests__Firestore_Emulator_.xml | 51 ------------------- .../Firestore_Unit_Tests.xml | 24 --------- 5 files changed, 112 deletions(-) delete mode 100644 .idea/copyright/Apache_2___Google.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/runConfigurations/FirestoreProdIntegrationTest.xml delete mode 100644 .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml delete mode 100644 .idea/runConfigurations/Firestore_Unit_Tests.xml diff --git a/.idea/copyright/Apache_2___Google.xml b/.idea/copyright/Apache_2___Google.xml deleted file mode 100644 index cba016dc880..00000000000 --- a/.idea/copyright/Apache_2___Google.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 8c478598102..00000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml deleted file mode 100644 index 6cc8a003a50..00000000000 --- a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - diff --git a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml deleted file mode 100644 index 874d64e132f..00000000000 --- a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Unit_Tests.xml b/.idea/runConfigurations/Firestore_Unit_Tests.xml deleted file mode 100644 index e8419c4a54d..00000000000 --- a/.idea/runConfigurations/Firestore_Unit_Tests.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From 896c748df079d425e2205e744c5ae9d44e43cc8f Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:21:49 -0700 Subject: [PATCH 12/16] Add firebase installations project path --- subprojects.cfg | 2 ++ 1 file changed, 2 insertions(+) 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 From 370b8624426ae3eb464eb0953a7ad2d6703234b4 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 13:59:28 -0700 Subject: [PATCH 13/16] Fixing formattinf issues. --- .../FirebaseInstallationsApi.java | 28 ++-- .../installations/FirebaseInstallations.java | 128 +++++++++--------- .../FirebaseInstallationsRegistrar.java | 20 +-- .../FirebaseInstallationsRegistrarTest.java | 4 +- .../FirebaseInstallationsTest.java | 4 +- 5 files changed, 90 insertions(+), 94 deletions(-) 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 index c02576a8efd..74c9fb9f984 100644 --- 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 @@ -24,19 +24,19 @@ */ 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 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(); + /** Async function that returns a auth token(public key) of this Firebase app installation. */ + Task getAuthToken(); - /** - * 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(); -} \ No newline at end of file + /** + * 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/src/main/java/com/google/firebase/installations/FirebaseInstallations.java b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java index 99affb741a3..037712a2f61 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -35,76 +35,76 @@ */ public class FirebaseInstallations implements FirebaseInstallationsApi { - private final OkHttpClient httpClient; + private final OkHttpClient httpClient; - private final FirebaseApp firebaseApp; + private final FirebaseApp firebaseApp; - /** package private constructor. */ - FirebaseInstallations(FirebaseApp firebaseApp) { - this.firebaseApp = firebaseApp; - httpClient = new OkHttpClient(); - } + /** package private constructor. */ + FirebaseInstallations(FirebaseApp firebaseApp) { + this.firebaseApp = firebaseApp; + httpClient = new OkHttpClient(); + } - /** - * 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 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 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 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() { - return Tasks.forResult("dummy_auth_token"); - } + /** Returns a auth token(public key) of this Firebase app installation. */ + @NonNull + @Override + public Task getAuthToken() { + return Tasks.forResult("dummy_auth_token"); + } - /** - * 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); - } + /** + * 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 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(); - } -} \ No newline at end of file + /** 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 index f36e8b3230a..e84168ab4fb 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java @@ -27,13 +27,13 @@ @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)); - } -} \ No newline at end of file + @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 index 63e6eab827a..5a7c505e9b6 100644 --- a/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java +++ b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsRegistrarTest.java @@ -15,6 +15,4 @@ package com.google.firebase.installations; /** Tests for {@link FirebaseInstallationsRegistrar}. */ -public class FirebaseInstallationsRegistrarTest { - -} \ No newline at end of file +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 index 96a33478d86..fe64dcf06b8 100644 --- a/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java +++ b/firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java @@ -15,6 +15,4 @@ package com.google.firebase.installations; /** Tests for {@link FirebaseInstallations}. */ -public class FirebaseInstallationsTest { - -} \ No newline at end of file +public class FirebaseInstallationsTest {} From d0ce8fa8f1e4030ee287e77c798306dce8941496 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 22 Jul 2019 14:28:39 -0700 Subject: [PATCH 14/16] Revert "Adding Firebase Installations module" with hidden files This reverts commit 2ec4aeff1e96446ad4737e0b4f75e24fa63eba55. --- .idea/copyright/Apache_2___Google.xml | 6 +++ .idea/copyright/profiles_settings.xml | 10 ++++ .../FirestoreProdIntegrationTest.xml | 21 ++++++++ ...Integration_Tests__Firestore_Emulator_.xml | 51 +++++++++++++++++++ .../Firestore_Unit_Tests.xml | 24 +++++++++ 5 files changed, 112 insertions(+) create mode 100644 .idea/copyright/Apache_2___Google.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/runConfigurations/FirestoreProdIntegrationTest.xml create mode 100644 .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml create mode 100644 .idea/runConfigurations/Firestore_Unit_Tests.xml diff --git a/.idea/copyright/Apache_2___Google.xml b/.idea/copyright/Apache_2___Google.xml new file mode 100644 index 00000000000..a0bb219243a --- /dev/null +++ b/.idea/copyright/Apache_2___Google.xml @@ -0,0 +1,6 @@ + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000000..0d00e324732 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/FirestoreProdIntegrationTest.xml b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml new file mode 100644 index 00000000000..fda38c03059 --- /dev/null +++ b/.idea/runConfigurations/FirestoreProdIntegrationTest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml new file mode 100644 index 00000000000..1c1053aa848 --- /dev/null +++ b/.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml @@ -0,0 +1,51 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Firestore_Unit_Tests.xml b/.idea/runConfigurations/Firestore_Unit_Tests.xml new file mode 100644 index 00000000000..5bfd8accf8a --- /dev/null +++ b/.idea/runConfigurations/Firestore_Unit_Tests.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file From 095296b1368fb001759a9617bf004daa940a732c Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Tue, 23 Jul 2019 11:03:56 -0700 Subject: [PATCH 15/16] Addressing review comments. --- .../gradle.properties | 2 +- .../src/main/AndroidManifest.xml | 2 +- .../FirebaseInstallationsApi.java | 2 +- .../InstallationTokenResult.java | 43 +++++ .../firebase-installations.gradle | 45 +---- firebase-installations/gradle.properties | 2 +- firebase-installations/lint.xml | 2 +- firebase-installations/proguard-rules.pro | 21 --- .../src/main/AndroidManifest.xml | 2 +- .../installations/FirebaseInstallations.java | 8 +- .../v1/firebase_installations_api.proto | 163 ------------------ .../src/main/res/values/strings.xml | 3 - 12 files changed, 52 insertions(+), 243 deletions(-) create mode 100644 firebase-installations-interop/src/main/java/com/google/firebase/installations/InstallationTokenResult.java delete mode 100644 firebase-installations/proguard-rules.pro delete mode 100644 firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto delete mode 100644 firebase-installations/src/main/res/values/strings.xml diff --git a/firebase-installations-interop/gradle.properties b/firebase-installations-interop/gradle.properties index 33cda300b91..752913a3eb5 100644 --- a/firebase-installations-interop/gradle.properties +++ b/firebase-installations-interop/gradle.properties @@ -1 +1 @@ -version=17.1.1 \ No newline at end of file +version=17.1.1 diff --git a/firebase-installations-interop/src/main/AndroidManifest.xml b/firebase-installations-interop/src/main/AndroidManifest.xml index 265d258f1b9..7ae18eafe43 100644 --- a/firebase-installations-interop/src/main/AndroidManifest.xml +++ b/firebase-installations-interop/src/main/AndroidManifest.xml @@ -14,4 +14,4 @@ \ No newline at end of file + package="com.google.firebase.installations.interop" /> 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 index 74c9fb9f984..6947d7ec037 100644 --- 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 @@ -31,7 +31,7 @@ public interface FirebaseInstallationsApi { Task getId(); /** Async function that returns a auth token(public key) of this Firebase app installation. */ - Task getAuthToken(); + Task getAuthToken(boolean forceRefresh); /** * Async function that deletes this Firebase app installation from Firebase backend. This call 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..9da035dcf09 --- /dev/null +++ b/firebase-installations-interop/src/main/java/com/google/firebase/installations/InstallationTokenResult.java @@ -0,0 +1,43 @@ +// 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; + +/** A set of values describing a FIS Auth Token Result. */ +public class InstallationTokenResult { + + /** A new FIS Auth-Token, created for this firebase installation. */ + private final String authToken; + /** + * The amount of time, in milliseconds, before the auth-token expires for this firebase + * installation. + */ + private final long tokenExpirationTimestampMillis; + + public InstallationTokenResult(@NonNull String authToken, long tokenExpirationTimestampMillis) { + this.authToken = authToken; + this.tokenExpirationTimestampMillis = tokenExpirationTimestampMillis; + } + + @NonNull + public String getAuthToken() { + return authToken; + } + + public long getTokenExpirationTimestampMillis() { + return tokenExpirationTimestampMillis; + } +} diff --git a/firebase-installations/firebase-installations.gradle b/firebase-installations/firebase-installations.gradle index 1db5bb60d1c..45123f1c6ce 100644 --- a/firebase-installations/firebase-installations.gradle +++ b/firebase-installations/firebase-installations.gradle @@ -15,39 +15,6 @@ plugins { id 'firebase-library' - id 'com.google.protobuf' -} - -protobuf { - // Configure the protoc executable - protoc { - // Download from repositories - artifact = 'com.google.protobuf:protoc:3.4.0' - } - plugins { - grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.21.0' - } - javalite { - // The codegen for lite comes as a separate artifact - artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0' - } - } - generateProtoTasks { - all().each { task -> - task.builtins { - // In most cases you don't need the full Java output - // if you use the lite output. - remove java - } - task.plugins { - grpc { - option 'lite' - } - javalite {} - } - } - } } android { @@ -59,13 +26,6 @@ android { versionName version testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } - sourceSets { - main { - proto { - srcDir 'src/main/proto' - } - } - } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -80,12 +40,8 @@ android { dependencies { implementation project(':firebase-common') implementation project(':firebase-installations-interop') - implementation project(':protolite-well-known-types') - implementation 'io.grpc:grpc-stub:1.21.0' - implementation 'io.grpc:grpc-protobuf-lite:1.21.0' implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'com.squareup.okhttp3:okhttp:3.12.1' implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.google.android.gms:play-services-tasks:17.0.0' @@ -94,4 +50,5 @@ dependencies { 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 index 33cda300b91..752913a3eb5 100644 --- a/firebase-installations/gradle.properties +++ b/firebase-installations/gradle.properties @@ -1 +1 @@ -version=17.1.1 \ No newline at end of file +version=17.1.1 diff --git a/firebase-installations/lint.xml b/firebase-installations/lint.xml index c478c9793de..9b9bd90b534 100644 --- a/firebase-installations/lint.xml +++ b/firebase-installations/lint.xml @@ -8,4 +8,4 @@ - \ No newline at end of file + diff --git a/firebase-installations/proguard-rules.pro b/firebase-installations/proguard-rules.pro deleted file mode 100644 index 481bb434814..00000000000 --- a/firebase-installations/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/firebase-installations/src/main/AndroidManifest.xml b/firebase-installations/src/main/AndroidManifest.xml index b7d77de60f9..08b562940aa 100644 --- a/firebase-installations/src/main/AndroidManifest.xml +++ b/firebase-installations/src/main/AndroidManifest.xml @@ -11,4 +11,4 @@ android:value="com.google.firebase.components.ComponentRegistrar" /> - \ No newline at end of file + 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 index 037712a2f61..d721f94c8e3 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -20,7 +20,6 @@ import com.google.android.gms.tasks.Tasks; import com.google.common.annotations.VisibleForTesting; import com.google.firebase.FirebaseApp; -import okhttp3.OkHttpClient; /** * Entry point for Firebase Installations. @@ -35,14 +34,11 @@ */ public class FirebaseInstallations implements FirebaseInstallationsApi { - private final OkHttpClient httpClient; - private final FirebaseApp firebaseApp; /** package private constructor. */ FirebaseInstallations(FirebaseApp firebaseApp) { this.firebaseApp = firebaseApp; - httpClient = new OkHttpClient(); } /** @@ -81,8 +77,8 @@ public Task getId() { /** Returns a auth token(public key) of this Firebase app installation. */ @NonNull @Override - public Task getAuthToken() { - return Tasks.forResult("dummy_auth_token"); + public Task getAuthToken(boolean forceRefresh) { + return Tasks.forResult(new InstallationTokenResult("dummy_auth_token", 1000l)); } /** diff --git a/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto b/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto deleted file mode 100644 index a73a74a3b27..00000000000 --- a/firebase-installations/src/main/proto/google/firebase/installations/v1/firebase_installations_api.proto +++ /dev/null @@ -1,163 +0,0 @@ -// 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. - -syntax = "proto3"; - -package google.firebase.installations.v1; - -import "google/api/annotations.proto"; -import "google/protobuf/duration.proto"; -import "google/protobuf/empty.proto"; - -option java_multiple_files = true; -option java_package = "com.google.firebase.installations.v1"; - -// Firebase Installations API -// -// Firebase Installations API enables registration, management and deletion -// of Firebase installations: app instances, webapp instances, or IoT devices -// that use Firebase services. -service FirebaseInstallationsService { - // Deletes an Installation - rpc DeleteInstallation(DeleteInstallationRequest) - returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v1/{name=projects/*/installations/*}" - }; - } - - // Creates (and registers) a new Firebase Installation, incl. its FID and - // Verification Key (used for authentication purposes) - // refer to https://cloud.google.com/apis/design/standard_methods - // for method definition formats. - rpc CreateInstallation(CreateInstallationRequest) returns (Installation) { - option (google.api.http) = { - post: "/v1/{parent=projects/*}/installations" - body: "installation" - }; - } - - // Creates a new short-lived FIS-Auth-Token (Bearer-Token for Installations) - rpc GenerateAuthToken(GenerateAuthTokenRequest) returns (AuthTokenInfo) { - option (google.api.http) = { - post: "/v1/{name=projects/*/installations/*}/authTokens:generate" - body: "*" - }; - } -} - -// The request to delete the data stored for a specific Installation and -// permanently disable its Firebase Installations ID and authentication -// credentials. This process triggers the Firebase GDPR delete-pipeline. -message DeleteInstallationRequest { - // Resource name of the installation. It must have the format of - // `projects/*/installations/*`. - string name = 1; -} - -// The request to register a new Installation. -message CreateInstallationRequest { - // The parent resource name. - // Identifies the Cloud Project owning this Installation. - // We accept both projectID and projectNumber. - string parent = 1; - - // The resource to create. - Installation installation = 2; -} - -// The request to register a new Installation. -message GenerateAuthTokenRequest { - // The Firebase Installation requesting for FIS-Auth-Token. - string name = 1; - - // Optional field that allows the Firebase Installation to update (some of) - // its attributes with FIS the server (ex: sdk_version) when it requests for a - // new FIS Auth-Token. - // (-- go/not-api-precedent: Updating the metadata has no relation to the - // generation of FIS Auth-Tokens. Ordinarily, generating a FIS Auth-Token and - // updating metadata should be handled by two separate endpoints. - // We decided to batch the requests in order to limit the number of necessary - // requests from the client, given that our users (Firebase Services) are - // targeting mobile applications and additional network requests increase the - // startup-time of applications which is undesirable for mobile platform. --) - Installation installation = 2; -} - -message AuthTokenInfo { - // A new FIS-Auth-Token, created for the Firebase Installation. - string token = 1; - - // The duration for which this auth_token will be valid. - // In a response's JSON format, the value is encoded as a string with the - // suffix "s" (indicating seconds), preceded by the number of seconds. - // Example: "604800s" - // (-- go/not-api-precedent: OnePlatform APIs usually do not use prepositions - // in field names, but we are doing so here to conform to the external OAuth - // terminology. --) - google.protobuf.Duration expires_in = 2; -} - -// next_id: 9 -message Installation { - // URI of the Firebase Installation with the following format: - // projects//installations/ - // Example: projects/35006771263/installations/eapzYQai_g8flVQyfKoGs7 - // This field is set only during response. - string name = 1; - - // Globally unique identifier of the Firebase Installation. - string fid = 2; - - // GMP App Id - Firebase Application identifier, generated by Firebase Console - string app_id = 3; - - // The current version of the used FIS client-SDK. - string sdk_version = 4; - - // The version of the Firebase Installations Internal Authentication scheme. - // This value is used as Authorization-Type of HTTP-header "Authorization". - // Compare: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication - // The internal client/server authentication of Firebase Installations may - // change in the future. Initial version is "FIS_v2". - // This field is optional. If not set the default version is assumed (FIS_v2). - string auth_version = 5; - - // A refresh token created for / assigned to the Firebase Installation by FIS. - // The Firebase Installation can use the refresh token to send requests to - // #GenerateAuthToken in order to request and generate new FIS Auth-Tokens. - // Used for FIS Internal Auth scheme FIS_v2. - // This field is set only during response. - string refresh_token = 6; - - // The verification-key (a.k.a. public-key) is used to authenticate the - // digital signatures sent by the Firebase Installation in requests to FIS. - // Used for FIS Internal Auth scheme FIS_v1. - // The public key is expected to be in X.509 format ("SubjectPublicKeyInfo"), - // compare RFC 5280 (https://tools.ietf.org/html/rfc5280#section-4.1). - string verification_key = 7; - - // The initial FIS Auth-Token, created for the Firebase Installation. - // This field is set only during response. - // (-- go/not-api-precedent: Ordinarily requesting a FIS Auth-Token should be - // achieved via a secondary request to endpoint #GenerateAuthToken. However - // the number of necessary requests has an impact on the startup time - // (particularly "cold-start") of mobile applications and FIS is used by - // Firebase Services that are targeting mobile applicatoins. Returning a FIS - // Auth-Token along with the created Installation resource allows us to reduce - // our client-server communication to 1 request during cold-start - // (i.e. 1st startup) of a newly installed app. This improves user experience - // as it reduces user-perceived latency. --) - AuthTokenInfo auth_token = 8; -} \ No newline at end of file diff --git a/firebase-installations/src/main/res/values/strings.xml b/firebase-installations/src/main/res/values/strings.xml deleted file mode 100644 index 88c6d0b6d8f..00000000000 --- a/firebase-installations/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - FirebaseInstallations - From ce22251dc7dd720196b74902414be2aea7f3a64b Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Tue, 23 Jul 2019 15:41:53 -0700 Subject: [PATCH 16/16] Making InstallationTokenResult an AutoValue class. --- .../firebase-installations-interop.gradle | 3 +++ .../InstallationTokenResult.java | 25 ++++++++----------- .../installations/FirebaseInstallations.java | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/firebase-installations-interop/firebase-installations-interop.gradle b/firebase-installations-interop/firebase-installations-interop.gradle index 1eec0386735..5acad3e1434 100644 --- a/firebase-installations-interop/firebase-installations-interop.gradle +++ b/firebase-installations-interop/firebase-installations-interop.gradle @@ -40,4 +40,7 @@ android { 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/src/main/java/com/google/firebase/installations/InstallationTokenResult.java b/firebase-installations-interop/src/main/java/com/google/firebase/installations/InstallationTokenResult.java index 9da035dcf09..df04f26ca38 100644 --- 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 @@ -15,29 +15,24 @@ package com.google.firebase.installations; import androidx.annotation.NonNull; +import com.google.auto.value.AutoValue; -/** A set of values describing a FIS Auth Token Result. */ -public class InstallationTokenResult { +/** 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. */ - private final String authToken; + @NonNull + public abstract String getAuthToken(); /** * The amount of time, in milliseconds, before the auth-token expires for this firebase * installation. */ - private final long tokenExpirationTimestampMillis; - - public InstallationTokenResult(@NonNull String authToken, long tokenExpirationTimestampMillis) { - this.authToken = authToken; - this.tokenExpirationTimestampMillis = tokenExpirationTimestampMillis; - } + public abstract long getTokenExpirationTimestampMillis(); @NonNull - public String getAuthToken() { - return authToken; - } - - public long getTokenExpirationTimestampMillis() { - return tokenExpirationTimestampMillis; + public static InstallationTokenResult create( + @NonNull String authToken, long tokenExpirationTimestampMillis) { + return new AutoValue_InstallationTokenResult(authToken, tokenExpirationTimestampMillis); } } 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 index d721f94c8e3..f135aa2e197 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -78,7 +78,7 @@ public Task getId() { @NonNull @Override public Task getAuthToken(boolean forceRefresh) { - return Tasks.forResult(new InstallationTokenResult("dummy_auth_token", 1000l)); + return Tasks.forResult(InstallationTokenResult.create("dummy_auth_token", 1000l)); } /**