Skip to content

Commit a163034

Browse files
committed
Merge branch 'master' into vk.agp_7.2
2 parents b936b3e + 58c1677 commit a163034

File tree

12 files changed

+192
-4
lines changed

12 files changed

+192
-4
lines changed

.github/workflows/ci_tests_experimental.yml renamed to .github/workflows/ci_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Tests (Experimental)
1+
name: CI Tests
22
concurrency:
33
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
44
cancel-in-progress: true

appcheck/firebase-appcheck/ktx/src/main/kotlin/com/google/firebase/appcheck/ktx/FirebaseAppCheck.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.appcheck.ktx
1616

17+
import com.google.firebase.BuildConfig
1718
import com.google.firebase.FirebaseApp
1819
import com.google.firebase.appcheck.AppCheckToken
1920
import com.google.firebase.appcheck.FirebaseAppCheck
@@ -43,7 +44,9 @@ operator fun AppCheckToken.component1() = token
4344
*/
4445
operator fun AppCheckToken.component2() = expireTimeMillis
4546

47+
internal const val LIBRARY_NAME: String = "fire-app-check-ktx"
48+
4649
class FirebaseAppCheckKtxRegistrar : ComponentRegistrar {
4750
override fun getComponents(): List<Component<*>> =
48-
listOf(LibraryVersionComponent.create("fire-app-check-ktx", BuildConfig.VERSION_NAME))
51+
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
4952
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import com.google.firebase.heartbeatinfo.DefaultHeartBeatController;
5252
import com.google.firebase.inject.Provider;
5353
import com.google.firebase.internal.DataCollectionConfigStorage;
54+
import com.google.firebase.tracing.ComponentMonitor;
55+
import com.google.firebase.tracing.FirebaseTrace;
5456
import java.nio.charset.Charset;
5557
import java.util.ArrayList;
5658
import java.util.Collections;
@@ -415,18 +417,25 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
415417
this.name = Preconditions.checkNotEmpty(name);
416418
this.options = Preconditions.checkNotNull(options);
417419

420+
FirebaseTrace.pushTrace("Firebase");
421+
422+
FirebaseTrace.pushTrace("ComponentDiscovery");
418423
List<Provider<ComponentRegistrar>> registrars =
419424
ComponentDiscovery.forContext(applicationContext, ComponentDiscoveryService.class)
420425
.discoverLazy();
426+
FirebaseTrace.popTrace(); // ComponentDiscovery
421427

428+
FirebaseTrace.pushTrace("Runtime");
422429
componentRuntime =
423430
ComponentRuntime.builder(UI_EXECUTOR)
424431
.addLazyComponentRegistrars(registrars)
425432
.addComponentRegistrar(new FirebaseCommonRegistrar())
426433
.addComponent(Component.of(applicationContext, Context.class))
427434
.addComponent(Component.of(this, FirebaseApp.class))
428435
.addComponent(Component.of(options, FirebaseOptions.class))
436+
.setProcessor(new ComponentMonitor())
429437
.build();
438+
FirebaseTrace.popTrace(); // Runtime
430439

431440
dataCollectionConfigStorage =
432441
new Lazy<>(
@@ -443,6 +452,8 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
443452
defaultHeartBeatController.get().registerHeartBeat();
444453
}
445454
});
455+
456+
FirebaseTrace.popTrace(); // Firebase
446457
}
447458

