Skip to content

feat(mobile-android): Studio Mode, record separate tracks, edit and export on the phone - #4774

Open
AatmanAJ wants to merge 1681 commits into
CapSoftware:mainfrom
AatmanAJ:feat/mobile-android-studio
Open

AatmanAJ wants to merge 1681 commits into
CapSoftware:mainfrom
AatmanAJ:feat/mobile-android-studio

Conversation

@AatmanAJ

@AatmanAJ AatmanAJ commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on the polish PR (#4768), which sits on the earlier Android PRs. The 15 commits from 176485cbe to 5dd38f373 are new here, followed by 43667eb6d and f0d3e38b52, which merge the polish branch at 0ba4261de and then at fe5ddde9b5. Then come a merge of the polish branch (d7a3a93f0), two test fixes (c46ae7b51, 5252ddf87), three more merges of the polish branch (1dc41e251, f39befdc9, bb2708697), the last of which brings in the recording engine's drain deadline, and a fix that keeps a Studio recording whose saving could not finish (80c259aa3). A last merge of the polish branch (5515305bc) 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.

Studio Mode for the Android app: record the screen, the camera and the microphone as separate tracks on the phone, then trim, style and export the result before anything uploads, in the same way as desktop Cap's Studio Mode.

What is in it

  • Mode switch. The recorder now offers Instant and Studio and remembers the last choice in DataStore. Studio shows its own panel: camera and microphone toggles, a live preview of the framed result, and "Continue your last recording". The Instant camera opens only in Instant mode, so the two never compete for the camera.
  • Recording. StudioRecordingService reuses the screen recording engine from feat(mobile-android): add screen recording #4767 and writes the screen with the microphone, plus the camera when it is on, as fragmented MP4 segments into a project under noBackupFilesDir/studio. The foreground service types are mediaProjection, plus microphone and camera on API 30 and later (they do not exist on API 29). It records from the front camera, or the back camera when a phone has no front one. When recording stops, TrackFiles joins each track's segments and muxes screen and microphone together. The camera's start offset against the screen is stored so the two line up. The notification reads "Tap to stop and edit it in Studio".
  • Project model. StudioProject mirrors desktop Cap's project configuration: clips, background (wallpaper, gradient or colour), padding, rounding, shadow, camera position, size, shape and mirroring, and zoom segments. The desktop gradient presets and eight of its wallpapers are included. StudioLayout lays out the frame the same way for the live preview and the export, including the eased zoom and the camera shrinking while zoomed in. UndoHistory keeps 100 steps.
  • Editor. Clips, Background, Camera and Zoom panels over a live preview. The preview, timeline and filmstrip are the existing Cap editor's, reused through a small PreviewPlayback interface instead of a fork. The camera track plays muted alongside the screen.
  • Export. Media3 Transformer 1.11.1 with H.264 and AAC. The encoder list puts hardware encoders first and allows fallback. The screen sequence carries the background, padding, rounded corners, shadow and zoom; the camera is a second sequence composited on top. The Media3 compositor draws the first input last, so the screen layer cuts a rounded hole where the camera sits instead of covering it. After export the user can upload to Cap through the existing upload pipeline, share through a FileProvider limited to cache/exports, or save to Movies/Cap through MediaStore. A failed export shows an error saying what went wrong, for example that the phone's encoder could not handle it, and the recording is left untouched.
  • Clean-up. Signing out discards an unfinished Studio recording and removes every project and shared export. Deleting a project removes its tracks and its export.

Dependencies and size

  • New: androidx.media3:media3-transformer and media3-effect 1.11.1, from the existing media3 version catalogue entry. With what they bring in, the release runtime classpath goes from 195 to 203 artefacts: media3-transformer, media3-effect, media3-muxer, kotlinx-coroutines-guava, JSR 305, Error Prone annotations and J2ObjC annotations, all Apache 2.0, and Checker Framework qualifiers 3.43.0, MIT, each read from its POM. The README licence table is updated.
  • Release APK (app-release-unsigned.apk, R8 on): 6,971,541 bytes at 327fd2925, the base of this PR, and 7,993,102 bytes at 4f015387b, so 1,021,561 bytes more (7,994,030 bytes at 5dd38f373, after the review fixes, and at 43667eb6d and f0d3e38b52, after merging the polish branch). DEX grows by 381,140 bytes, for Media3 Transformer and Effect plus the new code, and compressed resources by 610,401 bytes, mostly the wallpapers. The wallpapers are already WebP at 1280 by 800 and about quality 75, eight of them totalling 567,534 bytes. Re-encoding them from the desktop originals saved 2 per cent at the same quality, so they are unchanged.
  • R8: :app:testReleaseShrunkUnitTest passes with the new dependencies.

Security

  • StudioRecordingService is not exported and only starts from the app after the system screen capture consent.
  • The FileProvider (${applicationId}.files) is not exported, grants read access per share intent only, and exposes only cache/exports.
  • Recordings stay in noBackupFilesDir, so they are not part of cloud backups, and are removed on sign-out. Saving to Movies/Cap uses MediaStore with IS_PENDING and needs no storage permission.
  • The only new permission in the merged manifest is FOREGROUND_SERVICE_CAMERA. CAMERA was already there and is now also declared by the app, which lint requires for the camera service type.

Screenshots

API 35 phone emulator, dark, from the debug gallery at 4f015387b. The last two are frames from a real export made on the emulator: a red background, then a zoom with the camera bubble shrunk on top.

Recorder Clips Background
Recorder in Studio Mode Studio editor, clips Studio editor, background
Camera Zoom Export
Studio editor, camera Studio editor, zoom Export sheet
Exporting Exported frame Exported frame, zoomed
Export in progress Exported frame with a red background and the camera on top Exported frame while zoomed in

Fixed after review

  • Quick edits overwriting each other (079305824, cee19bf0d). Every edit started its own save, and all of them wrote through the same temporary file, so two quick edits could overwrite each other or leave an older one on disk. Edits now go through one queue that saves them in order, and a failed save shows "Cap couldn't save your changes." instead of being dropped. The queue belongs to the app's Studio projects rather than the editor, so closing the editor straight after an edit cannot cancel its save, and an edit still waiting to be written is what the project loads as if it is opened again. Tests: StudioProjectsTest.editsSaveInTheOrderTheyWereMadeAndTheLastOneWins, aProjectOpenedAgainBeforeItsLastEditIsWrittenShowsThatEdit and aFailedSaveIsReportedAndTheNextEditStillSaves.
  • A failed save losing the recording (ac90f47ac, 0c4ea2426). Joining and muxing the tracks deleted the recorded segments even when it failed, for example on a full disk, and then deleted the project. The service now writes the recording's details next to its segments before assembling them, and keeps both if assembly fails, with a notification asking to free up space and open Cap. Each time Cap comes to the foreground it finishes any such recording and opens it in the editor. Tests: StudioTest.aRecordingThatCannotBeSavedKeepsItsTracksUntilCapCanFinishIt, which makes the real muxer fail on the device by putting a folder where screen.mp4 goes, then sends Cap to the background and back, and StudioProjectsTest.aRecordingWithADraftButNoProjectIsUnfinishedUntilItIsFinished. If even the small details file cannot be written, the tracks are still kept, but Cap cannot finish that recording by itself.
  • A Studio project that no longer exists (5dd38f373). Opening one, for example after signing out while its saved notice was pending, left the editor on a loading spinner. It now closes and returns to the library. Test: StudioTest.aStudioProjectThatIsGoneClosesInsteadOfLoadingForever.
  • Uploads lost during a brief storage outage. The upload engine lower in the stack discarded an upload when storage asked it to send again later. b24ce21d41 retries it instead, and this PR includes that fix through the merge in 43667eb6d.
  • A copied link marked late. The recording coordinator lower in the stack copied a recording's link before marking it as copied, so anything reading the recording as soon as the link reached the clipboard could still see it unmarked. 5d4081dc15 marks it first, and this PR includes that fix through the merge in f0d3e38b52.
  • The camera playing early in the preview (4eabbf8c4). When the camera started after the screen, the preview clamped the camera clip to its start and played it early, while the export put a gap before it. The preview now waits out that gap clip by clip and hides the camera bubble until it starts. Reading the export path again for the same mismatch found the camera cutout skipped for the first seconds of the output whatever had been trimmed; it now follows the same per clip rule. Tests: CameraClipsTest, 6 cases.
  • A recording whose saving could not finish (80c259aa3). 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). Studio treated any screen failure as a lost recording and deleted the project. It now saves the kept screen track, drops a camera track that did not finish as it does for other camera failures, and the saved notification says "Couldn't finish saving, N s kept". An encoder that stops answering cannot be forced on the emulator, so this has no test of its own.

