-
Notifications
You must be signed in to change notification settings - Fork 9
chore: update Location tracking module config #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Shahroz16
merged 12 commits into
feat/real-time-location
from
feat/location-tracking-mode
Mar 4, 2026
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d48f3e
chore: replace enableLocationTracking boolean with LocationTrackingMo…
Shahroz16 93e89ba
chore: remove cacheOnly concept, match iOS behavior for ON_APP_START
Shahroz16 e480d68
chore: split LocationTracker into enrichment and sync concerns, add N…
Shahroz16 aa00d9b
Revert "chore: split LocationTracker into enrichment and sync concern…
Shahroz16 fdc44df
ignore late reqs
Shahroz16 c7810af
cancel on background
Shahroz16 d265290
clear correct job
Shahroz16 d21a04a
fix main thread poster
Shahroz16 033b1f7
move init to start
Shahroz16 9437cde
fix edge case
Shahroz16 069d75d
memory leak fix
Shahroz16 8ffd5b6
memory leak
Shahroz16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
core/src/main/kotlin/io/customer/sdk/core/util/MainThreadPoster.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package io.customer.sdk.core.util | ||
|
|
||
| import android.os.Handler | ||
| import android.os.Looper | ||
| import io.customer.base.internal.InternalCustomerIOApi | ||
|
|
||
| /** | ||
| * Abstracts posting work to the main thread. | ||
| * Enables testability by allowing tests to mock or replace the implementation. | ||
| */ | ||
| @InternalCustomerIOApi | ||
| interface MainThreadPoster { | ||
| fun post(block: () -> Unit) | ||
| } | ||
|
|
||
| /** | ||
| * Default implementation using Android [Handler] with the main [Looper]. | ||
| */ | ||
| @InternalCustomerIOApi | ||
| class HandlerMainThreadPoster : MainThreadPoster { | ||
| private val handler = Handler(Looper.getMainLooper()) | ||
|
|
||
| override fun post(block: () -> Unit) { | ||
| handler.post(block) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
location/src/main/kotlin/io/customer/location/LocationLifecycleObserver.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package io.customer.location | ||
|
|
||
| import androidx.lifecycle.DefaultLifecycleObserver | ||
| import androidx.lifecycle.LifecycleOwner | ||
|
|
||
| /** | ||
| * Cancels in-flight location requests when the app enters background. | ||
| * | ||
| * Registered with [ProcessLifecycleOwner] during module initialization. | ||
| * [onStop] fires when the app transitions to background — any active | ||
| * GPS request is cancelled to avoid unnecessary work while backgrounded. | ||
| * | ||
| * No mutable state — thread safety is inherent. | ||
| */ | ||
| internal class LocationLifecycleObserver( | ||
| private val locationServices: LocationServicesImpl | ||
| ) : DefaultLifecycleObserver { | ||
|
|
||
| override fun onStop(owner: LifecycleOwner) { | ||
| locationServices.cancelInFlightRequest() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
location/src/main/kotlin/io/customer/location/LocationTrackingMode.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package io.customer.location | ||
|
|
||
| /** | ||
| * Defines the tracking mode for the location module. | ||
| */ | ||
| enum class LocationTrackingMode { | ||
| /** | ||
| * Location tracking is disabled. | ||
| * All location operations will no-op silently. | ||
| */ | ||
| OFF, | ||
|
|
||
| /** | ||
| * Host app controls when location is captured. | ||
| * Use [LocationServices.setLastKnownLocation] or [LocationServices.requestLocationUpdate] | ||
| * to manually trigger location capture. This is the default mode. | ||
| */ | ||
| MANUAL, | ||
|
|
||
| /** | ||
| * SDK automatically captures location on cold start. | ||
| * | ||
| * The captured location goes through the normal sync path | ||
| * (cache + 24h/1km filter + track event if filter passes). | ||
| * Manual location APIs remain fully functional. | ||
| */ | ||
| ON_APP_START | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why we removed that lock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock was originally added when we used
last-winsdedup (cancel old → start new). That pattern creates a concurrent jobs scenario where the lock was needed to atomically cancel-then-relaunch.We switched to first-wins dedup (if a request is in flight, ignore the new call) what iOS is doing. With first-wins, there's only ever one job at a time — no concurrent job scenario, so the lock's original purpose is gone.
The only theoretical race is two threads calling requestLocationUpdate() simultaneously when no job is active, both could launch a job. The consequence is one redundant GPS request