Skip to content

Commit 1980321

Browse files
committed
Initial Code structure for FIS Android SDK (#648)
* Adding an interface library for Firebase Installations SDK * Adding Firebase Installations module * Adding Firebase Installations module. * Readding .idea files that were deleted in previous commit * Revert "Adding Firebase Installations module" This reverts commit 2ec4aef. * Revert "Readding .idea files that were deleted in previous commit" This reverts commit 7b4ebcf. * Add firebase installations project path * Adding Firebase Installations module. * Readding .idea files that were deleted in previous commit * Revert "Adding Firebase Installations module" This reverts commit 2ec4aef. * Revert "Readding .idea files that were deleted in previous commit" This reverts commit 7b4ebcf. * Add firebase installations project path * Fixing formattinf issues. * Revert "Adding Firebase Installations module" with hidden files This reverts commit 2ec4aef. * Addressing review comments. * Making InstallationTokenResult an AutoValue class.
1 parent 534e5b3 commit 1980321

File tree

14 files changed

+407
-0
lines changed

14 files changed

+407
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}
19+
20+
firebaseLibrary.publishJavadoc = false
21+
22+
android {
23+
compileSdkVersion project.targetSdkVersion
24+
defaultConfig {
25+
minSdkVersion project.minSdkVersion
26+
targetSdkVersion project.targetSdkVersion
27+
versionName version
28+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29+
}
30+
compileOptions {
31+
sourceCompatibility JavaVersion.VERSION_1_8
32+
targetCompatibility JavaVersion.VERSION_1_8
33+
}
34+
testOptions {
35+
unitTests {
36+
includeAndroidResources = true
37+
}
38+
}
39+
}
40+
41+
dependencies {
42+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
43+
44+
compileOnly "com.google.auto.value:auto-value-annotations:1.6.5"
45+
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
46+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=17.1.1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2019 Google LLC -->
3+
<!-- -->
4+
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
5+
<!-- you may not use this file except in compliance with the License. -->
6+
<!-- You may obtain a copy of the License at -->
7+
<!-- -->
8+
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
9+
<!-- -->
10+
<!-- Unless required by applicable law or agreed to in writing, software -->
11+
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
12+
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
13+
<!-- See the License for the specific language governing permissions and -->
14+
<!-- limitations under the License. -->
15+
16+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
17+
package="com.google.firebase.installations.interop" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 com.google.android.gms.tasks.Task;
18+
19+
/**
20+
* This is an interface of {@code FirebaseInstallations} that is only exposed to 2p via component
21+
* injection.
22+
*
23+
* @hide
24+
*/
25+
public interface FirebaseInstallationsApi {
26+
27+
/**
28+
* Async function that returns a globally unique identifier of this Firebase app installation.
29+
* This is a url-safe base64 string of a 128-bit integer.
30+
*/
31+
Task<String> getId();
32+
33+
/** Async function that returns a auth token(public key) of this Firebase app installation. */
34+
Task<InstallationTokenResult> getAuthToken(boolean forceRefresh);
35+
36+
/**
37+
* Async function that deletes this Firebase app installation from Firebase backend. This call
38+
* would possibly lead Firebase Notification, Firebase RemoteConfig, Firebase Predictions or
39+
* Firebase In-App Messaging not function properly.
40+
*/
41+
Task<Void> delete();
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.auto.value.AutoValue;
19+
20+
/** This class represents a set of values describing a FIS Auth Token Result. */
21+
@AutoValue
22+
public abstract class InstallationTokenResult {
23+
24+
/** A new FIS Auth-Token, created for this firebase installation. */
25+
@NonNull
26+
public abstract String getAuthToken();
27+
/**
28+
* The amount of time, in milliseconds, before the auth-token expires for this firebase
29+
* installation.
30+
*/
31+
public abstract long getTokenExpirationTimestampMillis();
32+
33+
@NonNull
34+
public static InstallationTokenResult create(
35+
@NonNull String authToken, long tokenExpirationTimestampMillis) {
36+
return new AutoValue_InstallationTokenResult(authToken, tokenExpirationTimestampMillis);
37+
}
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}
19+
20+
android {
21+
compileSdkVersion project.targetSdkVersion
22+
defaultConfig {
23+
minSdkVersion project.minSdkVersion
24+
targetSdkVersion project.targetSdkVersion
25+
multiDexEnabled true
26+
versionName version
27+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28+
}
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_1_8
31+
targetCompatibility JavaVersion.VERSION_1_8
32+
}
33+
testOptions {
34+
unitTests {
35+
includeAndroidResources = true
36+
}
37+
}
38+
}
39+
40+
dependencies {
41+
implementation project(':firebase-common')
42+
implementation project(':firebase-installations-interop')
43+
44+
implementation 'androidx.appcompat:appcompat:1.0.2'
45+
implementation 'androidx.multidex:multidex:2.0.1'
46+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
47+
48+
testImplementation 'androidx.test:core:1.2.0'
49+
testImplementation 'junit:junit:4.12'
50+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
51+
52+
androidTestImplementation 'androidx.test:runner:1.2.0'
53+
implementation 'com.google.guava:guava:16.0.+'
54+
}
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: 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: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
24+
/**
25+
* Entry point for Firebase Installations.
26+
*
27+
* <p>Firebase Installations does
28+
*
29+
* <ul>
30+
* <li>provide unique identifier for a Firebase installation
31+
* <li>provide auth token of a Firebase installation
32+
* <li>provide a API to GDPR-delete a Firebase installation
33+
* </ul>
34+
*/
35+
public class FirebaseInstallations implements FirebaseInstallationsApi {
36+
37+
private final FirebaseApp firebaseApp;
38+
39+
/** package private constructor. */
40+
FirebaseInstallations(FirebaseApp firebaseApp) {
41+
this.firebaseApp = firebaseApp;
42+
}
43+
44+
/**
45+
* Returns the {@link FirebaseInstallationsApi} initialized with the default {@link FirebaseApp}.
46+
*
47+
* @return a {@link FirebaseInstallationsApi} instance
48+
*/
49+
@NonNull
50+
public static FirebaseInstallations getInstance() {
51+
FirebaseApp defaultFirebaseApp = FirebaseApp.getInstance();
52+
return getInstance(defaultFirebaseApp);
53+
}
54+
55+
/**
56+
* Returns the {@link FirebaseInstallations} initialized with a custom {@link FirebaseApp}.
57+
*
58+
* @param app a custom {@link FirebaseApp}
59+
* @return a {@link FirebaseInstallations} instance
60+
*/
61+
@NonNull
62+
public static FirebaseInstallations getInstance(@NonNull FirebaseApp app) {
63+
Preconditions.checkArgument(app != null, "Null is not a valid value of FirebaseApp.");
64+
return (FirebaseInstallations) app.get(FirebaseInstallationsApi.class);
65+
}
66+
67+
/**
68+
* Returns a globally unique identifier of this Firebase app installation. This is a url-safe
69+
* base64 string of a 128-bit integer.
70+
*/
71+
@NonNull
72+
@Override
73+
public Task<String> getId() {
74+
return Tasks.forResult("fid-is-better-than-iid");
75+
}
76+
77+
/** Returns a auth token(public key) of this Firebase app installation. */
78+
@NonNull
79+
@Override
80+
public Task<InstallationTokenResult> getAuthToken(boolean forceRefresh) {
81+
return Tasks.forResult(InstallationTokenResult.create("dummy_auth_token", 1000l));
82+
}
83+
84+
/**
85+
* Call to delete this Firebase app installation from Firebase backend. This call would possibly
86+
* lead Firebase Notification, Firebase RemoteConfig, Firebase Predictions or Firebase In-App
87+
* Messaging not function properly.
88+
*/
89+
@NonNull
90+
@Override
91+
public Task<Void> delete() {
92+
return Tasks.forResult(null);
93+
}
94+
95+
/** Returns the application id of the {@link FirebaseApp} of this {@link FirebaseInstallations} */
96+
@VisibleForTesting
97+
String getApplicationId() {
98+
return firebaseApp.getOptions().getApplicationId();
99+
}
100+
101+
/** Returns the nick name of the {@link FirebaseApp} of this {@link FirebaseInstallations} */
102+
@VisibleForTesting
103+
String getName() {
104+
return firebaseApp.getName();
105+
}
106+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
/** Tests for {@link FirebaseInstallationsRegistrar}. */
18+
public class FirebaseInstallationsRegistrarTest {}

0 commit comments

Comments
 (0)