From 4dec67e791943dd37f36668f218ba2d4edfda6da Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Sat, 14 Nov 2026 00:03:24 +0100 Subject: [PATCH 1/2] Migrate samples to updated downloader and routing APIs - Consume combined map and terrain progress with zero-total handling - Use public download controls and identify routing lifecycle callers - Remove the unnecessary planning presentation override - Pin integration checks and guide links to the adopted SDK revision Signed-off-by: Alexander Borsuk --- .github/workflows/android-check.yaml | 2 +- README.md | 6 ++--- .../organicmaps/example/OfflineSearchTest.kt | 26 ++++++++++++++++++- .../example/OfflineSearchActivity.kt | 10 ++++--- .../organicmaps/example/RoutingActivity.kt | 13 +++------- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/.github/workflows/android-check.yaml b/.github/workflows/android-check.yaml index eecc444..10d8ed1 100644 --- a/.github/workflows/android-check.yaml +++ b/.github/workflows/android-check.yaml @@ -14,7 +14,7 @@ on: env: # Baseline for source integration checks; release checks use sdk_version. - SDK_REF: 49a72dc936db4e27b65673100680677680c736ee + SDK_REF: e757eeaca3664767dceec1bf33214e04023a2342 SAMPLES_SDK_VERSION: ${{ inputs.sdk_version || '0.0.0-sdk-check' }} SAMPLES_SDK_REPOSITORY: ${{ inputs.sdk_version && 'https://repo.maven.apache.org/maven2' || format('{0}/engine/android/build/sdk-check/repository', github.workspace) }} diff --git a/README.md b/README.md index c69fdd5..62c6c39 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Downloads continue independently of the screen and offer cancellation and retry. The SDK is a side product of the main Organic Maps application. Its application and SDK implementation are the source of truth; API stability is not guaranteed. These examples must adapt when SDK changes break integration. See the -[SDK integration guide](https://github.com/organicmaps/organicmaps/blob/49a72dc936db4e27b65673100680677680c736ee/android/sdk/README.md) +[SDK integration guide](https://github.com/organicmaps/organicmaps/blob/e757eeaca3664767dceec1bf33214e04023a2342/android/sdk/README.md) for initialization, lifecycle, permissions, packaging, and API contracts. ## Build and run @@ -27,11 +27,11 @@ For development with SDK source, publish its artifacts locally. The merged revis below provides `publishSdkForChecks`, documented in [organicmaps/organicmaps#14025](https://github.com/organicmaps/organicmaps/pull/14025). Building that checkout requires the upstream -[native build environment](https://github.com/organicmaps/organicmaps/blob/49a72dc936db4e27b65673100680677680c736ee/docs/INSTALL.md). +[native build environment](https://github.com/organicmaps/organicmaps/blob/e757eeaca3664767dceec1bf33214e04023a2342/docs/INSTALL.md). With an Organic Maps checkout in the sibling `organicmaps` directory: ```sh -git -C ../organicmaps fetch origin 49a72dc936db4e27b65673100680677680c736ee +git -C ../organicmaps fetch origin e757eeaca3664767dceec1bf33214e04023a2342 git -C ../organicmaps checkout --detach FETCH_HEAD git -C ../organicmaps submodule update --init --recursive --depth 1 (cd ../organicmaps/android && ./gradlew -Parm64 -PsdkVersion=0.0.0-sdk-check publishSdkForChecks) diff --git a/app/src/androidTestOffline/java/app/organicmaps/example/OfflineSearchTest.kt b/app/src/androidTestOffline/java/app/organicmaps/example/OfflineSearchTest.kt index 2cd55e9..5cb21ef 100644 --- a/app/src/androidTestOffline/java/app/organicmaps/example/OfflineSearchTest.kt +++ b/app/src/androidTestOffline/java/app/organicmaps/example/OfflineSearchTest.kt @@ -21,6 +21,7 @@ import app.organicmaps.sdk.search.SearchResult import java.util.Locale import org.junit.After import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith @@ -152,6 +153,26 @@ class OfflineSearchTest : } } + @Test + fun selectedDownloadCanBeCancelled() { + launchOffline().use { scenario -> + findRegions(scenario, "Andorra") + scenario.await { regionsComplete && regionResults.isNotEmpty() } + scenario.onActivity { + it.findViewById(R.id.search_results).performItemClick(null, 0, 0) + // One UI turn prevents completion from racing the cancellation check. + it.click(R.string.download_region) + try { + assertTrue(MapManager.isDownloading()) + it.click(R.string.cancel_download) + assertFalse(MapManager.isDownloading()) + } finally { + MapManager.cancel("Andorra") + } + } + } + } + @Test fun downloadEventsPreserveSearchFeedback() { launchOffline().use { scenario -> @@ -165,7 +186,10 @@ class OfflineSearchTest : val search = activity.findViewById(R.id.search_status) val region = activity.findViewById(R.id.region_status) val searchFeedback = search.text.toString() - activity.onProgress("Andorra", 50, 100) + // Different map and terrain fractions distinguish combined progress from either stream alone. + activity.onProgress("Andorra", MapManager.Progress(25, 100, 75, 100)) + assertEquals(activity.getString(R.string.download_progress, 50), region.text.toString()) + activity.onProgress("Andorra", MapManager.Progress(0, 0, 0, 0)) assertEquals(activity.getString(R.string.download_progress, 50), region.text.toString()) activity.onStatusChanged( listOf(MapManager.StorageCallbackData("Germany", CountryItem.STATUS_DONE, 0, false)), diff --git a/app/src/main/java/app/organicmaps/example/OfflineSearchActivity.kt b/app/src/main/java/app/organicmaps/example/OfflineSearchActivity.kt index d5b663c..1e4021d 100644 --- a/app/src/main/java/app/organicmaps/example/OfflineSearchActivity.kt +++ b/app/src/main/java/app/organicmaps/example/OfflineSearchActivity.kt @@ -61,7 +61,7 @@ class OfflineSearchActivity : val downloads = LinearLayout(this) panel.addView(downloads) downloads.button(R.string.download_region) { selectedRegion?.let(::download) } - downloads.button(R.string.cancel_download) { selectedRegion?.let(MapManager::nativeCancel) } + downloads.button(R.string.cancel_download) { selectedRegion?.let(MapManager::cancel) } downloads.button(R.string.retry_download) { selectedRegion?.let(::download) } regionStatus = TextView(this).apply { id = R.id.region_status @@ -177,9 +177,11 @@ class OfflineSearchActivity : if (data.any { it.countryId == selectedRegion }) refreshRegion() } - override fun onProgress(countryId: String, localSize: Long, remoteSize: Long) { - if (countryId == selectedRegion && remoteSize > 0) { - regionStatus.text = getString(R.string.download_progress, localSize * 100 / remoteSize) + override fun onProgress(countryId: String, progress: MapManager.Progress) { + if (countryId != selectedRegion) return + val total = progress.totalBytes + if (total > 0) { + regionStatus.text = getString(R.string.download_progress, progress.downloadedBytes * 100 / total) } } diff --git a/app/src/main/java/app/organicmaps/example/RoutingActivity.kt b/app/src/main/java/app/organicmaps/example/RoutingActivity.kt index 102a48f..e803118 100644 --- a/app/src/main/java/app/organicmaps/example/RoutingActivity.kt +++ b/app/src/main/java/app/organicmaps/example/RoutingActivity.kt @@ -179,7 +179,7 @@ class RoutingActivity : if (storageSlot >= 0) { // Navigation has no foreground service; planning can remain alive while the activity is stopped. if (!isChangingConfigurations && routing.isNavigating) routing.cancel() - routing.detach() + routing.detach(this) MapManager.nativeUnsubscribe(storageSlot) storageSlot = -1 } @@ -199,7 +199,7 @@ class RoutingActivity : outState.putInt("profile", selectedProfile) buildError?.let { outState.putInt("buildError", it) } outState.putInt("message", message) - if (initialized) routing.onSaveState() + if (initialized) routing.onSaveState(this) super.onSaveInstanceState(outState) } @@ -219,11 +219,6 @@ class RoutingActivity : updateMenu() } - override fun showRoutePlan(show: Boolean, completionListener: Runnable?) { - // The controller starts the build from this continuation, even with always-visible controls. - completionListener?.run() - } - override fun updateMenu() { if (!initialized) return fun title(point: MapObject?) = @@ -252,7 +247,7 @@ class RoutingActivity : waitingForMaps -> getString( R.string.download_progress, - MapManager.nativeGetOverallProgress(missingMaps.toTypedArray()), + MapManager.getOverallProgress(missingMaps.toTypedArray()), ) routing.isNavigating -> getString(R.string.navigating) @@ -316,7 +311,7 @@ class RoutingActivity : updateMenu() } - override fun onProgress(countryId: String, localSize: Long, remoteSize: Long) { + override fun onProgress(countryId: String, progress: MapManager.Progress) { if (countryId in missingMaps) updateMenu() } From 11ffb6fca490b687379d6c09f42d4c481aaab33f Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Sat, 14 Nov 2026 11:57:25 +0100 Subject: [PATCH 2/2] Collect Android CI failure diagnostics Signed-off-by: Alexander Borsuk --- .github/scripts/connected-samples.sh | 119 +++++++++++++++++++++++++++ .github/workflows/android-check.yaml | 21 ++++- 2 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 .github/scripts/connected-samples.sh diff --git a/.github/scripts/connected-samples.sh b/.github/scripts/connected-samples.sh new file mode 100644 index 0000000..8be3da1 --- /dev/null +++ b/.github/scripts/connected-samples.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Run from the samples checkout, inside android-emulator-runner's script hook. +diagnostics_dir="$PWD/app/build/ci-diagnostics" +mkdir -p "$diagnostics_dir" +adb_command=(adb -s "${ANDROID_SERIAL:-emulator-5554}") +logcat_pid= + +capture() { + local file="$1" duration="$2" command_status=0 + shift 2 + printf 'Collecting %s\n' "$file" + timeout --kill-after=5s "$duration" "$@" > "$diagnostics_dir/$file" 2>&1 || command_status=$? + printf '%s: exit %s\n' "$file" "$command_status" >> "$diagnostics_dir/collection-status.txt" + # A disconnected device must not replace the original test failure. + return 0 +} + +device_state() { + capture "device-$1.txt" 15s "${adb_command[@]}" shell \ + 'getprop; cat /proc/sys/kernel/random/boot_id /proc/uptime; pidof system_server; service check package' +} + +print_test_failures() { + printf '::group::Instrumentation failure traces\n' + python3 - <<'PY' +from pathlib import Path +import xml.etree.ElementTree as ET + +found = False +for path in sorted(Path("app/build/outputs/androidTest-results").rglob("*.xml")): + try: + root = ET.parse(path).getroot() + except (ET.ParseError, OSError) as error: + print(f"{path}: {error}") + continue + for parent in root.iter(): + for problem in parent: + if problem.tag not in ("failure", "error"): + continue + found = True + name = f"{parent.get('classname', '')}.{parent.get('name', parent.tag)}".lstrip(".") + print(f"\n{path}: {name}") + print(problem.get("message", "")) + print("".join(problem.itertext()).strip() or "No stack trace recorded.") +if not found: + print("No XML failure traces recorded; inspect logcat and the raw test results artifact.") +PY + printf '::endgroup::\n' +} + +finish() { + local test_status=$? + trap - EXIT + set +e + printf '%s\n' "$test_status" > "$diagnostics_dir/connected-samples-exit-code.txt" + + if ((test_status != 0)); then + capture adb-devices.txt 10s adb devices -l + device_state after + capture crash-buffer.txt 10s "${adb_command[@]}" logcat -b crash -d -v threadtime '*:V' + capture last-anr.txt 15s "${adb_command[@]}" shell dumpsys activity lastanr + capture runner-memory.txt 10s free -h + capture runner-disk.txt 10s df -h + capture runner-processes.txt 10s ps -eo pid,ppid,stat,%cpu,%mem,rss,args --sort=-rss + capture runner-kernel.txt 10s sudo -n dmesg --ctime + fi + + # Keep the failure tail free of the noise generated by bugreport itself. + if [[ -n "$logcat_pid" ]]; then + kill "$logcat_pid" 2>/dev/null + wait "$logcat_pid" 2>/dev/null + fi + + if ((test_status != 0)); then + print_test_failures + for file in device-before.txt device-after.txt adb-devices.txt crash-buffer.txt last-anr.txt \ + runner-memory.txt runner-disk.txt runner-kernel.txt logcat.txt; do + printf '::group::%s (last 500 lines; full file in sample-reports)\n' "$file" + tail -n 500 "$diagnostics_dir/$file" + printf '::endgroup::\n' + done + + # These can fail when Android services have died. Retain their errors and + # partial output; every command is bounded so diagnostics cannot hang CI. + # Root only after failure collection: restarting adbd interrupts logcat. + capture adb-root.txt 10s "${adb_command[@]}" root + capture adb-ready.txt 10s "${adb_command[@]}" wait-for-device + capture anr-pull.txt 15s "${adb_command[@]}" pull /data/anr "$diagnostics_dir/anr" + capture tombstones-pull.txt 15s "${adb_command[@]}" pull /data/tombstones "$diagnostics_dir/tombstones" + while IFS= read -r -d '' file; do + printf '::group::%s (first 500 lines; full file in sample-reports)\n' "${file#"$diagnostics_dir/"}" + head -n 500 "$file" + printf '::endgroup::\n' + done < <(find "$diagnostics_dir/anr" "$diagnostics_dir/tombstones" -type f ! -name '*.pb' -print0 2>/dev/null) + capture bugreport.txt 120s "${adb_command[@]}" bugreport "$diagnostics_dir/bugreport.zip" + printf '::group::Diagnostic collection status\n' + cat "$diagnostics_dir/collection-status.txt" + printf '::endgroup::\n' + fi + + exit "$test_status" +} + +trap finish EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +# Save all buffers on the host throughout the tests, including system_server and +# native crashes. An app-only filter or a post-failure dump can lose the cause. +"${adb_command[@]}" logcat -b all -v threadtime '*:V' > "$diagnostics_dir/logcat.txt" 2>&1 & +logcat_pid=$! +device_state before + +# Leave time for the EXIT trap to collect evidence if the test runner hangs. +timeout --kill-after=30s 15m ./gradlew --continue --console=plain --info --stacktrace \ + -PsdkRepository="$SAMPLES_SDK_REPOSITORY" -PsdkVersion="$SAMPLES_SDK_VERSION" connectedSamples \ + 2>&1 | tee "$diagnostics_dir/connected-samples.log" diff --git a/.github/workflows/android-check.yaml b/.github/workflows/android-check.yaml index 10d8ed1..5ddd5d0 100644 --- a/.github/workflows/android-check.yaml +++ b/.github/workflows/android-check.yaml @@ -65,7 +65,12 @@ jobs: run: ./gradlew -Px86_64 -PsdkVersion="$SAMPLES_SDK_VERSION" publishSdkForChecks - name: Build, lint and check Kotlin style for all samples working-directory: samples - run: ./gradlew -PsdkRepository="$SAMPLES_SDK_REPOSITORY" -PsdkVersion="$SAMPLES_SDK_VERSION" checkSamples + shell: bash + run: | + mkdir -p app/build/ci-diagnostics + ./gradlew --console=plain --stacktrace \ + -PsdkRepository="$SAMPLES_SDK_REPOSITORY" -PsdkVersion="$SAMPLES_SDK_VERSION" \ + checkSamples 2>&1 | tee app/build/ci-diagnostics/check-samples.log - name: Enable KVM run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules @@ -73,15 +78,23 @@ jobs: sudo udevadm trigger --name-match=kvm - name: Exercise sample lifecycle and result-list gestures uses: reactivecircus/android-emulator-runner@v2 + timeout-minutes: 40 with: api-level: 35 arch: x86_64 target: default profile: pixel_2 working-directory: samples - script: ./gradlew --continue -PsdkRepository="$SAMPLES_SDK_REPOSITORY" -PsdkVersion="$SAMPLES_SDK_VERSION" connectedSamples - - uses: actions/upload-artifact@v7 + # Collect device diagnostics before this action shuts down the emulator. + script: bash .github/scripts/connected-samples.sh + - name: Upload sample reports and diagnostics + uses: actions/upload-artifact@v7 if: always() with: name: sample-reports - path: samples/app/build/reports + path: | + samples/app/build/reports + samples/app/build/outputs/androidTest-results + samples/app/build/outputs/connected_android_test_additional_output + samples/app/build/ci-diagnostics + samples/build/reports