Skip to content

Commit 46726cb

Browse files
committed
Merge branch 'master' of github.com:firebase/firebase-android-sdk into enableRequestLimiter
2 parents 2266889 + 690d119 commit 46726cb

File tree

47 files changed

+700
-151
lines changed

Some content is hidden

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

47 files changed

+700
-151
lines changed

encoders/firebase-encoders-json/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=17.0.0
16-
latestReleasedVersion=16.1.0
15+
version=17.0.1
16+
latestReleasedVersion=17.0.0

encoders/firebase-encoders/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=16.0.0
15+
version=16.0.1

firebase-common/firebase-common.gradle

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,12 @@ dependencies {
8484

8585
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
8686

87-
androidTestImplementation 'junit:junit:4.12'
88-
androidTestImplementation 'androidx.test:runner:1.2.0'
87+
androidTestImplementation project(':integ-testing')
88+
androidTestImplementation 'junit:junit:4.13'
89+
androidTestImplementation 'androidx.test:runner:1.3.0'
90+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
8991
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
9092
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
9193
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.25.0'
9294
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.25.0'
93-
androidTestImplementation ('com.google.firebase:firebase-auth:17.0.0') {
94-
exclude group: "com.google.firebase", module: "firebase-common"
95-
}
96-
97-
androidTestImplementation ('com.google.firebase:firebase-core:16.0.9') {
98-
exclude group: "com.google.firebase", module: "firebase-common"
99-
}
10095
}

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

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
import androidx.test.runner.AndroidJUnit4;
4040
import com.google.android.gms.common.api.internal.BackgroundDetector;
4141
import com.google.common.base.Defaults;
42-
import com.google.firebase.auth.FirebaseAuth;
4342
import com.google.firebase.components.EagerSdkVerifier;
44-
import com.google.firebase.components.InitTracker;
4543
import com.google.firebase.components.TestComponentOne;
4644
import com.google.firebase.components.TestComponentTwo;
4745
import com.google.firebase.components.TestUserAgentDependentComponent;
@@ -144,10 +142,8 @@ public void testInitializeApp_shouldPublishVersionForFirebaseCommon() {
144142

145143
// After sorting the user agents are expected to be {"fire-android/", "fire-auth/x.y.z",
146144
// "fire-core/x.y.z", "test-component/1.2.3"}
147-
assertThat(actualUserAgent[0]).contains("fire-analytics");
148-
assertThat(actualUserAgent[1]).contains("fire-android");
149-
assertThat(actualUserAgent[2]).contains("fire-auth");
150-
assertThat(actualUserAgent[3]).contains("fire-core");
145+
assertThat(actualUserAgent[0]).contains("fire-android");
146+
assertThat(actualUserAgent[1]).contains("fire-core");
151147
}
152148

