Skip to content

Persist altitude adjustments clientside#488

Open
lmeier wants to merge 2 commits intomasterfrom
liammeier/fence-2560-pass-altitude-adjustment-diff-to-united-to-store-on
Open

Persist altitude adjustments clientside#488
lmeier wants to merge 2 commits intomasterfrom
liammeier/fence-2560-pass-altitude-adjustment-diff-to-united-to-store-on

Conversation

@lmeier
Copy link
Contributor

@lmeier lmeier commented Jan 26, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds client-side persistence for altitude adjustments received from the server. The feature stores altitude adjustments from track responses and includes them in subsequent track requests, enabling the server to maintain continuity of altitude data across multiple location updates.

Changes:

  • Added storage and retrieval methods for altitude adjustments in RadarState
  • Modified track request to include stored altitude adjustments
  • Modified track response handling to extract and persist altitude adjustments from the user object

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
sdk/src/main/java/io/radar/sdk/RadarState.kt Added getAltitudeAdjustments and setAltitudeAdjustments methods to persist altitude adjustments in SharedPreferences as JSON
sdk/src/main/java/io/radar/sdk/RadarApiClient.kt Added logic to include stored altitude adjustments in track requests and extract/store them from track responses

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +295 to +304
internal fun getAltitudeAdjustments(context: Context): JSONArray? {
val jsonString = getSharedPreferences(context).getString(KEY_ALTITUDE_ADJUSTMENTS, null)
return jsonString?.let {
try {
JSONArray(it)
} catch (e: Exception) {
null
}
}
}
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getAltitudeAdjustments method duplicates the logic from the existing stringToJsonObject helper function. For consistency with how getLastMotionActivity (line 271) and getLastPressure (line 283) are implemented, consider creating a similar helper function like stringToJsonArray and using it here.

Copilot uses AI. Check for mistakes.
Comment on lines +460 to +465
// Include stored altitudeAdjustments from previous track responses
val altitudeAdjustments = RadarState.getAltitudeAdjustments(context)
if (altitudeAdjustments != null && altitudeAdjustments.length() > 0) {
params.putOpt("altitudeAdjustments", altitudeAdjustments)
logger.d("Including ${altitudeAdjustments.length()} altitude adjustments in track request")
}
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new altitude adjustments persistence feature lacks test coverage. Given that the repository has comprehensive tests for similar persistence features (e.g., tags persistence in test_Radar_tags_persistence at line 516), consider adding tests to verify that altitude adjustments are correctly persisted to SharedPreferences and included in track requests. Tests should cover scenarios where altitude adjustments are retrieved from storage and included in requests, and where they are extracted from responses and stored.

Copilot uses AI. Check for mistakes.
Comment on lines +524 to +528
// Extract and store altitudeAdjustments from user object
val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments")
if (altitudeAdjustmentsObj != null) {
RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj)
}
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The altitude adjustments are only stored when present in the response, but never explicitly cleared when absent. This means once altitude adjustments are received, they will persist indefinitely until new ones are provided by the server. If the server's intent is to clear altitude adjustments by omitting the field or sending null/empty array, this logic won't handle that case. Consider also storing altitude adjustments when the field is explicitly null or an empty array to ensure they can be cleared when needed.

Suggested change
// Extract and store altitudeAdjustments from user object
val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments")
if (altitudeAdjustmentsObj != null) {
RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj)
}
// Extract and store altitudeAdjustments from user object.
// Always call setter so altitude adjustments can be cleared when absent or null.
val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments")
RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant