package com.ahmed.jarvis import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.provider.Telephony /** * Forwards incoming SMS to the gateway (the `sms_in` event, APP_PLAN §3). * * The gateway applies the sender watch-list; this receiver does no filtering * beyond grouping multipart messages. Delivery only reaches the WebSocket while * the Flutter engine is alive (foreground / recently backgrounded) — see * [MainActivity.forwardSms]. Guaranteed background forwarding would need a * persistent/headless service and is a documented TODO. */ class SmsReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (intent?.action != Telephony.Sms.Intents.SMS_RECEIVED_ACTION) return val messages = Telephony.Sms.Intents.getMessagesFromIntent(intent) ?: return if (messages.isEmpty()) return // Multipart texts arrive as several PDUs — stitch the body back together. val sender = messages[0].displayOriginatingAddress ?: messages[0].originatingAddress ?: "" val ts = messages[0].timestampMillis val body = buildString { for (m in messages) append(m.messageBody ?: "") } if (sender.isBlank() && body.isBlank()) return MainActivity.forwardSms(sender, body, ts) } }