-
Notifications
You must be signed in to change notification settings - Fork 9
chore: add SDK-managed one-shot location (requestLocationUpdateOnce) #657
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <!-- Coarse location is sufficient for city/timezone level tracking --> | ||
| <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
|
|
||
| </manifest> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package io.customer.location | ||
|
|
||
| import io.customer.location.provider.LocationProvider | ||
| import io.customer.location.provider.LocationRequestException | ||
| import io.customer.location.type.LocationGranularity | ||
| import io.customer.sdk.communication.Event | ||
| import io.customer.sdk.communication.EventBus | ||
| import io.customer.sdk.core.util.Logger | ||
| import kotlinx.coroutines.CancellationException | ||
|
|
||
| /** | ||
| * Coordinates location requests: one-shot only. | ||
| * Uses an injected [LocationProvider] for platform location access. | ||
| */ | ||
| internal class LocationOrchestrator( | ||
| private val config: LocationModuleConfig, | ||
| private val logger: Logger, | ||
| private val eventBus: EventBus, | ||
| private val locationProvider: LocationProvider | ||
| ) { | ||
|
|
||
| suspend fun requestLocationUpdate() { | ||
| if (!config.enableLocationTracking) { | ||
| logger.debug("Location tracking is disabled, ignoring requestLocationUpdate.") | ||
| return | ||
| } | ||
|
|
||
| val authStatus = locationProvider.currentAuthorizationStatus() | ||
| if (!authStatus.isAuthorized) { | ||
| logger.debug("Location permission not granted ($authStatus), ignoring request.") | ||
| return | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant authorization check in orchestrator and providerLow Severity
Additional Locations (1) |
||
|
|
||
| try { | ||
| val snapshot = locationProvider.requestLocation( | ||
| granularity = LocationGranularity.DEFAULT | ||
| ) | ||
| postLocation(snapshot.latitude, snapshot.longitude) | ||
| } catch (e: CancellationException) { | ||
| logger.debug("Location request was cancelled.") | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw e | ||
| } catch (e: LocationRequestException) { | ||
| logger.debug("Location request failed: ${e.error}") | ||
| } catch (e: Exception) { | ||
| logger.error("Location request failed with unexpected error: ${e.message}") | ||
| } | ||
| } | ||
|
|
||
| private fun postLocation(latitude: Double, longitude: Double) { | ||
| logger.debug("Tracking location: lat=$latitude, lng=$longitude") | ||
| val locationData = Event.LocationData( | ||
| latitude = latitude, | ||
| longitude = longitude | ||
| ) | ||
| eventBus.publish(Event.TrackLocationEvent(location = locationData)) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||


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.
Will this have any impact on customers' apps? Or was this added because only customers who want to use the location feature will include this module and should already be fine with the permission?
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.
it will only be added for the users who adds the module