Each new test fails with its fix taken out and passes with it in place.

Tests

At f0d3e38b52, after merging the polish branch at fe5ddde9b5: spotlessCheck :capkit:test :app:testDebugUnitTest :app:lintDebug :app:assembleDebug :app:assembleRelease :app:assembleDebugAndroidTest :media:testDebugUnitTest :media:lintDebug :app:testReleaseShrunkUnitTest passes, with lint reporting no errors or warnings.

  • capkit: 296 tests, 23 new. UndoHistoryTest (4), StudioTest (9: defaults, typed backgrounds through JSON, the desktop gradient presets, adding, moving and clamping zooms, trimming) and StudioLayoutTest (10: padding, rounding, aspect ratio, camera corner and size, the zoom window and its easing, export sizes).
  • JVM, :app:testDebugUnitTest: 567 tests. New: StudioProjectsTest (8: a saved project loads back, projects list newest first and skip unreadable folders, deleting a project removes its tracks and export, removing everything removes shared exports, and the four above) and CameraClipsTest (6).
  • Shrunk release classes: 3 tests. Media module: 66 tests.

With the drain deadline, the check line passes at the top of the Android stack, 276cfebaa, which contains 80c259aa3, and StudioTest passed 14 of 14 on API 35 there.

Device runs

Against the fixture server, with emulators booted with an emulated front and back camera. The merge in f0d3e38b52 changes only the recording coordinator and its JVM test, so these runs were not repeated after it.

  • API 35 (phone, 1080 by 2424). RecorderTest, MainShellTest, ScreenRecordingTest and StudioTest together: 21 of 21 on a local build from before the branch was rebased onto the current polish branch, and 20 of 21 on the first local build after the rebase. The failure was the export test's video duration check: with a still screen the recorder writes no new frames, so the source video ended 0.26 s before its audio. The check now allows for the gap already in the source (4f015387b). At 5dd38f373, all four classes pass 23 of 23, including the two new StudioTest cases. At 43667eb6d, after merging the final polish branch, 23 of 23 again, with nothing in the crash buffer.
  • StudioTest records a real session through the system consent dialog. It checks that the screen and camera are separate files with the expected tracks, opens the editor and uploads the export, and checks that a failed export keeps the recording. It also reads frames from an export to confirm the background, the zoom starting at the right moment and the camera drawn on top.
  • API 37, on that first local build after the rebase: 19 of 21. Recording works, including the camera foreground service during screen capture: the system logs "Background started FGS: Allowed" for every Studio start. The failed-export test passes. The 2 failures are both exports. On this emulator image every MediaCodec decoder in the app fails on its first input: c2.android.aac.decoder and c2.goldfish.h264.decoder both log Failed to send buffer with BufferPool. Error: 4 and then queueCSDInputBuffer failed w/ error 14. This is the same decoder failure seen on this image in feat(mobile-android): polish large screens, accessibility and release builds #4768, where fixture video could not play. Encoding works. At 43667eb6d, on a freshly wiped emulator: 21 of 23. The review fixes pass here too, including the recording kept when it cannot be saved and finished when Cap comes back, and the project that no longer exists. The 2 failures are the same two exports, with the same decoder errors in the log and nothing in the crash buffer. Export on Android 17 still needs checking on a real phone.

