Skip to content

[Fireperf][Fixit] Change AppStartTrace from singleton to normal object #4186

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -68,7 +68,6 @@ public class AppStartTrace implements ActivityLifecycleCallbacks {
private static final int CORE_POOL_SIZE = 0;
private static final int MAX_POOL_SIZE = 1; // Only need single thread

private static volatile AppStartTrace instance;
private static ExecutorService executorService;

private boolean isRegisteredForLifecycleCallbacks = false;
Expand Down Expand Up @@ -129,29 +128,17 @@ public static void setLauncherActivityOnResumeTime(String activity) {
// no-op, for backward compatibility with old version plugin.
}

public static AppStartTrace getInstance() {
return instance != null ? instance : getInstance(TransportManager.getInstance(), new Clock());
}

static AppStartTrace getInstance(TransportManager transportManager, Clock clock) {
if (instance == null) {
synchronized (AppStartTrace.class) {
if (instance == null) {
instance =
new AppStartTrace(
transportManager,
clock,
ConfigResolver.getInstance(),
new ThreadPoolExecutor(
CORE_POOL_SIZE,
MAX_POOL_SIZE,
/* keepAliveTime= */ MAX_LATENCY_BEFORE_UI_INIT + 10,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>()));
}
}
}
return instance;
public AppStartTrace() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if "De-singletoning this hides AppStartTrace.getInstance() from customers. " Customers can still call new AppStartTrace() I think.

this(
TransportManager.getInstance(),
new Clock(),
ConfigResolver.getInstance(),
new ThreadPoolExecutor(
CORE_POOL_SIZE,
MAX_POOL_SIZE,
/* keepAliveTime= */ MAX_LATENCY_BEFORE_UI_INIT + 10,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>()));
}

AppStartTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void attachInfo(Context context, ProviderInfo info) {
appStateMonitor.registerActivityLifecycleCallbacks(getContext());
appStateMonitor.registerForAppColdStart(new FirebasePerformanceInitializer());

AppStartTrace appStartTrace = AppStartTrace.getInstance();
AppStartTrace appStartTrace = new AppStartTrace();
appStartTrace.registerActivityLifecycleCallbacks(getContext());

mainHandler.post(new AppStartTrace.StartFromBackgroundRunnable(appStartTrace));
Expand Down