@app-swiss-knife/react-native-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -0
- package/SwissKnifePurchases.podspec +40 -0
- package/android/build.gradle +89 -0
- package/android/gradle.properties +3 -0
- package/android/src/main/AndroidManifest.xml +26 -0
- package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +216 -0
- package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingPackage.kt +17 -0
- package/android/src/main/java/com/swissknife/purchases/Conversions.kt +15 -0
- package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +371 -0
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +497 -0
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesPackage.kt +25 -0
- package/android/vendor/GENERATED.md +10 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +533 -0
- package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +326 -0
- package/android/vendor/java/com/appswissknife/analytics/FlushEventsWorker.kt +296 -0
- package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +503 -0
- package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +188 -0
- package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +204 -0
- package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +447 -0
- package/android/vendor/java/com/appswissknife/context/AppLifecycle.kt +120 -0
- package/android/vendor/java/com/appswissknife/context/Clock.kt +70 -0
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +138 -0
- package/android/vendor/java/com/appswissknife/context/IDs.kt +55 -0
- package/android/vendor/java/com/appswissknife/context/Reachability.kt +145 -0
- package/android/vendor/java/com/appswissknife/context/Session.kt +192 -0
- package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +945 -0
- package/android/vendor/java/com/appswissknife/crashreporting/SKScreenshot.kt +201 -0
- package/android/vendor/java/com/appswissknife/device/DeviceID.kt +172 -0
- package/android/vendor/java/com/appswissknife/diagnostics/SKLog.kt +97 -0
- package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +495 -0
- package/android/vendor/java/com/appswissknife/identity/Identity.kt +522 -0
- package/android/vendor/java/com/appswissknife/models/CustomerInfo.kt +67 -0
- package/android/vendor/java/com/appswissknife/models/Enums.kt +35 -0
- package/android/vendor/java/com/appswissknife/models/Offerings.kt +80 -0
- package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +89 -0
- package/android/vendor/java/com/appswissknife/models/StoreTransaction.kt +17 -0
- package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +507 -0
- package/android/vendor/java/com/appswissknife/net/ExponentialBackoff.kt +69 -0
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +582 -0
- package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +320 -0
- package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +219 -0
- package/android/vendor/java/com/appswissknife/performance/SKFrameTracker.kt +94 -0
- package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +428 -0
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +560 -0
- package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +100 -0
- package/android/vendor/java/com/appswissknife/purchases/PriceEnrichmentProvider.kt +36 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +120 -0
- package/android/vendor/res/xml/swissknife_data_extraction_rules.xml +20 -0
- package/ios/SwissKnifeCrashReporting.m +32 -0
- package/ios/SwissKnifeCrashReporting.swift +186 -0
- package/ios/SwissKnifeJSON.swift +347 -0
- package/ios/SwissKnifePurchases.m +124 -0
- package/ios/SwissKnifePurchases.swift +523 -0
- package/ios/vendor/GENERATED.md +10 -0
- package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +488 -0
- package/ios/vendor/SwissKnifeiOS/AttributesClient.swift +460 -0
- package/ios/vendor/SwissKnifeiOS/Attribution/Attribution.swift +307 -0
- package/ios/vendor/SwissKnifeiOS/Attribution/AttributionNetwork.swift +92 -0
- package/ios/vendor/SwissKnifeiOS/Attribution/AttributionState.swift +141 -0
- package/ios/vendor/SwissKnifeiOS/Context/AppLifecycle.swift +130 -0
- package/ios/vendor/SwissKnifeiOS/Context/Clock.swift +100 -0
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +190 -0
- package/ios/vendor/SwissKnifeiOS/Context/IDs.swift +64 -0
- package/ios/vendor/SwissKnifeiOS/Context/Reachability.swift +121 -0
- package/ios/vendor/SwissKnifeiOS/Context/Session.swift +223 -0
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +1287 -0
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKScreenshot.swift +175 -0
- package/ios/vendor/SwissKnifeiOS/DeviceID.swift +161 -0
- package/ios/vendor/SwissKnifeiOS/Diagnostics/SKLog.swift +128 -0
- package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +323 -0
- package/ios/vendor/SwissKnifeiOS/Identity/IdentityNetwork.swift +70 -0
- package/ios/vendor/SwissKnifeiOS/Net/BackendHttpClient.swift +329 -0
- package/ios/vendor/SwissKnifeiOS/Net/ExponentialBackoff.swift +87 -0
- package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +681 -0
- package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +409 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKFrameTracker.swift +89 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +440 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKURLSessionDelegate.swift +87 -0
- package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +646 -0
- package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +458 -0
- package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +374 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife+Analytics.swift +46 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife+DeviceID.swift +30 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife+Session.swift +47 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +417 -0
- package/ios/vendor/SwissKnifeiOS/Types.swift +496 -0
- package/lib/commonjs/attribution.js +55 -0
- package/lib/commonjs/attribution.js.map +1 -0
- package/lib/commonjs/identity.js +126 -0
- package/lib/commonjs/identity.js.map +1 -0
- package/lib/commonjs/index.js +118 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/analytics.js +646 -0
- package/lib/commonjs/modules/analytics.js.map +1 -0
- package/lib/commonjs/modules/attachments.js +169 -0
- package/lib/commonjs/modules/attachments.js.map +1 -0
- package/lib/commonjs/modules/crash-reporting.js +1327 -0
- package/lib/commonjs/modules/crash-reporting.js.map +1 -0
- package/lib/commonjs/modules/ids.js +50 -0
- package/lib/commonjs/modules/ids.js.map +1 -0
- package/lib/commonjs/modules/log.js +59 -0
- package/lib/commonjs/modules/log.js.map +1 -0
- package/lib/commonjs/modules/offline-store.js +44 -0
- package/lib/commonjs/modules/offline-store.js.map +1 -0
- package/lib/commonjs/modules/performance.js +494 -0
- package/lib/commonjs/modules/performance.js.map +1 -0
- package/lib/commonjs/native/module.js +41 -0
- package/lib/commonjs/native/module.js.map +1 -0
- package/lib/commonjs/native/spec.js +26 -0
- package/lib/commonjs/native/spec.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/purchases.js +194 -0
- package/lib/commonjs/purchases.js.map +1 -0
- package/lib/commonjs/types.js +236 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/attribution.js +51 -0
- package/lib/module/attribution.js.map +1 -0
- package/lib/module/identity.js +122 -0
- package/lib/module/identity.js.map +1 -0
- package/lib/module/index.js +36 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/analytics.js +642 -0
- package/lib/module/modules/analytics.js.map +1 -0
- package/lib/module/modules/attachments.js +162 -0
- package/lib/module/modules/attachments.js.map +1 -0
- package/lib/module/modules/crash-reporting.js +1320 -0
- package/lib/module/modules/crash-reporting.js.map +1 -0
- package/lib/module/modules/ids.js +44 -0
- package/lib/module/modules/ids.js.map +1 -0
- package/lib/module/modules/log.js +54 -0
- package/lib/module/modules/log.js.map +1 -0
- package/lib/module/modules/offline-store.js +39 -0
- package/lib/module/modules/offline-store.js.map +1 -0
- package/lib/module/modules/performance.js +491 -0
- package/lib/module/modules/performance.js.map +1 -0
- package/lib/module/native/module.js +34 -0
- package/lib/module/native/module.js.map +1 -0
- package/lib/module/native/spec.js +22 -0
- package/lib/module/native/spec.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/purchases.js +187 -0
- package/lib/module/purchases.js.map +1 -0
- package/lib/module/types.js +230 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/attribution.d.ts +24 -0
- package/lib/typescript/commonjs/attribution.d.ts.map +1 -0
- package/lib/typescript/commonjs/identity.d.ts +37 -0
- package/lib/typescript/commonjs/identity.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +15 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/analytics.d.ts +127 -0
- package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/attachments.d.ts +50 -0
- package/lib/typescript/commonjs/modules/attachments.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts +175 -0
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/ids.d.ts +17 -0
- package/lib/typescript/commonjs/modules/ids.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/log.d.ts +12 -0
- package/lib/typescript/commonjs/modules/log.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/offline-store.d.ts +9 -0
- package/lib/typescript/commonjs/modules/offline-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/performance.d.ts +75 -0
- package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/module.d.ts +6 -0
- package/lib/typescript/commonjs/native/module.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/spec.d.ts +119 -0
- package/lib/typescript/commonjs/native/spec.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/purchases.d.ts +68 -0
- package/lib/typescript/commonjs/purchases.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +384 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/module/attribution.d.ts +24 -0
- package/lib/typescript/module/attribution.d.ts.map +1 -0
- package/lib/typescript/module/identity.d.ts +37 -0
- package/lib/typescript/module/identity.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +15 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/analytics.d.ts +127 -0
- package/lib/typescript/module/modules/analytics.d.ts.map +1 -0
- package/lib/typescript/module/modules/attachments.d.ts +50 -0
- package/lib/typescript/module/modules/attachments.d.ts.map +1 -0
- package/lib/typescript/module/modules/crash-reporting.d.ts +175 -0
- package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -0
- package/lib/typescript/module/modules/ids.d.ts +17 -0
- package/lib/typescript/module/modules/ids.d.ts.map +1 -0
- package/lib/typescript/module/modules/log.d.ts +12 -0
- package/lib/typescript/module/modules/log.d.ts.map +1 -0
- package/lib/typescript/module/modules/offline-store.d.ts +9 -0
- package/lib/typescript/module/modules/offline-store.d.ts.map +1 -0
- package/lib/typescript/module/modules/performance.d.ts +75 -0
- package/lib/typescript/module/modules/performance.d.ts.map +1 -0
- package/lib/typescript/module/native/module.d.ts +6 -0
- package/lib/typescript/module/native/module.d.ts.map +1 -0
- package/lib/typescript/module/native/spec.d.ts +119 -0
- package/lib/typescript/module/native/spec.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/purchases.d.ts +68 -0
- package/lib/typescript/module/purchases.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +384 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/package.json +115 -0
- package/react-native.config.js +23 -0
- package/src/attribution.ts +56 -0
- package/src/identity.ts +133 -0
- package/src/index.ts +54 -0
- package/src/modules/analytics.ts +689 -0
- package/src/modules/attachments.ts +222 -0
- package/src/modules/crash-reporting.ts +1577 -0
- package/src/modules/ids.ts +41 -0
- package/src/modules/log.ts +56 -0
- package/src/modules/offline-store.ts +51 -0
- package/src/modules/performance.ts +589 -0
- package/src/native/module.ts +47 -0
- package/src/native/spec.ts +183 -0
- package/src/purchases.ts +214 -0
- package/src/types.ts +470 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// packages/swiss-knife-android/src/main/java/com/appswissknife/context/Session.kt
|
|
2
|
+
//
|
|
3
|
+
// Round-C cross-cutting primitive — Session lifecycle management. Mirror
|
|
4
|
+
// of `Sources/SwissKnifeiOS/Context/Session.swift`.
|
|
5
|
+
//
|
|
6
|
+
// Defines the SDK's notion of a "session" — a contiguous slice of
|
|
7
|
+
// foreground time. Before this primitive each module had its own ad-hoc
|
|
8
|
+
// session id:
|
|
9
|
+
// - SKAnalytics used Long(currentTimeMillis()) set at initialize() and
|
|
10
|
+
// never rotated.
|
|
11
|
+
// - SKCrashReporting used UUID.randomUUID().toString() rotated only on
|
|
12
|
+
// start().
|
|
13
|
+
// - Performance had no concept of sessions at all.
|
|
14
|
+
// Now every IngestItem carries the same session_id + session_number
|
|
15
|
+
// stamped by IngestClient at flush time.
|
|
16
|
+
//
|
|
17
|
+
// Restart rules
|
|
18
|
+
// -------------
|
|
19
|
+
// - First configure() call seeds the initial session.
|
|
20
|
+
// - Foreground after >5 min in background → new session. We track the
|
|
21
|
+
// last-background timestamp and on willEnterForeground compare to
|
|
22
|
+
// now; if the gap exceeds backgroundTimeout (default 300s), restart.
|
|
23
|
+
// Mirrors Amplitude / Mixpanel semantics.
|
|
24
|
+
// - Manual restart via Session.restart().
|
|
25
|
+
//
|
|
26
|
+
// Persistence
|
|
27
|
+
// -----------
|
|
28
|
+
// Only sessionNumber is persisted in SharedPreferences — an ordinal
|
|
29
|
+
// counter we want to survive process restarts ("this is the 42nd time
|
|
30
|
+
// the user opened the app"). The id itself is process-local; persisting
|
|
31
|
+
// it would defeat the "new session on cold start" semantic.
|
|
32
|
+
|
|
33
|
+
package com.appswissknife.context
|
|
34
|
+
|
|
35
|
+
import android.content.Context
|
|
36
|
+
import android.content.SharedPreferences
|
|
37
|
+
import com.appswissknife.net.IngestPlaceholderSession
|
|
38
|
+
import java.util.UUID
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Immutable session snapshot. Stamped onto every IngestItem at flush time.
|
|
42
|
+
*/
|
|
43
|
+
internal data class SessionSnapshot(
|
|
44
|
+
val id: String,
|
|
45
|
+
val startedAtMs: Long,
|
|
46
|
+
val sessionNumber: Int,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
internal data class SessionChange(val previous: SessionSnapshot, val current: SessionSnapshot)
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Global session manager. Production callers go through `Session.shared`;
|
|
53
|
+
* tests construct a private instance via `init(prefs, backgroundTimeoutMs)`
|
|
54
|
+
* to avoid stepping on the shared SharedPreferences.
|
|
55
|
+
*/
|
|
56
|
+
internal class Session(
|
|
57
|
+
private val prefs: SharedPreferences,
|
|
58
|
+
val backgroundTimeoutMs: Long = 5L * 60_000L,
|
|
59
|
+
private val clock: () -> Long = { System.currentTimeMillis() },
|
|
60
|
+
private val sessionIdFactory: () -> String = { IDs.sessionId() },
|
|
61
|
+
) {
|
|
62
|
+
|
|
63
|
+
companion object {
|
|
64
|
+
const val PREF_FILE = "swissknife_session_prefs"
|
|
65
|
+
const val KEY_COUNTER = "swissknife_session_number"
|
|
66
|
+
|
|
67
|
+
@Volatile
|
|
68
|
+
private var _shared: Session? = null
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Singleton — installed by SwissKnife.configure on first call. Tests
|
|
72
|
+
* should construct their own `Session` via the public ctor.
|
|
73
|
+
*/
|
|
74
|
+
fun shared(context: Context): Session {
|
|
75
|
+
_shared?.let { return it }
|
|
76
|
+
synchronized(this) {
|
|
77
|
+
_shared?.let { return it }
|
|
78
|
+
val ctx = context.applicationContext ?: context
|
|
79
|
+
val prefs = ctx.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE)
|
|
80
|
+
val s = Session(prefs)
|
|
81
|
+
_shared = s
|
|
82
|
+
return s
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
internal fun _resetSharedForTesting() {
|
|
87
|
+
synchronized(this) { _shared = null }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private val lock = Any()
|
|
92
|
+
private var snapshot: SessionSnapshot
|
|
93
|
+
private var backgroundedAtMs: Long? = null
|
|
94
|
+
private val observers = mutableMapOf<UUID, (SessionChange) -> Unit>()
|
|
95
|
+
private var lifecycleToken: UUID? = null
|
|
96
|
+
|
|
97
|
+
init {
|
|
98
|
+
val initial = prefs.getInt(KEY_COUNTER, 0) + 1
|
|
99
|
+
prefs.edit().putInt(KEY_COUNTER, initial).apply()
|
|
100
|
+
snapshot = SessionSnapshot(
|
|
101
|
+
id = sessionIdFactory(),
|
|
102
|
+
startedAtMs = clock(),
|
|
103
|
+
sessionNumber = initial,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
val current: SessionSnapshot
|
|
108
|
+
get() = synchronized(lock) { snapshot }
|
|
109
|
+
|
|
110
|
+
/** Force a new session right now (e.g. after an explicit logout). */
|
|
111
|
+
fun restart() {
|
|
112
|
+
rotate()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun addObserver(block: (SessionChange) -> Unit): UUID {
|
|
116
|
+
val token = UUID.randomUUID()
|
|
117
|
+
synchronized(lock) { observers[token] = block }
|
|
118
|
+
return token
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fun removeObserver(token: UUID) {
|
|
122
|
+
synchronized(lock) { observers.remove(token) }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Hook into AppLifecycle so background-timeout-based restarts happen
|
|
127
|
+
* automatically. Called once from SwissKnife.configure. Idempotent —
|
|
128
|
+
* calling twice replaces the previous subscription.
|
|
129
|
+
*/
|
|
130
|
+
fun startObservingLifecycle() {
|
|
131
|
+
lifecycleToken?.let { AppLifecycle.unsubscribe(it) }
|
|
132
|
+
lifecycleToken = AppLifecycle.subscribe { event -> handle(event) }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Install the IngestClient's session-snapshot supplier so flush-time
|
|
137
|
+
* stamps come from this manager.
|
|
138
|
+
*/
|
|
139
|
+
fun installAsIngestSupplier() {
|
|
140
|
+
IngestPlaceholderSession.supplier = {
|
|
141
|
+
val s = current
|
|
142
|
+
Pair(s.id, s.sessionNumber)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
internal fun handle(event: AppLifecycle.Event) {
|
|
147
|
+
when (event) {
|
|
148
|
+
AppLifecycle.Event.DidEnterBackground -> {
|
|
149
|
+
synchronized(lock) { backgroundedAtMs = clock() }
|
|
150
|
+
}
|
|
151
|
+
AppLifecycle.Event.WillEnterForeground -> {
|
|
152
|
+
val shouldRotate: Boolean = synchronized(lock) {
|
|
153
|
+
val bg = backgroundedAtMs ?: return@synchronized false
|
|
154
|
+
backgroundedAtMs = null
|
|
155
|
+
(clock() - bg) >= backgroundTimeoutMs
|
|
156
|
+
}
|
|
157
|
+
if (shouldRotate) rotate()
|
|
158
|
+
}
|
|
159
|
+
else -> Unit
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private fun rotate() {
|
|
164
|
+
val previous = current
|
|
165
|
+
val nextNumber = synchronized(lock) {
|
|
166
|
+
val n = prefs.getInt(KEY_COUNTER, 0) + 1
|
|
167
|
+
prefs.edit().putInt(KEY_COUNTER, n).apply()
|
|
168
|
+
n
|
|
169
|
+
}
|
|
170
|
+
val next = SessionSnapshot(
|
|
171
|
+
id = sessionIdFactory(),
|
|
172
|
+
startedAtMs = clock(),
|
|
173
|
+
sessionNumber = nextNumber,
|
|
174
|
+
)
|
|
175
|
+
val obsSnapshot: List<(SessionChange) -> Unit> = synchronized(lock) {
|
|
176
|
+
snapshot = next
|
|
177
|
+
observers.values.toList()
|
|
178
|
+
}
|
|
179
|
+
val change = SessionChange(previous, next)
|
|
180
|
+
for (obs in obsSnapshot) obs(change)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ----- Test seams -----
|
|
184
|
+
|
|
185
|
+
internal fun _setBackgroundedAtForTesting(ts: Long?) {
|
|
186
|
+
synchronized(lock) { backgroundedAtMs = ts }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
internal fun _handleEventForTesting(event: AppLifecycle.Event) {
|
|
190
|
+
handle(event)
|
|
191
|
+
}
|
|
192
|
+
}
|