Skip to content

fix(android): report a package that is not installed when terminating it - #498

Open
mobile-kevin wants to merge 1 commit into
mobile-next:mainfrom
mobile-kevin:fix-android-terminate-not-installed
Open

mobile-kevin wants to merge 1 commit into
mobile-next:mainfrom
mobile-kevin:fix-android-terminate-not-installed

Conversation

@mobile-kevin

@mobile-kevin mobile-kevin commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

mobilecli apps terminate <package> on Android reports success for a package that is not installed, because am force-stop exits 0 for any name:

$ mobilecli apps terminate com.mobilenext.notinstalled --device Pixel_9_Pro
{"status": "ok", "data": {"message": "Terminated app 'com.mobilenext.notinstalled' on device Pixel_9_Pro"}}

The iOS device and the simulator (#493) already fail with <package> not installed.

Fix

AndroidDevice.TerminateApp checks pm path <package> first and returns <package> not installed when it prints nothing. An installed app that is not running is still force-stopped without error, so callers that stop an app before relaunching it are unaffected.

pm path output is read by a small pure function, pmPathReportsInstalled, so an adb or device failure (non-empty output that is not package:…) is returned as an error instead of being read as "not installed".

Cost: one extra adb shell pm path per terminate (~50 ms on an emulator).

Testing

  • e2e, written first and failing on main: should report that a package which is not installed cannot be terminated failed with apps terminate com.mobilenext.notinstalled unexpectedly succeeded; it passes with the fix.
  • e2e guard: should terminate an installed app that is not running without an error passes before and after.
  • Unit tests for pmPathReportsInstalled: installed, split APK, not installed, adb failure.
  • Full Android emulator suite: 58 passed.
  • go test ./... passes; golangci-lint reports the same 84 findings as main, none new.

Found while QA-testing mobile-mcp (BUG-34).

Summary by CodeRabbit

  • Bug Fixes
    • Terminating an Android app now reports an error if the app is not installed or its installation status can’t be checked. Installed apps can still be stopped even if they aren’t running.

am force-stop exits 0 for any package name, so terminating an app that is
not installed reported success. Check pm path first and fail with
'<package> not installed', the message the iOS device and simulator give.
Terminating an installed app that is not running still succeeds.
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: mobile-next/mobilecli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 09d5edff-98e1-4b20-9852-fae200a8a560
📥 Commits

Reviewing files that changed from the base of the PR and between aca77be and e77f387.

📒 Files selected for processing (3)
  • devices/android.go
  • devices/android_apps_test.go
  • test/android.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

TerminateApp now checks whether an Android package is installed before running am force-stop. Added tests cover installation-check results and app termination behavior.

Changes

Android app termination

Layer / File(s) Summary
Package installation check
devices/android.go, devices/android_apps_test.go
isPackageInstalled uses pm path to identify installed packages. Unit tests cover regular and split APK paths, empty output, and an ADB device-not-found error.
Termination behavior
devices/android.go, test/android.spec.ts
TerminateApp returns an error when the package is absent or the installation check fails. Tests cover an absent package and repeated termination of the installed Settings app.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: gmegidish

Merge Risk: ⚪ Minimal · up to e77f3

Terminating an Android package that is not installed now reports an error instead of silently succeeding. Installed apps that are not running still terminate without error. No merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: report an error when terminating an Android package that is not installed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant