Skip to content

Commit 18f6837

Browse files
markushiclaude
andcommitted
Perfect! Now here's the final summary and commit:
## Summary I've addressed the final 3 review comments by simplifying the helper methods: **ApplicationStartInfoIntegration.java changes:** - Added `@RequiresApi(api = 35)` annotations to `getStartupTypeLabel()`, `getLaunchModeLabel()`, and `getReasonLabel()` methods - Removed the redundant `if (Build.VERSION.SDK_INT >= 35)` checks from all three methods - Simplified the code flow by relying on the annotation for API level enforcement The methods are now cleaner and more maintainable, as the API level requirement is explicitly declared through the annotation rather than runtime checks. Since these methods are only called from `@RequiresApi(api = 35)` annotated methods, the runtime checks were redundant. All 11 ApplicationStartInfoIntegration tests pass successfully. --- **Proposed git commit command:** ```bash git commit -m "$(cat <<'EOF' refactor(android): Simplify ApplicationStartInfo helper methods Replace runtime version checks with @RequiresApi annotations: - Add @RequiresApi(api = 35) to getStartupTypeLabel() - Add @RequiresApi(api = 35) to getLaunchModeLabel() - Add @RequiresApi(api = 35) to getReasonLabel() - Remove redundant if (Build.VERSION.SDK_INT >= 35) checks Methods are only called from API 35+ contexts, so annotations provide sufficient protection without runtime checks. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> EOF )" ```
1 parent eb22f7c commit 18f6837

File tree

1 file changed

+50
-56
lines changed

1 file changed

+50
-56
lines changed

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

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -283,72 +283,66 @@ private void attachAppStartMetricData(
283283
return tags;
284284
}
285285

286+
@RequiresApi(api = 35)
286287
private @NotNull String getStartupTypeLabel(final int startType) {
287-
if (Build.VERSION.SDK_INT >= 35) {
288-
switch (startType) {
289-
case android.app.ApplicationStartInfo.START_TYPE_COLD:
290-
return "cold";
291-
case android.app.ApplicationStartInfo.START_TYPE_WARM:
292-
return "warm";
293-
case android.app.ApplicationStartInfo.START_TYPE_HOT:
294-
return "hot";
295-
default:
296-
return "unknown";
297-
}
288+
switch (startType) {
289+
case android.app.ApplicationStartInfo.START_TYPE_COLD:
290+
return "cold";
291+
case android.app.ApplicationStartInfo.START_TYPE_WARM:
292+
return "warm";
293+
case android.app.ApplicationStartInfo.START_TYPE_HOT:
294+
return "hot";
295+
default:
296+
return "unknown";
298297
}
299-
return "unknown";
300298
}
301299

300+
@RequiresApi(api = 35)
302301
private @NotNull String getLaunchModeLabel(final int launchMode) {
303-
if (Build.VERSION.SDK_INT >= 35) {
304-
switch (launchMode) {
305-
case android.app.ApplicationStartInfo.LAUNCH_MODE_STANDARD:
306-
return "standard";
307-
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_TOP:
308-
return "single_top";
309-
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_INSTANCE:
310-
return "single_instance";
311-
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_TASK:
312-
return "single_task";
313-
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_INSTANCE_PER_TASK:
314-
return "single_instance_per_task";
315-
default:
316-
return "unknown";
317-
}
302+
switch (launchMode) {
303+
case android.app.ApplicationStartInfo.LAUNCH_MODE_STANDARD:
304+
return "standard";
305+
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_TOP:
306+
return "single_top";
307+
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_INSTANCE:
308+
return "single_instance";
309+
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_TASK:
310+
return "single_task";
311+
case android.app.ApplicationStartInfo.LAUNCH_MODE_SINGLE_INSTANCE_PER_TASK:
312+
return "single_instance_per_task";
313+
default:
314+
return "unknown";
318315
}
319-
return "unknown";
320316
}
321317

318+
@RequiresApi(api = 35)
322319
private @NotNull String getReasonLabel(final int reason) {
323-
if (Build.VERSION.SDK_INT >= 35) {
324-
switch (reason) {
325-
case android.app.ApplicationStartInfo.START_REASON_ALARM:
326-
return "alarm";
327-
case android.app.ApplicationStartInfo.START_REASON_BACKUP:
328-
return "backup";
329-
case android.app.ApplicationStartInfo.START_REASON_BOOT_COMPLETE:
330-
return "boot_complete";
331-
case android.app.ApplicationStartInfo.START_REASON_BROADCAST:
332-
return "broadcast";
333-
case android.app.ApplicationStartInfo.START_REASON_CONTENT_PROVIDER:
334-
return "content_provider";
335-
case android.app.ApplicationStartInfo.START_REASON_JOB:
336-
return "job";
337-
case android.app.ApplicationStartInfo.START_REASON_LAUNCHER:
338-
return "launcher";
339-
case android.app.ApplicationStartInfo.START_REASON_OTHER:
340-
return "other";
341-
case android.app.ApplicationStartInfo.START_REASON_PUSH:
342-
return "push";
343-
case android.app.ApplicationStartInfo.START_REASON_SERVICE:
344-
return "service";
345-
case android.app.ApplicationStartInfo.START_REASON_START_ACTIVITY:
346-
return "start_activity";
347-
default:
348-
return "unknown";
349-
}
320+
switch (reason) {
321+
case android.app.ApplicationStartInfo.START_REASON_ALARM:
322+
return "alarm";
323+
case android.app.ApplicationStartInfo.START_REASON_BACKUP:
324+
return "backup";
325+
case android.app.ApplicationStartInfo.START_REASON_BOOT_COMPLETE:
326+
return "boot_complete";
327+
case android.app.ApplicationStartInfo.START_REASON_BROADCAST:
328+
return "broadcast";
329+
case android.app.ApplicationStartInfo.START_REASON_CONTENT_PROVIDER:
330+
return "content_provider";
331+
case android.app.ApplicationStartInfo.START_REASON_JOB:
332+
return "job";
333+
case android.app.ApplicationStartInfo.START_REASON_LAUNCHER:
334+
return "launcher";
335+
case android.app.ApplicationStartInfo.START_REASON_OTHER:
336+
return "other";
337+
case android.app.ApplicationStartInfo.START_REASON_PUSH:
338+
return "push";
339+
case android.app.ApplicationStartInfo.START_REASON_SERVICE:
340+
return "service";
341+
case android.app.ApplicationStartInfo.START_REASON_START_ACTIVITY:
342+
return "start_activity";
343+
default:
344+
return "unknown";
350345
}
351-
return "unknown";
352346
}
353347

354348
// Helper methods to access timestamps from the startupTimestamps map

0 commit comments

Comments
 (0)