package com.inou.clawdnode import android.app.Application import android.app.NotificationChannel import android.app.NotificationManager import android.os.Build import com.inou.clawdnode.debug.DebugClient import com.inou.clawdnode.gateway.DirectGateway import com.inou.clawdnode.security.AuditLog import com.inou.clawdnode.security.DeviceIdentity import com.inou.clawdnode.security.TokenStore import com.inou.clawdnode.service.NotificationManager as AppNotificationManager /** * ClawdNode Application * * AI-powered phone assistant that connects to Clawdbot Gateway. * Enables Claude to answer calls, screen notifications, and act on your behalf. */ class ClawdNodeApp : Application() { lateinit var tokenStore: TokenStore private set lateinit var auditLog: AuditLog private set override fun onCreate() { super.onCreate() instance = this // Initialize security components tokenStore = TokenStore(this) auditLog = AuditLog(this) // Create notification channels createNotificationChannels() auditLog.log("APP_START", "ClawdNode v0.1.0 started") // Initialize debug client and log startup DebugClient.lifecycle("APP_CREATE", "ClawdNode v0.1.0 started") DebugClient.log("App initialized", mapOf( "gatewayUrl" to (tokenStore.gatewayUrl ?: "not set"), "hasToken" to (tokenStore.gatewayToken != null) )) // Connect to our DirectGateway (bidirectional WebSocket) setupDirectGateway() } private fun setupDirectGateway() { // Set up command handlers DirectGateway.onNotificationAction = { notificationId, action, replyText -> auditLog.log("COMMAND_RECEIVED", "notification.action: $action on $notificationId") AppNotificationManager.getInstance()?.triggerAction(notificationId, action, replyText) } DirectGateway.onCallAnswer = { callId -> auditLog.log("COMMAND_RECEIVED", "call.answer: $callId") // TODO: Implement call answering via TelecomManager } DirectGateway.onCallReject = { callId -> auditLog.log("COMMAND_RECEIVED", "call.reject: $callId") // TODO: Implement call rejection } DirectGateway.onCallHangup = { callId -> auditLog.log("COMMAND_RECEIVED", "call.hangup: $callId") // TODO: Implement call hangup } // Connect DirectGateway.connect() DebugClient.lifecycle("DIRECT_GATEWAY_SETUP", "Command handlers registered, connecting...") } private fun createNotificationChannels() { val manager = getSystemService(NotificationManager::class.java) // Foreground service channel (persistent) val serviceChannel = NotificationChannel( CHANNEL_SERVICE, "Connection Status", NotificationManager.IMPORTANCE_LOW ).apply { description = "Shows ClawdNode connection status" setShowBadge(false) } // Alerts channel (for important events) val alertChannel = NotificationChannel( CHANNEL_ALERTS, "Alerts", NotificationManager.IMPORTANCE_HIGH ).apply { description = "Important events requiring attention" } // Call events channel val callChannel = NotificationChannel( CHANNEL_CALLS, "Call Activity", NotificationManager.IMPORTANCE_DEFAULT ).apply { description = "Call screening and voice interaction events" } manager.createNotificationChannels(listOf(serviceChannel, alertChannel, callChannel)) } companion object { const val CHANNEL_SERVICE = "clawdnode_service" const val CHANNEL_ALERTS = "clawdnode_alerts" const val CHANNEL_CALLS = "clawdnode_calls" lateinit var instance: ClawdNodeApp private set } }