153149
@Test
@@ -304,7 +300,7 @@ public void testPersistenceKeyIsBijective() {
304300
// Order of test cases matters.
305301
@Test(expected = IllegalStateException.class)
306302
public void testMissingInit() {
307-
FirebaseAuth.getInstance();
303+
FirebaseApp.getInstance();
308304
}
309305

310306
@Test
@@ -313,10 +309,9 @@ public void testApiInitializedForNonDefaultApp() {
313309
assertThat(firebaseApp.isDefaultApp()).isFalse();
314310

315311
EagerSdkVerifier sdkVerifier = firebaseApp.get(EagerSdkVerifier.class);
316-
assertThat(sdkVerifier.isAuthInitialized()).isTrue();
317-
318-
// Analytics is only initialized for the default app.
319-
assertThat(sdkVerifier.isAnalyticsInitialized()).isFalse();
312+
assertThat(sdkVerifier.isEagerInitialized()).isTrue();
313+
assertThat(sdkVerifier.isEagerInDefaultAppInitialized()).isFalse();
314+
assertThat(sdkVerifier.isLazyInitialized()).isFalse();
320315
}
321316

322317
@Test
@@ -326,8 +321,9 @@ public void testApiInitForDefaultApp() {
326321
assertThat(firebaseApp.isDefaultApp()).isTrue();
327322

328323
EagerSdkVerifier sdkVerifier = firebaseApp.get(EagerSdkVerifier.class);
329-
assertThat(sdkVerifier.isAuthInitialized()).isTrue();
330-
assertThat(sdkVerifier.isAnalyticsInitialized()).isTrue();
324+
assertThat(sdkVerifier.isEagerInitialized()).isTrue();
325+
assertThat(sdkVerifier.isEagerInDefaultAppInitialized()).isTrue();
326+
assertThat(sdkVerifier.isLazyInitialized()).isFalse();
331327
}
332328

333329
@Test
@@ -372,25 +368,20 @@ public void testDirectBoot_shouldInitializeEagerComponentsOnDeviceUnlock() {
372368
isUserUnlocked.set(false);
373369
FirebaseApp firebaseApp = FirebaseApp.initializeApp(mockContext);
374370

375-
InitTracker tracker = firebaseApp.get(InitTracker.class);
376371
EagerSdkVerifier sdkVerifier = firebaseApp.get(EagerSdkVerifier.class);
377372

378-
// APIs are not initialized.
379-
assertThat(tracker.isInitialized()).isFalse();
380-
381-
assertThat(sdkVerifier.isAuthInitialized()).isFalse();
382-
assertThat(sdkVerifier.isAnalyticsInitialized()).isFalse();
373+
assertThat(sdkVerifier.isEagerInitialized()).isFalse();
374+
assertThat(sdkVerifier.isEagerInDefaultAppInitialized()).isFalse();
375+
assertThat(sdkVerifier.isLazyInitialized()).isFalse();
383376

384377
// User unlocks the device.
385378
isUserUnlocked.set(true);
386379
Intent userUnlockBroadcast = new Intent(Intent.ACTION_USER_UNLOCKED);
387380
localBroadcastManager.sendBroadcastSync(userUnlockBroadcast);
388381

389-
// APIs are initialized.
390-
assertThat(tracker.isInitialized()).isTrue();
391-
392-
assertThat(sdkVerifier.isAuthInitialized()).isTrue();
393-
assertThat(sdkVerifier.isAnalyticsInitialized()).isTrue();
382+
assertThat(sdkVerifier.isEagerInitialized()).isTrue();
383+
assertThat(sdkVerifier.isEagerInDefaultAppInitialized()).isTrue();
384+
assertThat(sdkVerifier.isLazyInitialized()).isFalse();
394385
}
395386

396387
@Test
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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;
16+
17+
import androidx.test.core.app.ApplicationProvider;
18+
import com.google.firebase.FirebaseOptions.Builder;
19+
import com.google.firebase.testing.integ.StrictModeRule;
20+
import org.junit.Rule;
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
24+
@RunWith(androidx.test.ext.junit.runners.AndroidJUnit4.class)
25+
public class StrictModeTest {
26+
27+
@Rule public StrictModeRule strictMode = new StrictModeRule();
28+
29+
@Test
30+
public void initializingFirebaseApp_shouldNotViolateStrictMode() {
31+
strictMode.runOnMainThread(
32+
() -> {
33+
FirebaseApp app =
34+
FirebaseApp.initializeApp(
35+
ApplicationProvider.getApplicationContext(),
36+
new Builder()
37+
.setApiKey("api")
38+
.setProjectId("123")
39+
.setApplicationId("appId")
40+
.build(),
41+
"hello");
42+
app.initializeAllComponents();
43+
});
44+
}
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.components;
16+
17+
class EagerComponent extends InitializingComponent {
18+
19+
EagerComponent(InitializationTracker tracker) {
20+
super(tracker);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.components;
16+
17+
class EagerInDefaultAppComponent extends InitializingComponent {
18+
19+
EagerInDefaultAppComponent(InitializationTracker tracker) {
20+
super(tracker);
21+
}
22+
}

firebase-common/src/androidTest/java/com/google/firebase/components/EagerSdkVerifier.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,22 @@
1414

1515
package com.google.firebase.components;
1616

17-
import com.google.firebase.analytics.connector.AnalyticsConnector;
18-
import com.google.firebase.auth.FirebaseAuth;
19-
import com.google.firebase.inject.Provider;
20-
2117
public class EagerSdkVerifier {
22-
private final Lazy<FirebaseAuth> authLazy;
23-
private final Lazy<AnalyticsConnector> analyticsLazy;
18+
private final InitializationTracker initializationTracker;
19+
20+
public EagerSdkVerifier(InitializationTracker initializationTracker) {
21+
this.initializationTracker = initializationTracker;
22+
}
2423

25-
EagerSdkVerifier(Provider<FirebaseAuth> authLazy, Provider<AnalyticsConnector> analyticsLazy) {
26-
this.authLazy = (Lazy<FirebaseAuth>) authLazy;
27-
this.analyticsLazy = (Lazy<AnalyticsConnector>) analyticsLazy;
24+
public boolean isLazyInitialized() {
25+
return initializationTracker.isInitialized(LazyComponent.class);
2826
}
2927

30-
public boolean isAuthInitialized() {
31-
return authLazy.isInitialized();
28+
public boolean isEagerInitialized() {
29+
return initializationTracker.isInitialized(EagerComponent.class);
3230
}
3331

34-
public boolean isAnalyticsInitialized() {
35-
return analyticsLazy.isInitialized();
32+
public boolean isEagerInDefaultAppInitialized() {
33+
return initializationTracker.isInitialized(EagerInDefaultAppComponent.class);
3634
}
3735
}

firebase-common/src/androidTest/java/com/google/firebase/components/EagerSdkVerifierRegistrar.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,35 @@
1414

1515
package com.google.firebase.components;
1616

17-
import com.google.firebase.analytics.connector.AnalyticsConnector;
18-
import com.google.firebase.auth.FirebaseAuth;
19-
import java.util.Collections;
17+
import java.util.Arrays;
2018
import java.util.List;
2119

2220
public class EagerSdkVerifierRegistrar implements ComponentRegistrar {
2321
@Override
2422
public List<Component<?>> getComponents() {
25-
return Collections.singletonList(
26-
Component.builder(EagerSdkVerifier.class)
27-
.add(Dependency.requiredProvider(FirebaseAuth.class))
28-
.add(Dependency.requiredProvider(AnalyticsConnector.class))
23+
return Arrays.asList(
24+
Component.builder(InitializationTracker.class)
25+
.factory(container -> new InitializationTracker())
26+
.build(),
27+
Component.builder(EagerComponent.class)
28+
.add(Dependency.required(InitializationTracker.class))
29+
.factory(container -> new EagerComponent(container.get(InitializationTracker.class)))
30+
.alwaysEager()
31+
.build(),
32+
Component.builder(EagerInDefaultAppComponent.class)
33+
.add(Dependency.required(InitializationTracker.class))
2934
.factory(
3035
container ->
31-
new EagerSdkVerifier(
32-
container.getProvider(FirebaseAuth.class),
33-
container.getProvider(AnalyticsConnector.class)))
36+
new EagerInDefaultAppComponent(container.get(InitializationTracker.class)))
37+
.eagerInDefaultApp()
38+
.build(),
39+
Component.builder(LazyComponent.class)
40+
.add(Dependency.required(InitializationTracker.class))
41+
.factory(container -> new LazyComponent(container.get(InitializationTracker.class)))
42+
.build(),
43+
Component.builder(EagerSdkVerifier.class)
44+
.add(Dependency.required(InitializationTracker.class))
45+
.factory(container -> new EagerSdkVerifier(container.get(InitializationTracker.class)))
3446
.build());
3547
}
3648
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.components;
16+
17+
import java.util.HashSet;
18+
import java.util.Set;
19+
20+
public class InitializationTracker {
21+
private final Set<Class<? extends InitializingComponent>> initialized = new HashSet<>();
22+
23+
synchronized void initialize(Class<? extends InitializingComponent> component) {
24+
initialized.add(component);
25+
}
26+
27+
synchronized boolean isInitialized(Class<? extends InitializingComponent> component) {
28+
return initialized.contains(component);
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.components;
16+
17+
abstract class InitializingComponent {
18+
InitializingComponent(InitializationTracker tracker) {
19+
tracker.initialize(this.getClass());
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.components;
16+
17+
class LazyComponent extends InitializingComponent {
18+
19+
LazyComponent(InitializationTracker tracker) {
20+
super(tracker);
21+
}
22+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import android.util.Log;
3030
import androidx.annotation.NonNull;
3131
import androidx.annotation.Nullable;
32+
import androidx.annotation.RestrictTo;
33+
import androidx.annotation.RestrictTo.Scope;
3234
import androidx.annotation.VisibleForTesting;
3335
import androidx.collection.ArrayMap;
3436
import androidx.core.os.UserManagerCompat;
@@ -452,6 +454,13 @@ public boolean isDefaultApp() {
452454
return DEFAULT_APP_NAME.equals(getName());
453455
}
454456

457+
/** @hide */
458+
@VisibleForTesting
459+
@RestrictTo(Scope.TESTS)
460+
void initializeAllComponents() {
461+
componentRuntime.initializeAllComponentsForTests();
462+
}
463+
455464
private void notifyBackgroundStateChangeListeners(boolean background) {
456465
Log.d(LOG_TAG, "Notifying background state change listeners.");
457466
for (BackgroundStateChangeListener listener : backgroundStateChangeListeners) {

0 commit comments

Comments
 (0)