Skip to content

Android session owner survives Activity lifecycle - #65

Closed
YashasVM wants to merge 11 commits into
agent/A2-async-teardownfrom
agent/A3-session-owner
Closed

YashasVM wants to merge 11 commits into
agent/A2-async-teardownfrom
agent/A3-session-owner

Conversation

@YashasVM

@YashasVM YashasVM commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #63

Summary

  • Move the phone camera session into a foreground PhoneSessionService and PhoneSessionRuntime, keeping camera, encoders, SRT, discovery, control, listener, reservation, and session state outside MainActivity.
  • Keep the Activity as an observer and preview-surface provider. Detaching the Activity no longer tears down a live encoder capture session.
  • Define lifecycle behavior for Home, lock, Settings, task removal, permission loss, explicit Stop/Start, and process recreation. Notification Stop persists the stopped state.
  • Add lifecycle state behavior tests and emulator-capable Activity/service/permission tests. The service routes Stop cleanup through one critical SessionWorker task and retries if its reserved queue slot is temporarily full.

Verification

  • ANDROID_HOME=/home/yvm/.local/share/android-sdk ./gradlew :app:testDebugUnitTest :app:compileDebugAndroidTestKotlin :app:assembleDebug — passed.
  • python -m pytest -q — 117 passed.
  • git diff --check — passed.
  • Instrumentation tests compile but were not executed; no emulator or device is attached. Stopped relaunch test covers the Stopped UI, absence of app notifications, and a wait beyond the foreground-service startup timeout.
  • Physical background-camera behavior is INCONCLUSIVE and still requires a device check.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9399a75f-2c97-4b57-b8b3-10eb1cd54ee5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@YashasVM YashasVM left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yashas's code review bot: IMPORTANT — the new service-owned session still routes media transport recovery through the Activity observer. Both audio and video encoded-access-unit callbacks do observer?.onMediaTransportFailure(...), and MainActivity merely forwards that back to sessionRuntime.handleMediaTransportFailure(...). onStop() intentionally sets sessionRuntime.observer = null, so while the app is Home/locked/backgrounded—the exact lifecycle this PR is meant to support—an SRT send failure is silently dropped. The runtime can remain in a stale live/connecting state and never run its disconnect/recovery path until some unrelated event occurs. Transport recovery is session ownership logic and must not depend on an attached Activity: invoke handleMediaTransportFailure() directly from the runtime callbacks (with the existing generation checks), using the observer only for resulting UI/status events. Please add a regression test that detaches/nulls the observer, injects a recoverable transport failure, and verifies the runtime still transitions/reconnects/cleans up correctly. Treating this as merge-blocking despite the green CI.

@YashasVM YashasVM left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yashas's code review bot: Re-reviewed head 2f2b22f after the latest update. The previous merge-blocking transport-recovery finding is still present: both audio and video encoded-access-unit callbacks still invoke observer?.onMediaTransportFailure(...), while the Activity observer is intentionally detached in the background. Therefore a recoverable SRT send failure can still be dropped while the service owns the session without an Activity. All exact-head CI workflows are green, but they do not cover this detached-observer failure path. Please move transport-failure handling into PhoneSessionRuntime itself (keeping observer callbacks for UI only) and add a regression test with observer == null before treating this PR as merge-ready.

@YashasVM YashasVM closed this Sep 25, 2026
@YashasVM
YashasVM deleted the agent/A3-session-owner branch September 28, 2026 18:34
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