-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.embrace.android.embracesdk.internal.capture.activity | ||
|
||
public interface OpenEvents { | ||
|
||
public fun create(instanceId: Int, activityName: String, timestampMs: Long) | ||
|
||
public fun createEnd(instanceId: Int, timestampMs: Long) | ||
|
||
public fun start(instanceId: Int, activityName: String, timestampMs: Long) | ||
|
||
public fun startEnd(instanceId: Int, timestampMs: Long) | ||
|
||
public fun resume(instanceId: Int, activityName: String, timestampMs: Long) | ||
|
||
public fun resumeEnd(instanceId: Int, timestampMs: Long) | ||
|
||
public fun render(instanceId: Int, activityName: String, timestampMs: Long) | ||
|
||
public fun renderEnd(instanceId: Int, timestampMs: Long) | ||
|
||
public enum class OpenType(public val typeName: String) { | ||
COLD("cold"), HOT("hot") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package io.embrace.android.embracesdk.internal.capture.activity | ||
|
||
import android.app.Activity | ||
import android.os.Build | ||
import android.os.Bundle | ||
import io.embrace.android.embracesdk.internal.clock.nanosToMillis | ||
import io.embrace.android.embracesdk.internal.session.lifecycle.ActivityLifecycleListener | ||
import io.embrace.android.embracesdk.internal.utils.VersionChecker | ||
import io.opentelemetry.sdk.common.Clock | ||
|
||
internal class OpenEventEmitter( | ||
private val openEvents: OpenEvents, | ||
private val clock: Clock, | ||
private val versionChecker: VersionChecker, | ||
Check warning on line 14 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L11-L14
|
||
) : ActivityLifecycleListener { | ||
override fun onActivityPreCreated(activity: Activity, savedInstanceState: Bundle?) { | ||
create(activity) | ||
Check warning on line 17 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L17
|
||
} | ||
|
||
override fun onActivityCreated(activity: Activity, bundle: Bundle?) { | ||
if (!versionChecker.firePrePostEvents()) { | ||
create(activity) | ||
Check warning on line 22 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L22
|
||
} | ||
} | ||
|
||
override fun onActivityPostCreated(activity: Activity, savedInstanceState: Bundle?) { | ||
createEnd(activity) | ||
Check warning on line 27 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L27
|
||
} | ||
|
||
override fun onActivityPreStarted(activity: Activity) { | ||
start(activity) | ||
Check warning on line 31 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L31
|
||
} | ||
|
||
override fun onActivityStarted(activity: Activity) { | ||
if (!versionChecker.firePrePostEvents()) { | ||
createEnd(activity) | ||
start(activity) | ||
Check warning on line 37 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L36-L37
|
||
} | ||
} | ||
|
||
override fun onActivityPostStarted(activity: Activity) { | ||
startEnd(activity) | ||
Check warning on line 42 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L42
|
||
} | ||
|
||
override fun onActivityPreResumed(activity: Activity) { | ||
resume(activity) | ||
Check warning on line 46 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L46
|
||
} | ||
|
||
override fun onActivityResumed(activity: Activity) { | ||
if (!versionChecker.firePrePostEvents()) { | ||
startEnd(activity) | ||
resumeEnd(activity) | ||
Check warning on line 52 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L51-L52
|
||
} | ||
} | ||
|
||
override fun onActivityPostResumed(activity: Activity) { | ||
resumeEnd(activity) | ||
Check warning on line 57 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L57
|
||
} | ||
|
||
private fun create(activity: Activity) { | ||
openEvents.create( | ||
instanceId = traceInstanceId(activity), | ||
activityName = activity.localClassName, | ||
timestampMs = nowMs() | ||
Check warning on line 64 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L61-L64
|
||
) | ||
} | ||
|
||
private fun createEnd(activity: Activity) { | ||
openEvents.createEnd( | ||
instanceId = traceInstanceId(activity), | ||
timestampMs = nowMs() | ||
Check warning on line 71 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L69-L71
|
||
) | ||
} | ||
|
||
private fun start(activity: Activity) { | ||
openEvents.start( | ||
instanceId = traceInstanceId(activity), | ||
activityName = activity.localClassName, | ||
timestampMs = nowMs() | ||
Check warning on line 79 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L76-L79
|
||
) | ||
} | ||
|
||
private fun startEnd(activity: Activity) { | ||
openEvents.startEnd( | ||
instanceId = traceInstanceId(activity), | ||
timestampMs = nowMs() | ||
Check warning on line 86 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L84-L86
|
||
) | ||
} | ||
|
||
private fun resume(activity: Activity) { | ||
openEvents.resume( | ||
instanceId = traceInstanceId(activity), | ||
activityName = activity.localClassName, | ||
timestampMs = nowMs() | ||
Check warning on line 94 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L91-L94
|
||
) | ||
} | ||
|
||
private fun resumeEnd(activity: Activity) { | ||
openEvents.resumeEnd( | ||
instanceId = traceInstanceId(activity), | ||
timestampMs = nowMs() | ||
Check warning on line 101 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L99-L101
|
||
) | ||
} | ||
|
||
private fun VersionChecker.firePrePostEvents(): Boolean = isAtLeast(Build.VERSION_CODES.Q) | ||
Check warning on line 105 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L105
|
||
|
||
private fun traceInstanceId(activity: Activity): Int = activity.hashCode() | ||
Check warning on line 107 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L107
|
||
|
||
private fun nowMs(): Long = clock.now().nanosToMillis() | ||
Check warning on line 109 in embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt Codecov / codecov/patchembrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/OpenEventEmitter.kt#L109
|
||
} |