Skip to content

fix: report real app name and focused activity for android foreground app - #403

Merged
gmegidish merged 1 commit into
mainfrom
fix/android-foreground-app-name
Sep 9, 2026
Merged

gmegidish merged 1 commit into
mainfrom
fix/android-foreground-app-name

Conversation

@gmegidish

@gmegidish gmegidish commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Problem

mobilecli apps foreground on Android echoed the package name twice:

{ "packageName": "com.mobilenext.playground", "appName": "com.mobilenext.playground", "version": "1.0" }

GetForegroundApp assigned AppName: packageName directly. iOS resolves a real label, so the two platforms disagreed.

Fix

The label was already available. PackageLister.displayName on the agent side resolves it through nonLocalizedLabel and then the package's own resources, and ListApps already returns it. The foreground path just never asked, so it now looks the package up in that listing.

No change was needed in agents/android.

When the on-device agent is unavailable the listing call fails and callers get the package name back rather than an error, so setups without the agent behave as before.

Also included: the activity is parsed out of the mCurrentFocus component and exposed as an optional activity field, since dumpsys already reports it next to the package.

Result

{
  "packageName": "com.mobilenext.playground",
  "appName": "Playground",
  "version": "1.0",
  "activity": "com.mobilenext.playground.BasicUIActivity"
}

Test plan

  • go build ./...
  • go vet ./devices/
  • go test ./devices/ passes
  • Three new unit tests on appNameFor: label found, package absent from the listing, package present with an empty label
  • Verified against a Pixel 9 Pro emulator, output above
  • Verify on a device without the agent installed, expecting the package name as the fallback

Summary by CodeRabbit

  • New Features
    • Foreground app information now includes the currently focused Android activity.
    • Android app names are displayed using their launcher labels when available.
    • If no launcher label is found, the package name is shown instead.

… app

GetForegroundApp assigned the package name to AppName, so every Android
response echoed the package twice while iOS returned a real label. The
label is already resolved by PackageLister.displayName on the agent side,
so look the package up in that listing instead. When the agent is
unavailable the lookup fails and callers still get the package name back
rather than an error, matching the previous behaviour.

Also parse the activity out of the mCurrentFocus component and expose it
as an optional field, since dumpsys already reports it alongside the
package.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: 86c635c6-9128-4189-b3b6-bcb2e354c059

📥 Commits

Reviewing files that changed from the base of the PR and between 89e32f4 and 256ff03.

📒 Files selected for processing (3)
  • devices/android.go
  • devices/android_apps_test.go
  • devices/common.go

Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.


📝 Walkthrough

Walkthrough

Android foreground app detection now returns the focused package and activity. It resolves the application label through installed package data and falls back to the package name when lookup fails or the label is empty.

Changes

Android foreground app detection

Layer / File(s) Summary
Foreground component contract
devices/common.go, devices/android.go
ForegroundAppInfo now includes an optional Activity field. Android foreground detection parses the focused window component into package and activity values.
Foreground label resolution and validation
devices/android.go, devices/android_apps_test.go
GetForegroundApp resolves application labels through installed package data and falls back to the package name. Tests cover known packages, unknown packages, and empty labels.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 256ff

Android foreground reporting now returns resolved app labels with package-name fallbacks and optionally includes the focused activity. The updated behavior and fallback cases are covered, with no current merge-readiness risk identified.

Sequence Diagram(s)

sequenceDiagram
  participant GetForegroundApp
  participant getForegroundComponent
  participant listAllPackages
  GetForegroundApp->>getForegroundComponent: read focused window component
  getForegroundComponent-->>GetForegroundApp: return package and activity
  GetForegroundApp->>listAllPackages: resolve package label
  listAllPackages-->>GetForegroundApp: return label or package fallback
  GetForegroundApp-->>GetForegroundApp: populate ForegroundAppInfo
Loading

Suggested reviewers: hakanor

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 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 changes: reporting the resolved Android app name and the focused activity for the foreground app.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/android-foreground-app-name

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

@gmegidish
gmegidish merged commit 1cab74f into main Sep 9, 2026
17 checks passed
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