Skip to content

Refactor startup executor #6040

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 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading