@@ -2,7 +2,6 @@ package io.customer.location
22
33import androidx.lifecycle.DefaultLifecycleObserver
44import androidx.lifecycle.LifecycleOwner
5- import java.lang.ref.WeakReference
65
76/* *
87 * Manages location lifecycle tied to app foreground/background transitions.
@@ -12,33 +11,25 @@ import java.lang.ref.WeakReference
1211 * when [trackingMode] is [LocationTrackingMode.ON_APP_START].
1312 * - [onStop]: cancels any in-flight GPS request when the app enters background.
1413 *
15- * Uses a [WeakReference] to [LocationServicesImpl] so that [ProcessLifecycleOwner]
16- * (which lives for the entire process) does not prevent SDK cleanup. When the SDK
17- * is reset via [CustomerIO.clearInstance], the services become eligible for GC,
18- * the weak reference clears, and this observer becomes a no-op.
19- *
2014 * Thread safety: all lifecycle callbacks are delivered on the main thread
2115 * by [ProcessLifecycleOwner], so no synchronization is needed.
2216 */
2317internal class LocationLifecycleObserver (
24- locationServices : LocationServicesImpl ,
18+ private val locationServices : LocationServicesImpl ,
2519 private val trackingMode : LocationTrackingMode
2620) : DefaultLifecycleObserver {
2721
28- private val servicesRef = WeakReference (locationServices)
2922 private var hasRequestedOnStart = false
3023
3124 override fun onStart (owner : LifecycleOwner ) {
32- val services = servicesRef.get() ? : return
3325 if (trackingMode == LocationTrackingMode .ON_APP_START && ! hasRequestedOnStart) {
3426 hasRequestedOnStart = true
35- services .requestLocationUpdate()
27+ locationServices .requestLocationUpdate()
3628 }
3729 }
3830
3931 override fun onStop (owner : LifecycleOwner ) {
40- val services = servicesRef.get() ? : return
41- val wasCancelled = services.cancelInFlightRequest()
32+ val wasCancelled = locationServices.cancelInFlightRequest()
4233 // If the GPS request was still in flight when we backgrounded,
4334 // allow onStart to retry on the next foreground entry.
4435 if (wasCancelled) {
0 commit comments