Skip to content

Commit

Permalink
Refactor startup executor (#6040)
Browse files Browse the repository at this point in the history
- Use backgroundExecutorService from firebase common executor to process
setting fetch task
- Remove some legacy logic

#no-changelog
  • Loading branch information
themiswang committed Jul 3, 2024
1 parent 038bf4c commit 2ddda55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.google.firebase.sessions.api.FirebaseSessionsDependencies;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

/**
Expand All @@ -71,7 +72,7 @@ public class FirebaseCrashlytics {
@NonNull Deferred<CrashlyticsNativeComponent> nativeComponent,
@NonNull Deferred<AnalyticsConnector> analyticsConnector,
@NonNull Deferred<FirebaseRemoteConfigInterop> remoteConfigInteropDeferred,
@Background ExecutorService liteExecutorService,
@Background ExecutorService backgroundExecutorService,
@Blocking ExecutorService blockingExecutorService) {

Context context = app.getApplicationContext();
Expand Down Expand Up @@ -151,8 +152,8 @@ public class FirebaseCrashlytics {

Logger.getLogger().v("Installer package name is: " + appData.installerPackageName);

final ExecutorService threadPoolExecutor =
ExecutorUtils.buildSingleThreadExecutorService("com.google.firebase.crashlytics.startup");
final Executor threadPoolExecutor =
ExecutorUtils.buildSequentialExecutor(backgroundExecutorService);

final SettingsController settingsController =
SettingsController.create(
Expand Down Expand Up @@ -182,17 +183,9 @@ public Object then(@NonNull Task<Void> task) throws Exception {

final boolean finishCoreInBackground = core.onPreExecute(appData, settingsController);

Tasks.call(
threadPoolExecutor,
new Callable<Void>() {
@Override
public Void call() throws Exception {
if (finishCoreInBackground) {
core.doBackgroundInitializationAsync(settingsController);
}
return null;
}
});
if (finishCoreInBackground) {
core.doBackgroundInitializationAsync(settingsController);
}

return new FirebaseCrashlytics(core);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
import static java.util.concurrent.TimeUnit.SECONDS;

import android.annotation.SuppressLint;

import com.google.firebase.concurrent.FirebaseExecutors;
import com.google.firebase.crashlytics.internal.Logger;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -34,6 +37,10 @@ public final class ExecutorUtils {

private ExecutorUtils() {}

public static Executor buildSequentialExecutor(Executor commonExecutor) {
return FirebaseExecutors.newSequentialExecutor(commonExecutor);
}

public static ExecutorService buildSingleThreadExecutorService(String name) {
final ThreadFactory threadFactory = ExecutorUtils.getNamedThreadFactory(name);
final ExecutorService executor =
Expand Down

0 comments on commit 2ddda55

Please sign in to comment.