Skip to content

feat(mobile-android): add the camera recorder - #4766

Open
AatmanAJ wants to merge 1067 commits into
CapSoftware:mainfrom
AatmanAJ:feat/mobile-android-camera
Open

AatmanAJ wants to merge 1067 commits into
CapSoftware:mainfrom
AatmanAJ:feat/mobile-android-camera

Conversation

@AatmanAJ

@AatmanAJ AatmanAJ commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on the recording engine PR (#4764), which sits on the earlier Android PRs. Only the top 15 commits are new here, from "render camera frames upright through GL" onwards (b0ed15449 to edc680317), then a merge of the recording engine PR (91cadad00), two fixes after review (19807755e, f68a4661b), a second merge of the recording engine PR (1ed64d194), a fix after review (712104580), a third merge of the recording engine PR with its review fixes (62a61d6fb), a fix for the notification permission (14cfec5ff), its test (092644604, made to wait for the camera in 48d38ff0c) and a fourth merge of the recording engine PR, which brings in the sign-in fixes from #4734 (aae17d165), and a fifth merge of the recording engine PR (759a73c8f). It brings in the review fixes from the earlier Android PRs, among them: sign-out clears notifications and stops playback, Cap images send the video access token, paging carries on after a refresh and shows its errors, the screen stays on while a Cap plays, an upload that storage asks to send later is retried, and lint no longer fails when a newer Kotlin is released. Then come a fix after review (15861a5e8) and its test (5c23ceaf3), two more merges of the recording engine PR (666bf9bdf, 9862f4e59), a fix that keeps a segment writer alive until its recording is saved (d45d50ed7), a merge of the recording engine PR that brings in its drain deadline (effb7ce6f) and a fix that says how much of a recording was kept when saving stops (dfdb927d4). A last merge of the recording engine PR (69b5716c9) brings in the recording engine's fix that keeps the debug pattern recorder's footage when saving stops early (077ea1786, #4764). Once the PRs below merge this shows only its own diff.

This PR adds the camera recorder, the Android counterpart of the iOS Instant Mode camera recording.

What is in it

The Record tab and the Add menu's Record now open the recorder instead of the placeholder. Someone can record themselves with the front or back camera and the microphone, and when they stop, the link to the Cap is on their clipboard, while the segments upload through the recording engine from the previous PR.

  • Capture (media). GlFrameRenderer draws camera frames upright through OpenGL to the viewfinder and to the encoder, mirroring only the front camera's viewfinder and cropping each sensor to the recording's shape. MicrophoneCapture records 48 kHz mono on the capture clock. CameraCapture opens, flips and closes the camera with Camera2.
  • State machine. RecordModel is a port of the iOS RecordModel: preparing, camera denied, unavailable, ready, recording and finishing. It drives the camera through RecorderCommand values, which CameraRecorder carries out, so every transition runs on the JVM. Recording creates the job and begins its uploads, so the Cap is created while the first frames are encoded.
  • Recorder screen. Black and dark like the iOS recorder: the capture mode switch with Studio and Screenshot coming soon, the Camera and Screen picker with Screen coming soon until screen recording lands, the record button, the flip button and the timer. The screen stays on and the system bars hide while recording.
  • Flipping. A recording keeps the shape it started with: a quarter turn waits until it ends, a half turn applies at once. A flip whose new camera fails opens the previous one again, so the recording carries on, as on iOS.
  • Permissions. The recorder asks for the camera and microphone once when it opens and checks again whenever it comes back to the front. Without the camera it shows "Cap needs your camera" with Open Settings; without the microphone it records without sound and shows Microphone off. The camera and microphone are declared as not required, so a device without them can still install the app.
  • Free plan and short recordings. On the free plan a recording stops itself at 5 minutes with the iOS message, the timer shows "/ 5:00" and turns orange with a haptic for the last 30 seconds, and the idle recorder says so. A recording shorter than one second is thrown away with "Recording was too short" and its Cap is deleted.
  • Discarding. Closing or going back while recording asks "Discard this recording?"; Discard cancels the writer and deletes the job and its Cap. Closing is not possible while a recording is finishing.
  • Backgrounding and interruptions. Going to the background stops the recording, keeps what was recorded and closes the camera, which opens again on return. A camera taken away by the system stops a recording the same way.
  • Recent recordings. As in the iOS RecentRecordings: up to six recordings, the newest three shown, each with its upload progress, ready or failed. The newest link is copied when its recording stops, or when its Cap is created if that comes later, as iOS does in RecordingCoordinator.swift, with a toast when the recorder is not showing. A failed upload shows why and has its Cap deleted. Tapping a row opens its Cap. The list starts empty when another account signs in.
  • Upload notification. Once a recording stops and its Cap exists, its upload shows in the shade as "Uploading recording" with its percentage, then "Ready to share" or the error, through the Live Updates PR's RecordingUploadFeed, with the same throttle, stale state and dismissal as other uploads.
  • Waiting for unfinished jobs. The recent list is a second collector of the recording events, so the upload worker now waits on a revision counter instead of taking events, and cannot miss the one that ends its wait.

Screenshots

The recorder on the API 37 emulator, filming the emulator's virtual back camera scene, in the light and dark system themes. Taken at 1ed64d194, this PR's tip, so they include the status bar fix: the recorder is always dark and its status bar icons stay white in both themes. While recording, the system bars are hidden.

Light Dark
Ready Camera recorder ready, white status bar icons, light theme Camera recorder ready, white status bar icons, dark theme
Recording Camera recorder recording, light theme Camera recorder recording, dark theme
Discard confirmation Discard this recording? dialog, light theme Discard this recording? dialog, dark theme
Recent recordings Two camera recordings in the recent list, light theme Two camera recordings in the recent list, dark theme
Camera permission request System camera permission request over the recorder, light theme System camera permission request over the recorder, dark theme
Camera blocked Cap needs your camera, with Open Settings, light theme Cap needs your camera, with Open Settings, dark theme

In the dark recent list, Android's own clipboard preview shows the link that was just copied.

The last 30 seconds warning, on a free account 4:39 into a recording. The timer turns orange 30 seconds before the five minute stop. Light theme only.

Timer at 4:39 of 5:00 in orange

Where it differs from iOS, on purpose

  • The camera stops in the background. Android does not let an app record from the camera in the background, so leaving the app stops the recording and keeps it rather than pausing.
  • The 5 minute limit lives with the recorder. The free plan stop is part of RecordModel, not the shared recording limits, so it is tested with the recorder's transitions.
  • No upgrade link. iOS shows it only on the US App Store, so it stays behind a flag that is off.
  • No test camera source in the app. The media tests use the emulator's image cameras for a known picture instead.
  • Date in titles. A recording's title uses the device locale's medium date and short time, which is close to, but not the same as, the iOS format.

Tests

  • capkit, :capkit:test: 269 tests, 1 new: the wait for unfinished jobs ends while something else collects the recording events.
  • JVM, :app:testDebugUnitTest: 489 tests on edc680317 and 495 on the merge, 27 of them new (two more after review, below). RecordModelTest (22) goes through each row of the recorder's transition table on virtual time against a loopback server and real recording uploads: permissions, camera failure, recording, stopping, the too-short discard with its Cap deleted, a writer failure that keeps what is on disk, the 5 minute stop without waiting 5 minutes, discard, teardown, upload failure, interruption, backgrounding, a failed flip and rotation. RecordingCoordinatorTest (5) checks the automatic link copy, a failed upload's message and deleted Cap, the list's length, the updates fed to the upload notification from uploading to failed, and that another account starts with an empty list.
  • media, :media:testDebugUnitTest: 61 tests, 31 of them new: FrameGeometryTest 9, PcmConverterTest 8, CameraChoiceTest 7 and FrameClockTest 7.
  • Instrumented, app: new RecorderTest (3) checks that the recorder offers Instant Mode and the camera, that the other capture modes say they are coming soon, and that closing it returns to Caps. MainShellTest now grants the camera and microphone and looks for "Instant Mode" on the Record tab. RecordingNotificationsTest (1) is described under the review fixes below.
  • Instrumented, media, 28 new: GlFrameRendererTest (16) for orientation, mirroring, cropping, the encoder outliving the viewfinder and the capture clock; CameraCaptureTest (9) for 10 seconds of camera and microphone as 2 second segments, a flip mid-recording without a gap, a scene staying upright and unmirrored across a flip, interruptions and repeated open and close; MicrophoneCaptureTest (3).

Device pass

Pinned to one run at 13954befa, the screen recorder PR's tip, which contains this PR. Both emulators ran headless against a local fixture server. RecorderTest and the media camera tests ran once per API level.

API 37 (cap_cam_37) API 29 (cap_cam_29)
App instrumented 93 run, 90 passed, 3 failed 93 run, 93 passed
Media instrumented 41 run, 37 passed, 4 skipped 41 run, 35 passed, 6 skipped

The 3 API 37 failures are the known Cap detail ones, listed separately because they are not in this PR's code: CapDetailTest.playAndPause and aShareLinkWithATimeOpensTheCapThere (Compose did not go idle while the emulator decoded the video) and aChosenSpeedIsKeptAfterTheAppIsOpenedAgain (touch input could not be injected). The skipped tests are all in CameraCaptureTest, which skips what the emulator's cameras cannot do: two cameras, a flip, or the frame rate it asks for. The crash buffers were empty after every suite.

The front camera tests need an AVD with an emulated front camera. The cap_phone_* AVDs have hw.camera.front=none, so this run used cap_cam_37 and cap_cam_29, booted with -camera-front emulated and -camera-back emulated.

Fixed after review

  • The recorder is always dark, but in the light theme the status bar kept its dark icons, so the clock and signal were nearly invisible over it. The recorder now asks for light icons while it is showing and puts back the previous appearance when it closes (19807755e). The new RecorderTest.theRecorderShowsLightStatusBarIconsAndRestoresThemOnClose failed without the fix on the API 37 emulator in the light theme and passes with it.
  • The five minute limit was lifted only when the session knew the plan was upgraded, and the plan lived in memory only, so a Cap Pro account whose plan request failed was stopped at five minutes. The session now saves each plan it fetches and falls back to the saved one when the request fails (f68a4661b). The new RecordModelTest.capProKeepsNoLimitWhenThePlanCannotBeFetched fails without the fix.
  • A Cap Pro account confirmed during a recording was still stopped at five minutes, because the limit was settled from the plan known when the recording started. The recorder now waits the five minutes and then checks the plan, and the plan request reads the saved plan first (712104580). The new RecordModelTest.aProPlanConfirmedDuringARecordingLiftsTheFiveMinuteStop fails without the fix.
  • Someone who only recorded, without importing anything first, was never asked for notification permission on Android 13 and later, so the upload progress, completion and failure notifications were dropped. Closing the recorder now asks, as the import flows do, once there is a recording in the recent list (14cfec5ff). The new RecordingNotificationsTest.closingTheRecorderAfterARecordingAsksForNotifications (092644604) revokes the permission, records 2 seconds of camera through the test's loopback relay, which now serves the recording endpoints, closes the recorder and waits for the system permission dialog. 48d38ff0c makes it wait for the camera to be ready before it records. On the API 37 emulator it fails without the fix, as no dialog appears, and passes with it.
  • A video that finished playing under the recorder turned keepScreenOn off for the whole window, so the screen could sleep and stop a camera recording. The player and the recorder now each use Modifier.keepScreenOn(), which Compose counts per window, so neither can clear the other's request (15861a5e8). CapDetailTest.aVideoThatStopsUnderTheRecorderLeavesTheScreenOnForTheRecording plays a Cap, opens the recorder over it, starts a recording and pauses the video, then checks the screen is still kept on. It passes on the API 29 emulator and fails against the code before the fix (5c23ceaf3).
  • The recording engine now gives up on an encoder that never finishes draining and completes with an UNFINISHED failure that carries the seconds it kept (feat(mobile-android): add the recording engine #4764). The recorder already kept the segments on disk after a writer failure; it now also says "Couldn't finish saving, N s kept" (dfdb927d4). RecordModelTest.anEncoderThatNeverFinishesSavesWhatWasKeptAndSaysSo fails without the fix ("expected:<Couldn't finish saving, 3 s kept> but was:") and passes with it. The merge that brought in the deadline (effb7ce6f) met d45d50ed7 in SegmentWriter.finish. That fix holds a finishing writer in a static set so it cannot be finalised with its codecs while it waits for the end of stream. Both are kept: finish starts the deadline and adds the writer to the set, and releasing the writer, on success, failure or the deadline, removes it.

Checked

  • ./gradlew spotlessCheck :capkit:test :app:testDebugUnitTest :app:lintDebug :app:assembleDebug :app:assembleRelease :app:assembleDebugAndroidTest :media:testDebugUnitTest :media:lintDebug :media:assembleDebugAndroidTest passes on edc680317, on the merge, 91cadad00, on f68a4661b after the review fixes, with 269 capkit, 496 app and 61 media JVM tests, on the second merge, 1ed64d194, with 270 capkit, 505 app and 61 media JVM tests, on 712104580 with 270 capkit, 506 app and 61 media JVM tests, and on the third merge, 62a61d6fb, on 14cfec5ff, on 092644604 and on 48d38ff0c, with 272 capkit, 506 app and 61 media JVM tests, on the fourth merge, aae17d165, with 272 capkit, 513 app and 61 media JVM tests, and on the fifth merge, 759a73c8f, on 15861a5e8 and on 5c23ceaf3, each with 273 capkit, 520 app and 61 media JVM tests. With the drain deadline, the check line passes at the top of the Android stack, 276cfebaa, which contains dfdb927d4.

Not checked

  • RecorderTest 20 times in a row. It touches timing, and the device pass above ran it once per API level.
  • On a physical phone, which the emulator cannot stand in for:
    1. The camera in real time; the API 29 emulator never reaches the 29 fps the camera tests ask for.
    2. Real sensor orientation, and that the front camera's saved video is upright and not mirrored.
    3. The hardware encoder fed from OpenGL.
    4. A 15 second front camera recording with a flip in the middle, against a real Cap server: one recording with consecutive segments, upright on both sides of the flip, the link on the clipboard, and the Cap playing.
    5. Pressing Home while recording keeps the recording.
    6. Denying the camera shows the blocked view, and Open Settings opens the app's settings.
    7. Screenshots: ready, recording, the last 30 seconds warning, blocked and the recent list.
  • Releasing the renderer straight after the camera closes when leaving the recorder.
  • An activity recreated for a theme or locale change while recording discards the recording.
  • The title's date format against iOS.

Confidence Score: 0/5RetriggerView in Greptile

The PR is not ready to merge because earlier upload, navigation, and test failures remain.

Findings

  1. P1 Cancelled uploads still look active ▶
  2. P1 Loom imports ignore Cancel ▶
  3. P1 Old folders break new recordings ▶
  4. P1 Organization analytics cannot open ▶
  5. P1 Tests use removed controls ▶
  6. P1 Background upload failures disappear ▶
  7. P1 Background upload failures disappear ▶
  8. P1 Permission test skips Allow ▶
Fix with agent prompt
### Issue 1
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/services/UploadActions.kt:undefined-57
Cancelling a recording upload removes its job, but `RecordingCoordinator` ignores `Discarded`. The result page stays on Uploading and still offers the deleted link. The pending `LiveUpdate` timer also posts the notification again after 45 seconds.

Send cancellation through the coordinator and notification feed so the page and notification stop tracking the recording.

### Issue 2
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/app/Notifications.kt:101-107
`Notifications.upload()` now adds Cancel upload to Loom imports, but `UploadActionReceiver` only handles file uploads and recordings. Loom imports have neither kind of local job, so tapping Cancel upload only hides the notification. The server keeps importing, and the next progress update posts the notification again.

Hide this action for Loom until cancellation is supported, or add a working Loom cancellation path.

### Issue 3
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/MainShell.kt:220-224
`recorderFolderId` is never cleared after recording from a folder. Opening Settings, switching organizations, and returning still passes the old folder into `RecordModel`. The next recording combines the new organization with the old folder, so its create request fails.

Clear the folder when leaving a folder-scoped recording and when the organization changes.

### Issue 4
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/MainShell.kt:96-98
Removing `Route.Analytics` and its tab leaves no way to open organization-wide analytics. The only remaining `AnalyticsScreen` uses `AnalyticsScope.Cap`, which does not show the organization's totals, space filter, or top Caps.

Keep an entry to organization analytics in the new navigation.

### Issue 5
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/record/RecorderHome.kt:266-271
The new recorder home has no Close button, but `RecorderTest.theRecorderMatchesItsStatusBarIconsToTheThemeAndRestoresThemOnClose` and `RecordingNotificationsTest` still click it. Both fail before checking their intended behavior.

`UploadFlowTest` also looks for Add or the upload banner immediately after launch, without opening the library. Update these tests for the new account and library entry points.

### Issue 6
apps/mobile-android/capkit/src/main/kotlin/so/cap/kit/RecordingUploads.kt:undefined-58
`MutableSharedFlow` has no replay here, so it drops events when nobody is collecting. Android can restart `RecordingUploadWorker` without opening `MainActivity`; the worker resumes uploads, but only `MainActivity` starts `RecordingCoordinator`. If a recovered upload fails then, its `Failed` event disappears. Opening the app later cannot deliver that event to the coordinator, so its error notice and failed-Cap cleanup never run. Preserve pending events or restore those actions from saved job state when the coordinator starts.

### Issue 7
apps/mobile-android/capkit/src/main/kotlin/so/cap/kit/RecordingUploads.kt:58-59
`MutableSharedFlow` has no replay here, so it drops events when nobody is collecting. `extraBufferCapacity` does not keep them for a future collector. Android can restart `RecordingUploadWorker` without opening `MainActivity`, where `RecordingCoordinator.start()` runs.

If a recovered upload fails then, its `Failed` event disappears. Opening the app later cannot show the error or run the coordinator's Cap cleanup. Preserve pending events, or restore these actions from saved job state when the coordinator starts.

### Issue 8
apps/mobile-android/app/src/androidTest/kotlin/so/cap/mobile/RecordingNotificationsTest.kt:undefined-108
`RecordingNotificationsTest` now reaches the result screen, but waits directly for Android's permission dialog after tapping Close. The new callback calls `askForNotifications()`, which first opens `RuntimePermissionPrimeSheet`. Only tapping that sheet's Allow button launches Android's dialog. Since the test never taps Allow, it times out instead of checking notification permission. Tap Allow before waiting for `permissionDialog`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR adds Android camera recording, live segment uploads, and a recorder page.

  • Android recordings become shareable Caps with upload progress.
  • Android users can sign in, browse Caps, and use core Cap tools.
  • Mobile sharing settings and browser sign-in callbacks carry extra details.
  • Android changes now trigger a dedicated CI check.

Reviews (53) · Last reviewed commit: "fix(mobile-android): format the camera f..." · Reviewed by Greptile

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@AatmanAJ is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread .github/workflows/ci.yml Resolved
@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

1 similar comment
@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

3 similar comments
@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

5 similar comments
@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

…ttings

Notification rows drew the stock Material switch, which is a different
size and colour from the 44x26 design switch every other settings row
uses. They now show CapSwitchTrack. The two switch lines on Recording
defaults each drew a top and a bottom hairline, so the rule between them
was twice as thick as every other divider.
ad499fe made the upload events a shared flow so every collector sees
them, which also means an event emitted while nobody collects is gone.
The test asked for one Progress event at a time, so the burst of three
concurrent segment uploads finished between two of its calls and it
waited for the rest of its minute. It now collects from before the job
begins. awaitJob subscribes before it checks the job for the same reason.
The app is unaffected: RecordingCoordinator collects for its whole life.
Keeps this layer's theme root, which already wraps Root in the picture
in picture box.

This branch has not been deployed

No deployments
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