Skip to content

Commit 6ecd31e

Browse files
committed
Address PR feedback
1 parent e92a82b commit 6ecd31e

File tree

4 files changed

+18
-27
lines changed

4 files changed

+18
-27
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/AnrV2Integration.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ public void register(@NotNull IScopes scopes, @NotNull SentryOptions options) {
8686
.getExecutorService()
8787
.submit(
8888
new ApplicationExitInfoHistoryDispatcher(
89-
context,
90-
scopes,
91-
this.options,
92-
dateProvider,
93-
new AnrV2Policy(scopes, this.options)));
89+
context, scopes, this.options, dateProvider, new AnrV2Policy(this.options)));
9490
} catch (Throwable e) {
9591
options.getLogger().log(SentryLevel.DEBUG, "Failed to start ANR processor.", e);
9692
}
@@ -109,11 +105,9 @@ public void close() throws IOException {
109105
private static final class AnrV2Policy
110106
implements ApplicationExitInfoHistoryDispatcher.ApplicationExitInfoPolicy {
111107

112-
private final @NotNull IScopes scopes;
113108
private final @NotNull SentryAndroidOptions options;
114109

115-
AnrV2Policy(final @NotNull IScopes scopes, final @NotNull SentryAndroidOptions options) {
116-
this.scopes = scopes;
110+
AnrV2Policy(final @NotNull SentryAndroidOptions options) {
117111
this.options = options;
118112
}
119113

sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,17 @@ private void setAnrExceptions(
810810
private void applyAnrProfile(
811811
@NotNull SentryEvent event, @NotNull Backfillable hint, boolean isBackgroundAnr) {
812812

813-
// Skip background ANRs (profiling only runs in foreground)
813+
// Skip background ANRs (as profiling only runs in foreground)
814814
if (isBackgroundAnr) {
815815
return;
816816
}
817817

818-
// Get timestamp from hint (ANR hints implement AbnormalExit which has timestamp())
818+
final String cacheDirPath = options.getCacheDirPath();
819+
if (cacheDirPath == null) {
820+
return;
821+
}
822+
final File cacheDir = new File(cacheDirPath);
823+
819824
if (!(hint instanceof AbnormalExit)) {
820825
return;
821826
}
@@ -827,13 +832,6 @@ private void applyAnrProfile(
827832
anrTimestamp = event.getTimestamp().getTime();
828833
}
829834

830-
// Read profile from disk
831-
final String cacheDirPath = options.getCacheDirPath();
832-
if (cacheDirPath == null) {
833-
return;
834-
}
835-
final File cacheDir = new File(cacheDirPath);
836-
837835
AnrProfile anrProfile = null;
838836
try {
839837
final File lastFile = AnrProfileRotationHelper.getLastFile(cacheDir);
@@ -857,14 +855,12 @@ private void applyAnrProfile(
857855
return;
858856
}
859857

860-
// Validate timestamp
861858
options.getLogger().log(SentryLevel.INFO, "ANR profile found");
862859
if (anrTimestamp < anrProfile.startTimeMs || anrTimestamp > anrProfile.endtimeMs) {
863860
options.getLogger().log(SentryLevel.DEBUG, "ANR profile found, but doesn't match");
864861
return;
865862
}
866863

867-
// Identify culprit
868864
final AggregatedStackTrace culprit = AnrCulpritIdentifier.identify(anrProfile.stacks);
869865
if (culprit == null) {
870866
return;
@@ -873,7 +869,6 @@ private void applyAnrProfile(
873869
// Capture profile chunk
874870
final SentryId profilerId = captureAnrProfile(anrTimestamp, anrProfile);
875871

876-
// Set exceptions with culprit
877872
final StackTraceElement[] stack = culprit.getStack();
878873
if (stack.length > 0) {
879874
final StackTraceElement stackTraceElement = stack[0];
@@ -882,7 +877,14 @@ private void applyAnrProfile(
882877
final AnrException exception = new AnrException(message);
883878
exception.setStackTrace(stack);
884879

885-
event.setExceptions(sentryExceptionFactory.getSentryExceptions(exception));
880+
final @NotNull List<SentryException> sentryException =
881+
sentryExceptionFactory.getSentryExceptions(exception);
882+
for (final @NotNull SentryException e : sentryException) {
883+
final Mechanism mechanism = new Mechanism();
884+
mechanism.setType("ANR");
885+
e.setMechanism(mechanism);
886+
}
887+
event.setExceptions(sentryException);
886888

887889
if (profilerId != null) {
888890
event.getContexts().setProfile(new ProfileContext(profilerId));

sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfilingIntegration.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
5454
"SentryAndroidOptions is required");
5555
this.logger = options.getLogger();
5656

57-
if (this.options == null) {
58-
return;
59-
}
60-
6157
if (((SentryAndroidOptions) options).isEnableAnrProfiling()) {
6258
addIntegrationToSdkVersion("AnrProfiling");
6359
AppState.getInstance().addAppStateListener(this);
@@ -151,7 +147,7 @@ protected void checkMainThread(final @NotNull Thread mainThread) throws IOExcept
151147
final long now = SystemClock.uptimeMillis();
152148
final long diff = now - lastMainThreadExecutionTime;
153149

154-
if (diff < 1000) {
150+
if (diff < THRESHOLD_SUSPICION_MS) {
155151
mainThreadState = MainThreadState.IDLE;
156152
}
157153

sentry-android-core/src/main/java/io/sentry/android/core/anr/StackTraceConverter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ private static SentryStackFrame createSentryStackFrame(@NotNull StackTraceElemen
141141
frame.setFunction(element.getMethodName());
142142
frame.setModule(element.getClassName());
143143
frame.setLineno(element.getLineNumber() > 0 ? element.getLineNumber() : null);
144-
frame.setInApp(true);
145144
if (element.isNativeMethod()) {
146145
frame.setNative(true);
147146
}

0 commit comments

Comments
 (0)