Left out

Captions, zooms driven by taps, scene and layout segments, and editing a project on another device. Desktop Cap has these, but none fits this first version. Screenshot Mode follows in the next PR.

Confidence Score: 0/5RetriggerView in Greptile

The import fix is sound, but earlier problems with device-test compilation, saved projects, navigation, and uploads still block merging.

Findings

  1. P1 Cancelling can crash Cap ▶
  2. P1 Saved projects cannot reopen ▶
  3. P1 Tablet sidebar actions break ▶
  4. P1 Organization analytics becomes unreachable ▶
  5. P1 Background upload results disappear ▶
  6. P1 Device tests cannot compile ▶
  7. P2 Small blue text loses contrast ▶
  8. P2 Cancelled uploads still look active ▶
  9. P2 Shortcuts forget the screen choice ▶
  10. P2 Studio ignores source choices ▶
Fix with agent prompt
### Issue 1
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/services/UploadActions.kt:64-65
If storage is full, `pendingUploads.remove(capId)` can throw `IOException` while writing `pending.json`, before it deletes the staged file. This standalone coroutine has only `finally`, so the exception escapes and crashes Cap after the worker has already been cancelled. The saved upload record and staged file remain.

Catch the storage failure, keep cleanup retryable, and report that cancellation could not finish.

