Skip to content

Commit 93e89ba

Browse files
Shahroz16claude
andcommitted
chore: remove cacheOnly concept, match iOS behavior for ON_APP_START
ON_APP_START auto-captured location now goes through the normal path (cache + sync filter + track event if filter passes) instead of skipping the track event. This aligns with iOS SDK behavior where all location updates are treated uniformly regardless of source. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8d48f3e commit 93e89ba

File tree

5 files changed

+12
-57
lines changed

5 files changed

+12
-57
lines changed

location/src/main/kotlin/io/customer/location/LocationOrchestrator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class LocationOrchestrator(
1717
private val locationProvider: LocationProvider
1818
) {
1919

20-
suspend fun requestLocationUpdate(cacheOnly: Boolean = false) {
20+
suspend fun requestLocationUpdate() {
2121
if (!config.isEnabled) {
2222
logger.debug("Location tracking is disabled, ignoring requestLocationUpdate.")
2323
return
@@ -34,7 +34,7 @@ internal class LocationOrchestrator(
3434
granularity = LocationGranularity.DEFAULT
3535
)
3636
logger.debug("Tracking location: lat=${snapshot.latitude}, lng=${snapshot.longitude}")
37-
locationTracker.onLocationReceived(snapshot.latitude, snapshot.longitude, cacheOnly)
37+
locationTracker.onLocationReceived(snapshot.latitude, snapshot.longitude)
3838
} catch (e: CancellationException) {
3939
logger.debug("Location request was cancelled.")
4040
throw e

location/src/main/kotlin/io/customer/location/LocationTracker.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,16 @@ internal class LocationTracker(
7474
}
7575

7676
/**
77-
* Processes an incoming location: caches in memory, persists coordinates,
78-
* and optionally attempts to send a location track event.
79-
*
80-
* @param cacheOnly when true, updates the in-memory cache and persists
81-
* coordinates but does NOT send a "Location Update" track event.
82-
* Used by ON_APP_START auto-requests to refresh cached location for
83-
* identify context enrichment without generating a discrete event.
77+
* Processes an incoming location: caches in memory, persists
78+
* coordinates, and attempts to send a location track event.
8479
*/
85-
fun onLocationReceived(latitude: Double, longitude: Double, cacheOnly: Boolean = false) {
86-
logger.debug("Location update received: lat=$latitude, lng=$longitude, cacheOnly=$cacheOnly")
80+
fun onLocationReceived(latitude: Double, longitude: Double) {
81+
logger.debug("Location update received: lat=$latitude, lng=$longitude")
8782

8883
lastLocation = LocationCoordinates(latitude = latitude, longitude = longitude)
8984
locationPreferenceStore.saveCachedLocation(latitude, longitude)
9085

91-
if (!cacheOnly) {
92-
trySendLocationTrack(latitude, longitude)
93-
}
86+
trySendLocationTrack(latitude, longitude)
9487
}
9588

9689
/**

location/src/main/kotlin/io/customer/location/ModuleLocation.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ class ModuleLocation @JvmOverloads constructor(
117117
}
118118

119119
// ON_APP_START: auto-capture location on cold start.
120-
// Fire-and-forget — refreshes cached location so subsequent identify() calls
121-
// carry fresh data. If permissions are denied or services disabled, orchestrator
122-
// silently no-ops.
120+
// Fire-and-forget — captures location and sends through the normal path
121+
// (cache + sync filter + track event if filter passes).
122+
// If permissions are denied or services disabled, orchestrator silently no-ops.
123123
if (moduleConfig.trackingMode == LocationTrackingMode.ON_APP_START) {
124124
locationScope.launch {
125-
orchestrator.requestLocationUpdate(cacheOnly = true)
125+
orchestrator.requestLocationUpdate()
126126
}
127127
}
128128
}

location/src/test/java/io/customer/location/LocationServicesImplTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LocationServicesImplTest {
2727
val services = LocationServicesImpl(config, logger, tracker, orchestrator, scope)
2828
services.setLastKnownLocation(37.7749, -122.4194)
2929

30-
verify(exactly = 0) { tracker.onLocationReceived(any(), any(), any()) }
30+
verify(exactly = 0) { tracker.onLocationReceived(any(), any()) }
3131
}
3232

3333
@Test

location/src/test/java/io/customer/location/LocationTrackerTest.kt

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -214,44 +214,6 @@ class LocationTrackerTest {
214214
verify(exactly = 0) { dataPipeline.track(any(), any()) }
215215
}
216216

217-
// -- onLocationReceived with cacheOnly --
218-
219-
@Test
220-
fun givenCacheOnly_expectPersistsToStore() {
221-
tracker.onLocationReceived(37.7749, -122.4194, cacheOnly = true)
222-
223-
verify { store.saveCachedLocation(37.7749, -122.4194) }
224-
}
225-
226-
@Test
227-
fun givenCacheOnly_expectUpdatesIdentifyContext() {
228-
tracker.onLocationReceived(37.7749, -122.4194, cacheOnly = true)
229-
230-
val context = tracker.getIdentifyContext()
231-
context.shouldNotBeEmpty()
232-
context["location_latitude"] shouldBeEqualTo 37.7749
233-
context["location_longitude"] shouldBeEqualTo -122.4194
234-
}
235-
236-
@Test
237-
fun givenCacheOnly_expectTrackNotCalled() {
238-
tracker.onLocationReceived(37.7749, -122.4194, cacheOnly = true)
239-
240-
verify(exactly = 0) { dataPipeline.track(any(), any()) }
241-
}
242-
243-
@Test
244-
fun givenCacheOnlyFalse_expectTrackCalled() {
245-
tracker.onLocationReceived(37.7749, -122.4194, cacheOnly = false)
246-
247-
verify {
248-
dataPipeline.track(
249-
name = EventNames.LOCATION_UPDATE,
250-
properties = mapOf("latitude" to 37.7749, "longitude" to -122.4194)
251-
)
252-
}
253-
}
254-
255217
// -- resetContext (synchronous, called by analytics.reset during clearIdentify) --
256218

257219
@Test

0 commit comments

Comments
 (0)