mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 18:30:20 +01:00
Improve and streamline Application#onCreate.
This commit is contained in:
committed by
Alan Evans
parent
c27300c19d
commit
cdd7b2deb9
@@ -0,0 +1,68 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.signal.core.util.logging.Log;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public final class AppStartup {
|
||||
|
||||
private static final String TAG = Log.tag(AppStartup.class);
|
||||
|
||||
private final List<Task> blocking;
|
||||
private final List<Task> deferred;
|
||||
|
||||
public AppStartup() {
|
||||
this.blocking = new LinkedList<>();
|
||||
this.deferred = new LinkedList<>();
|
||||
}
|
||||
|
||||
public @NonNull
|
||||
AppStartup addBlocking(@NonNull String name, @NonNull Runnable task) {
|
||||
blocking.add(new Task(name, task));
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NonNull
|
||||
AppStartup addDeferred(@NonNull Runnable task) {
|
||||
deferred.add(new Task("", task));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
Stopwatch stopwatch = new Stopwatch("init");
|
||||
|
||||
for (Task task : blocking) {
|
||||
task.getRunnable().run();
|
||||
stopwatch.split(task.getName());
|
||||
}
|
||||
|
||||
for (Task task : deferred) {
|
||||
SignalExecutors.BOUNDED.execute(task.getRunnable());
|
||||
}
|
||||
|
||||
stopwatch.split("schedule-deferred");
|
||||
stopwatch.stop(TAG);
|
||||
}
|
||||
|
||||
private class Task {
|
||||
private final String name;
|
||||
private final Runnable runnable;
|
||||
|
||||
protected Task(@NonNull String name, @NonNull Runnable runnable) {
|
||||
this.name = name;
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@NonNull String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @NonNull Runnable getRunnable() {
|
||||
return runnable;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.view.Choreographer;
|
||||
import android.view.Display;
|
||||
@@ -23,7 +24,7 @@ public class FrameRateTracker {
|
||||
|
||||
private static final int MAX_CONSECUTIVE_FRAME_LOGS = 10;
|
||||
|
||||
private final Context context;
|
||||
private final Application context;
|
||||
|
||||
private double refreshRate;
|
||||
private long idealTimePerFrameNanos;
|
||||
@@ -33,8 +34,8 @@ public class FrameRateTracker {
|
||||
|
||||
private long consecutiveFrameWarnings;
|
||||
|
||||
public FrameRateTracker(@NonNull Context context) {
|
||||
this.context = context;
|
||||
public FrameRateTracker(@NonNull Application application) {
|
||||
this.context = application;
|
||||
|
||||
updateRefreshRate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user