Skip to content

Feat/android fgs survive task removal - #1234

Open
mdydek wants to merge 9 commits into
mainfrom
feat/android-fgs-survive-task-removal
Open

Feat/android fgs survive task removal#1234
mdydek wants to merge 9 commits into
mainfrom
feat/android-fgs-survive-task-removal

Conversation

@mdydek

@mdydek mdydek commented Aug 17, 2026

Copy link
Copy Markdown
Member

Closes #

⚠️ Breaking changes ⚠️

  • get rid of the icons in the recording notification, the ui is different based on the manufacturer, android versions, thus the current approach is to fallback to simple text buttons, which will be placed by the system possibly in the correct arrangement

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web
  • Updated old arch android spec file

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

WPT non-regression comparison

ERROR — the comparison did not produce a report; the test run itself likely failed.

Workflow run · this comment is updated on every push.

@mdydek
mdydek marked this pull request as ready for review August 20, 2026 11:38
@closetcaiman closetcaiman added feature New user-facing features or major capabilities android Native Android implementation, C++/Java/Kotlin bindings, or Android-specific issues labels Aug 20, 2026
</TabItem>
</Tabs>

### Keeping the recording alive when the app is closed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this android specific? Maybe we could add a badge?

assignOnErrorCallbackId(0);
}
void assignOnErrorCallbackId(uint64_t callbackId);
// Defined inline so AudioRecorder.cpp doesn't drag this class's whole

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible to omit/reduce this trip to gain access to Recorder?

@closetcaiman
closetcaiman requested review from maciejmakowski2003 and a lite review from Copilot and removed request for Copilot August 24, 2026 08:22
michalsek and others added 8 commits August 27, 2026 21:20
The recording notification's pause, resume and stop actions now act on the
recorder natively, so they keep working after the app task is removed while
the foreground service (stopWithTask=false) keeps the recording alive:

- ActiveRecorderHandle: process-global one-slot handle to the live recorder
  (registered by AudioRecorderHostObject), with a consume-once stash of the
  file info produced by a native stop
- NativeRecorderControl: static-JNI entry points callable from Kotlin without
  a React context; the notification receiver stops/pauses/resumes through it
  on an executor and still emits the matching AudioEvent so a live app can
  sync its UI (new event: RECORDING_NOTIFICATION_STOP)
- RecordingNotification rewritten to standard NotificationCompat actions
  (RemoteViews layouts removed), rebuilt on every show(); adds stop action,
  action titles, deepLinkUri tap routing (ACTION_VIEW) and a chronometer that
  excludes paused spans; native pause/resume re-post the notification so the
  action button flips without JS
- onErrorAfterClose now restores the pre-teardown state after a stream
  reclaim instead of force-resuming a paused recording

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
With stopWithTask=false a recording outlives the app UI, but a remounted
screen (or relaunched app) had no way to learn about it — recorder state was
only reachable through the instance that started it:

- new JSI globals backed by ActiveRecorderHandle, surfaced as statics:
  AudioRecorder.isRecordingOngoing() and the consume-once
  AudioRecorder.takeLastRecordingResult() for files finalized by the
  notification stop action (mock parity + jest coverage included)
- Record demo mounts directly in the live recorder's state, picks up
  natively stopped files, keeps the recording alive across screen exits and
  only enables file output when no session is ongoing (re-enabling
  mid-recording replaces the writer and resets the duration)
- deep-link routing for the notification tap (react-navigation linking),
  duration displays seeded from the recorder instead of assuming a fresh
  session, and RecordingTime rewritten to plain state — the animated-prop
  binding went stale on the frozen value while paused and showed zeros

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@michalsek
michalsek requested a balanced review from Copilot August 27, 2026 19:42

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@michalsek
michalsek force-pushed the feat/android-fgs-survive-task-removal branch from a16212c to 6dd83cf Compare August 27, 2026 19:45

@michalsek michalsek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a bit of comments for later 👉 👈

Comment on lines +24 to +26
// A recording can outlive this screen (and, with `stopWithTask: false`, the whole
// app UI). Mounting directly in the right state lets every child initialize from
// the live recorder instead of transitioning out of a transient Idle render.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// A recording can outlive this screen (and, with `stopWithTask: false`, the whole
// app UI). Mounting directly in the right state lets every child initialize from
// the live recorder instead of transitioning out of a transient Idle render.
// Recover from "app disabled" state - recording can survive the app kill (android)

