bug: [React Native/Android] KeepAliveService never starts when CAMERA is not granted (Android 14+)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- android, react-native, typescript
- Domain
- mobile
Research direction
Start with android/src/main/java/com/cloudflare/realtimekit/KeepAliveService.java and trace onStartCommand() and startMeetingService() to see how the foreground service types are selected. Check the Android permission APIs used in the suggested fix, then verify audio-only startup keeps the microphone service running without camera permission; done means the service starts with the granted types and camera users can still use the camera type.
Written by the indexing model from the issue text.
Description
Package: @cloudflare/realtimekit-react-native 2.0.0. 2.0.1-staging.0 has the same KeepAliveService.java.
Platform: Android 14+ (targetSdk 34+).
What happens
KeepAliveService.onStartCommand() always calls
startForeground(NOTIFICATION_ID, notification,
FOREGROUND_SERVICE_TYPE_CAMERA | FOREGROUND_SERVICE_TYPE_MICROPHONE | FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
On Android 14+, every type passed to startForeground() must meet its runtime prerequisites: camera needs the CAMERA permission granted, and microphone needs RECORD_AUDIO (docs). In an audio-only meeting, or whenever the user hasn't granted camera, the call throws. The catch (RuntimeException e) then logs startForeground failed, stopping service and calls stopSelf().
The result is that the background-support feature added in 2.0.0 silently does nothing. When the app goes to the background, the microphone is no longer covered by a microphone foreground service, so the other side stops hearing the user.
How to observe (derived from the source; not captured on a device)
- Use
useRealtimeKitClient()with the defaultkeepAliveServiceand join a meeting withaudio: true, video: false, without ever granting camera. - Run
adb logcat -s KeepAliveService. The expected line isstartForeground failed, stopping service: …, and no ongoing-call notification should appear. - Background the app while talking. Without a
microphoneforeground service, Android's while-in-use rules cut microphone access, so the remote side should stop hearing you.
Expected
The service starts with the types whose permissions are actually granted.
Suggested fix
Build the type mask from the granted permissions. Video users keep the camera type; audio-only users still get microphone + mediaPlayback:
--- a/android/src/main/java/com/cloudflare/realtimekit/KeepAliveService.java
+++ b/android/src/main/java/com/cloudflare/realtimekit/KeepAliveService.java
@@ -1,5 +1,6 @@
package com.cloudflare.realtimekit;
+import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@@ -18,6 +19,7 @@
import android.util.Log;
import androidx.core.app.NotificationCompat;
+import androidx.core.content.ContextCompat;
/**
* Foreground service that keeps the app alive in the background during a
@@ -93,10 +95,7 @@
Notification notification = buildNotification();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- startForeground(NOTIFICATION_ID, notification,
- ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
- | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
- | ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
+ startForeground(NOTIFICATION_ID, notification, foregroundServiceTypes());
} else {
startForeground(NOTIFICATION_ID, notification);
}
@@ -109,6 +108,23 @@
return START_NOT_STICKY;
}
+ // Android 14+ rejects camera/microphone types whose runtime permission is not granted.
+ private int foregroundServiceTypes() {
+ int types = ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK;
+ if (isGranted(Manifest.permission.RECORD_AUDIO)) {
+ types |= ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
+ }
+ if (isGranted(Manifest.permission.CAMERA)) {
+ types |= ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;
+ }
+ return types;
+ }
+
+ private boolean isGranted(String permission) {
+ return ContextCompat.checkSelfPermission(this, permission)
+ == PackageManager.PERMISSION_GRANTED;
+ }
+
// -----------------------------------------------------------------------
private void createNotificationChannel() {
The manifest entry (camera|microphone|mediaPlayback) can stay as is, because a subset of the declared types is allowed.
One limitation: startMeetingService() runs once at the end of setupStreams(), after setupPermissions(). If camera is granted later in the meeting, the running service won't have the camera type until it is started again. Calling startForeground() again with the new mask after a later permission grant would cover that.
- Dominant language
- TypeScript
- Stars
- 74
- Forks
- 26
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 10
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/realtimekit-ui
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
cloudflare/realtimekit-ui#205 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
cloudflare/realtimekit-ui#209 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
cloudflare/realtimekit-ui#198 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
cloudflare/realtimekit-ui#167 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
cloudflare/realtimekit-ui#164 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
All issues in cloudflare/realtimekit-ui
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vercel-labs/ui#809 ·
Maintainers usually reply within 1 day
-
bot:ai-assisted component:platform-js status:untriaged
Difficulty 1/5 Under an hour Newbie friendliness 74/100
midnightntwrk/platform-js#38 ·
-
[bug] Second false positive on high-cost plugin alert: detection only compares patch entry id, community plugin dsh-auto | [bug] 高成本插件告警第二次误报:检测只比对 patch 条目 id,社区插件 dsh-auto-review 被认成 @deepseek-ai/dsh-experimental-auto-reviewPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ranxianglei/billion-context#7068 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
mybigday/whisper.rn#348 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
six-group/six-webcomponents#600 ·