Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sdk/src/main/java/io/radar/sdk/RadarApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ internal class RadarApiClient(
params.putOpt("locationMetadata", locationMetadata)
}
params.putOpt("pushNotificationToken", RadarSettings.pushNotificationToken)

// 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")
}
Comment on lines +460 to +465
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.

} catch (e: JSONException) {
callback?.onComplete(RadarStatus.ERROR_BAD_REQUEST)
Expand Down Expand Up @@ -514,6 +521,11 @@ internal class RadarApiClient(
RadarEvent.fromJson(eventsArr)
}
val user = res.optJSONObject("user")?.let { userObj ->
// Extract and store altitudeAdjustments from user object
val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments")
if (altitudeAdjustmentsObj != null) {
RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj)
}
Comment on lines +524 to +528
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.
RadarUser.fromJson(userObj)
}
val nearbyGeofences = res.optJSONArray("nearbyGeofences")?.let { nearbyGeofencesArr ->
Expand Down
20 changes: 20 additions & 0 deletions sdk/src/main/java/io/radar/sdk/RadarState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.content.edit
import io.radar.sdk.model.RadarBeacon
import org.json.JSONArray
import org.json.JSONObject

internal object RadarState {
Expand Down Expand Up @@ -40,6 +41,7 @@ internal object RadarState {
private const val KEY_LAST_BEACON_UIDS = "last_beacon_uids"
private const val KEY_LAST_MOTION_ACTIVITY = "last_motion_activity"
private const val KEY_LAST_PRESSURE = "last_pressure"
private const val KEY_ALTITUDE_ADJUSTMENTS = "altitude_adjustments"

private fun getSharedPreferences(context: Context): SharedPreferences {
return context.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE)
Expand Down Expand Up @@ -289,4 +291,22 @@ internal object RadarState {
putString(KEY_LAST_PRESSURE, jsonString)
}
}

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
}
}
}
Comment on lines +295 to +304
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.

internal fun setAltitudeAdjustments(context: Context, altitudeAdjustments: JSONArray?) {
val jsonString = altitudeAdjustments?.toString()
getSharedPreferences(context).edit {
putString(KEY_ALTITUDE_ADJUSTMENTS, jsonString)
}
}
}