Skip to content

Conversation

@RKRitik
Copy link
Contributor

@RKRitik RKRitik commented Nov 22, 2025

While testing the app on my Android simulator, the app crashed when I tried to record Audio.
It happened due to not having RECORD_AUDIO permission on Android 14+
Added necessary check for this permission on clicking record.

Summary by CodeRabbit

  • Bug Fixes
    • Improved audio streaming reliability on Android 34+ by ensuring microphone permissions are properly validated before the foreground service starts.
    • Added user alerts when microphone permissions are denied, providing better feedback.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Added Android 34+ microphone permission handling to the audio streamer hook. Introduced ensureForegroundServiceMicPermission() helper that checks platform/version, requests RECORD_AUDIO permission (implicitly enabling FOREGROUND_SERVICE_MICROPHONE), and alerts on denial. Integrated into startForegroundServiceNotification() to ensure permission granted before service startup.

Changes

Cohort / File(s) Summary
Microphone foreground service permission handling
app/app/hooks/useAudioStreamer.ts
Added Alert import from react-native; introduced ensureForegroundServiceMicPermission() helper to validate Android 34+ RECORD_AUDIO permission with platform/version checks, permission requests, denial alerts, and logging; updated startForegroundServiceNotification() to await and enforce permission check before proceeding.

Sequence Diagram(s)

sequenceDiagram
    participant Code as Calling Code
    participant Start as startForegroundServiceNotification()
    participant Perm as ensureForegroundServiceMicPermission()
    participant Platform as Platform/Permissions API
    participant Alert as Alert Dialog

    Code->>Start: initiate
    Start->>Perm: await ensureForegroundServiceMicPermission()
    Perm->>Platform: check platform & version
    
    alt Android 34+
        Perm->>Platform: request RECORD_AUDIO
        Platform-->>Perm: permission result
        alt Permission Granted
            Perm->>Perm: log success
            Perm-->>Start: return true
            Start->>Platform: start foreground service notification
        else Permission Denied
            Perm->>Alert: show denial alert
            Perm->>Perm: log denial
            Perm-->>Start: return false
            Start->>Start: abort (early return)
        end
    else Pre-Android 34
        Perm->>Perm: log skipped
        Perm-->>Start: return true
        Start->>Platform: start foreground service notification
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Platform-specific conditional logic (Android 34+ version check) requires verification
  • Permission request error handling path and alert messaging should be validated
  • Integration point in startForegroundServiceNotification() to confirm proper async/await usage and early abort behavior

Poem

🐰 A rabbit's burrow needs good sound,
So on Android we've got our ground—
Permissions checked before the bell,
Microphone foreground services swell!
No more denied when we need to hear,
The audio streams crystal clear. 🎙️

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding a permission check for RECORD_AUDIO on Android 14+ versions to fix the crash.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@RKRitik
Copy link
Contributor Author

RKRitik commented Nov 22, 2025

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
app/app/hooks/useAudioStreamer.ts (3)

74-74: Improve Alert structure for better UX.

The Alert displays a very long message as the first parameter without a proper title. Consider restructuring to use separate title and message parameters for better readability and UX.

Apply this diff to improve the Alert structure:

-        Alert.alert('RECORD_AUDIO permission is required for microphone foreground service. Please grant microphone permission in app settings.');
+        Alert.alert(
+          'Microphone Permission Required',
+          'Please grant microphone permission in app settings to use the audio recording feature.',
+          [{ text: 'OK' }]
+        );

70-72: Consider adding a rationale for better permission request UX.

The permission request could benefit from providing a rationale explaining why the permission is needed. While the Alert handles denial, adding context upfront improves the user experience.

Consider adding a rationale to the permission request:

       const audioResult = await PermissionsAndroid.request(
-        PermissionsAndroid.PERMISSIONS.RECORD_AUDIO
+        PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
+        {
+          title: 'Microphone Permission',
+          message: 'This app needs microphone access to record and stream audio.',
+          buttonPositive: 'Allow',
+        }
       );

59-85: Consider requesting permission earlier in the user flow.

The permission is requested when starting the foreground service, which may interrupt the user experience at a critical moment. Consider requesting the RECORD_AUDIO permission earlier in the flow—such as during app onboarding, when the user first navigates to a recording screen, or when they tap a record button—before attempting to start the foreground service.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c75e9eb and e6252cd.

📒 Files selected for processing (1)
  • app/app/hooks/useAudioStreamer.ts (2 hunks)
🔇 Additional comments (2)
app/app/hooks/useAudioStreamer.ts (2)

3-3: LGTM! Alert import correctly added.

The Alert import is necessary for the permission denial notification and is properly added to the existing react-native imports.


60-62: Platform.Version check is correct.

React Native's Platform.Version returns a number representing the Android API level on Android, so Platform.Version < 34 correctly identifies Android devices running versions below API level 34 (Android 14).

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