chahinebrini 63fae25531 fix(android-protection): explicit specialUse FGS type — Samsung/Android 16 crash loop
RebreakVpnService.onStartCommand crashed with SecurityException because Android 16's validateForegroundServiceType rejects the implicit 2-arg startForeground(). Now passes FOREGROUND_SERVICE_TYPE_SPECIAL_USE explicitly (Google's documented best practice) and guards the call so a failed foreground promotion stops the service cleanly instead of crashing the app. Verified vs reported Galaxy A54 / Android 16 signature (97% of crash events, 1-user crash loop).

Bundles pending working-tree work across native/marketing/locales/mac + graphify-out rebuild. gitignore: google-services.json + /screenshots/.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 22:33:28 +02:00

61 lines
2.8 KiB
TypeScript

import { useEffect } from 'react';
import { isRealtimeErrorReal } from '../lib/realtimeStatus';
import { Platform } from 'react-native';
import { useRouter } from 'expo-router';
import { supabase } from '../lib/supabase';
import { useCallStore, type CallPeer } from '../stores/call';
/**
* Lauscht (app-weit, solange eingeloggt) auf den persönlichen Ring-Channel
* `call-ring:<myUserId>` und zeigt bei einer eingehenden Einladung den
* Call-Screen. Phase 1 = foreground-only (klingelt nur bei offener App;
* Wake-when-closed via VoIP-Push ist Phase 2).
*/
export function useIncomingCalls(myUserId: string | undefined) {
const router = useRouter();
useEffect(() => {
if (!myUserId) return;
console.log('[CALL/recv] subscribing call-ring channel for', myUserId);
const chan = supabase.channel(`call-ring:${myUserId}`);
chan.on('broadcast', { event: 'ring' }, (msg: any) => {
console.log('[CALL/recv] RING received', msg?.payload);
const callId = msg?.payload?.callId as string | undefined;
const from = msg?.payload?.from as CallPeer | undefined;
if (!callId || !from) return;
// Schon in einem AKTIVEN Call → ignorieren (MVP: kein call-waiting).
// 'ended' ist KEIN aktiver Call (nur ein noch nicht aufgeräumter Rest eines
// vorherigen Calls) → durchlassen, receiveIncoming räumt ihn auf. Sonst
// blockt ein stale 'ended' jeden neuen Anruf.
const st = useCallStore.getState().status;
if (st !== 'idle' && st !== 'ended') return;
useCallStore.getState().receiveIncoming(callId, from);
// iOS: CallKit (via VoIP-Push → reportNewIncomingCall) IST die Eingehend-UI.
// Hier NICHT zu /call navigieren, sonst Doppel-UI (CallKit-Banner +
// Fullscreen-/call). Der Realtime-Ring dient auf iOS nur der Store-
// Hydration; der /call-Screen kommt erst nach „Annehmen" (CallKit →
// useCallKeepEvents.onAnswer → router.push('/call')).
// Android: Custom-/call ist die gewünschte Eingehend-UI.
if (Platform.OS !== 'ios') router.push('/call');
});
chan.on('broadcast', { event: 'cancel' }, (msg: any) => {
const callId = msg?.payload?.callId as string | undefined;
const st = useCallStore.getState();
console.log('[CALL/recv] CANCEL received callId=', callId, 'storeStatus=', st.status, 'storeCallId=', st.callId);
if (st.callId === callId && st.status === 'incoming') {
// Caller hat aufgelegt bevor wir annehmen konnten → verpasster Anruf.
st.hangup('unanswered');
}
});
chan.subscribe((status: string, err?: any) => {
if (isRealtimeErrorReal()) console.log('[CALL/recv] call-ring subscribe status:', status, err ?? '');
});
return () => {
console.log('[CALL/recv] unsubscribing call-ring for', myUserId);
supabase.removeChannel(chan);
};
}, [myUserId, router]);
}