13
13
// limitations under the License.
14
14
package com .google .firebase .messaging ;
15
15
16
+ import static com .google .firebase .messaging .FcmExecutors .newFileIOExecutor ;
16
17
import static com .google .firebase .messaging .FcmExecutors .newInitExecutor ;
17
18
import static com .google .firebase .messaging .FcmExecutors .newTaskExecutor ;
18
19
import static com .google .firebase .messaging .FcmExecutors .newTopicsSyncExecutor ;
@@ -110,8 +111,9 @@ public class FirebaseMessaging {
110
111
private final GmsRpc gmsRpc ;
111
112
private final RequestDeduplicator requestDeduplicator ;
112
113
private final AutoInit autoInit ;
113
- private final Executor fileIoExecutor ;
114
+ private final Executor initExecutor ;
114
115
private final Executor taskExecutor ;
116
+ private final Executor fileExecutor ;
115
117
private final Task <TopicsSubscriber > topicsSubscriberTask ;
116
118
private final Metadata metadata ;
117
119
@@ -195,7 +197,8 @@ static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp firebaseA
195
197
new GmsRpc (
196
198
firebaseApp , metadata , userAgentPublisher , heartBeatInfo , firebaseInstallationsApi ),
197
199
/* taskExecutor= */ newTaskExecutor (),
198
- /* fileIoExecutor= */ newInitExecutor ());
200
+ /* initExecutor= */ newInitExecutor (),
201
+ /* fileExecutor= */ newFileIOExecutor ());
199
202
}
200
203
201
204
FirebaseMessaging (
@@ -207,7 +210,8 @@ static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp firebaseA
207
210
Metadata metadata ,
208
211
GmsRpc gmsRpc ,
209
212
Executor taskExecutor ,
210
- Executor fileIoExecutor ) {
213
+ Executor initExecutor ,
214
+ Executor fileExecutor ) {
211
215
212
216
FirebaseMessaging .transportFactory = transportFactory ;
213
217
@@ -221,7 +225,8 @@ static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp firebaseA
221
225
this .taskExecutor = taskExecutor ;
222
226
this .gmsRpc = gmsRpc ;
223
227
this .requestDeduplicator = new RequestDeduplicator (taskExecutor );
224
- this .fileIoExecutor = fileIoExecutor ;
228
+ this .initExecutor = initExecutor ;
229
+ this .fileExecutor = fileExecutor ;
225
230
226
231
Context appContext = firebaseApp .getApplicationContext ();
227
232
if (appContext instanceof Application ) {
@@ -243,7 +248,7 @@ static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp firebaseA
243
248
});
244
249
}
245
250
246
- fileIoExecutor .execute (
251
+ initExecutor .execute (
247
252
() -> {
248
253
if (isAutoInitEnabled ()) {
249
254
startSyncIfNecessary ();
@@ -257,7 +262,7 @@ static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp firebaseA
257
262
// During FCM instantiation, as part of the initial setup, we spin up a couple of background
258
263
// threads to handle topic syncing and proxy notification configuration.
259
264
topicsSubscriberTask .addOnSuccessListener (
260
- fileIoExecutor ,
265
+ initExecutor ,
261
266
topicsSubscriber -> {
262
267
// Topics operations relay on IID for token generation, thus the sync is also
263
268
// subject to an auto-init check.
@@ -266,7 +271,7 @@ static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp firebaseA
266
271
}
267
272
});
268
273
269
- fileIoExecutor .execute (
274
+ initExecutor .execute (
270
275
() ->
271
276
// Initializes proxy notification support for the app.
272
277
ProxyNotificationInitializer .initialize (context ));
@@ -363,7 +368,7 @@ public boolean isNotificationDelegationEnabled() {
363
368
* @return A Task that completes when the notification delegation has been set.
364
369
*/
365
370
public Task <Void > setNotificationDelegationEnabled (boolean enable ) {
366
- return ProxyNotificationInitializer .setEnableProxyNotification (fileIoExecutor , context , enable );
371
+ return ProxyNotificationInitializer .setEnableProxyNotification (initExecutor , context , enable );
367
372
}
368
373
369
374
/**
@@ -381,7 +386,7 @@ public Task<String> getToken() {
381
386
return iid .getTokenTask ();
382
387
}
383
388
TaskCompletionSource <String > taskCompletionSource = new TaskCompletionSource <>();
384
- fileIoExecutor .execute (
389
+ initExecutor .execute (
385
390
() -> {
386
391
try {
387
392
taskCompletionSource .setResult (blockingGetToken ());
@@ -405,7 +410,7 @@ public Task<String> getToken() {
405
410
public Task <Void > deleteToken () {
406
411
if (iid != null ) {
407
412
TaskCompletionSource <Void > taskCompletionSource = new TaskCompletionSource <>();
408
- fileIoExecutor .execute (
413
+ initExecutor .execute (
409
414
() -> {
410
415
try {
411
416
iid .deleteToken (Metadata .getDefaultSenderId (firebaseApp ), INSTANCE_ID_SCOPE );
@@ -604,7 +609,7 @@ String blockingGetToken() throws IOException {
604
609
gmsRpc
605
610
.getToken ()
606
611
.onSuccessTask (
607
- Runnable :: run , // direct executor
612
+ fileExecutor ,
608
613
token -> {
609
614
getStore (context )
610
615
.saveToken (
0 commit comments