Skip to content

Commit bdadd2b

Browse files
buenaflorclaude
andcommitted
feat(extend-app-start): Add setData and isExtended to AppStartExtension
Move these component accessors into the component-extraction PR (they were introduced later in the wiring PR). Keeps the full AppStartExtension surface and its unit tests together here; the wiring PR only consumes them. Inert on its own. Regenerated apiDump. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 210b4ee commit bdadd2b

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

sentry-android-core/api/sentry-android-core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public final class io/sentry/android/core/AppStartExtension : io/sentry/IAppStar
193193
public fun getExtendedAppStartSpan ()Lio/sentry/ISpan;
194194
public fun getExtendedEndTime ()Lio/sentry/SentryDate;
195195
public fun isActive ()Z
196+
public fun isExtended ()Z
197+
public fun setData (Ljava/lang/String;Ljava/lang/Object;)V
196198
public fun setExtendAppStartListener (Lio/sentry/android/core/AppStartExtension$ExtendAppStartListener;)V
197199
}
198200

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ public void extendAppStart() {
8080
}
8181
}
8282

83+
/**
84+
* Sets data on the owned (eager) transaction if it is still open. Used to attach the screen name
85+
* once the first activity is known, since the transaction is created in {@code onCreate} before
86+
* any activity exists.
87+
*/
88+
public void setData(final @NotNull String key, final @Nullable Object value) {
89+
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
90+
if (extendedTransaction != null && !extendedTransaction.isFinished()) {
91+
extendedTransaction.setData(key, value);
92+
}
93+
}
94+
}
95+
8396
@Override
8497
public void finishExtendedAppStart() {
8598
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
@@ -108,6 +121,16 @@ public boolean isActive() {
108121
}
109122
}
110123

124+
/**
125+
* Whether this app start was extended at all, regardless of finish or deadline state. Used by the
126+
* event processor to decide whether to apply the never-shorten vital logic.
127+
*/
128+
public boolean isExtended() {
129+
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
130+
return extendedSpan != null;
131+
}
132+
}
133+
111134
public void finishTransaction(final @NotNull SentryDate endTimestamp) {
112135
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
113136
final @Nullable ITransaction transaction = extendedTransaction;

sentry-android-core/src/test/java/io/sentry/android/core/AppStartExtensionTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ class AppStartExtensionTest {
135135
assertFalse(ext.isActive)
136136
}
137137

138+
@Test
139+
fun `isExtended stays true once extended, even after the transaction finishes`() {
140+
val ext = extension(windowOpen = true)
141+
assertFalse(ext.isExtended)
142+
val (txn, _) = ext.registerHandOver()
143+
ext.extendAppStart()
144+
assertTrue(ext.isExtended)
145+
whenever(txn.isFinished).thenReturn(true)
146+
assertFalse(ext.isActive)
147+
assertTrue(ext.isExtended)
148+
}
149+
138150
@Test
139151
fun `finishTransaction finishes the transaction at the given timestamp`() {
140152
val ext = extension(windowOpen = true)

0 commit comments

Comments
 (0)