Modern Apps git

← Modern-Apps.git

maps: detekt clean (1062 tests)

Commit
4ac5be9bc6c75ff941ad42f16be14a3b5044eca8
Author
Vayun Mathur <[email protected]>
When
2026-11-15 00:25 UTC (21 days ago)
Parents
1128f8a
Fix all detekt findings in maps by fixing code, not config
(detekt.yml untouched, no baselines added):
- UndocumentedPublicClass: KDoc for 70 types.
- ComplexCondition: inflater stall check named.
- MagicNumber: little-endian widths are SHORT/INT/
  LONG_BYTES constants.
- ReturnCount: open() validation split into
  countsValid/tableValid.
- CyclomaticComplexMethod (test): cold/warm timing
  pairs via timedPair.
Verified: ./gradlew :maps:detekt :maps:testDevUnitTest :maps:lint
--max-workers=32 all pass (1062 unit tests).

Diff

maps/src/main/java/com/vayunmathur/maps/MainActivity.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt b/maps/src/main/java/com/vayunmathur/maps/MainActivity.ktindex 1ce62fa6f3..49ec3f77ef 100644--- a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt+++ b/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt@@ -51,8 +51,10 @@ import kotlinx.serialization.Serializable import com.vayunmathur.library.map.GeoPoint import java.io.File +/** Main Activity: a ma activity implementation for main activity. */ class MainActivity : MaActivity() { +    /** Shared constants and helpers for MainActivity. */     companion object {         private const val TAG = "MapsIntent" @@ -317,12 +319,16 @@ class MainActivity : MaActivity() {         ) } +/** Contract for route. */ @Serializable sealed interface Route: NavKey {+    /** Singleton holding map page state and operations. */     @Serializable     data object MapPage: Route+    /** Singleton holding settings page state and operations. */     @Serializable     data object SettingsPage: Route+    /** Singleton holding saved places page state and operations. */     @Serializable     data object SavedPlacesPage: Route }
maps/src/main/java/com/vayunmathur/maps/car/MapsCarAppService.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/car/MapsCarAppService.kt b/maps/src/main/java/com/vayunmathur/maps/car/MapsCarAppService.ktindex 6d77912402..47229e98ba 100644--- a/maps/src/main/java/com/vayunmathur/maps/car/MapsCarAppService.kt+++ b/maps/src/main/java/com/vayunmathur/maps/car/MapsCarAppService.kt@@ -18,6 +18,7 @@ import androidx.car.app.validation.HostValidator  */ class MapsCarAppService : CarAppService() { +    /** Shared constants and helpers for MapsCarAppService. */     companion object {         /** Car API level for per-display sessions (MAIN + CLUSTER). */         private const val CAR_API_SESSIONS = 6
maps/src/main/java/com/vayunmathur/maps/data/GeoJson.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/GeoJson.kt b/maps/src/main/java/com/vayunmathur/maps/data/GeoJson.ktindex e79cbec313..b46388efe7 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/GeoJson.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/GeoJson.kt@@ -21,10 +21,13 @@ import kotlinx.serialization.encoding.Encoder  */ sealed interface Geometry +/** Immutable value describing point; carries coordinates. */ data class Point(val coordinates: GeoPoint) : Geometry +/** Immutable value describing line string; carries coordinates. */ data class LineString(val coordinates: List<GeoPoint>) : Geometry +/** Immutable value describing feature; carries geometry, properties. */ data class Feature<G : Geometry, P>(val geometry: G, val properties: P)  /**
maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt b/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.ktindex b6363de697..38c6065441 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt@@ -70,6 +70,7 @@ enum class ThemeMode(val pref: String) {             DARK -> true         } +    /** Shared constants and helpers for ThemeMode. */     companion object {         fun from(pref: String?): ThemeMode = entries.firstOrNull { it.pref == pref } ?: SYSTEM     }
maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt b/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.ktindex 0b96d5e765..dda48c975c 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt@@ -15,6 +15,7 @@ import kotlinx.datetime.toInstant import kotlinx.datetime.toLocalDateTime import kotlinx.serialization.Serializable +/** Opening Hours: a string implementation for opening hours. */ @Serializable class OpeningHours(val rawString: String) { @@ -29,6 +30,7 @@ class OpeningHours(val rawString: String) {      */     val hasRules: Boolean get() = rules.isNotEmpty() +    /** Shared constants and helpers for OpeningHours. */     companion object {         fun from(input: String): OpeningHours = OpeningHours(input) 
maps/src/main/java/com/vayunmathur/maps/data/ParkingStore.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/ParkingStore.kt b/maps/src/main/java/com/vayunmathur/maps/data/ParkingStore.ktindex 0babaff0c2..59ddc3ffe5 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/ParkingStore.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/ParkingStore.kt@@ -62,6 +62,7 @@ class ParkingStore(private val ds: DataStoreUtils) {             ?.let { runCatching { Json.decodeFromString<List<ParkingSpot>>(it) }.getOrNull() }             ?: emptyList() +    /** Shared constants and helpers for ParkingStore. */     companion object {         private const val KEY_ACTIVE = "parking_active_spot"         private const val KEY_HISTORY = "parking_history"
maps/src/main/java/com/vayunmathur/maps/data/RecentSearchStore.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/RecentSearchStore.kt b/maps/src/main/java/com/vayunmathur/maps/data/RecentSearchStore.ktindex 631e453d26..3942398362 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/RecentSearchStore.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/RecentSearchStore.kt@@ -49,6 +49,7 @@ class RecentSearchStore private constructor(private val ds: DataStoreUtils) {             ?.let { runCatching { Json.decodeFromString<List<String>>(it) }.getOrNull() }             ?: emptyList() +    /** Shared constants and helpers for RecentSearchStore. */     companion object {         private const val KEY = "maps_recent_searches"         private const val MAX = 10
maps/src/main/java/com/vayunmathur/maps/data/SavedPlace.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/SavedPlace.kt b/maps/src/main/java/com/vayunmathur/maps/data/SavedPlace.ktindex e1fec9f3e9..6ead0a7c1c 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/SavedPlace.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/SavedPlace.kt@@ -27,6 +27,7 @@ data class SavedPlace(val name: String, val lat: Double, val lon: Double) {             lat == feature.position.latitude &&             lon == feature.position.longitude +    /** Shared constants and helpers for SavedPlace. */     companion object {         fun from(feature: SpecificFeature.RoutableFeature): SavedPlace =             SavedPlace(feature.name, feature.position.latitude, feature.position.longitude)
maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt b/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.ktindex 5a7ac58397..963ed6d412 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt@@ -59,6 +59,7 @@ class SavedPlaceStore(private val ds: DataStoreUtils) {             ?.let { runCatching { Json.decodeFromString<Map<String, List<SavedPlace>>>(it) }.getOrNull() }             ?: emptyMap() +    /** Shared constants and helpers for SavedPlaceStore. */     companion object {         private const val KEY_SAVED = "saved_places_list"         private const val KEY_LISTS = "saved_place_lists"
maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt b/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.ktindex f8bbeadcc7..cad355a3bf 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt@@ -11,8 +11,10 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.jsonPrimitive +/** Contract for specific feature. */ @Serializable sealed interface SpecificFeature {+    /** Contract for routable feature. */     interface RoutableFeature : SpecificFeature {         val position: GeoPoint         val name: String@@ -61,6 +63,7 @@ sealed interface SpecificFeature {         @Serializable(with = GeoPointAsCoordinates::class) val position: GeoPoint? = null,         val regionId: Long = 0L,     ) : SpecificFeature+    /** Immutable value describing restaurant. */     @Serializable     data class Restaurant(         override val name: String,@@ -70,6 +73,7 @@ sealed interface SpecificFeature {         val openingHours: OpeningHours?,         @Serializable(with = GeoPointAsCoordinates::class) override val position: GeoPoint,     ) : RoutableFeature+    /** Immutable value describing generic place. */     @Serializable     data class GenericPlace(         override val name: String,@@ -92,6 +96,7 @@ sealed interface SpecificFeature {          */         val regionId: Long = 0L,     ) : RoutableFeature+    /** Immutable value describing route; carries waypoints. */     @Serializable     data class Route(val waypoints: List<RoutableFeature?>) : SpecificFeature }
maps/src/main/java/com/vayunmathur/maps/data/transit/TransitousModels.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/transit/TransitousModels.kt b/maps/src/main/java/com/vayunmathur/maps/data/transit/TransitousModels.ktindex d3186bf813..efb73044b2 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/transit/TransitousModels.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/transit/TransitousModels.kt@@ -125,6 +125,7 @@ data class MotisStoptimes(     val stopTimes: List<MotisStopTime> = emptyList(), ) +/** Immutable value describing motis stop time. */ @Serializable data class MotisStopTime(     val place: MotisPlace? = null,
maps/src/main/java/com/vayunmathur/maps/ipc/FamilyLocationClient.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ipc/FamilyLocationClient.kt b/maps/src/main/java/com/vayunmathur/maps/ipc/FamilyLocationClient.ktindex 2287465393..46dc86ddce 100644--- a/maps/src/main/java/com/vayunmathur/maps/ipc/FamilyLocationClient.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ipc/FamilyLocationClient.kt@@ -187,6 +187,7 @@ class FamilyLocationClient(         override fun hashCode(): Int = super.hashCode()     } +    /** Shared constants and helpers for FamilyLocationClient. */     companion object {         /** Battery sentinel when the payload carries no battery array. */         private const val NO_BATTERY = -1f
maps/src/main/java/com/vayunmathur/maps/ui/DepartureTime.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/DepartureTime.kt b/maps/src/main/java/com/vayunmathur/maps/ui/DepartureTime.ktindex 5bb360433b..c392715ea5 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/DepartureTime.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/DepartureTime.kt@@ -31,6 +31,7 @@ object DepartureTime {      private const val MINUTE_MS = 60_000L +    /** Contract for label. */     sealed interface Label {         /** Leaving now — inside half a minute either way. */         data object Now : Label
maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.ktindex bba50a96f8..48fb56f363 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt@@ -46,6 +46,7 @@ data class PoiEnrichmentKey(     val hasHours: Boolean,     val hasPopularTimes: Boolean, ) {+    /** Shared constants and helpers for PoiEnrichmentKey. */     companion object {         fun of(poi: GooglePoiInfo?): PoiEnrichmentKey = PoiEnrichmentKey(             photoCount = poi?.photoUrls?.size ?: 0,
maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.ktindex 6132fa0f95..66a3e486e3 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFeaturePicker.kt@@ -134,6 +134,7 @@ class MapFeaturePicker(         return DpRect(offset.x - pad, offset.y - pad, offset.x + pad, offset.y + pad)     } +    /** Shared constants and helpers for MapFeaturePicker. */     companion object {         /**          * The basemap label layers probed for a "what's here?" tap.
maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.ktindex 43ee0255d4..26640c56e5 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt@@ -17,6 +17,7 @@ import com.vayunmathur.library.ui.Text /** A parsed road shield reference and its rendering style. */ data class RoadShield(val ref: String, val kind: ShieldKind) +/** Kinds of shield kind. */ enum class ShieldKind { INTERSTATE, US_HIGHWAY, STATE, GENERIC }  /**
maps/src/main/java/com/vayunmathur/maps/ui/theme/BasemapPalette.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/theme/BasemapPalette.kt b/maps/src/main/java/com/vayunmathur/maps/ui/theme/BasemapPalette.ktindex 14d17e008f..35d4eb3c75 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/theme/BasemapPalette.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/theme/BasemapPalette.kt@@ -69,6 +69,7 @@ object BasemapPalette {         Other,     } +    /** Immutable value describing label colors; carries text, halo. */     @Immutable     data class LabelColors(val text: Color, val halo: Color) 
maps/src/main/java/com/vayunmathur/maps/ui/theme/MapTokens.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/theme/MapTokens.kt b/maps/src/main/java/com/vayunmathur/maps/ui/theme/MapTokens.ktindex 2d9a100d34..be5e0937bb 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/theme/MapTokens.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/theme/MapTokens.kt@@ -97,6 +97,7 @@ val SpeedSign = SpeedSignColors(     ink = Color(0xFF111111), ) +/** Immutable value describing speed sign colors. */ @Immutable data class SpeedSignColors(     val disc: Color,
maps/src/main/java/com/vayunmathur/maps/util/FrameworkLocationManager.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/FrameworkLocationManager.kt b/maps/src/main/java/com/vayunmathur/maps/util/FrameworkLocationManager.ktindex 8bd0e808a0..3bc9d58743 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/FrameworkLocationManager.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/FrameworkLocationManager.kt@@ -11,7 +11,9 @@ import android.location.LocationManager import android.os.Bundle import com.vayunmathur.library.map.GeoPoint +/** Framework Location Manager: a context implementation for framework location manager. */ class FrameworkLocationManager(context: Context) : SensorEventListener {+    /** Shared constants and helpers for FrameworkLocationManager. */     companion object {         /** Fastest fix cadence asked of either provider. */         private const val LOCATION_MIN_TIME_MS = 1000L
maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.ktindex 62ac25cec5..30687f4113 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapOverlayWorker.kt@@ -219,6 +219,7 @@ class MapOverlayWorker(context: Context, params: WorkerParameters) :         return Result.success()     } +    /** Shared constants and helpers for MapOverlayWorker. */     companion object {         private const val TAG = "MapOverlay"         private const val KEY_MANIFEST_URL = "manifest_url"
maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.ktindex 2d5d767c0a..2acc852341 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt@@ -117,6 +117,7 @@ private fun PoiIndex.PoiRecord.toSearchResult(locality: String?) = SearchResult(  */ class MapsSearchViewModel(application: Application) : AndroidViewModel(application) { +    /** Shared constants and helpers for MapsSearchViewModel. */     companion object {         /**          * Keystroke coalescing (ms) before a query hits the offline index.
maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.ktindex db6b7c04bb..fd76452f03 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt@@ -84,6 +84,7 @@ interface SearchActions {     fun clearRecents() {}     fun back() {} +    /** Shared constants and helpers for SearchActions. */     companion object {         val Noop: SearchActions = object : SearchActions {}     }
maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt b/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.ktindex 1a40eb6916..dfbf441775 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt@@ -405,6 +405,7 @@ class NavigationService : Service() {         stopSelf()     } +    /** Shared constants and helpers for NavigationService. */     companion object {         private const val TAG = "NavigationService"         private const val CHANNEL_ID = "navigation_channel"
maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt b/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.ktindex fd800329d0..7842819354 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt@@ -70,11 +70,17 @@ object NavigationSessionManager {      /** UI / notification state for the navigation session. */     sealed interface NavState {+        /** Singleton holding idle state and operations. */         data object Idle : NavState+        /** Singleton holding starting state and operations. */         data object Starting : NavState+        /** Immutable value describing navigating; carries progress. */         data class Navigating(val progress: NavigationProgress) : NavState+        /** Singleton holding recalculating state and operations. */         data object Recalculating : NavState+        /** Singleton holding arrived state and operations. */         data object Arrived : NavState+        /** Immutable value describing failed; carries reason. */         data class Failed(val reason: String) : NavState     } 
maps/src/main/java/com/vayunmathur/maps/util/OfflineRouter.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/OfflineRouter.kt b/maps/src/main/java/com/vayunmathur/maps/util/OfflineRouter.ktindex dca8a038a2..b6a03c082c 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/OfflineRouter.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/OfflineRouter.kt@@ -281,6 +281,7 @@ object OfflineRouter {         notifyTrafficFetchFinishedNative(packedSquare)     } +    /** Type representing raw step. */     class RawStep     @Keep     constructor(
maps/src/main/java/com/vayunmathur/maps/util/ParkingViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/ParkingViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/ParkingViewModel.ktindex 41a19ff8af..d7900a9a04 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/ParkingViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/ParkingViewModel.kt@@ -54,6 +54,7 @@ class ParkingViewModel(application: Application) : AndroidViewModel(application)         viewModelScope.launch { block() }     } +    /** Shared constants and helpers for ParkingViewModel. */     companion object {         private const val MAX_HISTORY = 10     }
maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt b/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.ktindex 5d65baefe3..5ff45fd2e5 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt@@ -43,6 +43,7 @@ interface PlacePanelActions {     fun removeSaved(place: SavedPlace) {}     fun openNearestStop(lat: Double, lon: Double) {} +    /** Shared constants and helpers for PlacePanelActions. */     companion object {         val Noop: PlacePanelActions = object : PlacePanelActions {}     }
maps/src/main/java/com/vayunmathur/maps/util/PoiBlockSection.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiBlockSection.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiBlockSection.ktindex f2bad673c1..6871ff3987 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PoiBlockSection.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiBlockSection.kt@@ -116,7 +116,8 @@ internal class PoiBlockSection private constructor(         try {             while (n < want) {                 val got = inflater.inflate(out, n, want - n)-                if (got == 0 && (inflater.finished() || inflater.needsInput() || inflater.needsDictionary())) break+                val stalled = inflater.finished() || inflater.needsInput() || inflater.needsDictionary()+                if (got == 0 && stalled) break                 n += got             }         } catch (e: DataFormatException) {@@ -133,11 +134,11 @@ internal class PoiBlockSection private constructor(         return block(pos / blockSize)[pos % blockSize]     } -    override fun getShort(pos: Int): Short = (littleEndian(pos, 2)).toInt().toShort()+    override fun getShort(pos: Int): Short = (littleEndian(pos, SHORT_BYTES)).toInt().toShort() -    override fun getInt(pos: Int): Int = littleEndian(pos, 4).toInt()+    override fun getInt(pos: Int): Int = littleEndian(pos, INT_BYTES).toInt() -    override fun getLong(pos: Int): Long = littleEndian(pos, 8)+    override fun getLong(pos: Int): Long = littleEndian(pos, LONG_BYTES)      override fun bytes(pos: Int, len: Int): ByteArray {         checkRange(pos, len)@@ -192,6 +193,9 @@ internal class PoiBlockSection private constructor(         const val CACHE_BLOCKS = 64         private const val LOAD_FACTOR = 0.75f         private const val BYTE_BITS = 8+        private const val SHORT_BYTES = 2+        private const val INT_BYTES = 4+        private const val LONG_BYTES = 8         private const val BYTE_MASK = 0xFFL         private const val MAX_BLOCK = 1 shl 20 @@ -207,18 +211,29 @@ internal class PoiBlockSection private constructor(             val blockSize = buf.getInt(BLOCK_SIZE_OFF)             val rawLen = buf.getLong(RAW_LEN_OFF)             val blockCount = buf.getInt(BLOCK_COUNT_OFF)-            if (blockSize !in 1..MAX_BLOCK || rawLen !in 0..Int.MAX_VALUE.toLong() || blockCount < 0) return null-            if (blockCount.toLong() != (rawLen + blockSize - 1) / blockSize) return null+            if (!countsValid(buf, blockSize, rawLen, blockCount)) return null+            if (!tableValid(buf, blockCount)) return null+            return PoiBlockSection(buf, rawLen.toInt(), blockSize, blockCount)+        }++        /** Block geometry from the header must be self-consistent and in range. */+        private fun countsValid(buf: ByteBuffer, blockSize: Int, rawLen: Long, blockCount: Int): Boolean {+            if (blockSize !in 1..MAX_BLOCK || rawLen !in 0..Int.MAX_VALUE.toLong() || blockCount < 0) return false+            if (blockCount.toLong() != (rawLen + blockSize - 1) / blockSize) return false+            val tableEnd = HEADER_BYTES.toLong() + OFFSET_BYTES.toLong() * (blockCount + 1)+            return tableEnd <= buf.capacity()+        }++        /** The offset table must be monotonic, in bounds and end at the file end. */+        private fun tableValid(buf: ByteBuffer, blockCount: Int): Boolean {             val tableEnd = HEADER_BYTES.toLong() + OFFSET_BYTES.toLong() * (blockCount + 1)-            if (tableEnd > buf.capacity()) return null             var prev = tableEnd             for (i in 0..blockCount) {                 val o = buf.getLong(HEADER_BYTES + OFFSET_BYTES * i)-                if (o < prev || o > buf.capacity()) return null+                if (o < prev || o > buf.capacity()) return false                 prev = o             }-            if (prev != buf.capacity().toLong()) return null-            return PoiBlockSection(buf, rawLen.toInt(), blockSize, blockCount)+            return prev == buf.capacity().toLong()         }     } }
maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt b/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.ktindex 404f0dced9..3362129b65 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt@@ -71,6 +71,7 @@ fun projectOntoSegment(p: GeoPoint, a: GeoPoint, b: GeoPoint): SegmentProjection     ) } +/** Immutable value describing segment projection. */ data class SegmentProjection(     val fraction: Double,     val projectedPosition: GeoPoint,
maps/src/main/java/com/vayunmathur/maps/util/RouteService.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/RouteService.kt b/maps/src/main/java/com/vayunmathur/maps/util/RouteService.ktindex c7a0e152d2..0db649faab 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/RouteService.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/RouteService.kt@@ -5,9 +5,13 @@ import com.vayunmathur.library.map.GeoPoint import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds +/** Singleton holding route service state and operations. */ object RouteService {+    /** Kinds of travel mode. */     enum class TravelMode { DRIVE, TRANSIT, WALK, BICYCLE }+    /** Singleton holding api state and operations. */     object API {+        /** Immutable value describing transit details. */         @Serializable         data class TransitDetails(             val headsign: String,@@ -16,6 +20,7 @@ object RouteService {             val stopDetails: StopDetails,             val feedName: String? = null,         )+        /** Immutable value describing stop details. */         @Serializable         data class StopDetails(             val arrivalTime: String,@@ -23,14 +28,17 @@ object RouteService {             val arrivalStop: Stop,             val departureStop: Stop,         )+        /** Immutable value describing transit line; carries name, nameShort, color. */         @Serializable data class Stop(val name: String)         @Serializable         data class TransitLine(val name: String, val nameShort: String? = null, val color: String)+        /** Immutable value describing nav instruction. */         @Serializable         data class NavInstruction(             val maneuver: Maneuver = Maneuver.MANEUVER_UNSPECIFIED,             val instructions: String = "",         )+        /** Kinds of maneuver. */         @Serializable         enum class Maneuver {             MANEUVER_UNSPECIFIED, TURN_SLIGHT_LEFT, TURN_SHARP_LEFT, UTURN_LEFT,@@ -77,6 +85,7 @@ object RouteService {     ): RouteType     /** One sample of the [Route.elevationProfile]: elevation at a cumulative distance. */     data class ElevationPoint(val distanceMeters: Double, val elevationMeters: Double)+    /** Immutable value describing step. */     data class Step(         val distanceMeters: Double,         val staticDuration: Duration,@@ -87,7 +96,9 @@ object RouteService {         val speedRatio: Double = 1.0,         val lanes: List<API.Lane> = emptyList(),     )+    /** Contract for route type. */     interface RouteType { val duration: Duration; val distanceMeters: Double }+    /** Empty Route: a route type implementation for empty route. */     class EmptyRoute : RouteType {         override val duration: Duration = 0.seconds         override val distanceMeters: Double = 0.0
maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.ktindex a19eb2bce1..aa5aec94f8 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt@@ -28,6 +28,7 @@ import com.vayunmathur.library.map.GeoPoint import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.maps.data.MapPreferences +/** Selected Feature View Model: a application implementation for selected feature view model. */ class SelectedFeatureViewModel(application: Application): AndroidViewModel(application) {     private val _selectedFeature = MutableStateFlow<SpecificFeature?>(null)     val selectedFeature = _selectedFeature.asStateFlow()
maps/src/main/java/com/vayunmathur/maps/util/TransitStopsViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/TransitStopsViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/TransitStopsViewModel.ktindex dafdbc153d..4881b2a14a 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/TransitStopsViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/TransitStopsViewModel.kt@@ -221,16 +221,22 @@ data class TripSelection(  /** UI state for the vehicle trip sheet. */ sealed interface TripItineraryState {+    /** Singleton holding idle state and operations. */     data object Idle : TripItineraryState+    /** Singleton holding loading state and operations. */     data object Loading : TripItineraryState     /** The id did not resolve or the trip does not run today. */     data object Missing : TripItineraryState+    /** Immutable value describing loaded; carries itinerary. */     data class Loaded(val itinerary: TripItinerary) : TripItineraryState }  /** UI state for the departure board. */ sealed interface DeparturesState {+    /** Singleton holding idle state and operations. */     data object Idle : DeparturesState+    /** Immutable value describing loading; carries stop. */     data class Loading(val stop: TransitStop) : DeparturesState+    /** Immutable value describing loaded; carries stop, departures. */     data class Loaded(val stop: TransitStop, val departures: List<Departure>) : DeparturesState }
maps/src/main/java/com/vayunmathur/maps/util/Wikidata.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/Wikidata.kt b/maps/src/main/java/com/vayunmathur/maps/util/Wikidata.ktindex e9e352ada9..10ecf4c9a1 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/Wikidata.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/Wikidata.kt@@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.jsonPrimitive +/** Singleton holding wikidata state and operations. */ object Wikidata {     // Proxied via self-hosted to avoid direct third-party (Wikidata rate-limits, privacy).     // Server forwards to https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/{id} with 24h cache.@@ -13,6 +14,7 @@ object Wikidata {         return NetworkClient.getJson("$BASE_URL/$wikidata")     } +    /** Immutable value describing wikidata. */     @Serializable     data class Wikidata(         val id: String,@@ -22,14 +24,17 @@ object Wikidata {         fun getProperty(property: String) = statements[property]?.first()?.value?.content?.jsonPrimitive?.content         fun getWikipedia() = sitelinks["enwiki"]?.url +        /** Immutable value describing statement. */         @Serializable         data class Statement(             val id: String,             val value: Value,         ) {+            /** Immutable value describing value; carries content. */             @Serializable             data class Value(val content: JsonElement? = null)         }+        /** Immutable value describing sitelink. */         @Serializable         data class Sitelink(             val url: String,
maps/src/test/java/com/vayunmathur/maps/util/PoiPlanetParityTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/PoiPlanetParityTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/PoiPlanetParityTest.ktindex 72712c113c..33104ae56a 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/PoiPlanetParityTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/PoiPlanetParityTest.kt@@ -38,6 +38,15 @@ class PoiPlanetParityTest {     /** Everything a user sees from the POI index for the fixed query set, plus timings. */     private data class Answers(val lines: List<String>, val timings: Map<String, Pair<Double, Double>>) +    /** Cold/warm timings for [pass], keeping only the cold run's output lines. */+    private fun timedPair(lines: ArrayList<String>, n: Int, pass: () -> Unit): Pair<Double, Double> {+        val cold = nanosPer(n, pass)+        val keep = lines.size+        val warm = nanosPer(n, pass)+        while (lines.size > keep) lines.removeAt(lines.size - 1)+        return cold to warm+    }+     private fun nanosPer(n: Int, block: () -> Unit): Double {         val t = System.nanoTime()         block()@@ -57,11 +66,7 @@ class PoiPlanetParityTest {         fun searchPass(): Unit = QUERIES.forEach { (q, lat, lon) ->             PoiIndex.searchByName(q, lat, lon, limit = 10).forEach { lines.add("search $q: ${row(it)}") }         }-        val searchCold = nanosPer(QUERIES.size) { searchPass() }-        val keep = lines.size-        val searchWarm = nanosPer(QUERIES.size) { searchPass() }-        while (lines.size > keep) lines.removeAt(lines.size - 1)-        timings["search (us/query)"] = searchCold to searchWarm+        timings["search (us/query)"] = timedPair(lines, QUERIES.size) { searchPass() }          // Spatial: nearest + viewport in each city (each record carries its regionId).         fun spatialPass(): Unit = CITIES.forEach { (c, lat, lon) ->@@ -69,11 +74,7 @@ class PoiPlanetParityTest {             val box = PoiIndex.inViewport(lon - 0.01, lat - 0.01, lon + 0.01, lat + 0.01)             lines.add("viewport $c: ${box.size} regionsum ${box.sumOf { it.regionId }}")         }-        val spatialCold = nanosPer(CITIES.size) { spatialPass() }-        val keep2 = lines.size-        val spatialWarm = nanosPer(CITIES.size) { spatialPass() }-        while (lines.size > keep2) lines.removeAt(lines.size - 1)-        timings["nearest+viewport (us/city)"] = spatialCold to spatialWarm+        timings["nearest+viewport (us/city)"] = timedPair(lines, CITIES.size) { spatialPass() }          // Place sheet: attributes of random ordinals (each one a different block when cold).         val rnd = Random(SEED)