Skip to content

Commit 55246a2

Browse files
author
Michael Lehenbauer
committed
Merge branch 'master' into mikelehen/collection-group-queries
2 parents 029578b + f474060 commit 55246a2

File tree

83 files changed

+3101
-1156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3101
-1156
lines changed

ci/fireci/setup.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
setup(
2525
name='fireci',
2626
version='0.1',
27-
# this is a temporary measure until opencensus 0.2 release is out.
28-
dependency_links=[
29-
'https://github.com/census-instrumentation/opencensus-python/tarball/master#egg=opencensus'
30-
],
3127
install_requires=[
3228
'click==7.0',
33-
'opencensus',
29+
'opencensus==0.2.0',
3430
'google-cloud-monitoring==0.31.1',
3531
],
3632
packages=find_packages(exclude=['tests']),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
apply plugin: 'com.android.library'
16+
apply plugin: 'kotlin-android'
17+
18+
android {
19+
compileSdkVersion project.targetSdkVersion
20+
defaultConfig {
21+
minSdkVersion project.minSdkVersion
22+
targetSdkVersion project.targetSdkVersion
23+
versionName version
24+
buildConfigField('String', 'LIBRARY_NAME', "\"$project.name\"")
25+
buildConfigField('String', 'KOTLIN_VERSION', "\"$kotlinVersion\"")
26+
}
27+
sourceSets {
28+
main.java.srcDirs += 'src/main/kotlin'
29+
test.java.srcDirs += 'src/test/kotlin'
30+
}
31+
testOptions.unitTests.includeAndroidResources = true
32+
}
33+
34+
dependencies {
35+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
36+
37+
implementation project(':firebase-common')
38+
implementation 'com.android.support:support-annotations:28.0.0'
39+
40+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
41+
testImplementation 'junit:junit:4.12'
42+
testImplementation "com.google.truth:truth:$googleTruthVersion"
43+
}

firebase-common-ktx/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=17.0.0-alpha01
2+
android.enableUnitTestBinaryResources=true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.firebase.ktx">
4+
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
5+
<!--<uses-sdk android:minSdkVersion="14"/>-->
6+
<application>
7+
<service android:name="com.google.firebase.components.ComponentDiscoveryService">
8+
<meta-data android:name="com.google.firebase.components:com.google.firebase.ktx.FirebaseCommonKtxRegistrar"
9+
android:value="com.google.firebase.components.ComponentRegistrar" />
10+
</service>
11+
</application>
12+
</manifest>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
package com.google.firebase.ktx
15+
16+
import android.content.Context
17+
import android.support.annotation.Keep
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.FirebaseOptions
20+
import com.google.firebase.components.Component
21+
import com.google.firebase.components.ComponentRegistrar
22+
import com.google.firebase.platforminfo.LibraryVersionComponent
23+
24+
/**
25+
* Single access point to all firebase sdks from Kotlin.
26+
*
27+
* <p>Acts as a target for extension methods provided by sdks.
28+
*/
29+
object Firebase
30+
31+
/** Returns the default firebase app instance. */
32+
val Firebase.app: FirebaseApp
33+
get() = FirebaseApp.getInstance()
34+
35+
/** Returns a named firebase app instance. */
36+
fun Firebase.app(name: String): FirebaseApp = FirebaseApp.getInstance(name)
37+
38+
/** Initializes and returns a FirebaseApp. */
39+
fun Firebase.initialize(context: Context) = FirebaseApp.initializeApp(context)
40+
41+
/** Initializes and returns a FirebaseApp. */
42+
fun Firebase.initialize(context: Context, options: FirebaseOptions) =
43+
FirebaseApp.initializeApp(context, options)
44+
45+
/** Initializes and returns a FirebaseApp. */
46+
fun Firebase.initialize(context: Context, options: FirebaseOptions, name: String) =
47+
FirebaseApp.initializeApp(context, options, name)
48+
49+
/** Returns options of default FirebaseApp */
50+
val Firebase.options: FirebaseOptions
51+
get() = Firebase.app.options
52+
53+
/** @hide */
54+
@Keep
55+
class FirebaseCommonKtxRegistrar : ComponentRegistrar {
56+
override fun getComponents(): List<Component<*>> {
57+
return listOf(
58+
LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.VERSION_NAME),
59+
LibraryVersionComponent.create("kotlin", BuildConfig.KOTLIN_VERSION))
60+
}
61+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.ktx;
16+
17+
import com.google.common.truth.Truth.assertThat
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.FirebaseOptions
20+
import com.google.firebase.platforminfo.UserAgentPublisher
21+
import org.junit.Test
22+
import org.junit.runner.RunWith
23+
import org.robolectric.RobolectricTestRunner
24+
import org.robolectric.RuntimeEnvironment
25+
26+
fun withApp(name: String, block: FirebaseApp.() -> Unit) {
27+
val app = Firebase.initialize(RuntimeEnvironment.application,
28+
FirebaseOptions.Builder()
29+
.setApplicationId("appId")
30+
.build(),
31+
name)
32+
try {
33+
block(app)
34+
} finally {
35+
app.delete()
36+
}
37+
}
38+
39+
@RunWith(RobolectricTestRunner::class)
40+
class VersionTests {
41+
@Test
42+
fun libraryVersions_shouldBeRegisteredWithRuntime() {
43+
withApp("ktxTestApp") {
44+
val uaPublisher = get(UserAgentPublisher::class.java)
45+
assertThat(uaPublisher.userAgent).contains("kotlin")
46+
assertThat(uaPublisher.userAgent).contains(BuildConfig.LIBRARY_NAME)
47+
}
48+
}
49+
}
50+
51+
@RunWith(RobolectricTestRunner::class)
52+
class KtxTests {
53+
@Test
54+
fun `Firebase#app should delegate to FirebaseApp#getInstance()`() {
55+
withApp(FirebaseApp.DEFAULT_APP_NAME) {
56+
assertThat(Firebase.app).isSameAs(FirebaseApp.getInstance())
57+
}
58+
}
59+
60+
@Test
61+
fun `Firebase#app(String) should delegate to FirebaseApp#getInstance(String)`() {
62+
val appName = "testApp"
63+
withApp(appName) {
64+
assertThat(Firebase.app(appName)).isSameAs(FirebaseApp.getInstance(appName))
65+
}
66+
}
67+
68+
@Test
69+
fun `Firebase#options should delegate to FirebaseApp#getInstance()#options`() {
70+
withApp(FirebaseApp.DEFAULT_APP_NAME) {
71+
assertThat(Firebase.options).isSameAs(FirebaseApp.getInstance().options)
72+
}
73+
}
74+
75+
@Test
76+
fun `Firebase#initialize(Context, FirebaseOptions) should initialize the app correctly`() {
77+
val options = FirebaseOptions.Builder().setApplicationId("appId").build()
78+
val app = Firebase.initialize(RuntimeEnvironment.application, options)
79+
try {
80+
assertThat(app).isNotNull()
81+
assertThat(app.name).isEqualTo(FirebaseApp.DEFAULT_APP_NAME)
82+
assertThat(app.options).isSameAs(options)
83+
assertThat(app.applicationContext).isSameAs(RuntimeEnvironment.application)
84+
} finally {
85+
app.delete()
86+
}
87+
}
88+
89+
@Test
90+
fun `Firebase#initialize(Context, FirebaseOptions, String) should initialize the app correctly`() {
91+
val options = FirebaseOptions.Builder().setApplicationId("appId").build()
92+
val name = "appName"
93+
val app = Firebase.initialize(RuntimeEnvironment.application, options, name)
94+
try {
95+
assertThat(app).isNotNull()
96+
assertThat(app.name).isEqualTo(name)
97+
assertThat(app.options).isSameAs(options)
98+
assertThat(app.applicationContext).isSameAs(RuntimeEnvironment.application)
99+
} finally {
100+
app.delete()
101+
}
102+
}
103+
}

firebase-common/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=16.0.5
2-
latestReleasedVersion=16.0.4
1+
version=16.1.1
2+
latestReleasedVersion=16.1.0

firebase-common/src/androidTest/java/com/google/firebase/FirebaseAppTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public void testBackgroundStateChangeCallbacks() {
120120

121121
@Test
122122
public void testInitializeApp_shouldPublishUserAgentPublisherThatReturnsPublishedVersions() {
123-
String[] expectedUserAgent = {"firebase-common/16.0.5", "test-component/1.2.3"};
124123
Context mockContext = createForwardingMockContext();
125124
FirebaseApp firebaseApp = FirebaseApp.initializeApp(mockContext);
126125

@@ -144,9 +143,10 @@ public void testInitializeApp_shouldPublishVersionForFirebaseCommon() {
144143
String[] actualUserAgent = userAgentPublisher.getUserAgent().split(" ");
145144
Arrays.sort(actualUserAgent);
146145

147-
// After sorting the user agents are expected to be {"firebase-common/x.y.z",
146+
// After sorting the user agents are expected to be {"fire-android/", "fire-core/x.y.z",
148147
// "test-component/1.2.3"}
149-
assertThat(actualUserAgent[0]).contains("firebase-common");
148+
assertThat(actualUserAgent[0]).contains("fire-android");
149+
assertThat(actualUserAgent[1]).contains("fire-core");
150150
}
151151

152152
@Test

firebase-common/src/main/java/com/google/firebase/FirebaseApp.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public class FirebaseApp {
153153
@GuardedBy("LOCK")
154154
static final Map<String, FirebaseApp> INSTANCES = new ArrayMap<>();
155155

156-
private static final String FIREBASE_COMMON = "firebase-common";
156+
private static final String FIREBASE_ANDROID = "fire-android";
157+
private static final String FIREBASE_COMMON = "fire-core";
157158

158159
private final Context applicationContext;
159160
private final String name;
@@ -232,7 +233,7 @@ public static List<FirebaseApp> getApps(Context context) {
232233
*
233234
* @throws IllegalStateException if the default app was not initialized.
234235
*/
235-
@Nullable
236+
@NonNull
236237
@PublicApi
237238
public static FirebaseApp getInstance() {
238239
synchronized (LOCK) {
@@ -256,6 +257,7 @@ public static FirebaseApp getInstance() {
256257
* @throws IllegalStateException if the {@link FirebaseApp} was not initialized, either via {@link
257258
* #initializeApp(Context, FirebaseOptions, String)}.
258259
*/
260+
@NonNull
259261
@PublicApi
260262
public static FirebaseApp getInstance(@NonNull String name) {
261263
synchronized (LOCK) {
@@ -297,7 +299,7 @@ public static FirebaseApp getInstance(@NonNull String name) {
297299
*/
298300
@Nullable
299301
@PublicApi
300-
public static FirebaseApp initializeApp(Context context) {
302+
public static FirebaseApp initializeApp(@NonNull Context context) {
301303
synchronized (LOCK) {
302304
if (INSTANCES.containsKey(DEFAULT_APP_NAME)) {
303305
return getInstance();
@@ -323,8 +325,10 @@ public static FirebaseApp initializeApp(Context context) {
323325
* to do so automatically in {@link com.google.firebase.provider.FirebaseInitProvider}. Automatic
324326
* initialization that way is the expected situation.
325327
*/
328+
@NonNull
326329
@PublicApi
327-
public static FirebaseApp initializeApp(Context context, FirebaseOptions options) {
330+
public static FirebaseApp initializeApp(
331+
@NonNull Context context, @NonNull FirebaseOptions options) {
328332
return initializeApp(context, options, DEFAULT_APP_NAME);
329333
}
330334

@@ -338,8 +342,10 @@ public static FirebaseApp initializeApp(Context context, FirebaseOptions options
338342
* @throws IllegalStateException if an app with the same name has already been initialized.
339343
* @return an instance of {@link FirebaseApp}
340344
*/
345+
@NonNull
341346
@PublicApi
342-
public static FirebaseApp initializeApp(Context context, FirebaseOptions options, String name) {
347+
public static FirebaseApp initializeApp(
348+
@NonNull Context context, @NonNull FirebaseOptions options, @NonNull String name) {
343349
GlobalBackgroundStateListener.ensureBackgroundStateListenerRegistered(context);
344350
String normalizedName = normalize(name);
345351
final FirebaseApp firebaseApp;
@@ -382,6 +388,25 @@ public void setIdTokenListenersCountChangedListener(
382388
idTokenListenersCountChangedListener.onListenerCountChanged(idTokenListeners.size());
383389
}
384390

391+
/**
392+
* Fetch the UID of the currently logged-in user.
393+
*
394+
* @deprecated use {@link com.google.firebase.auth.internal.InternalAuthProvider#getUid()} from
395+
* firebase-auth-interop instead.
396+
* @hide
397+
*/
398+
@Deprecated
399+
@Nullable
400+
@KeepForSdk
401+
public String getUid() throws FirebaseApiNotAvailableException {
402+
checkNotDeleted();
403+
if (tokenProvider == null) {
404+
throw new FirebaseApiNotAvailableException(
405+
"firebase-auth is not " + "linked, please fall back to unauthenticated mode.");
406+
}
407+
return tokenProvider.getUid();
408+
}
409+
385410
/**
386411
* Fetch a valid STS Token.
387412
*
@@ -394,6 +419,7 @@ public void setIdTokenListenersCountChangedListener(
394419
* @hide
395420
*/
396421
@Deprecated
422+
@NonNull
397423
@KeepForSdk
398424
public Task<GetTokenResult> getToken(boolean forceRefresh) {
399425
checkNotDeleted();
@@ -407,25 +433,6 @@ public Task<GetTokenResult> getToken(boolean forceRefresh) {
407433
}
408434
}
409435

410-
/**
411-
* Fetch the UID of the currently logged-in user.
412-
*
413-
* @deprecated use {@link com.google.firebase.auth.internal.InternalAuthProvider#getUid()} from
414-
* firebase-auth-interop instead.
415-
* @hide
416-
*/
417-
@Deprecated
418-
@Nullable
419-
@KeepForSdk
420-
public String getUid() throws FirebaseApiNotAvailableException {
421-
checkNotDeleted();
422-
if (tokenProvider == null) {
423-
throw new FirebaseApiNotAvailableException(
424-
"firebase-auth is not " + "linked, please fall back to unauthenticated mode.");
425-
}
426-
return tokenProvider.getUid();
427-
}
428-
429436
/**
430437
* Deletes the {@link FirebaseApp} and all its data. All calls to this {@link FirebaseApp}
431438
* instance will throw once it has been called.
@@ -541,6 +548,7 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
541548
Component.of(applicationContext, Context.class),
542549
Component.of(this, FirebaseApp.class),
543550
Component.of(options, FirebaseOptions.class),
551+
LibraryVersionComponent.create(FIREBASE_ANDROID, ""),
544552
LibraryVersionComponent.create(FIREBASE_COMMON, BuildConfig.VERSION_NAME),
545553
DefaultUserAgentPublisher.component());
546554
publisher = componentRuntime.get(Publisher.class);

0 commit comments

Comments
 (0)