Skip to content

Commit b7a34fb

Browse files
authored
Update component runtime to pick up any one of the couroutine dispatcher interface (#5300)
1 parent fe84885 commit b7a34fb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

firebase-components/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Unreleased
2+
* [changed] Internal changes to ensure only one interface is provided for
3+
kotlinx.coroutines.CoroutineDispatcher interfaces when both firebase-common and
4+
firebase-common-ktx provide them.
5+
26

37

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ComponentRuntime implements ComponentContainer, ComponentLoader {
4949
private final Map<Qualified<?>, Provider<?>> lazyInstanceMap = new HashMap<>();
5050
private final Map<Qualified<?>, LazySet<?>> lazySetMap = new HashMap<>();
5151
private final List<Provider<ComponentRegistrar>> unprocessedRegistrarProviders;
52+
private Set<String> processedCoroutineDispatcherInterfaces = new HashSet<>();
5253
private final EventBus eventBus;
5354
private final AtomicReference<Boolean> eagerComponentsInitializedWith = new AtomicReference<>();
5455
private final ComponentRegistrarProcessor componentRegistrarProcessor;
@@ -123,6 +124,25 @@ private void discoverComponents(List<Component<?>> componentsToAdd) {
123124
}
124125
}
125126

127+
// kotlinx.coroutines.CoroutineDispatcher interfaces could be provided by both new version of
128+
// firebase-common and old version of firebase-common-ktx. In this scenario take the first
129+
// interface which was provided.
130+
131+
Iterator<Component<?>> it = componentsToAdd.iterator();
132+
while (it.hasNext()) {
133+
Component component = it.next();
134+
for (Object anInterface : component.getProvidedInterfaces().toArray()) {
135+
if (anInterface.toString().contains("kotlinx.coroutines.CoroutineDispatcher")) {
136+
if (processedCoroutineDispatcherInterfaces.contains(anInterface.toString())) {
137+
it.remove();
138+
break;
139+
} else {
140+
processedCoroutineDispatcherInterfaces.add(anInterface.toString());
141+
}
142+
}
143+
}
144+
}
145+
126146
if (components.isEmpty()) {
127147
CycleDetector.detect(componentsToAdd);
128148
} else {

0 commit comments

Comments
 (0)