125 lines
4.2 KiB
Kotlin
125 lines
4.2 KiB
Kotlin
package com.inou.moltmobile
|
|
|
|
import android.app.Application
|
|
import android.app.NotificationChannel
|
|
import android.app.NotificationManager
|
|
import android.os.Build
|
|
import com.inou.moltmobile.debug.DebugClient
|
|
import com.inou.moltmobile.gateway.DirectGateway
|
|
import com.inou.moltmobile.security.AuditLog
|
|
import com.inou.moltmobile.security.DeviceIdentity
|
|
import com.inou.moltmobile.security.TokenStore
|
|
import com.inou.moltmobile.service.NotificationManager as AppNotificationManager
|
|
|
|
/**
|
|
* MoltMobile Application
|
|
*
|
|
* AI-powered phone assistant that connects to Clawdbot Gateway.
|
|
* Enables Claude to answer calls, screen notifications, and act on your behalf.
|
|
*/
|
|
class MoltMobileApp : 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", "MoltMobile v0.2.0 started")
|
|
|
|
// Initialize debug client and log startup
|
|
DebugClient.lifecycle("APP_CREATE", "MoltMobile v0.2.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.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
|
|
}
|
|
|
|
// Initialize with context (for AudioManager)
|
|
DirectGateway.initialize(this)
|
|
|
|
// 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 MoltMobile 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 = "moltmobile_service"
|
|
const val CHANNEL_ALERTS = "moltmobile_alerts"
|
|
const val CHANNEL_CALLS = "moltmobile_calls"
|
|
|
|
lateinit var instance: MoltMobileApp
|
|
private set
|
|
}
|
|
}
|