-
-
Notifications
You must be signed in to change notification settings - Fork 455
Fix Ensure app start type is set, even when ActivityLifecycleIntegration is not running #4216
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
Changes from all commits
1642088
98fc65d
c4adbda
c8abed5
8823143
7c4b39a
9289aa7
d564f99
edb4764
dc65675
0e7d541
3aee7d9
73fd1a1
84f56cd
c159be0
8541dc0
441675c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,13 @@ | |
import static io.sentry.Sentry.APP_START_PROFILING_CONFIG_FILE_NAME; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.pm.ProviderInfo; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.os.Process; | ||
import android.os.SystemClock; | ||
import androidx.annotation.NonNull; | ||
import io.sentry.ILogger; | ||
import io.sentry.ITransactionProfiler; | ||
import io.sentry.JsonSerializer; | ||
|
@@ -22,9 +18,7 @@ | |
import io.sentry.SentryLevel; | ||
import io.sentry.SentryOptions; | ||
import io.sentry.TracesSamplingDecision; | ||
import io.sentry.android.core.internal.util.FirstDrawDoneListener; | ||
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector; | ||
import io.sentry.android.core.performance.ActivityLifecycleCallbacksAdapter; | ||
import io.sentry.android.core.performance.AppStartMetrics; | ||
import io.sentry.android.core.performance.TimeSpan; | ||
import java.io.BufferedReader; | ||
|
@@ -33,7 +27,6 @@ | |
import java.io.FileNotFoundException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
@@ -185,8 +178,9 @@ private void onAppLaunched( | |
|
||
// performance v2: Uses Process.getStartUptimeMillis() | ||
// requires API level 24+ | ||
if (buildInfoProvider.getSdkInfoVersion() < android.os.Build.VERSION_CODES.N) { | ||
return; | ||
if (buildInfoProvider.getSdkInfoVersion() >= android.os.Build.VERSION_CODES.N) { | ||
final @NotNull TimeSpan appStartTimespan = appStartMetrics.getAppStartTimeSpan(); | ||
appStartTimespan.setStartedAt(Process.getStartUptimeMillis()); | ||
} | ||
|
||
if (context instanceof Application) { | ||
|
@@ -196,40 +190,6 @@ private void onAppLaunched( | |
return; | ||
} | ||
|
||
final @NotNull TimeSpan appStartTimespan = appStartMetrics.getAppStartTimeSpan(); | ||
appStartTimespan.setStartedAt(Process.getStartUptimeMillis()); | ||
appStartMetrics.registerApplicationForegroundCheck(app); | ||
|
||
final AtomicBoolean firstDrawDone = new AtomicBoolean(false); | ||
|
||
activityCallback = | ||
new ActivityLifecycleCallbacksAdapter() { | ||
@Override | ||
public void onActivityStarted(@NonNull Activity activity) { | ||
if (firstDrawDone.get()) { | ||
return; | ||
} | ||
if (activity.getWindow() != null) { | ||
FirstDrawDoneListener.registerForNextDraw( | ||
activity, () -> onAppStartDone(), buildInfoProvider); | ||
} else { | ||
new Handler(Looper.getMainLooper()).post(() -> onAppStartDone()); | ||
} | ||
} | ||
}; | ||
|
||
app.registerActivityLifecycleCallbacks(activityCallback); | ||
} | ||
|
||
synchronized void onAppStartDone() { | ||
final @NotNull AppStartMetrics appStartMetrics = AppStartMetrics.getInstance(); | ||
appStartMetrics.getSdkInitTimeSpan().stop(); | ||
appStartMetrics.getAppStartTimeSpan().stop(); | ||
|
||
if (app != null) { | ||
if (activityCallback != null) { | ||
app.unregisterActivityLifecycleCallbacks(activityCallback); | ||
} | ||
} | ||
appStartMetrics.registerLifecycleCallbacks(app); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a behavioural change, as we were not doing it on API < 24, while now we would. I'd keep the previous check that returns early There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's on purpose - otherwise we would need to duplicate half of the logic within |
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.