Skip to content

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

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

AatmanAJ wants to merge 886 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: 1/5RetriggerView in Greptile

Do not merge until organization-only sharing, empty-library navigation, and background countdown starts are fixed.

Findings

  1. P1 Security Organization-only sharing can expose recordings ▶
  2. P1 Empty spaces hide library navigation ▶
  3. P1 Countdown survives leaving Cap ▶
  4. P2 Empty libraries hide upload feedback ▶
  5. P2 Small blue text loses contrast ▶
Fix with agent prompt
### Issue 1
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/cap/MoreMenu.kt:237-242
If the organization has no email restriction, choosing “Only people in your organization” publishes a private recording to anyone with its link. This row always sends `LinkAccess.RESTRICTED`, but the server enforces that choice only when `allowedEmailDomain` is nonempty.

Only offer this choice when the server reports that organization restrictions are available; otherwise keep the recording private.

**How this was verified:** The organization row publishes the recording, while `VideosPolicy` checks email access only when the organization has a nonempty email restriction.

### Issue 2
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/home/LibraryContent.kt:124-125
Opening an empty shared space sets `showsDesignedEmpty` to true. Passing `showsDetails = false` then removes `ScopeBar`, which contains the only controls for switching to My Caps or another space. The selected space is saved across launches, so restarting does not restore those controls.

Keep the scope controls visible when the current collection is empty.

### Issue 3
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/record/RecordScreen.kt:139-144
The countdown job is cancelled only when the recorder leaves composition. `ON_STOP` pauses `RecordModel` but leaves the countdown running. If the user backgrounds Cap or locks the phone during a screen or Studio countdown, the delayed action still starts the foreground service. On Android versions that restrict background camera and microphone starts, this can throw instead of starting the recording.

Cancel pending starts when the activity stops, or wait until it is foregrounded again.

### Issue 4
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/features/home/LibraryContent.kt:141-155
The new empty-page branches skip `UploadBanner`. A first upload stays invisible while Cap prepares the file. If preparation fails, the library remains empty, so the error and dismiss action stay hidden too.

Render the upload banner outside the empty/nonempty choice.

### Issue 5
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.

---

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

Summary

Adds Android Studio recording, local editing, and export, along with recording defaults and redesigned library, playback, sharing, and settings pages.

  • Android users can sign in, browse Caps, and manage their recordings in Cap.
  • Studio recordings become editable phone projects that can be exported or shared.
  • Mobile sign-in callbacks return the state sent with each login attempt.
  • The mobile fixture server remembers the selected organization.

Reviews (15) · Last reviewed commit: "style(mobile-android): format the studio..." · 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.

Comment on lines +237 to +242
CapRadioRow(
stringResource(R.string.cap_audience_organization),
selected = cap.isPublic && restricted,
onClick = {
management.setAudience(isPublic = true, LinkAccess.RESTRICTED)
},

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.

P1 security Organization-only sharing can expose recordings

If the organization has no email restriction, choosing “Only people in your organization” publishes a private recording to anyone with its link. This row always sends LinkAccess.RESTRICTED, but the server enforces that choice only when allowedEmailDomain is nonempty.

Only offer this choice when the server reports that organization restrictions are available; otherwise keep the recording private.

How this was verified: The organization row publishes the recording, while VideosPolicy checks email access only when the organization has a nonempty email restriction.

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/features/cap/MoreMenu.kt
Line: 237-242

Comment:
**Organization-only sharing can expose recordings**

If the organization has no email restriction, choosing “Only people in your organization” publishes a private recording to anyone with its link. This row always sends `LinkAccess.RESTRICTED`, but the server enforces that choice only when `allowedEmailDomain` is nonempty.

Only offer this choice when the server reports that organization restrictions are available; otherwise keep the recording private.

**How this was verified:** The organization row publishes the recording, while `VideosPolicy` checks email access only when the organization has a nonempty email restriction.

---

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

Comment on lines +124 to +125
if (showsLibraryChrome) {
LibraryHeader(session, library, onAdd, showsDetails = !showsDesignedEmpty)

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.

P1 Empty spaces hide library navigation

Opening an empty shared space sets showsDesignedEmpty to true. Passing showsDetails = false then removes ScopeBar, which contains the only controls for switching to My Caps or another space. The selected space is saved across launches, so restarting does not restore those controls.

Keep the scope controls visible when the current collection is empty.

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/features/home/LibraryContent.kt
Line: 124-125

Comment:
**Empty spaces hide library navigation**

Opening an empty shared space sets `showsDesignedEmpty` to true. Passing `showsDetails = false` then removes `ScopeBar`, which contains the only controls for switching to My Caps or another space. The selected space is saved across launches, so restarting does not restore those controls.

Keep the scope controls visible when the current collection is empty.

---

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

Comment on lines +139 to +144
val countdownJob = remember { SupervisorJob() }
val countdown =
remember(countdownJob) {
RecordingCountdown(CoroutineScope(countdownJob + Dispatchers.Default))
}
DisposableEffect(countdownJob) { onDispose { countdownJob.cancel() } }

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.

P1 Countdown survives leaving Cap

The countdown job is cancelled only when the recorder leaves composition. ON_STOP pauses RecordModel but leaves the countdown running. If the user backgrounds Cap or locks the phone during a screen or Studio countdown, the delayed action still starts the foreground service. On Android versions that restrict background camera and microphone starts, this can throw instead of starting the recording.

Cancel pending starts when the activity stops, or wait until it is foregrounded again.

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/features/record/RecordScreen.kt
Line: 139-144

Comment:
**Countdown survives leaving Cap**

The countdown job is cancelled only when the recorder leaves composition. `ON_STOP` pauses `RecordModel` but leaves the countdown running. If the user backgrounds Cap or locks the phone during a screen or Studio countdown, the delayed action still starts the foreground service. On Android versions that restrict background camera and microphone starts, this can throw instead of starting the recording.

Cancel pending starts when the activity stops, or wait until it is foregrounded again.

---

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

Comment on lines +141 to +155
when {
showsDesignedEmpty -> {
LibraryEmptyState(Modifier.fillMaxSize())
}
loadedEmpty -> {
Box(Modifier.fillMaxSize(), Alignment.Center) {
EmptyState(
icon = R.drawable.ic_video_library,
title = stringResource(R.string.home_folder_empty_title),
modifier = Modifier.padding(horizontal = CapTheme.pageMargin),
description = stringResource(R.string.home_empty_space),
)
}
}
else -> {

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 Empty libraries hide upload feedback

The new empty-page branches skip UploadBanner. A first upload stays invisible while Cap prepares the file. If preparation fails, the library remains empty, so the error and dismiss action stay hidden too.

Render the upload banner outside the empty/nonempty choice.

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/features/home/LibraryContent.kt
Line: 141-155

Comment:
**Empty libraries hide upload feedback**

The new empty-page branches skip `UploadBanner`. A first upload stays invisible while Cap prepares the file. If preparation fails, the library remains empty, so the error and dismiss action stay hidden too.

Render the upload banner outside the empty/nonempty choice.

---

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

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