Skip to content

Commit da631d2

Browse files
authored
Expose the transport factory as a Qualified component (#5237)
* Expose the transport factory as a Qualified dependency. * Add CHANGELOG entry * Fix version bump.
1 parent 56d5bb6 commit da631d2

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

firebase-datatransport/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# Unreleased
2-
3-
2+
* [feature] Expose the transport factory as a qualified dependency based on the endpoint connected.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
version=18.1.9
22
latestReleasedVersion=18.1.8
33
android.enableUnitTestBinaryResources=true
4-
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 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.datatransport;
16+
17+
import java.lang.annotation.ElementType;
18+
import java.lang.annotation.Target;
19+
import javax.inject.Qualifier;
20+
21+
@Qualifier
22+
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
23+
public @interface LegacyTransportBackend {}

firebase-datatransport/src/main/java/com/google/firebase/datatransport/package-info.java renamed to firebase-datatransport/src/main/java/com/google/firebase/datatransport/TransportBackend.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Google LLC
1+
// Copyright 2023 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,5 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/** @hide */
1615
package com.google.firebase.datatransport;
16+
17+
import java.lang.annotation.ElementType;
18+
import java.lang.annotation.Target;
19+
import javax.inject.Qualifier;
20+
21+
@Qualifier
22+
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
23+
public @interface TransportBackend {}

firebase-datatransport/src/main/java/com/google/firebase/datatransport/TransportRegistrar.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
import android.content.Context;
1818
import androidx.annotation.Keep;
19+
import androidx.annotation.NonNull;
1920
import com.google.android.datatransport.TransportFactory;
2021
import com.google.android.datatransport.cct.CCTDestination;
2122
import com.google.android.datatransport.runtime.TransportRuntime;
2223
import com.google.firebase.components.Component;
2324
import com.google.firebase.components.ComponentRegistrar;
2425
import com.google.firebase.components.Dependency;
26+
import com.google.firebase.components.Qualified;
2527
import com.google.firebase.platforminfo.LibraryVersionComponent;
2628
import java.util.Arrays;
2729
import java.util.List;
@@ -31,6 +33,7 @@ public class TransportRegistrar implements ComponentRegistrar {
3133
private static final String LIBRARY_NAME = "fire-transport";
3234

3335
@Override
36+
@NonNull
3437
public List<Component<?>> getComponents() {
3538
return Arrays.asList(
3639
Component.builder(TransportFactory.class)
@@ -42,6 +45,22 @@ public List<Component<?>> getComponents() {
4245
return TransportRuntime.getInstance().newFactory(CCTDestination.LEGACY_INSTANCE);
4346
})
4447
.build(),
48+
Component.builder(Qualified.qualified(LegacyTransportBackend.class, TransportFactory.class))
49+
.add(Dependency.required(Context.class))
50+
.factory(
51+
c -> {
52+
TransportRuntime.initialize(c.get(Context.class));
53+
return TransportRuntime.getInstance().newFactory(CCTDestination.LEGACY_INSTANCE);
54+
})
55+
.build(),
56+
Component.builder(Qualified.qualified(TransportBackend.class, TransportFactory.class))
57+
.add(Dependency.required(Context.class))
58+
.factory(
59+
c -> {
60+
TransportRuntime.initialize(c.get(Context.class));
61+
return TransportRuntime.getInstance().newFactory(CCTDestination.INSTANCE);
62+
})
63+
.build(),
4564
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
4665
}
4766
}

0 commit comments

Comments
 (0)