Skip to content

Commit dca81d0

Browse files
committed
Adding Firebase Installations module.
1 parent 2ec4aef commit dca81d0

File tree

11 files changed

+459
-0
lines changed

11 files changed

+459
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
plugins {
17+
id 'firebase-library'
18+
id 'com.google.protobuf'
19+
}
20+
21+
protobuf {
22+
// Configure the protoc executable
23+
protoc {
24+
// Download from repositories
25+
artifact = 'com.google.protobuf:protoc:3.4.0'
26+
}
27+
plugins {
28+
grpc {
29+
artifact = 'io.grpc:protoc-gen-grpc-java:1.21.0'
30+
}
31+
javalite {
32+
// The codegen for lite comes as a separate artifact
33+
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
34+
}
35+
}
36+
generateProtoTasks {
37+
all().each { task ->
38+
task.builtins {
39+
// In most cases you don't need the full Java output
40+
// if you use the lite output.
41+
remove java
42+
}
43+
task.plugins {
44+
grpc {
45+
option 'lite'
46+
}
47+
javalite {}
48+
}
49+
}
50+
}
51+
}
52+
53+
android {
54+
compileSdkVersion project.targetSdkVersion
55+
defaultConfig {
56+
minSdkVersion project.minSdkVersion
57+
targetSdkVersion project.targetSdkVersion
58+
multiDexEnabled true
59+
versionName version
60+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
61+
}
62+
sourceSets {
63+
main {
64+
proto {
65+
srcDir 'src/main/proto'
66+
}
67+
}
68+
}
69+
compileOptions {
70+
sourceCompatibility JavaVersion.VERSION_1_8
71+
targetCompatibility JavaVersion.VERSION_1_8
72+
}
73+
testOptions {
74+
unitTests {
75+
includeAndroidResources = true
76+
}
77+
}
78+
}
79+
80+
dependencies {
81+
implementation project(':firebase-common')
82+
implementation project(':firebase-installations-interop')
83+
implementation project(':protolite-well-known-types')
84+
85+
implementation 'io.grpc:grpc-stub:1.21.0'
86+
implementation 'io.grpc:grpc-protobuf-lite:1.21.0'
87+
implementation 'androidx.appcompat:appcompat:1.0.2'
88+
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
89+
implementation 'androidx.multidex:multidex:2.0.1'
90+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
91+
92+
testImplementation 'androidx.test:core:1.2.0'
93+
testImplementation 'junit:junit:4.12'
94+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
95+
96+
androidTestImplementation 'androidx.test:runner:1.2.0'
97+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=17.1.1

firebase-installations/lint.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<lint>
3+
<!--gRPC's DNS name resolver checks for javax.naming at runtime to determine if it can be used, but fails gracefullt without it. This lint error is safe to ignore.-->
4+
<!--See : https://github.com/grpc/grpc-java/blob/b0f423295b4674cb5247a6143fd211b050ef0065/core/src/main/java/io/grpc/internal/JndiResourceResolverFactory.java#L73-->
5+
<issue id="InvalidPackage">
6+
<ignore path="*/io.grpc/grpc-core/*"/>
7+
</issue>
8+
9+
<!-- Disable the given check in this project -->
10+
<issue id="GradleCompatible" severity="ignore" />
11+
</lint>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.firebase.installations">
4+
5+
<application>
6+
<service
7+
android:name="com.google.firebase.components.ComponentDiscoveryService"
8+
android:exported="false">
9+
<meta-data
10+
android:name="com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar"
11+
android:value="com.google.firebase.components.ComponentRegistrar" />
12+
</service>
13+
</application>
14+
</manifest>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.installations;
16+
17+
import androidx.annotation.NonNull;
18+
import com.google.android.gms.common.internal.Preconditions;
19+
import com.google.android.gms.tasks.Task;
20+
import com.google.android.gms.tasks.Tasks;
21+
import com.google.common.annotations.VisibleForTesting;
22+
import com.google.firebase.FirebaseApp;
23+
import okhttp3.OkHttpClient;
24+
25+
/**
26+
* Entry point for Firebase Installations.
27+
*
28+
* <p>Firebase Installations does
29+
*
30+
* <ul>
31+
* <li>provide unique identifier for a Firebase installation
32+
* <li>provide auth token of a Firebase installation
33+
* <li>provide a API to GDPR-delete a Firebase installation
34+
* </ul>
35+
*/
36+
public class FirebaseInstallations implements FirebaseInstallationsApi {
37+
38+
private final OkHttpClient httpClient;
39+
40+
private final FirebaseApp firebaseApp;
41+
42+
/** package private constructor. */
43+
FirebaseInstallations(FirebaseApp firebaseApp) {
44+
this.firebaseApp = firebaseApp;
45+
httpClient = new OkHttpClient();
46+
}
47+
48+
/**
49+
* Returns the {@link FirebaseInstallationsApi} initialized with the default {@link FirebaseApp}.
50+
*
51+
* @return a {@link FirebaseInstallationsApi} instance
52+
*/
53+
@NonNull
54+
public static FirebaseInstallations getInstance() {
55+
FirebaseApp defaultFirebaseApp = FirebaseApp.getInstance();
56+
return getInstance(defaultFirebaseApp);
57+
}
58+
59+
/**
60+
* Returns the {@link FirebaseInstallations} initialized with a custom {@link FirebaseApp}.
61+
*
62+
* @param app a custom {@link FirebaseApp}
63+
* @return a {@link FirebaseInstallations} instance
64+
*/
65+
@NonNull
66+
public static FirebaseInstallations getInstance(@NonNull FirebaseApp app) {
67+
Preconditions.checkArgument(app != null, "Null is not a valid value of FirebaseApp.");
68+
return (FirebaseInstallations) app.get(FirebaseInstallationsApi.class);
69+
}
70+
71+
/**
72+
* Returns a globally unique identifier of this Firebase app installation. This is a url-safe
73+
* base64 string of a 128-bit integer.
74+
*/
75+
@NonNull
76+
@Override
77+
public Task<String> getId() {
78+
return Tasks.forResult("fid-is-better-than-iid");
79+
}
80+
81+
/** Returns a auth token(public key) of this Firebase app installation. */
82+
@NonNull
83+
@Override
84+
public Task<String> getAuthToken() {
85+
return Tasks.forResult("dummy_auth_token");
86+
}
87+
88+
/**
89+
* Call to delete this Firebase app installation from Firebase backend. This call would possibly
90+
* lead Firebase Notification, Firebase RemoteConfig, Firebase Predictions or Firebase In-App
91+
* Messaging not function properly.
92+
*/
93+
@NonNull
94+
@Override
95+
public Task<Void> delete() {
96+
return Tasks.forResult(null);
97+
}
98+
99+
/** Returns the application id of the {@link FirebaseApp} of this {@link FirebaseInstallations} */
100+
@VisibleForTesting
101+
String getApplicationId() {
102+
return firebaseApp.getOptions().getApplicationId();
103+
}
104+
105+
/** Returns the nick name of the {@link FirebaseApp} of this {@link FirebaseInstallations} */
106+
@VisibleForTesting
107+
String getName() {
108+
return firebaseApp.getName();
109+
}
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.installations;
16+
17+
import androidx.annotation.Keep;
18+
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.components.Component;
20+
import com.google.firebase.components.ComponentRegistrar;
21+
import com.google.firebase.components.Dependency;
22+
import com.google.firebase.platforminfo.LibraryVersionComponent;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
26+
/** @hide */
27+
@Keep
28+
public class FirebaseInstallationsRegistrar implements ComponentRegistrar {
29+
30+
@Override
31+
public List<Component<?>> getComponents() {
32+
return Arrays.asList(
33+
Component.builder(FirebaseInstallationsApi.class)
34+
.add(Dependency.required(FirebaseApp.class))
35+
.factory(c -> new FirebaseInstallations(c.get(FirebaseApp.class)))
36+
.build(),
37+
LibraryVersionComponent.create("fire-installations", BuildConfig.VERSION_NAME));
38+
}
39+
}

0 commit comments

Comments
 (0)