### Issue 2
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/record/RecordScreen.kt:undefined-823
Changing `onLibrary` to `onOpenLibrary` removes the only way to reopen a saved Studio project. `Controls` still receives `lastProject` and `onOpenStudio`, but no longer uses them. After closing the editor or restarting Cap, users can only open the uploaded Caps library, which does not list local Studio projects. Keep a separate action for continuing the saved project.

### Issue 3
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/MainShell.kt:316-321
With `[Main, Caps, Cap]`, the tablet still shows the library sidebar, but this guard rejects folder taps because `backStack` ends with the selected Cap. The sidebar's close callback and the folder's back callback also remove the selected Cap instead of leaving their own page. Use `CapsPath` or `openFromLibrary` to target the sidebar rather than the last entry in the full stack.

### Issue 4
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/MainShell.kt:420-425
The shell removes the Analytics tab and organization-wide route without adding another entry. The only remaining production call to `AnalyticsScreen` uses `AnalyticsScope.Cap`. Users can no longer see organization totals, filter by space, or open Top Caps. Keep organization analytics reachable from the new navigation.

### Issue 5
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 listening, despite `extraBufferCapacity`. `RecordingUploadWorker` can resume after a process restart without opening `MainActivity`, which is the only place that starts the event listener. Completion or failure events then disappear, leaving final notification updates missing. Opening Cap later cannot recover a dropped completion because the saved job has already been deleted.

The old channel kept these events. Keep them until the coordinator receives them, or start a listener before background uploads resume.

### Issue 6
apps/mobile-android/app/src/androidTest/kotlin/so/cap/mobile/StudioTest.kt:54-59
`StudioTest` now imports features missing from this branch, including `CaptionSettings`, `DeviceFrames`, and `StudioBatch`. It also calls missing helpers and passes `motionBlur` and `captions` to `startStudioExport`, which accepts neither argument. This prevents `:app:assembleDebugAndroidTest` from compiling, so none of the device tests can run.

Keep these tests with the production changes they cover, and restore calls that match this branch.

