Skip to content

Commit 70bc56c

Browse files
authored
Add FIS Kotlin Extensions SDK. (#1901)
1 parent 1162c4a commit 70bc56c

File tree

6 files changed

+205
-0
lines changed

6 files changed

+205
-0
lines changed

firebase-installations/ktx/api.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Signature format: 2.0
2+
package com.google.firebase.installations.ktx {
3+
4+
public final class InstallationsKt {
5+
ctor public InstallationsKt();
6+
method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstallations(@NonNull com.google.firebase.ktx.Firebase);
7+
method @NonNull public static com.google.firebase.installations.FirebaseInstallations installations(@NonNull com.google.firebase.ktx.Firebase, @NonNull com.google.firebase.FirebaseApp app);
8+
}
9+
10+
}
11+

firebase-installations/ktx/ktx.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2020 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+
plugins {
16+
id 'firebase-library'
17+
id 'kotlin-android'
18+
}
19+
20+
firebaseLibrary {
21+
releaseWith project(':firebase-installations')
22+
publishJavadoc = true
23+
publishSources = true
24+
}
25+
26+
android {
27+
compileSdkVersion project.targetSdkVersion
28+
defaultConfig {
29+
minSdkVersion project.minSdkVersion
30+
multiDexEnabled true
31+
targetSdkVersion project.targetSdkVersion
32+
versionName version
33+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34+
}
35+
sourceSets {
36+
main.java.srcDirs += 'src/main/kotlin'
37+
test.java.srcDirs += 'src/test/kotlin'
38+
androidTest.java.srcDirs += 'src/androidTest/kotlin'
39+
}
40+
testOptions.unitTests.includeAndroidResources = true
41+
}
42+
43+
dependencies {
44+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
45+
46+
implementation project(':firebase-common')
47+
implementation project(':firebase-common:ktx')
48+
implementation project(':firebase-components')
49+
implementation project(':firebase-installations')
50+
implementation project(':firebase-installations-interop')
51+
52+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
53+
testImplementation 'junit:junit:4.13'
54+
testImplementation "com.google.truth:truth:$googleTruthVersion"
55+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.ktx">
4+
<application>
5+
<service
6+
android:name="com.google.firebase.components.ComponentDiscoveryService"
7+
android:exported="false">
8+
<meta-data
9+
android:name="com.google.firebase.components:com.google.firebase.installations.ktx.FirebaseInstallationsKtxRegistrar"
10+
android:value="com.google.firebase.components.ComponentRegistrar" />
11+
</service>
12+
</application>
13+
</manifest>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2020 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.ktx
16+
17+
import com.google.firebase.FirebaseApp
18+
import com.google.firebase.components.Component
19+
import com.google.firebase.components.ComponentRegistrar
20+
import com.google.firebase.installations.FirebaseInstallations
21+
import com.google.firebase.ktx.Firebase
22+
import com.google.firebase.platforminfo.LibraryVersionComponent
23+
24+
/** Returns the [FirebaseInstallations] instance of the default [FirebaseApp]. */
25+
val Firebase.installations: FirebaseInstallations
26+
get() = FirebaseInstallations.getInstance()
27+
28+
/** Returns the [FirebaseInstallations] instance of a given [FirebaseApp]. */
29+
fun Firebase.installations(app: FirebaseApp): FirebaseInstallations =
30+
FirebaseInstallations.getInstance(app)
31+
32+
internal const val LIBRARY_NAME: String = "fire-installations-ktx"
33+
34+
/** @suppress */
35+
class FirebaseInstallationsKtxRegistrar : ComponentRegistrar {
36+
override fun getComponents(): List<Component<*>> =
37+
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
38+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2020 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.ktx
16+
17+
import com.google.common.truth.Truth
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.FirebaseOptions
20+
import com.google.firebase.installations.FirebaseInstallations
21+
import com.google.firebase.ktx.Firebase
22+
import com.google.firebase.ktx.app
23+
import com.google.firebase.ktx.initialize
24+
import com.google.firebase.platforminfo.UserAgentPublisher
25+
import org.junit.After
26+
import org.junit.Before
27+
import org.junit.Test
28+
import org.junit.runner.RunWith
29+
import org.robolectric.RobolectricTestRunner
30+
import org.robolectric.RuntimeEnvironment
31+
32+
const val APP_ID = "APP_ID"
33+
const val API_KEY = "API_KEY"
34+
35+
const val EXISTING_APP = "existing"
36+
37+
abstract class BaseTestCase {
38+
@Before
39+
fun setUp() {
40+
Firebase.initialize(
41+
RuntimeEnvironment.application,
42+
FirebaseOptions.Builder()
43+
.setApplicationId(APP_ID)
44+
.setApiKey(API_KEY)
45+
.setProjectId("123")
46+
.build()
47+
)
48+
49+
Firebase.initialize(
50+
RuntimeEnvironment.application,
51+
FirebaseOptions.Builder()
52+
.setApplicationId(APP_ID)
53+
.setApiKey(API_KEY)
54+
.setProjectId("123")
55+
.build(),
56+
EXISTING_APP
57+
)
58+
}
59+
60+
@After
61+
fun cleanUp() {
62+
FirebaseApp.clearInstancesForTest()
63+
}
64+
}
65+
66+
@RunWith(RobolectricTestRunner::class)
67+
class FunctionsTests : BaseTestCase() {
68+
@Test
69+
fun `installations should delegate to FirebaseFunctions#getInstance()`() {
70+
Truth.assertThat(Firebase.installations).isSameInstanceAs(FirebaseInstallations.getInstance())
71+
}
72+
73+
@Test
74+
fun `functions(app) should delegate to FirebaseFunctions#getInstance(FirebaseApp)`() {
75+
val app = Firebase.app(EXISTING_APP)
76+
Truth.assertThat(Firebase.installations(app)).isSameInstanceAs(FirebaseInstallations.getInstance(app))
77+
}
78+
}
79+
80+
@RunWith(RobolectricTestRunner::class)
81+
class LibraryVersionTest : BaseTestCase() {
82+
@Test
83+
fun `library version should be registered with runtime`() {
84+
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
85+
Truth.assertThat(publisher.userAgent).contains(LIBRARY_NAME)
86+
}
87+
}

subprojects.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ firebase-inappmessaging-display:ktx
2828
firebase-installations-interop
2929
firebase-installations
3030
firebase-installations:customer-lint-checks
31+
firebase-installations:ktx
3132
firebase-segmentation
3233
firebase-storage
3334
firebase-storage:ktx

0 commit comments

Comments
 (0)