Skip to content

Enable thread pool linter check. #4297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.android.gms.common.internal.Preconditions.checkNotNull;

import android.annotation.SuppressLint;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -45,6 +46,8 @@ public class DebugAppCheckProvider implements AppCheckProvider {
private final RetryManager retryManager;
private final Task<String> debugSecretTask;

// TODO(b/258273630): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public DebugAppCheckProvider(@NonNull FirebaseApp firebaseApp, @Nullable String debugSecret) {
checkNotNull(firebaseApp);
this.networkClient = new NetworkClient(firebaseApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.appcheck.playintegrity.internal;

import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.tasks.Task;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class PlayIntegrityAppCheckProvider implements AppCheckProvider {
private final ExecutorService backgroundExecutor;
private final RetryManager retryManager;

// TODO(b/258273630): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public PlayIntegrityAppCheckProvider(@NonNull FirebaseApp firebaseApp) {
this(
firebaseApp.getOptions().getGcmSenderId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.android.gms.common.internal.Preconditions.checkNotEmpty;
import static com.google.android.gms.common.internal.Preconditions.checkNotNull;

import android.annotation.SuppressLint;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -56,6 +57,8 @@ public class SafetyNetAppCheckProvider implements AppCheckProvider {
private final String apiKey;

/** @param firebaseApp the FirebaseApp to which this Factory is tied. */
// TODO(b/258273630): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public SafetyNetAppCheckProvider(@NonNull FirebaseApp firebaseApp) {
this(
firebaseApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.android.gms.common.internal.Preconditions.checkNotNull;

import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class DefaultFirebaseAppCheck extends FirebaseAppCheck {
private AppCheckProvider appCheckProvider;
private AppCheckToken cachedToken;

// TODO(b/258273630): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public DefaultFirebaseAppCheck(
@NonNull FirebaseApp firebaseApp,
@NonNull Provider<HeartBeatController> heartBeatController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.tasks.OnFailureListener;
Expand All @@ -41,6 +42,8 @@ public class DefaultTokenRefresher {
private volatile ScheduledFuture<?> refreshFuture;
private volatile long delayAfterFailureSeconds;

// TODO(b/258273630): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
DefaultTokenRefresher(@NonNull DefaultFirebaseAppCheck firebaseAppCheck) {
this(checkNotNull(firebaseAppCheck), Executors.newScheduledThreadPool(/* corePoolSize= */ 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.firebase.appdistribution.impl.TaskUtils.runAsyncInTask;
import static com.google.firebase.appdistribution.impl.TaskUtils.safeSetTaskException;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -52,6 +53,8 @@ class AabUpdater {
@GuardedBy("updateAabLock")
private boolean hasBeenSentToPlayForCurrentTask = false;

// TODO(b/258264924): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
AabUpdater() {
this(
FirebaseAppDistributionLifecycleNotifier.getInstance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.firebase.appdistribution.impl.TaskUtils.safeSetTaskException;
import static com.google.firebase.appdistribution.impl.TaskUtils.safeSetTaskResult;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
Expand Down Expand Up @@ -62,6 +63,8 @@ class ApkUpdater {

private final Object updateTaskLock = new Object();

// TODO(b/258264924): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public ApkUpdater(@NonNull FirebaseApp firebaseApp, @NonNull ApkInstaller apkInstaller) {
this(
Executors.newSingleThreadExecutor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.firebase.appdistribution.impl.TaskUtils.runAsyncInTask;

import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
Expand Down Expand Up @@ -63,6 +64,9 @@ private interface FidDependentJob<TResult> {
private final FirebaseApp firebaseApp;
private final Provider<FirebaseInstallationsApi> firebaseInstallationsApiProvider;
private final TesterApiHttpClient testerApiHttpClient;

// TODO(b/258264924): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
private final Executor taskExecutor = Executors.newSingleThreadExecutor();

FirebaseAppDistributionTesterApiClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.remoteconfig;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.GuardedBy;
Expand Down Expand Up @@ -87,6 +88,8 @@ public class RemoteConfigComponent {
private Map<String, String> customHeaders = new HashMap<>();

/** Firebase Remote Config Component constructor. */
// TODO(b/258275481): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
RemoteConfigComponent(
Context context,
FirebaseApp firebaseApp,
Expand Down Expand Up @@ -211,6 +214,8 @@ public synchronized void setCustomHeaders(Map<String, String> customHeaders) {
this.customHeaders = customHeaders;
}

// TODO(b/258275481): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
private ConfigCacheClient getCacheClient(String namespace, String configStoreType) {
String fileName =
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
package com.google.firebase.crashlytics.internal.common;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ApplicationExitInfo;
import android.content.Context;
Expand Down Expand Up @@ -734,6 +735,9 @@ private Task<Void> logAnalyticsAppExceptionEvent(long timestamp) {
return Tasks.forResult(null);
}
Logger.getLogger().d("Logging app exception event to Firebase Analytics");

// TODO(b/258263226): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
final ThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
return Tasks.call(
executor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static java.util.concurrent.TimeUnit.SECONDS;

import android.annotation.SuppressLint;
import com.google.firebase.crashlytics.internal.Logger;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -43,6 +44,8 @@ public static ExecutorService buildSingleThreadExecutorService(String name) {

public static ScheduledExecutorService buildSingleThreadScheduledExecutorService(String name) {
final ThreadFactory threadFactory = ExecutorUtils.getNamedThreadFactory(name);
// TODO(b/258263226): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
final ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor(threadFactory);
ExecutorUtils.addDelayedShutdownHook(name, executor);
Expand Down Expand Up @@ -70,6 +73,8 @@ public void onRun() {
};
}

// TODO(b/258263226): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
private static ExecutorService newSingleThreadExecutor(
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return Executors.unconfigurableExecutorService(
Expand All @@ -88,11 +93,14 @@ private static void addDelayedShutdownHook(String serviceName, ExecutorService s
serviceName, service, DEFAULT_TERMINATION_TIMEOUT, SECONDS);
}

// TODO(b/258263226): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
private static void addDelayedShutdownHook(
final String serviceName,
final ExecutorService service,
final long terminationTimeout,
final TimeUnit timeUnit) {

Runtime.getRuntime()
.addShutdownHook(
new Thread(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ final class ReportQueue {
onDemandCounter);
}

// TODO(b/258263226): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
ReportQueue(
double ratePerMinute,
double base,
Expand Down Expand Up @@ -120,7 +122,8 @@ TaskCompletionSource<CrashlyticsReportWithSessionId> enqueueReport(
}
}

@SuppressLint("DiscouragedApi") // best effort only
// TODO(b/258263226): Migrate to go/firebase-android-executors
@SuppressLint({"DiscouragedApi", "ThreadPoolCreation"}) // best effort only
public void flushScheduledReportsIfAble() {
CountDownLatch latch = new CountDownLatch(1);
new Thread(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.database.core;

import android.annotation.SuppressLint;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
Expand All @@ -25,6 +26,8 @@ class ThreadPoolEventTarget implements EventTarget {

private final ThreadPoolExecutor executor;

// TODO(b/258277572): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public ThreadPoolEventTarget(
final ThreadFactory wrappedFactory, final ThreadInitializer threadInitializer) {
int poolSize = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.firebase.firestore.util.Assert.fail;
import static com.google.firebase.firestore.util.Assert.hardAssert;

import android.annotation.SuppressLint;
import androidx.annotation.Nullable;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
Expand Down Expand Up @@ -162,6 +163,9 @@ private static Executor createDefaultExecutor() {
int maxPoolSize = corePoolSize;
int keepAliveSeconds = 1;
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

// TODO(b/258277574): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
ThreadPoolExecutor executor =
new ThreadPoolExecutor(
corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.SECONDS, queue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.firebase.firestore.util.Assert.fail;
import static com.google.firebase.firestore.util.Assert.hardAssert;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -243,6 +244,8 @@ public Thread newThread(@NonNull Runnable runnable) {
}
}

// TODO(b/258277574): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
SynchronizedShutdownAwareExecutor() {
DelayedStartFactory threadFactory = new DelayedStartFactory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.inappmessaging.internal;

import android.annotation.SuppressLint;
import androidx.annotation.VisibleForTesting;
import com.google.firebase.abt.AbtException;
import com.google.firebase.abt.AbtExperimentInfo;
Expand All @@ -33,7 +34,10 @@
public class AbtIntegrationHelper {
private final FirebaseABTesting abTesting;

@VisibleForTesting Executor executor = Executors.newSingleThreadExecutor();
// TODO(b/258280977): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
@VisibleForTesting
Executor executor = Executors.newSingleThreadExecutor();

@Inject
public AbtIntegrationHelper(FirebaseABTesting abTesting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.inappmessaging.internal;

import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.google.firebase.inappmessaging.FirebaseInAppMessagingClickListener;
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDismissListener;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class DeveloperListenerManager {
registeredImpressionListeners = new HashMap<>();

private static BlockingQueue<Runnable> mCallbackQueue = new LinkedBlockingQueue<>();

// TODO(b/258280977): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
private static final ThreadPoolExecutor CALLBACK_QUEUE_EXECUTOR =
new ThreadPoolExecutor(
POOL_SIZE,
Expand Down Expand Up @@ -182,6 +186,8 @@ static class FIAMThreadFactory implements ThreadFactory {

@SuppressWarnings("ThreadPriorityCheck")
@Override
// TODO(b/258280977): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public Thread newThread(@NonNull Runnable r) {
Thread t = new Thread(r, "FIAM-" + mNameSuffix + threadNumber.getAndIncrement());
t.setDaemon(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.installations;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -96,6 +97,8 @@ public class FirebaseInstallations implements FirebaseInstallationsApi {
private final AtomicInteger mCount = new AtomicInteger(1);

@Override
// TODO(b/258422917): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
public Thread newThread(Runnable r) {
return new Thread(
r, String.format("firebase-installations-executor-%d", mCount.getAndIncrement()));
Expand Down Expand Up @@ -123,6 +126,8 @@ public Thread newThread(Runnable r) {
+ "Please retry your last request.";

/** package private constructor. */
// TODO(b/258422917): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
FirebaseInstallations(
FirebaseApp firebaseApp, @NonNull Provider<HeartBeatController> heartBeatProvider) {
this(
Expand All @@ -142,6 +147,8 @@ public Thread newThread(Runnable r) {
new RandomFidGenerator());
}

// TODO(b/258422917): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
FirebaseInstallations(
ExecutorService backgroundExecutor,
FirebaseApp firebaseApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ android {
timeOutInMs 60 * 1000
}

lintOptions {
abortOnError false
}

compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion 19
Expand Down
Loading