fix(android): review findings on the tile store, widgets, location, billing and the share sheet

- Tile store: the WebView's headers go along (a URL-restricted Mapbox token
  is checked against the Referer), and anything but a tile is left to the
  WebView, so a 401/403 never comes from the store.
- Widgets read their snapshot inside the composition, so every write reaches
  a running Glance session; the trip picker updates only the widget the id
  belongs to.
- Location: Approximate counts as allowed; the stream pauses with the app,
  resumes with it, and stops when the page reloads or the activity goes.
- Billing: an already-owned subscription comes back as the purchase, so the
  shell redeems it; a payment that clears outside the sheet is announced
  (storeTransaction) and found again at start (storeUnfinished).
- getWindowLayout answers with the last posture and hinge, not the bare window.
- Share sheet: keeps the picked trip through rotation and folding, and takes
  content:// only, never a file:// path read with TREK's own rights.
This commit is contained in:
Maurice
2026-11-07 14:57:50 +01:00
parent 46f4cab1b7
commit ec22642f38
14 changed files with 241 additions and 31 deletions
@@ -8,6 +8,7 @@ import com.liketrek.trek.screen.TrekWindowLayout
import com.liketrek.trek.share.ShareHandoff
import com.liketrek.trek.share.ShareItem
import com.liketrek.trek.share.ShareLoader
import com.liketrek.trek.tiles.TrekTileStore
import java.time.LocalDate
import org.json.JSONArray
import org.json.JSONObject
@@ -115,4 +116,46 @@ class NativeLogicTest {
assertEquals("token-cloud.plus.yearly-2000", found?.purchaseToken)
assertNull(TrekBilling.newest(emptyList(), "cloud."))
}
@Test
fun mapboxRequestsKeepTheWebViewsHeaders() {
val forwarded = TrekTileStore.forwardedHeaders(
mapOf(
"Referer" to "https://trek.example.com/",
"Origin" to "https://trek.example.com",
"User-Agent" to "Mozilla/5.0 (Linux; Android 16; wv)",
"Accept" to "application/x-protobuf",
"Accept-Encoding" to "gzip",
"Connection" to "keep-alive",
"Host" to "api.mapbox.com",
),
)
// A URL-restricted token is checked against the Referer, so it has to go along.
assertEquals("https://trek.example.com/", forwarded["Referer"])
assertEquals("https://trek.example.com", forwarded["Origin"])
assertEquals("Mozilla/5.0 (Linux; Android 16; wv)", forwarded["User-Agent"])
assertEquals("application/x-protobuf", forwarded["Accept"])
assertNull(forwarded["Accept-Encoding"])
assertNull(forwarded["Connection"])
assertNull(forwarded["Host"])
assertEquals(emptyMap<String, String>(), TrekTileStore.forwardedHeaders(null))
}
@Test
fun aPaymentThatClearedLaterIsTheUndeliveredOne() {
fun purchase(product: String, time: Long, acknowledged: Boolean) = Purchase(
JSONObject()
.put("productIds", JSONArray().put(product))
.put("purchaseTime", time)
.put("purchaseState", 0)
.put("acknowledged", acknowledged)
.put("purchaseToken", "token-$time")
.toString(),
"sig",
)
val renewed = purchase("cloud.plus.yearly", 3000, acknowledged = true)
val cleared = purchase("cloud.start.monthly", 2000, acknowledged = false)
assertEquals("token-2000", TrekBilling.undelivered(listOf(renewed, cleared), "cloud.")?.purchaseToken)
assertNull(TrekBilling.undelivered(listOf(renewed), "cloud."))
}
}