Skip to content

Commit 59930cf

Browse files
davidmotsonDavid Motsonashvili
and
David Motsonashvili
authored
Move Firebase Installations to the new, injected executors (#4514)
* Move Firebase Installations to the new, injected executors * added sequential executor as network executor to fix tests * re-organized libraries and test executor Co-authored-by: David Motsonashvili <[email protected]>
1 parent d02ec6e commit 59930cf

File tree

4 files changed

+80
-72
lines changed

4 files changed

+80
-72
lines changed

firebase-installations/firebase-installations.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies {
4141
implementation project(':firebase-common')
4242
implementation project(':firebase-installations-interop')
4343
implementation project(':firebase-components')
44+
implementation project(':firebase-annotations')
4445

4546
implementation 'androidx.multidex:multidex:2.0.1'
4647
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
@@ -50,6 +51,7 @@ dependencies {
5051
compileOnly "com.google.auto.value:auto-value-annotations:1.6.5"
5152
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
5253

54+
testImplementation project(':integ-testing')
5355
testImplementation 'androidx.test:core:1.2.0'
5456
testImplementation 'junit:junit:4.12'
5557
testImplementation "org.robolectric:robolectric:$robolectricVersion"

firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@
4444
import java.util.Iterator;
4545
import java.util.List;
4646
import java.util.Set;
47+
import java.util.concurrent.Executor;
4748
import java.util.concurrent.ExecutorService;
48-
import java.util.concurrent.LinkedBlockingQueue;
4949
import java.util.concurrent.ThreadFactory;
50-
import java.util.concurrent.ThreadPoolExecutor;
51-
import java.util.concurrent.TimeUnit;
5250
import java.util.concurrent.atomic.AtomicInteger;
5351

5452
/**
@@ -71,7 +69,7 @@ public class FirebaseInstallations implements FirebaseInstallationsApi {
7169
private final RandomFidGenerator fidGenerator;
7270
private final Object lock = new Object();
7371
private final ExecutorService backgroundExecutor;
74-
private final ExecutorService networkExecutor;
72+
private final Executor networkExecutor;
7573
/* FID of this Firebase Installations instance. Cached after successfully registering and
7674
persisting the FID locally. NOTE: cachedFid resets if FID is deleted.*/
7775
@GuardedBy("this")
@@ -129,15 +127,13 @@ public Thread newThread(Runnable r) {
129127
// TODO(b/258422917): Migrate to go/firebase-android-executors
130128
@SuppressLint("ThreadPoolCreation")
131129
FirebaseInstallations(
132-
FirebaseApp firebaseApp, @NonNull Provider<HeartBeatController> heartBeatProvider) {
130+
FirebaseApp firebaseApp,
131+
@NonNull Provider<HeartBeatController> heartBeatProvider,
132+
@NonNull ExecutorService backgroundExecutor,
133+
@NonNull Executor networkExecutor) {
133134
this(
134-
new ThreadPoolExecutor(
135-
CORE_POOL_SIZE,
136-
MAXIMUM_POOL_SIZE,
137-
KEEP_ALIVE_TIME_IN_SECONDS,
138-
TimeUnit.SECONDS,
139-
new LinkedBlockingQueue<>(),
140-
THREAD_FACTORY),
135+
backgroundExecutor,
136+
networkExecutor,
141137
firebaseApp,
142138
new FirebaseInstallationServiceClient(
143139
firebaseApp.getApplicationContext(), heartBeatProvider),
@@ -151,6 +147,7 @@ public Thread newThread(Runnable r) {
151147
@SuppressLint("ThreadPoolCreation")
152148
FirebaseInstallations(
153149
ExecutorService backgroundExecutor,
150+
Executor networkExecutor,
154151
FirebaseApp firebaseApp,
155152
FirebaseInstallationServiceClient serviceClient,
156153
PersistedInstallation persistedInstallation,
@@ -164,14 +161,7 @@ public Thread newThread(Runnable r) {
164161
this.iidStore = iidStore;
165162
this.fidGenerator = fidGenerator;
166163
this.backgroundExecutor = backgroundExecutor;
167-
this.networkExecutor =
168-
new ThreadPoolExecutor(
169-
CORE_POOL_SIZE,
170-
MAXIMUM_POOL_SIZE,
171-
KEEP_ALIVE_TIME_IN_SECONDS,
172-
TimeUnit.SECONDS,
173-
new LinkedBlockingQueue<>(),
174-
THREAD_FACTORY);
164+
this.networkExecutor = networkExecutor;
175165
}
176166

177167
/**

firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallationsRegistrar.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616

1717
import androidx.annotation.Keep;
1818
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.annotations.concurrent.Background;
20+
import com.google.firebase.annotations.concurrent.Blocking;
1921
import com.google.firebase.components.Component;
2022
import com.google.firebase.components.ComponentRegistrar;
2123
import com.google.firebase.components.Dependency;
24+
import com.google.firebase.components.Qualified;
25+
import com.google.firebase.concurrent.FirebaseExecutors;
2226
import com.google.firebase.heartbeatinfo.HeartBeatConsumerComponent;
2327
import com.google.firebase.heartbeatinfo.HeartBeatController;
2428
import com.google.firebase.platforminfo.LibraryVersionComponent;
2529
import java.util.Arrays;
2630
import java.util.List;
31+
import java.util.concurrent.Executor;
32+
import java.util.concurrent.ExecutorService;
2733

2834
/** @hide */
2935
@Keep
@@ -37,10 +43,16 @@ public List<Component<?>> getComponents() {
3743
.name(LIBRARY_NAME)
3844
.add(Dependency.required(FirebaseApp.class))
3945
.add(Dependency.optionalProvider(HeartBeatController.class))
46+
.add(Dependency.required(Qualified.qualified(Background.class, ExecutorService.class)))
47+
.add(Dependency.required(Qualified.qualified(Blocking.class, Executor.class)))
4048
.factory(
4149
c ->
4250
new FirebaseInstallations(
43-
c.get(FirebaseApp.class), c.getProvider(HeartBeatController.class)))
51+
c.get(FirebaseApp.class),
52+
c.getProvider(HeartBeatController.class),
53+
c.get(Qualified.qualified(Background.class, ExecutorService.class)),
54+
FirebaseExecutors.newSequentialExecutor(
55+
c.get(Qualified.qualified(Blocking.class, Executor.class)))))
4456
.build(),
4557
HeartBeatConsumerComponent.create(),
4658
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));

0 commit comments

Comments
 (0)