-
Notifications
You must be signed in to change notification settings - Fork 8
/
FinalEnvelopeParams.kt
94 lines (85 loc) · 2.86 KB
/
FinalEnvelopeParams.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package io.embrace.android.embracesdk.session.message
import io.embrace.android.embracesdk.event.EventService
import io.embrace.android.embracesdk.internal.StartupEventInfo
import io.embrace.android.embracesdk.payload.Session
import io.embrace.android.embracesdk.session.captureDataSafely
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType
/**
* Holds the parameters & logic needed to create a final session object that can be
* sent to the backend.
*/
internal sealed class FinalEnvelopeParams(
val initial: Session,
val endTime: Long,
val lifeEventType: Session.LifeEventType?,
crashId: String?,
val endType: SessionSnapshotType,
val isCacheAttempt: Boolean
) {
val crashId: String? = when {
crashId.isNullOrEmpty() -> null
else -> crashId
}
abstract val terminationTime: Long?
abstract val receivedTermination: Boolean?
abstract val endTimeVal: Long?
abstract fun getStartupEventInfo(eventService: EventService): StartupEventInfo?
/**
* Initial parameters required to create a background activity object.
*/
internal class BackgroundActivityParams(
initial: Session,
endTime: Long,
lifeEventType: Session.LifeEventType?,
endType: SessionSnapshotType,
crashId: String? = null,
) : FinalEnvelopeParams(
initial,
endTime,
lifeEventType,
crashId,
endType,
lifeEventType == null
) {
override val terminationTime: Long? = null
override val receivedTermination: Boolean? = null
override val endTimeVal: Long? = null
override fun getStartupEventInfo(eventService: EventService): StartupEventInfo? = null
}
/**
* Initial parameters required to create a session object.
*/
internal class SessionParams(
initial: Session,
endTime: Long,
lifeEventType: Session.LifeEventType?,
endType: SessionSnapshotType,
crashId: String? = null,
) : FinalEnvelopeParams(
initial,
endTime,
lifeEventType,
crashId,
endType,
endType == SessionSnapshotType.PERIODIC_CACHE
) {
override val terminationTime: Long? = when {
endType.forceQuit -> endTime
else -> null
}
override val receivedTermination: Boolean? = when {
endType.forceQuit -> true
else -> null
}
// We don't set end time for force-quit, as the API interprets this to be a clean
// termination
override val endTimeVal: Long? = when {
endType.forceQuit -> null
else -> endTime
}
override fun getStartupEventInfo(eventService: EventService) = when {
initial.isColdStart -> captureDataSafely(eventService::getStartupMomentInfo)
else -> null
}
}
}