448459
private void checkNotDeleted() {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2022 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.tracing;
16+
17+
import com.google.firebase.components.Component;
18+
import com.google.firebase.components.ComponentRegistrar;
19+
import com.google.firebase.components.ComponentRegistrarProcessor;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
/** Wraps components to trace their initialization time. */
24+
public class ComponentMonitor implements ComponentRegistrarProcessor {
25+
@Override
26+
public List<Component<?>> processRegistrar(ComponentRegistrar registrar) {
27+
List<Component<?>> components = new ArrayList<>();
28+
for (Component comp : registrar.getComponents()) {
29+
String name = comp.getName();
30+
if (name != null) {
31+
@SuppressWarnings("unchecked")
32+
Component<Object> old = (Component<Object>) comp;
33+
comp =
34+
old.withFactory(
35+
c -> {
36+
try {
37+
FirebaseTrace.pushTrace(name);
38+
return old.getFactory().create(c);
39+
} finally {
40+
FirebaseTrace.popTrace();
41+
}
42+
});
43+
}
44+
components.add(comp);
45+
}
46+
return components;
47+
}
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2022 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.tracing;
16+
17+
import android.os.Build;
18+
import android.os.Trace;
19+
20+
/** Utility to consistently wrap trace calls with version checking. */
21+
public final class FirebaseTrace {
22+
23+
private FirebaseTrace() {}
24+
25+
public static void pushTrace(String name) {
26+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
27+
Trace.beginSection(name);
28+
}
29+
}
30+
31+
public static void popTrace() {
32+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
33+
Trace.endSection();
34+
}
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2022 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+
/** @hide */
16+
package com.google.firebase.tracing;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2022 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.tracing;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import androidx.test.ext.junit.runners.AndroidJUnit4;
20+
import com.google.firebase.components.Component;
21+
import com.google.firebase.components.ComponentContainer;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
@RunWith(AndroidJUnit4.class)
28+
public class ComponentMonitorTest {
29+
30+
@Test
31+
public void testComponentMonitorTransformation() {
32+
List<Component<?>> list = new ArrayList<Component<?>>();
33+
list.add(
34+
Component.builder(ComponentHolder.class)
35+
.factory(ComponentHolder::new)
36+
.name("test")
37+
.build());
38+
list.add(
39+
Component.builder(ComponentHolder.class).factory(ComponentHolder::new).name("foo").build());
40+
list.add(
41+
Component.builder(ComponentHolder.class).factory(ComponentHolder::new).name("bar").build());
42+
ComponentMonitor monitor = new ComponentMonitor();
43+
List<Component<?>> transformed = monitor.processRegistrar(() -> list);
44+
assertThat(list.size()).isEqualTo(transformed.size());
45+
for (int i = 0; i < list.size(); i++) {
46+
assertThat(list.get(i).getName()).isEqualTo(transformed.get(i).getName());
47+
assertThat(transformed.get(i).getFactory().create(null)).isNotNull();
48+
}
49+
}
50+
51+
private static final class ComponentHolder {
52+
private final ComponentContainer container;
53+
54+
public ComponentHolder(ComponentContainer container) {
55+
this.container = container;
56+
}
57+
}
58+
}

firebase-components/firebase-components.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ android {
4444
dependencies {
4545
implementation project(':firebase-annotations')
4646
implementation 'androidx.annotation:annotation:1.1.0'
47-
47+
implementation "com.google.errorprone:error_prone_annotations:2.9.0"
4848
testImplementation 'androidx.test:runner:1.2.0'
4949
testImplementation 'androidx.test.ext:junit:1.1.1'
5050
testImplementation "org.robolectric:robolectric:$robolectricVersion"

firebase-components/src/main/java/com/google/firebase/components/Component.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import androidx.annotation.IntDef;
1818
import androidx.annotation.NonNull;
1919
import androidx.annotation.Nullable;
20+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2021
import java.lang.annotation.Retention;
2122
import java.lang.annotation.RetentionPolicy;
2223
import java.util.Arrays;
@@ -265,6 +266,7 @@ public Builder<T> name(@NonNull String name) {
265266
}
266267

267268
/** Add a {@link Dependency} to the {@link Component} being built. */
269+
@CanIgnoreReturnValue
268270
public Builder<T> add(Dependency dependency) {
269271
Preconditions.checkNotNull(dependency, "Null dependency");
270272
validateInterface(dependency.getInterface());
@@ -273,21 +275,25 @@ public Builder<T> add(Dependency dependency) {
273275
}
274276

275277
/** Make the {@link Component} initialize upon startup. */
278+
@CanIgnoreReturnValue
276279
public Builder<T> alwaysEager() {
277280
return setInstantiation(Instantiation.ALWAYS_EAGER);
278281
}
279282

280283
/** Make the component initialize upon startup in default app. */
284+
@CanIgnoreReturnValue
281285
public Builder<T> eagerInDefaultApp() {
282286
return setInstantiation(Instantiation.EAGER_IN_DEFAULT_APP);
283287
}
284288

285289
/** Make the {@link Component} eligible to publish events of provided eventType. */
290+
@CanIgnoreReturnValue
286291
public Builder<T> publishes(Class<?> eventType) {
287292
publishedEvents.add(eventType);
288293
return this;
289294
}
290295

296+
@CanIgnoreReturnValue
291297
private Builder<T> setInstantiation(@Instantiation int instantiation) {
292298
Preconditions.checkState(
293299
this.instantiation == Instantiation.LAZY, "Instantiation type has already been set.");
@@ -302,11 +308,13 @@ private void validateInterface(Class<?> anInterface) {
302308
}
303309

304310
/** Set the factory that will be used to initialize the {@link Component}. */
311+
@CanIgnoreReturnValue
305312
public Builder<T> factory(ComponentFactory<T> value) {
306313
factory = Preconditions.checkNotNull(value, "Null factory");
307314
return this;
308315
}
309316

317+
@CanIgnoreReturnValue
310318
private Builder<T> intoSet() {
311319
type = ComponentType.SET;
312320
return this;

firebase-components/src/main/java/com/google/firebase/components/ComponentRuntime.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import androidx.annotation.RestrictTo;
1919
import androidx.annotation.RestrictTo.Scope;
2020
import androidx.annotation.VisibleForTesting;
21+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2122
import com.google.firebase.dynamicloading.ComponentLoader;
2223
import com.google.firebase.events.Publisher;
2324
import com.google.firebase.events.Subscriber;
@@ -358,21 +359,25 @@ public static final class Builder {
358359
this.defaultExecutor = defaultExecutor;
359360
}
360361

362+
@CanIgnoreReturnValue
361363
public Builder addLazyComponentRegistrars(Collection<Provider<ComponentRegistrar>> registrars) {
362364
this.lazyRegistrars.addAll(registrars);
363365
return this;
364366
}
365367

368+
@CanIgnoreReturnValue
366369
public Builder addComponentRegistrar(ComponentRegistrar registrar) {
367370
this.lazyRegistrars.add(() -> registrar);
368371
return this;
369372
}
370373

374+
@CanIgnoreReturnValue
371375
public Builder addComponent(Component<?> component) {
372376
this.additionalComponents.add(component);
373377
return this;
374378
}
375379

380+
@CanIgnoreReturnValue
376381
public Builder setProcessor(ComponentRegistrarProcessor processor) {
377382
this.componentRegistrarProcessor = processor;
378383
return this;

firebase-components/src/main/java/com/google/firebase/components/Preconditions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.components;
1616

17+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
18+
1719
public final class Preconditions {
1820

1921
public static void checkArgument(boolean expression, String errorMessage) {
@@ -22,13 +24,15 @@ public static void checkArgument(boolean expression, String errorMessage) {
2224
}
2325
}
2426

27+
@CanIgnoreReturnValue
2528
public static <T> T checkNotNull(T reference) {
2629
if (reference == null) {
2730
throw new NullPointerException();
2831
}
2932
return reference;
3033
}
3134

35+
@CanIgnoreReturnValue
3236
public static <T> T checkNotNull(T reference, String errorMessage) {
3337
if (reference == null) {
3438
throw new NullPointerException(errorMessage);

firebase-inappmessaging-display/src/androidTest/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
43
package="com.google.firebase.inappmessaging.display.test">
54

65
<application>

0 commit comments

Comments
 (0)