### Issue 7
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/designsystem/Color.kt:159-160
`LightColorScheme.primary` now uses `#4785FF` against `#FCFCFC`, giving about 3.4:1 contrast instead of the previous colour’s roughly 4.8:1. Links, transcript timestamps, and text buttons use this colour. Selected library chips also put white text on this blue. This makes these labels harder to read, especially for people with low vision.

Keep the brand blue for decoration, but use a darker text colour in light mode and a readable foreground for filled chips.

### Issue 8
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/services/UploadActions.kt:undefined-57
Cancelling a recording upload calls `discard()`, but `RecordingCoordinator` ignores the resulting `Discarded` event. The recent recording stays “Uploading,” and its `LiveUpdate` timer posts the cancelled notification again after 45 seconds.

Route cancellation through the coordinator so it removes the recent item and stops its notification updates before clearing the notification.

### Issue 9
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/record/RecordScreen.kt:745-747
The new “Use screen” action changes `model.mode` but does not save the choice, unlike the existing mode picker. A later Instant widget or tile start reads the old camera choice and switches back to Camera. This sends users who chose the fallback because camera access was unavailable back to the same blocked mode.

Call `capture.setInstantMode(RecordMode.SCREEN.name)` here too.

### Issue 10
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/record/RecordScreen.kt:837-843
The new Camera/Screen picker also appears in Studio, but it changes only `model.mode`. The shutter still starts `StudioRecordingService` with the separate `studioCamera` setting. Selecting Screen therefore leaves the camera enabled while showing Screen as selected.

Show this picker only in Instant mode, where these choices work.

---

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

Summary

This update restores the missing Compose clip import in RecordScreen.kt.

  • Studio Mode records screen, microphone, and camera tracks on Android.
  • Studio projects can be styled, trimmed, zoomed, and exported on the phone.
  • Cap’s Android app brings its mobile screens and recording tools to Android.
  • Mobile sign-in carries a per-attempt state, and Cap sharing choices have an owner-only endpoint.

Reviews (57) · Last reviewed commit: "Merge branch 'final-round/importfix-poli..." · 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.

@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

2 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

3 similar comments
@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

Comment on lines +159 to +160
primary = CapColorTokens.Blue,
onPrimary = CapColorTokens.White,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Small blue text loses contrast

LightColorScheme.primary now uses #4785FF against #FCFCFC, giving about 3.4:1 contrast instead of the previous colour’s roughly 4.8:1. Links, transcript timestamps, and text buttons use this colour. Selected library chips also put white text on this blue. This makes these labels harder to read, especially for people with low vision.

Keep the brand blue for decoration, but use a darker text colour in light mode and a readable foreground for filled chips.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/mobile-android/app/src/main/kotlin/so/cap/mobile/designsystem/Color.kt
Line: 159-160

Comment:
**Small blue text loses contrast**

`LightColorScheme.primary` now uses `#4785FF` against `#FCFCFC`, giving about 3.4:1 contrast instead of the previous colour’s roughly 4.8:1. Links, transcript timestamps, and text buttons use this colour. Selected library chips also put white text on this blue. This makes these labels harder to read, especially for people with low vision.

Keep the brand blue for decoration, but use a darker text colour in light mode and a readable foreground for filled chips.

---

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

@AatmanAJ

AatmanAJ commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

1 similar comment
@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

2 similar comments
@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

The camera track starts a few hundredths of a second after the screen, so
the export hid the camera for its first frame while the editor preview
already held the camera's first frame across that lead (781b18c). The
export now does the same: for up to CAMERA_HOLD_MILLIS before the camera
footage starts, the camera sequence shows its first frame as a still
image, and the overlay and cutout treat that time as covered.

The synthetic video helper moves out of StudioPreviewTest so the new
export test can build a project whose camera starts 40 ms late.
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.
…ng settings

The settings tests leave a ten second countdown with the camera and
microphone off, so Studio tests that ran after them waited out a longer
countdown than the bounded recording wait allows. Each Studio test now
sets the recording defaults it relies on before it opens the recorder.

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