Skip to content

No crash when the app is opened right after an update (2.30.1) - #309

Merged
compot-dev merged 2 commits into
v2from
fix/web-service-race-308
Nov 25, 2026
Merged

compot-dev merged 2 commits into
v2from
fix/web-service-race-308

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Closes #308.

  • WebService.stop leaves a service whose start is still pending (stopping it before startForeground ends the app); onStartCommand calls startForeground and then stops itself when the app is open or opening, as it did with remote access off.
  • The version under Exit has no trailing comma in a build without a git commit (GIT_HASH is empty in a container that cannot see the repository). VersionLineTest.
  • tests/e2e.sh: an update and an open in one device shell, five times: no crash, the service gone afterwards.

Checks (local, Docker): unit tests, lint (13 warnings as before), check-version.sh. The new e2e check on the old code, API 34: 2 of 5 starts hit the race and both crashed. With the fix: UDP API 21 and 34 20/20, TCP API 21 and 34 21/21. On API 34 the race came up once in each run; whether it does depends on timing. On API 21 there are no foreground service starts, so it only checks that the service goes away.

A service asked for with startForegroundService must not be stopped before
startForeground: WebService.stop leaves a pending one, which stops itself in
onStartCommand when the app is open. No trailing comma under Exit without a
git hash. e2e opens the app right after an update, five times.

Closes #308
@compot-dev compot-dev added the bug Something isn't working label Nov 25, 2026
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Prevent a foreground-service crash when opening the app after an update

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Defer stopping the update-started web service until it reaches the foreground, preventing an app
 crash.
• Remove the trailing comma from the Exit version when a build has no git hash.
• Add a repeated update-and-open regression check and release version 2.30.1.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: post-update web access integration, release identity and application version presentation.
  • The update receiver, foreground service, and DebugServer jointly implement one end-to-end outcome: restoring the local read-only web page after an update.
  • They are lifecycle and implementation hops of the same capability, not separate functional scopes.
  • This is an independent user-facing outcome from the post-update web-access integration: it formats release metadata in the menu and changes no web-service, camera, tunnel, or persistent-state behavior.
Sources

android/app/build.gradle[26-30]

        applicationId "com.openipc.decoder"
        minSdk 21
        targetSdk 36
        versionCode 73
        versionName "2.30.1"

android/app/src/main/java/com/openipc/decoder/MenuManager.java[443-446]

    /** The version and the commit; a build without git has no hash, and then no comma (#308). */
    static String versionLine(String version, String gitHash) {
        return "v" + version + (gitHash == null || gitHash.isEmpty() ? "" : ", " + gitHash);
    }
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before: the update broadcast started the foreground service, while an activity opening could independently call stopService before onStartCommand.
  • After: a pending state defers that stop and onStartCommand clears the state, performs foreground startup, then checks whether the activity opened and stops itself.
  • New correctness condition: the pending flag and the onStartCommand/activity ordering must agree across the startup race so the service is neither stopped before foreground promotion nor left running after the screen opens.
  • The source traces the only inspected consumer path through BootReceiver and Decoder.onResume; no additional functional consumer was found.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If this changed lifecycle behavior regresses, the post-update read-only web page could be unavailable or the application could fail during the foreground-service transition.
  • The affected outcome is limited to this web-access capability; no video, tunnel, persistent state, or external transaction is involved.
  • Reverting the code can restore the lifecycle logic, but a currently unavailable page may still require reopening the app or restarting the service.
  • This assessment is conditional because no specific fault is supported by the inspected source.
  • Recoverable by code rollback and, for an already missed service start, reopening the app or otherwise restarting the service.
  • No persistent data repair or external compensation is indicated.
Assessed commit 1500397
Diagram

sequenceDiagram
    participant OS as Android OS
    participant Receiver as BootReceiver
    participant Service as WebService
    participant App as Decoder
    OS->>Receiver: Package replaced
    Receiver->>Service: Start after update
    Service->>OS: Request foreground start
    OS->>App: Open activity
    App->>Service: Stop requested
    Note over Service: Defer while pending
    OS->>Service: onStartCommand
    Service->>OS: startForeground
    Service->>OS: stopSelf if app open
Loading
High-Level Assessment

Keep the deferred-stop approach: the web service must still start after an update when the app remains closed, but Android requires a requested foreground service to call startForeground before it stops. Checking whether the activity opened in onStartCommand handles both outcomes without changing that behavior.

Files changed (6) +70 / -4

Bug fix (2) +18 / -2
MenuManager.javaOmit the Exit version comma when no git hash exists +6/-1

Omit the Exit version comma when no git hash exists

• Routes the displayed version through a helper that appends the commit only when a nonempty hash is available.

android/app/src/main/java/com/openipc/decoder/MenuManager.java

WebService.javaDefer stopping a service awaiting its foreground start +12/-1

Defer stopping a service awaiting its foreground start

• Tracks update-triggered starts so an opening activity cannot stop the service before startForeground. After entering the foreground, the service stops itself if remote access is disabled or the app has opened.

android/app/src/main/java/com/openipc/decoder/WebService.java

Tests (2) +43 / -0
VersionLineTest.javaTest version formatting with and without a commit +21/-0

Test version formatting with and without a commit

• Checks that the Exit version includes a commit when present and has no trailing comma for empty or null hashes.

android/app/src/test/java/com/openipc/decoder/VersionLineTest.java

e2e.shExercise immediate app opening after repeated updates +22/-0

Exercise immediate app opening after repeated updates

• Installs and opens the app in one device-shell command five times, then checks for foreground-service crashes and a service left running after the activity opens.

tests/e2e.sh

Documentation (1) +7 / -0
CHANGELOG.mdDocument the 2.30.1 fixes +7/-0

Document the 2.30.1 fixes

• Adds release notes for the post-update crash fix and the Exit version formatting correction.

CHANGELOG.md

Other (1) +2 / -2
build.gradleBump the app to version 2.30.1 +2/-2

Bump the app to version 2.30.1

• Increments versionCode to 73 and versionName to 2.30.1.

android/app/build.gradle

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. The update race test can pass without updates ✓ Resolved
Description
The device-shell command in the new e2e loop separates pm install from am start with ;, so an
installation failure does not prevent the activity launch. If an install fails, the test can still
pass because it checks only for a crash and a lingering service; the count of update events is
printed but never required.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev

Copy link
Copy Markdown
Collaborator Author

Qodo's finding is right, fixed in 1500397: each of the five updates must report Success or the check fails. Verified with an APK path that does not exist: the check fails (0 of 5) and nothing else does. The count of races is still only printed: whether the service is starting when the app opens depends on timing (an app opened before the broadcast starts no service), so requiring it would make the check flaky.

@compot-dev
compot-dev merged commit cab4ea8 into v2 Nov 25, 2026
7 checks passed
@compot-dev
compot-dev deleted the fix/web-service-race-308 branch November 25, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when the app is opened right after an update: WebService stopped before startForeground

1 participant