|
14 | 14 | package com.google.firebase.messaging; |
15 | 15 |
|
16 | 16 | import static com.google.firebase.messaging.FirebaseMessaging.TAG; |
| 17 | +import static java.util.concurrent.TimeUnit.SECONDS; |
17 | 18 |
|
18 | 19 | import android.annotation.SuppressLint; |
19 | 20 | import android.content.ComponentName; |
|
26 | 27 | import androidx.annotation.Nullable; |
27 | 28 | import androidx.annotation.VisibleForTesting; |
28 | 29 | import com.google.android.gms.common.stats.ConnectionTracker; |
29 | | -import com.google.android.gms.common.util.concurrent.NamedThreadFactory; |
30 | 30 | import com.google.android.gms.tasks.Task; |
31 | 31 | import com.google.android.gms.tasks.TaskCompletionSource; |
32 | 32 | import com.google.errorprone.annotations.CanIgnoreReturnValue; |
|
35 | 35 | import java.util.concurrent.ScheduledExecutorService; |
36 | 36 | import java.util.concurrent.ScheduledFuture; |
37 | 37 | import java.util.concurrent.ScheduledThreadPoolExecutor; |
38 | | -import java.util.concurrent.TimeUnit; |
39 | 38 |
|
40 | 39 | /** |
41 | 40 | * Helper object to abstract the ServiceConnection lifecycle for binding to services within the same |
@@ -65,7 +64,7 @@ void arrangeTimeout(ScheduledExecutorService executor) { |
65 | 64 | finish(); |
66 | 65 | }, |
67 | 66 | EnhancedIntentService.MESSAGE_TIMEOUT_S, |
68 | | - TimeUnit.SECONDS); |
| 67 | + SECONDS); |
69 | 68 |
|
70 | 69 | getTask() |
71 | 70 | .addOnCompleteListener( |
@@ -100,18 +99,20 @@ void finish() { |
100 | 99 | @GuardedBy("this") |
101 | 100 | private boolean connectionInProgress = false; |
102 | 101 |
|
103 | | - // TODO(b/258424124): Migrate to go/firebase-android-executors |
104 | | - @SuppressLint("ThreadPoolCreation") |
105 | 102 | WithinAppServiceConnection(Context context, String action) { |
106 | 103 | // Class instances are owned by a static variable in FirebaseInstanceIdReceiver |
107 | 104 | // and GcmReceiver so that they survive getting gc'd and reinstantiated, so use a |
108 | 105 | // scheduled thread pool executor with core size of 0 so that the no threads will be |
109 | 106 | // kept idle. |
110 | | - this( |
111 | | - context, |
112 | | - action, |
113 | | - new ScheduledThreadPoolExecutor( |
114 | | - 0, new NamedThreadFactory("Firebase-FirebaseInstanceIdServiceConnection"))); |
| 107 | + this(context, action, createScheduledThreadPoolExecutor()); |
| 108 | + } |
| 109 | + |
| 110 | + @SuppressLint("ThreadPoolCreation") |
| 111 | + private static ScheduledThreadPoolExecutor createScheduledThreadPoolExecutor() { |
| 112 | + ScheduledThreadPoolExecutor threadPoolExecutor = new ScheduledThreadPoolExecutor(1); |
| 113 | + threadPoolExecutor.setKeepAliveTime(EnhancedIntentService.MESSAGE_TIMEOUT_S * 2, SECONDS); |
| 114 | + threadPoolExecutor.allowCoreThreadTimeOut(true); |
| 115 | + return threadPoolExecutor; |
115 | 116 | } |
116 | 117 |
|
117 | 118 | @VisibleForTesting |
|
0 commit comments