• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snowplow / snowplow-android-tracker / #1055

pending completion
#1055

push

github-actions

mscwilson
Merge branch 'release/5.0.0-beta.1' into next

214 of 214 new or added lines in 18 files covered. (100.0%)

3599 of 4680 relevant lines covered (76.9%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/snowplow-tracker/src/main/java/com/snowplowanalytics/core/statemachine/LifecycleStateMachine.kt
1
/*
2
 * Copyright (c) 2015-2023 Snowplow Analytics Ltd. All rights reserved.
3
 *
4
 * This program is licensed to you under the Apache License Version 2.0,
5
 * and you may not use this file except in compliance with the Apache License Version 2.0.
6
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
 *
8
 * Unless required by applicable law or agreed to in writing,
9
 * software distributed under the Apache License Version 2.0 is distributed on an
10
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
 */
13
package com.snowplowanalytics.core.statemachine
14

15
import com.snowplowanalytics.snowplow.entity.LifecycleEntity
16
import com.snowplowanalytics.snowplow.event.Background
17
import com.snowplowanalytics.snowplow.event.Event
18
import com.snowplowanalytics.snowplow.event.Foreground
19
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson
20
import com.snowplowanalytics.snowplow.tracker.InspectableEvent
21

22
class LifecycleStateMachine : StateMachineInterface {
1✔
23
    /*
24
     States: Visible, NotVisible
25
     Events: FG (Foreground), BG (Background)
26
     Transitions:
27
      - Visible (BG) NotVisible
28
      - NotVisible (FG) Visible
29
     Entity Generation:
30
      - Visible, NotVisible
31
     */
32

33
    override val identifier: String
34
        get() = ID
1✔
35
    
36
    override val subscribedEventSchemasForTransitions: List<String>
37
        get() = listOf(Background.schema, Foreground.schema)
1✔
38

39
    override val subscribedEventSchemasForEntitiesGeneration: List<String>
40
        get() = listOf("*")
1✔
41

42
    override val subscribedEventSchemasForPayloadUpdating: List<String>
43
        get() = emptyList()
1✔
44

45
    override val subscribedEventSchemasForAfterTrackCallback: List<String>
46
        get() = emptyList()
1✔
47

48
    override fun transition(event: Event, currentState: State?): State? {
49
        if (event is Foreground) {
1✔
50
            return LifecycleState(true, event.foregroundIndex)
1✔
51
        }
52
        if (event is Background) {
1✔
53
            return LifecycleState(false, event.backgroundIndex)
1✔
54
        }
55
        return null
×
56
    }
57

58
    override fun entities(event: InspectableEvent, state: State?): List<SelfDescribingJson>? {
59
        if (state == null) return listOf<SelfDescribingJson>(LifecycleEntity(true))
1✔
60
        
61
        val s = state as? LifecycleState
1✔
62
        return s?.let { listOf<SelfDescribingJson>(LifecycleEntity(it.isForeground).index(it.index)) }
1✔
63
    }
64

65
    override fun payloadValues(event: InspectableEvent, state: State?): Map<String, Any>? {
66
        return null
×
67
    }
68

69
    override fun afterTrack(event: InspectableEvent) {
70
    }
×
71

72
    companion object {
1✔
73
        val ID: String
74
            get() = "Lifecycle"
1✔
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc