Skip to content

feat(app): allow configurable and accessible audio storage folder (#4702) - #17543

Closed
TheRWX wants to merge 1 commit into
BasedHardware:mainfrom
TheRWX:feat/accessible-audio-storage
Closed

TheRWX wants to merge 1 commit into
BasedHardware:mainfrom
TheRWX:feat/accessible-audio-storage

Conversation

@TheRWX

@TheRWX TheRWX commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4702

Allows users to configure an accessible storage directory (such as Music/Omi or Documents/Omi) for batch audio recordings instead of being restricted to sandboxed app documents storage (Android/data/com.friend.ios/), which is inaccessible in modern Android (API 30+) Scoped Storage without ADB/root.

Key Changes

  1. Configurable Storage Preference: Added customAudioStorageDir getter/setter on SharedPreferencesUtil in app/lib/backend/preferences.dart.
  2. Precedence Resolution: Added resolveBatchAudioDirectoryPath(...) (pure precedence engine), resolveEffectiveBatchAudioDirectory() (async runtime resolver), and setCustomAudioStorageDirectory() (atomic preference updater with fallback synchronization) in app/lib/utils/batch_recording.dart.
  3. Capture Controller Hardening: Replaced unconditional directory overwrites in CaptureController (setBatchMode, _initiateDeviceAudioStreaming, and _startPhoneMicBatch) to use resolveEffectiveBatchAudioDirectory().
  4. Local Recordings & Playback Integration:
    • Updated LocalRecordingsProvider._dir() to scan the effective batch audio directory.
    • Updated Wal.getFilePath() in wal.dart to inspect customAudioStorageDir and batchAudioDir before falling back to getApplicationDocumentsDirectory(), ensuring uninterrupted playback and waveform generation.
  5. Transcribe Later Settings UI: Added an "Audio Storage Folder" section in the Transcribe Later modal sheet (app/lib/pages/settings/profile.dart) featuring the active folder path, a folder picker (FilePicker.platform.getDirectoryPath), and a reset action.

Verification & Testing

  • Unit Tests (test/unit/batch_audio_directory_resolution_test.dart):
    • Pure precedence resolution (custom > configured > default).
    • Blank/whitespace string handling.
    • Filesystem existence checks and automatic fallback.
    • Setting and resetting custom audio storage directories.
    • LocalRecordingsProvider discovery of files in custom storage.
    • Wal.getFilePath() resolution across custom and fallback locations.
  • Widget Tests (test/widgets/audio_storage_folder_sheet_test.dart):
    • Verified UI rendering of current storage folder.
    • Verified folder change interaction and reset-to-default button behavior.
  • Regression Tests:
    • test/unit/local_recordings_owner_test.dart (5/5 passed).
    • test/unit/local_recordings_auto_upload_test.dart (14/14 passed).
  • Static Analysis & Preflight:
    • flutter analyze on touched/new files: 0 issues found.
    • scripts/pr-preflight: 20/20 checks passed cleanly.

Failure-Class: none
PayPal: [email protected]

Review in cubic

…sedHardware#4702)

Allow users to select an accessible storage directory (such as
Music/Omi or Documents/Omi) for batch audio recordings instead of
being restricted to sandboxed app documents storage
(Android/data/com.friend.ios/).

- Add customAudioStorageDir preference in SharedPreferencesUtil
- Add resolveEffectiveBatchAudioDirectory and setCustomAudioStorageDirectory
  in batch_recording.dart
- Update capture_controller.dart to preserve configured audio directories
  instead of clobbering with default app documents directory
- Update LocalRecordingsProvider and Wal.getFilePath to scan and resolve
  recordings from custom directory with transparent fallback to default
- Add directory picker and reset controls in Transcribe Later sheet
- Add comprehensive unit and widget tests for precedence resolution,
  filesystem fallbacks, directory scanning, and settings UI

Closes BasedHardware#4702
Failure-Class: none
PayPal: [email protected]
@TheRWX
TheRWX requested a review from mdmohsin7 as a code owner September 23, 2026 16:12

@Git-on-my-level Git-on-my-level 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.

Thanks @TheRWX — this tackles a long-standing maintainer-labeled request (#4702) and the Dart-side engineering is genuinely tidy. Verified the full wiring: setCustomAudioStorageDirectory() syncs the existing batchAudioDir pref, which the native writers (OmiBatchAudioWriter.loadConfig() on Android, BatchAudioWriter.swift on iOS) read at session bring-up, and file_picker (8.3.2) is already on main — no new dependency. I'm requesting changes for one blocking platform issue plus smaller items.

Blocking: scoped storage makes user-picked folders unwritable on Android 11+

The native writers create files via raw java.io (BaseBatchAudioWriter.openLocked(): dir.mkdirs() then RandomAccessFile(file, "rw")), and .bin is not a media type. The app targets SDK 36 and the manifest's requestLegacyExternalStorage="true" is ignored from Android 11 on; there is no MANAGE_EXTERNAL_STORAGE permission or persisted SAF grant, and file_picker returns a plain path string with no durable URI access. On exactly the devices this feature targets (issue #4702 is about Android/data being inaccessible on modern Android), picking Music/Omi will make openLocked() fail and the writer silently drops frames — recordings stop landing anywhere. The new tests exercise the resolver and the sheet but never run the native writer, so green CI does not cover this path. This needs a mechanism decision (SAF DocumentFile with persisted permissions, MediaStore-compatible formats, or another route) before this shape can work.

Per-file notes:

  • app/lib/backend/preferences.dart — clean additive customAudioStorageDir getter/setter, empty default means no migration concern.
  • app/lib/utils/batch_recording.dart — resolveBatchAudioDirectoryPath()/resolveEffectiveBatchAudioDirectory() precedence is clear and well tested. One real bug in setCustomAudioStorageDirectory(): await dir.create(recursive: true) is wrapped in catch (_) {}, and on Android the create is exactly what will fail for shared-storage paths — the sheet then shows the picked folder as active while the resolver silently falls back to app storage. Please surface the failure (snackbar + don't persist) instead of swallowing it.
  • app/lib/pages/settings/profile.dart — isScrollControlled: true + SingleChildScrollView and the mounted checks are all correct. The new section's strings ('Audio Storage Folder', 'Change Folder', 'Reset', 'Default App Storage …', 'Failed to select folder: …') are hardcoded while the rest of this sheet uses context.l10n — please localize. Also a UX note: switching folders doesn't migrate existing recordings and LocalRecordingsProvider.refresh() scans only the effective directory, so previously recorded items disappear from the Transcribe Later list until Reset; a one-line hint would avoid confusion.
  • app/lib/providers/local_recordings_provider.dart — consolidating _dir() onto the shared resolver is the right deduplication.
  • app/lib/services/capture/capture_controller.dart — all three sites (setBatchMode, _initiateDeviceAudioStreaming, _startPhoneMicBatch) now persist the resolved dir instead of unconditionally overwriting it with app-docs; this correctly preserves the custom choice the old code would have clobbered.
  • app/lib/services/wals/wal.dart — getFilePath()'s custom → configured → docs fallback keeps playback/waveform working for files left in the old location, and the startsWith('/') short-circuit is sensible. The _fs${frameSize} → _${frameSize} interpolation change in getFileName()/getFileNameByTimeStarts() renders identically, but since _fsN is a parsed filename contract (BatchRecordingInfo.fromFileName() and desktop WALModel.swift match on it), it would be safer to drop that cosmetic hunk to keep the diff focused.
  • app/test/unit/batch_audio_directory_resolution_test.dart and app/test/widgets/audio_storage_folder_sheet_test.dart — good coverage of precedence, whitespace handling, existence fallback, set/reset, and sheet rendering; the only gap is the native-write path, which flutter test cannot reach.

iOS note: FilePicker.getDirectoryPath() on iOS does not persist a security-scoped bookmark here, so access to the picked folder may not survive relaunch/reinstall — worth verifying on device before merge.

Leaving for human maintainer review: this needs a storage-mechanism product decision (SAF/MediaStore vs alternatives) and on-device verification, not just code fixes.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (configurable audio storage folder) — approve only per policy; already has CHANGES_REQUESTED from another reviewer, DIRTY.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (configurable audio storage folder) — approve-only per policy. Leaving reviewer's engineering concerns for maintainer follow-up; not merging.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (configurable audio storage folder) — approve-only per policy. CHANGES_REQUESTED (Git-on-my-level, previously verified substantive) remains open; leaving for maintainer follow-up, not merging.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (configurable audio storage folder) for open issue #4702 — approve only per policy, not a bug fix. CHANGES_REQUESTED from a reviewer flags a real Android scoped-storage gap (SAF/MediaStore needed); leaving for maintainer follow-up, not merging.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (configurable audio storage folder, #4702) — approve-only per policy; not merging (feature + DIRTY + open reviewer concerns).

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this contribution! Our review requested some changes (see above) and we haven't heard back in a while. If you're still working on it, just push a commit or leave a comment within the next 7 days. To keep the queue healthy we'll close this PR in 14 days if it stays inactive — and it can always be reopened once updates land. Happy to re-review!

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Oct 11, 2026
@TheRWX

TheRWX commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Still active on this — thanks for the thorough review.

The scoped-storage blocker is right: raw java.io writes into a file_picker path won't work on Android 11+. Before I change the native writers, I'd like a maintainer decision on the mechanism. My proposal:

  • Persisted SAF grant (ACTION_OPEN_DOCUMENT_TREE + takePersistableUriPermission), storing the tree URI instead of a path.
  • Writing .bin files through DocumentFile / ContentResolver in BaseBatchAudioWriter.openLocked(), falling back to app-private storage if the grant is revoked.
  • Surfacing failures (no silent frame drops) and not persisting a folder that can't be written.

Does that route work for you, or would you prefer MediaStore or another approach? Once there's a direction I'll implement it, rebase onto current main, and also address the smaller items (surfaced create error, localized strings, reverting the wal.dart hunk, a migration hint). Holding the PR at its current head until then.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @TheRWX 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

@aryanorastar aryanorastar removed the stale-candidate Candidate for kind stale follow-up label Oct 20, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Closing due to inactivity after requested changes — this is not a reflection on the idea. Feel free to reopen (or open a fresh PR referencing this one) whenever the updates are ready, and we'll gladly re-review. Thanks again for contributing!

@github-actions

Copy link
Copy Markdown
Contributor

Hey @TheRWX 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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

Labels

flutter flutter work needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the folder where the app stores audio files to make it accessible.

4 participants