Comment on lines +160 to +161
// The stop action already stopped the recorder natively and hid the notification;
// here we only pick up the resulting files and sync the UI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// The stop action already stopped the recorder natively and hid the notification;
// here we only pick up the resulting files and sync the UI.

Comment on lines +328 to +329
// Re-enabling file output during an ongoing recording replaces the file writer,
// which starts a new file and resets the duration — skip it when resyncing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Re-enabling file output during an ongoing recording replaces the file writer,
// which starts a new file and resets the duration — skip it when resyncing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

might be also worth changing on the native side to handle that and make enable a no-op in that case

Comment on lines +335 to +336
// The recording and its notification intentionally stay alive when leaving this
// screen; they can be stopped from the notification or after coming back.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// The recording and its notification intentionally stay alive when leaving this
// screen; they can be stopped from the notification or after coming back.

Comment on lines +339 to +341
if (!AudioRecorder.isRecordingOngoing()) {
AudioManager.setAudioSessionActivity(false);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

Comment on lines +81 to +102
/**
* Shows a stop action that ends the recording natively — it works even when
* the app task has been removed and JS is unreachable. A live app is
* additionally notified through the `recordingNotificationStop` event.
* Default: false.
*/
showStopAction?: boolean;
/** Label of the pause action. Default: 'Pause'. */
pauseActionTitle?: string;
/** Label of the resume action. Default: 'Resume'. */
resumeActionTitle?: string;
/** Label of the stop action. Default: 'Stop'. */
stopActionTitle?: string;
/**
* URI attached to the notification tap intent, e.g. `myapp://record`.
* Delivered through React Native's `Linking` (initial URL on cold start,
* `url` event otherwise), so it can route to a specific screen. Without it,
* tapping the notification opens the app's launcher activity.
*/
deepLinkUri?: string;
/** Shows the elapsed recording time in the notification. Default: false. */
usesChronometer?: boolean;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

jsdoc-style

Comment on lines +18 to +23
/**
* Controls `android:stopWithTask` on the injected foreground service. When
* false, swiping the app away from recents keeps the service — and therefore
* the app process and any in-progress recording — running (Android calls
* onTaskRemoved instead of stopping the service). Defaults to true.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Controls `android:stopWithTask` on the injected foreground service. When
* false, swiping the app away from recents keeps the service and therefore
* the app process and any in-progress recording running (Android calls
* onTaskRemoved instead of stopping the service). Defaults to true.
*/

Comment on lines +59 to +67
/**
* Checks whether a recording session is ongoing (recording or paused). Native
* source of truth that needs no reference to the recorder instance, so a
* remounted screen (e.g. after navigating away and back, or reopening an app
* whose recording kept running under an Android foreground service with
* `stopWithTask: false`) can seed its UI state from it. Reflects the most
* recently created `AudioRecorder` — constructing another instance
* mid-recording displaces the probed one.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Checks whether a recording session is ongoing (recording or paused). Native
* source of truth that needs no reference to the recorder instance, so a
* remounted screen (e.g. after navigating away and back, or reopening an app
* whose recording kept running under an Android foreground service with
* `stopWithTask: false`) can seed its UI state from it. Reflects the most
* recently created `AudioRecorder` constructing another instance
* mid-recording displaces the probed one.
*/

Comment on lines +72 to +79
/**
* Returns the file info of a recording that was stopped natively (via the
* recording notification stop action, which finalizes the files even when no
* JS listener is reachable), or `null` if there is none. Consume-once: the
* result is cleared on read, so a second call returns `null`. Recordings
* stopped through {@link stop} resolve their promise with the file info
* instead and never appear here.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Returns the file info of a recording that was stopped natively (via the
* recording notification stop action, which finalizes the files even when no
* JS listener is reachable), or `null` if there is none. Consume-once: the
* result is cleared on read, so a second call returns `null`. Recordings
* stopped through {@link stop} resolve their promise with the file info
* instead and never appear here.
*/

assignOnErrorCallbackId(0);
}
void assignOnErrorCallbackId(uint64_t callbackId);
// Defined inline so AudioRecorder.cpp doesn't drag this class's whole

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤔

title?: string;
contentText?: string;
paused?: boolean; // flag indicating whether to display pauseIcon or resumeIcon
paused?: boolean; // flag indicating whether to display the pause or the resume action

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
paused?: boolean; // flag indicating whether to display the pause or the resume action
paused?: boolean;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android Native Android implementation, C++/Java/Kotlin bindings, or Android-specific issues feature New user-facing features or major capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants