rework-app #54
@ -12,6 +12,8 @@
|
|||||||
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
|
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
|
||||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
||||||
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
|
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="Icing Dialer"
|
android:label="Icing Dialer"
|
||||||
|
@ -6,7 +6,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.CallLog
|
import android.provider.CallLog
|
||||||
@ -26,23 +25,76 @@ class MainActivity : FlutterActivity() {
|
|||||||
private val CALL_CHANNEL = "call_service"
|
private val CALL_CHANNEL = "call_service"
|
||||||
private val TAG = "MainActivity"
|
private val TAG = "MainActivity"
|
||||||
private val REQUEST_CODE_SET_DEFAULT_DIALER = 1001
|
private val REQUEST_CODE_SET_DEFAULT_DIALER = 1001
|
||||||
|
private val REQUEST_CODE_CALL_LOG_PERMISSION = 1002
|
||||||
|
private var pendingIncomingCall: Pair<String?, Boolean>? = null
|
||||||
|
private var wasPhoneLocked: Boolean = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
Log.d(TAG, "onCreate started")
|
Log.d(TAG, "onCreate started")
|
||||||
Log.d(TAG, "Waiting for Flutter to signal permissions")
|
wasPhoneLocked = intent.getBooleanExtra("wasPhoneLocked", false)
|
||||||
|
Log.d(TAG, "Was phone locked at start: $wasPhoneLocked")
|
||||||
|
updateLockScreenFlags(intent)
|
||||||
|
handleIncomingCallIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
setIntent(intent)
|
||||||
|
wasPhoneLocked = intent.getBooleanExtra("wasPhoneLocked", false)
|
||||||
|
Log.d(TAG, "onNewIntent, wasPhoneLocked: $wasPhoneLocked")
|
||||||
|
updateLockScreenFlags(intent)
|
||||||
|
handleIncomingCallIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateLockScreenFlags(intent: Intent?) {
|
||||||
|
val isIncomingCall = intent?.getBooleanExtra("isIncomingCall", false) ?: false
|
||||||
|
if (isIncomingCall && wasPhoneLocked) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
|
setShowWhenLocked(true)
|
||||||
|
setTurnScreenOn(true)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.addFlags(
|
||||||
|
android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||||
|
android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Enabled showWhenLocked and turnScreenOn for incoming call")
|
||||||
|
} else {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
|
setShowWhenLocked(false)
|
||||||
|
setTurnScreenOn(false)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.clearFlags(
|
||||||
|
android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||||
|
android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Disabled showWhenLocked and turnScreenOn for normal usage")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
super.configureFlutterEngine(flutterEngine)
|
super.configureFlutterEngine(flutterEngine)
|
||||||
Log.d(TAG, "Configuring Flutter engine")
|
Log.d(TAG, "Configuring Flutter engine")
|
||||||
|
|
||||||
MyInCallService.channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALL_CHANNEL)
|
MyInCallService.channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALL_CHANNEL)
|
||||||
|
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALL_CHANNEL)
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALL_CHANNEL)
|
||||||
.setMethodCallHandler { call, result ->
|
.setMethodCallHandler { call, result ->
|
||||||
when (call.method) {
|
when (call.method) {
|
||||||
"permissionsGranted" -> {
|
"permissionsGranted" -> {
|
||||||
Log.d(TAG, "Received permissionsGranted from Flutter")
|
Log.d(TAG, "Received permissionsGranted from Flutter")
|
||||||
|
pendingIncomingCall?.let { (phoneNumber, showScreen) ->
|
||||||
|
if (showScreen) {
|
||||||
|
MyInCallService.channel?.invokeMethod("incomingCallFromNotification", mapOf(
|
||||||
|
"phoneNumber" to phoneNumber,
|
||||||
|
"wasPhoneLocked" to wasPhoneLocked
|
||||||
|
))
|
||||||
|
pendingIncomingCall = null
|
||||||
|
}
|
||||||
|
}
|
||||||
checkAndRequestDefaultDialer()
|
checkAndRequestDefaultDialer()
|
||||||
result.success(true)
|
result.success(true)
|
||||||
}
|
}
|
||||||
@ -60,37 +112,104 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"hangUpCall" -> {
|
"hangUpCall" -> {
|
||||||
val success = CallService.hangUpCall(this)
|
val success = MyInCallService.currentCall?.let {
|
||||||
|
it.disconnect()
|
||||||
|
Log.d(TAG, "Call disconnected")
|
||||||
|
MyInCallService.channel?.invokeMethod("callEnded", mapOf(
|
||||||
|
"callId" to it.details.handle.toString(),
|
||||||
|
"wasPhoneLocked" to wasPhoneLocked
|
||||||
|
))
|
||||||
|
true
|
||||||
|
} ?: false
|
||||||
if (success) {
|
if (success) {
|
||||||
result.success(mapOf("status" to "ended"))
|
result.success(mapOf("status" to "ended"))
|
||||||
|
if (wasPhoneLocked) {
|
||||||
|
Log.d(TAG, "Finishing and removing task after hangup, phone was locked")
|
||||||
|
finishAndRemoveTask()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.error("HANGUP_FAILED", "Failed to end call", null)
|
Log.w(TAG, "No active call to hang up")
|
||||||
|
result.error("HANGUP_FAILED", "No active call to hang up", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"answerCall" -> {
|
"answerCall" -> {
|
||||||
val success = MyInCallService.currentCall?.let {
|
val success = MyInCallService.currentCall?.let {
|
||||||
it.answer(0) // 0 for default video state (audio-only)
|
it.answer(0)
|
||||||
Log.d(TAG, "Answered call")
|
Log.d(TAG, "Answered call")
|
||||||
true
|
true
|
||||||
} ?: false
|
} ?: false
|
||||||
if (success) {
|
if (success) {
|
||||||
result.success(mapOf("status" to "answered"))
|
result.success(mapOf("status" to "answered"))
|
||||||
} else {
|
} else {
|
||||||
|
Log.w(TAG, "No active call to answer")
|
||||||
result.error("ANSWER_FAILED", "No active call to answer", null)
|
result.error("ANSWER_FAILED", "No active call to answer", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"callEndedFromFlutter" -> {
|
||||||
|
Log.d(TAG, "Call ended from Flutter, wasPhoneLocked: $wasPhoneLocked")
|
||||||
|
if (wasPhoneLocked) {
|
||||||
|
finishAndRemoveTask()
|
||||||
|
Log.d(TAG, "Finishing and removing task after call ended, phone was locked")
|
||||||
|
}
|
||||||
|
result.success(true)
|
||||||
|
}
|
||||||
|
"getCallState" -> {
|
||||||
|
val stateStr = when (MyInCallService.currentCall?.state) {
|
||||||
|
android.telecom.Call.STATE_ACTIVE -> "active"
|
||||||
|
android.telecom.Call.STATE_RINGING -> "ringing"
|
||||||
|
android.telecom.Call.STATE_DIALING -> "dialing"
|
||||||
|
android.telecom.Call.STATE_DISCONNECTED -> "disconnected"
|
||||||
|
android.telecom.Call.STATE_DISCONNECTING -> "disconnecting"
|
||||||
|
else -> "unknown"
|
||||||
|
}
|
||||||
|
Log.d(TAG, "getCallState called, returning: $stateStr")
|
||||||
|
result.success(stateStr)
|
||||||
|
}
|
||||||
|
"muteCall" -> {
|
||||||
|
val mute = call.argument<Boolean>("mute") ?: false
|
||||||
|
val success = MyInCallService.currentCall?.let {
|
||||||
|
MyInCallService.toggleMute(mute)
|
||||||
|
} ?: false
|
||||||
|
if (success) {
|
||||||
|
Log.d(TAG, "Mute call set to $mute")
|
||||||
|
result.success(mapOf("status" to "success"))
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "No active call or failed to mute")
|
||||||
|
result.error("MUTE_FAILED", "No active call or failed to mute", null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"speakerCall" -> {
|
||||||
|
val speaker = call.argument<Boolean>("speaker") ?: false
|
||||||
|
val success = MyInCallService.currentCall?.let {
|
||||||
|
MyInCallService.toggleSpeaker(speaker)
|
||||||
|
} ?: false
|
||||||
|
if (success) {
|
||||||
|
Log.d(TAG, "Speaker call set to $speaker")
|
||||||
|
result.success(mapOf("status" to "success"))
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "No active call or failed to set speaker")
|
||||||
|
result.error("SPEAKER_FAILED", "No active call or failed to set speaker", null)
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> result.notImplemented()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KEYSTORE_CHANNEL)
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KEYSTORE_CHANNEL)
|
||||||
.setMethodCallHandler { call, result -> KeystoreHelper(call, result).handleMethodCall() }
|
.setMethodCallHandler { call, result ->
|
||||||
|
KeystoreHelper(call, result).handleMethodCall()
|
||||||
|
}
|
||||||
|
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALLLOG_CHANNEL)
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALLLOG_CHANNEL)
|
||||||
.setMethodCallHandler { call, result ->
|
.setMethodCallHandler { call, result ->
|
||||||
if (call.method == "getCallLogs") {
|
if (call.method == "getCallLogs") {
|
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {
|
||||||
val callLogs = getCallLogs()
|
val callLogs = getCallLogs()
|
||||||
result.success(callLogs)
|
result.success(callLogs)
|
||||||
|
} else {
|
||||||
|
requestPermissions(arrayOf(Manifest.permission.READ_CALL_LOG), REQUEST_CODE_CALL_LOG_PERMISSION)
|
||||||
|
result.error("PERMISSION_DENIED", "Call log permission not granted", null)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.notImplemented()
|
result.notImplemented()
|
||||||
}
|
}
|
||||||
@ -109,8 +228,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER)
|
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER)
|
||||||
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER)
|
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER)
|
||||||
Log.d(TAG, "Launched RoleManager intent for default dialer on API 29+")
|
Log.d(TAG, "Launched RoleManager intent for default dialer on API 29+")
|
||||||
} else {
|
|
||||||
Log.d(TAG, "RoleManager: Available=${roleManager.isRoleAvailable(RoleManager.ROLE_DIALER)}, Held=${roleManager.isRoleHeld(RoleManager.ROLE_DIALER)}")
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
|
val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
|
||||||
@ -148,6 +265,18 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
if (requestCode == REQUEST_CODE_CALL_LOG_PERMISSION) {
|
||||||
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.d(TAG, "Call log permission granted")
|
||||||
|
MyInCallService.channel?.invokeMethod("callLogPermissionGranted", null)
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Call log permission denied")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getCallLogs(): List<Map<String, Any?>> {
|
private fun getCallLogs(): List<Map<String, Any?>> {
|
||||||
val logsList = mutableListOf<Map<String, Any?>>()
|
val logsList = mutableListOf<Map<String, Any?>>()
|
||||||
val cursor: Cursor? = contentResolver.query(
|
val cursor: Cursor? = contentResolver.query(
|
||||||
@ -171,4 +300,25 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
return logsList
|
return logsList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleIncomingCallIntent(intent: Intent?) {
|
||||||
|
intent?.let {
|
||||||
|
if (it.getBooleanExtra("isIncomingCall", false)) {
|
||||||
|
val phoneNumber = it.getStringExtra("phoneNumber")
|
||||||
|
val showScreen = it.getBooleanExtra("showIncomingCallScreen", false)
|
||||||
|
Log.d(TAG, "Received incoming call intent for $phoneNumber, showScreen=$showScreen, wasPhoneLocked=$wasPhoneLocked")
|
||||||
|
if (showScreen) {
|
||||||
|
if (MyInCallService.channel != null) {
|
||||||
|
MyInCallService.channel?.invokeMethod("incomingCallFromNotification", mapOf(
|
||||||
|
"phoneNumber" to phoneNumber,
|
||||||
|
"wasPhoneLocked" to wasPhoneLocked
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
pendingIncomingCall = Pair(phoneNumber, true)
|
||||||
|
Log.d(TAG, "Flutter channel not ready, storing pending call: $phoneNumber")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,8 +1,19 @@
|
|||||||
package com.icing.dialer.services
|
package com.icing.dialer.services
|
||||||
|
|
||||||
|
import android.app.KeyguardManager
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.media.AudioManager
|
||||||
|
import android.os.Build
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.telecom.InCallService
|
import android.telecom.InCallService
|
||||||
|
import android.telecom.CallAudioState
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import com.icing.dialer.activities.MainActivity
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
class MyInCallService : InCallService() {
|
class MyInCallService : InCallService() {
|
||||||
@ -10,6 +21,37 @@ class MyInCallService : InCallService() {
|
|||||||
var channel: MethodChannel? = null
|
var channel: MethodChannel? = null
|
||||||
var currentCall: Call? = null
|
var currentCall: Call? = null
|
||||||
private const val TAG = "MyInCallService"
|
private const val TAG = "MyInCallService"
|
||||||
|
private const val NOTIFICATION_CHANNEL_ID = "incoming_call_channel"
|
||||||
|
private const val NOTIFICATION_ID = 1
|
||||||
|
var wasPhoneLocked: Boolean = false
|
||||||
|
private var instance: MyInCallService? = null
|
||||||
|
|
||||||
|
fun toggleMute(mute: Boolean): Boolean {
|
||||||
|
return instance?.let { service ->
|
||||||
|
try {
|
||||||
|
service.setMuted(mute)
|
||||||
|
Log.d(TAG, "Requested to set call mute state to $mute")
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Failed to set mute state: $e")
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toggleSpeaker(speaker: Boolean): Boolean {
|
||||||
|
return instance?.let { service ->
|
||||||
|
try {
|
||||||
|
val route = if (speaker) CallAudioState.ROUTE_SPEAKER else CallAudioState.ROUTE_EARPIECE
|
||||||
|
service.setAudioRoute(route)
|
||||||
|
Log.d(TAG, "Requested to set audio route to $route")
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Failed to set audio route: $e")
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val callCallback = object : Call.Callback() {
|
private val callCallback = object : Call.Callback() {
|
||||||
@ -26,44 +68,135 @@ class MyInCallService : InCallService() {
|
|||||||
Log.d(TAG, "State changed: $stateStr for call ${call.details.handle}")
|
Log.d(TAG, "State changed: $stateStr for call ${call.details.handle}")
|
||||||
channel?.invokeMethod("callStateChanged", mapOf(
|
channel?.invokeMethod("callStateChanged", mapOf(
|
||||||
"callId" to call.details.handle.toString(),
|
"callId" to call.details.handle.toString(),
|
||||||
"state" to stateStr
|
"state" to stateStr,
|
||||||
|
"wasPhoneLocked" to wasPhoneLocked
|
||||||
|
))
|
||||||
|
if (state == Call.STATE_RINGING) {
|
||||||
|
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
wasPhoneLocked = keyguardManager.isKeyguardLocked
|
||||||
|
Log.d(TAG, "Phone locked at ringing: $wasPhoneLocked")
|
||||||
|
showIncomingCallScreen(call.details.handle.toString().replace("tel:", ""))
|
||||||
|
} else if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) {
|
||||||
|
Log.d(TAG, "Call ended: ${call.details.handle}, wasPhoneLocked: $wasPhoneLocked")
|
||||||
|
channel?.invokeMethod("callEnded", mapOf(
|
||||||
|
"callId" to call.details.handle.toString(),
|
||||||
|
"wasPhoneLocked" to wasPhoneLocked
|
||||||
))
|
))
|
||||||
if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) {
|
|
||||||
Log.d(TAG, "Call ended: ${call.details.handle}")
|
|
||||||
channel?.invokeMethod("callEnded", mapOf("callId" to call.details.handle.toString()))
|
|
||||||
currentCall = null
|
currentCall = null
|
||||||
|
cancelNotification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCallAdded(call: Call) {
|
override fun onCallAdded(call: Call) {
|
||||||
super.onCallAdded(call)
|
super.onCallAdded(call)
|
||||||
|
instance = this
|
||||||
currentCall = call
|
currentCall = call
|
||||||
val stateStr = when (call.state) {
|
val stateStr = when (call.state) {
|
||||||
Call.STATE_DIALING -> "dialing"
|
Call.STATE_DIALING -> "dialing"
|
||||||
Call.STATE_ACTIVE -> "active"
|
Call.STATE_ACTIVE -> "active"
|
||||||
Call.STATE_RINGING -> "ringing"
|
Call.STATE_RINGING -> "ringing"
|
||||||
else -> "dialing" // Default for outgoing
|
else -> "dialing"
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Call added: ${call.details.handle}, state: $stateStr")
|
Log.d(TAG, "Call added: ${call.details.handle}, state: $stateStr")
|
||||||
channel?.invokeMethod("callAdded", mapOf(
|
channel?.invokeMethod("callAdded", mapOf(
|
||||||
"callId" to call.details.handle.toString(),
|
"callId" to call.details.handle.toString(),
|
||||||
"state" to stateStr
|
"state" to stateStr
|
||||||
))
|
))
|
||||||
|
if (stateStr == "ringing") {
|
||||||
|
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
wasPhoneLocked = keyguardManager.isKeyguardLocked
|
||||||
|
Log.d(TAG, "Phone locked at call added: $wasPhoneLocked")
|
||||||
|
showIncomingCallScreen(call.details.handle.toString().replace("tel:", ""))
|
||||||
|
}
|
||||||
call.registerCallback(callCallback)
|
call.registerCallback(callCallback)
|
||||||
|
if (callAudioState != null) {
|
||||||
|
val audioState = callAudioState
|
||||||
|
channel?.invokeMethod("audioStateChanged", mapOf(
|
||||||
|
"route" to audioState.route,
|
||||||
|
"muted" to audioState.isMuted,
|
||||||
|
"speaker" to (audioState.route == CallAudioState.ROUTE_SPEAKER)
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Log.w("MyInCallService", "callAudioState is null in onCallAdded")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCallRemoved(call: Call) {
|
override fun onCallRemoved(call: Call) {
|
||||||
super.onCallRemoved(call)
|
super.onCallRemoved(call)
|
||||||
Log.d(TAG, "Call removed: ${call.details.handle}")
|
Log.d(TAG, "Call removed: ${call.details.handle}, wasPhoneLocked: $wasPhoneLocked")
|
||||||
call.unregisterCallback(callCallback)
|
call.unregisterCallback(callCallback)
|
||||||
channel?.invokeMethod("callRemoved", mapOf("callId" to call.details.handle.toString()))
|
channel?.invokeMethod("callRemoved", mapOf(
|
||||||
|
"callId" to call.details.handle.toString(),
|
||||||
|
"wasPhoneLocked" to wasPhoneLocked
|
||||||
|
))
|
||||||
currentCall = null
|
currentCall = null
|
||||||
|
instance = null
|
||||||
|
cancelNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCallAudioStateChanged(state: android.telecom.CallAudioState) {
|
override fun onCallAudioStateChanged(state: CallAudioState) {
|
||||||
super.onCallAudioStateChanged(state)
|
super.onCallAudioStateChanged(state)
|
||||||
Log.d(TAG, "Audio state changed: route=${state.route}")
|
Log.d(TAG, "Audio state changed: route=${state.route}, muted=${state.isMuted}")
|
||||||
channel?.invokeMethod("audioStateChanged", mapOf("route" to state.route))
|
channel?.invokeMethod("audioStateChanged", mapOf(
|
||||||
|
"route" to state.route,
|
||||||
|
"muted" to state.isMuted,
|
||||||
|
"speaker" to (state.route == CallAudioState.ROUTE_SPEAKER)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showIncomingCallScreen(phoneNumber: String) {
|
||||||
|
val intent = Intent(this, MainActivity::class.java).apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
|
putExtra("phoneNumber", phoneNumber)
|
||||||
|
putExtra("isIncomingCall", true)
|
||||||
|
putExtra("showIncomingCallScreen", true)
|
||||||
|
putExtra("wasPhoneLocked", wasPhoneLocked)
|
||||||
|
}
|
||||||
|
|
||||||
|
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
if (keyguardManager.isKeyguardLocked) {
|
||||||
|
startActivity(intent)
|
||||||
|
Log.d(TAG, "Launched MainActivity directly for locked screen, phoneNumber: $phoneNumber")
|
||||||
|
} else {
|
||||||
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val channel = NotificationChannel(
|
||||||
|
NOTIFICATION_CHANNEL_ID,
|
||||||
|
"Incoming Calls",
|
||||||
|
NotificationManager.IMPORTANCE_HIGH
|
||||||
|
).apply {
|
||||||
|
description = "Notifications for incoming calls"
|
||||||
|
enableVibration(true)
|
||||||
|
setShowBadge(true)
|
||||||
|
}
|
||||||
|
notificationManager.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
val pendingIntent = PendingIntent.getActivity(
|
||||||
|
this, 0, intent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||||
|
.setSmallIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.setContentTitle("Incoming Call")
|
||||||
|
.setContentText("Call from $phoneNumber")
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setFullScreenIntent(pendingIntent, true)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setOngoing(true)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
startActivity(intent)
|
||||||
|
notificationManager.notify(NOTIFICATION_ID, notification)
|
||||||
|
Log.d(TAG, "Launched MainActivity with notification for unlocked screen, phoneNumber: $phoneNumber")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cancelNotification() {
|
||||||
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
notificationManager.cancel(NOTIFICATION_ID)
|
||||||
|
Log.d(TAG, "Notification canceled")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,154 +1,442 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import '../../presentation/features/call/call_page.dart';
|
import '../../presentation/features/call/call_page.dart';
|
||||||
import '../../presentation/features/call/incoming_call_page.dart'; // Import the new page
|
import '../../presentation/features/call/incoming_call_page.dart'; // Import the new page
|
||||||
|
import 'contact_service.dart';
|
||||||
|
|
||||||
class CallService {
|
class CallService {
|
||||||
static const MethodChannel _channel = MethodChannel('call_service');
|
static const MethodChannel _channel = MethodChannel('call_service');
|
||||||
static String? currentPhoneNumber;
|
static String? currentPhoneNumber;
|
||||||
|
static String? currentDisplayName;
|
||||||
|
static Uint8List? currentThumbnail;
|
||||||
static bool _isCallPageVisible = false;
|
static bool _isCallPageVisible = false;
|
||||||
|
static Map<String, dynamic>? _pendingCall;
|
||||||
|
static bool wasPhoneLocked = false;
|
||||||
|
static String? _activeCallNumber;
|
||||||
|
static bool _isNavigating = false;
|
||||||
|
final ContactService _contactService = ContactService();
|
||||||
|
final _callStateController = StreamController<String>.broadcast();
|
||||||
|
final _audioStateController = StreamController<Map<String, dynamic>>.broadcast();
|
||||||
|
Map<String, dynamic>? _currentAudioState;
|
||||||
|
|
||||||
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
|
Stream<String> get callStateStream => _callStateController.stream;
|
||||||
|
Stream<Map<String, dynamic>> get audioStateStream => _audioStateController.stream;
|
||||||
|
Map<String, dynamic>? get currentAudioState => _currentAudioState;
|
||||||
|
|
||||||
CallService() {
|
CallService() {
|
||||||
_channel.setMethodCallHandler((call) async {
|
_channel.setMethodCallHandler((call) async {
|
||||||
final context = navigatorKey.currentContext;
|
print('CallService: Handling method call: ${call.method}, with args: ${call.arguments}');
|
||||||
print('CallService: Received method ${call.method} with args ${call.arguments}');
|
|
||||||
if (context == null) {
|
|
||||||
print('CallService: Navigator context is null, cannot navigate');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (call.method) {
|
switch (call.method) {
|
||||||
case "callAdded":
|
case "callAdded":
|
||||||
final phoneNumber = call.arguments["callId"] as String;
|
final phoneNumber = call.arguments["callId"] as String?;
|
||||||
final state = call.arguments["state"] as String;
|
final state = call.arguments["state"] as String?;
|
||||||
currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
|
if (phoneNumber == null || state == null) {
|
||||||
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
print('CallService: Invalid callAdded args: $call.arguments');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final decodedPhoneNumber = Uri.decodeComponent(phoneNumber.replaceFirst('tel:', ''));
|
||||||
|
print('CallService: Decoded phone number: $decodedPhoneNumber');
|
||||||
|
if (_activeCallNumber != decodedPhoneNumber) {
|
||||||
|
currentPhoneNumber = decodedPhoneNumber;
|
||||||
|
if (currentDisplayName == null || currentDisplayName == currentPhoneNumber) {
|
||||||
|
await _fetchContactInfo(decodedPhoneNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print('CallService: Call added, number: $currentPhoneNumber, displayName: $currentDisplayName, state: $state');
|
||||||
|
_callStateController.add(state);
|
||||||
if (state == "ringing") {
|
if (state == "ringing") {
|
||||||
_navigateToIncomingCallPage(context);
|
_handleIncomingCall(decodedPhoneNumber);
|
||||||
} else {
|
} else {
|
||||||
_navigateToCallPage(context);
|
_navigateToCallPage();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "callStateChanged":
|
case "callStateChanged":
|
||||||
final state = call.arguments["state"] as String;
|
final state = call.arguments["state"] as String?;
|
||||||
print('CallService: State changed to $state');
|
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||||
|
if (state == null) {
|
||||||
|
print('CallService: Invalid callStateChanged args: $call.arguments');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
print('CallService: State changed to $state, wasPhoneLocked: $wasPhoneLocked');
|
||||||
|
_callStateController.add(state);
|
||||||
if (state == "disconnected" || state == "disconnecting") {
|
if (state == "disconnected" || state == "disconnecting") {
|
||||||
_closeCallPage(context);
|
_closeCallPage();
|
||||||
|
if (wasPhoneLocked) {
|
||||||
|
await _channel.invokeMethod("callEndedFromFlutter");
|
||||||
|
}
|
||||||
|
_activeCallNumber = null;
|
||||||
} else if (state == "active" || state == "dialing") {
|
} else if (state == "active" || state == "dialing") {
|
||||||
_navigateToCallPage(context);
|
final phoneNumber = call.arguments["callId"] as String?;
|
||||||
|
if (phoneNumber != null && _activeCallNumber != Uri.decodeComponent(phoneNumber.replaceFirst('tel:', ''))) {
|
||||||
|
currentPhoneNumber = Uri.decodeComponent(phoneNumber.replaceFirst('tel:', ''));
|
||||||
|
if (currentDisplayName == null || currentDisplayName == currentPhoneNumber) {
|
||||||
|
await _fetchContactInfo(currentPhoneNumber!);
|
||||||
|
}
|
||||||
|
} else if (currentPhoneNumber != null && _activeCallNumber != currentPhoneNumber) {
|
||||||
|
if (currentDisplayName == null || currentDisplayName == currentPhoneNumber) {
|
||||||
|
await _fetchContactInfo(currentPhoneNumber!);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print('CallService: Skipping fetch, active call: $_activeCallNumber, current: $currentPhoneNumber, displayName: $currentDisplayName');
|
||||||
|
}
|
||||||
|
_navigateToCallPage();
|
||||||
} else if (state == "ringing") {
|
} else if (state == "ringing") {
|
||||||
_navigateToIncomingCallPage(context);
|
final phoneNumber = call.arguments["callId"] as String?;
|
||||||
|
if (phoneNumber == null) {
|
||||||
|
print('CallService: Invalid ringing callId: $call.arguments');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final decodedPhoneNumber = Uri.decodeComponent(phoneNumber.replaceFirst('tel:', ''));
|
||||||
|
if (_activeCallNumber != decodedPhoneNumber) {
|
||||||
|
currentPhoneNumber = decodedPhoneNumber;
|
||||||
|
if (currentDisplayName == null || currentDisplayName == currentPhoneNumber) {
|
||||||
|
await _fetchContactInfo(decodedPhoneNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_handleIncomingCall(decodedPhoneNumber);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "callEnded":
|
case "callEnded":
|
||||||
case "callRemoved":
|
case "callRemoved":
|
||||||
print('CallService: Call ended/removed');
|
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||||
_closeCallPage(context);
|
print('CallService: Call ended/removed, wasPhoneLocked: $wasPhoneLocked');
|
||||||
|
_closeCallPage();
|
||||||
|
if (wasPhoneLocked) {
|
||||||
|
await _channel.invokeMethod("callEndedFromFlutter");
|
||||||
|
}
|
||||||
currentPhoneNumber = null;
|
currentPhoneNumber = null;
|
||||||
|
currentDisplayName = null;
|
||||||
|
currentThumbnail = null;
|
||||||
|
_activeCallNumber = null;
|
||||||
|
break;
|
||||||
|
case "incomingCallFromNotification":
|
||||||
|
final phoneNumber = call.arguments["phoneNumber"] as String?;
|
||||||
|
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||||
|
if (phoneNumber == null) {
|
||||||
|
print('CallService: Invalid incomingCallFromNotification args: $call.arguments');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final decodedPhoneNumber = Uri.decodeComponent(phoneNumber);
|
||||||
|
if (_activeCallNumber != decodedPhoneNumber) {
|
||||||
|
currentPhoneNumber = decodedPhoneNumber;
|
||||||
|
if (currentDisplayName == null || currentDisplayName == currentPhoneNumber) {
|
||||||
|
await _fetchContactInfo(decodedPhoneNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print('CallService: Incoming call from notification: $decodedPhoneNumber, displayName: $currentDisplayName, wasPhoneLocked: $wasPhoneLocked');
|
||||||
|
_handleIncomingCall(decodedPhoneNumber);
|
||||||
|
break;
|
||||||
|
case "audioStateChanged":
|
||||||
|
final route = call.arguments["route"] as int?;
|
||||||
|
final muted = call.arguments["muted"] as bool?;
|
||||||
|
final speaker = call.arguments["speaker"] as bool?;
|
||||||
|
print('CallService: Audio state changed, route: $route, muted: $muted, speaker: $speaker');
|
||||||
|
final audioState = {
|
||||||
|
"route": route,
|
||||||
|
"muted": muted,
|
||||||
|
"speaker": speaker,
|
||||||
|
};
|
||||||
|
_currentAudioState = audioState;
|
||||||
|
_audioStateController.add(audioState);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _navigateToCallPage(BuildContext context) {
|
Future<String?> getCallState() async {
|
||||||
if (_isCallPageVisible && ModalRoute.of(context)?.settings.name == '/call') {
|
try {
|
||||||
print('CallService: CallPage already visible, skipping navigation');
|
final state = await _channel.invokeMethod('getCallState');
|
||||||
|
print('CallService: getCallState returned: $state');
|
||||||
|
return state as String?;
|
||||||
|
} catch (e) {
|
||||||
|
print('CallService: Error getting call state: $e');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> muteCall(BuildContext context, {required bool mute}) async {
|
||||||
|
try {
|
||||||
|
print('CallService: Toggling mute to $mute');
|
||||||
|
final result = await _channel.invokeMethod('muteCall', {'mute': mute});
|
||||||
|
print('CallService: muteCall result: $result');
|
||||||
|
final resultMap = Map<String, dynamic>.from(result as Map);
|
||||||
|
if (resultMap['status'] != 'success') {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Failed to toggle mute')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return resultMap;
|
||||||
|
} catch (e) {
|
||||||
|
print('CallService: Error toggling mute: $e');
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Error toggling mute: $e')),
|
||||||
|
);
|
||||||
|
return {'status': 'error', 'message': e.toString()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> speakerCall(BuildContext context, {required bool speaker}) async {
|
||||||
|
try {
|
||||||
|
print('CallService: Toggling speaker to $speaker');
|
||||||
|
final result = await _channel.invokeMethod('speakerCall', {'speaker': speaker});
|
||||||
|
print('CallService: speakerCall result: $result');
|
||||||
|
return Map<String, dynamic>.from(result);
|
||||||
|
} catch (e) {
|
||||||
|
print('CallService: Error toggling speaker: $e');
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Failed to toggle speaker: $e')),
|
||||||
|
);
|
||||||
|
return {'status': 'error', 'message': e.toString()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispose() {
|
||||||
|
_callStateController.close();
|
||||||
|
_audioStateController.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||||
|
try {
|
||||||
|
print('CallService: Fetching contact info for $phoneNumber');
|
||||||
|
final contacts = await _contactService.fetchContacts();
|
||||||
|
print('CallService: Retrieved ${contacts.length} contacts');
|
||||||
|
final normalizedPhoneNumber = _normalizePhoneNumber(phoneNumber);
|
||||||
|
print('CallService: Normalized phone number: $normalizedPhoneNumber');
|
||||||
|
for (var contact in contacts) {
|
||||||
|
for (var phone in contact.phones) {
|
||||||
|
final normalizedContactNumber = _normalizePhoneNumber(phone.number);
|
||||||
|
print('CallService: Comparing $normalizedPhoneNumber with contact number $normalizedContactNumber');
|
||||||
|
if (normalizedContactNumber == normalizedPhoneNumber) {
|
||||||
|
currentDisplayName = contact.displayName;
|
||||||
|
currentThumbnail = contact.thumbnail;
|
||||||
|
print('CallService: Found contact - displayName: $currentDisplayName, thumbnail: ${currentThumbnail != null ? "present" : "null"}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print('CallService: Navigating to CallPage');
|
}
|
||||||
|
}
|
||||||
|
currentDisplayName = phoneNumber;
|
||||||
|
currentThumbnail = null;
|
||||||
|
print('CallService: No contact match, using phoneNumber as displayName: $currentDisplayName');
|
||||||
|
} catch (e) {
|
||||||
|
print('CallService: Error fetching contact info: $e');
|
||||||
|
currentDisplayName = phoneNumber;
|
||||||
|
currentThumbnail = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _normalizePhoneNumber(String number) {
|
||||||
|
return number.replaceAll(RegExp(r'[\s\-\(\)]'), '').replaceFirst(RegExp(r'^\+'), '');
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleIncomingCall(String phoneNumber) {
|
||||||
|
if (_activeCallNumber == phoneNumber && _isCallPageVisible) {
|
||||||
|
print('CallService: Incoming call for $phoneNumber already active, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_activeCallNumber = phoneNumber;
|
||||||
|
|
||||||
|
final context = navigatorKey.currentContext;
|
||||||
|
if (context == null) {
|
||||||
|
print('CallService: Context is null, queuing incoming call: $phoneNumber');
|
||||||
|
_pendingCall = {"phoneNumber": phoneNumber};
|
||||||
|
Future.delayed(Duration(milliseconds: 500), () => _checkPendingCall());
|
||||||
|
} else {
|
||||||
|
_navigateToIncomingCallPage(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _checkPendingCall() async {
|
||||||
|
if (_pendingCall == null) {
|
||||||
|
print('CallService: No pending call to process');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final phoneNumber = _pendingCall!["phoneNumber"];
|
||||||
|
if (_activeCallNumber == phoneNumber && _isCallPageVisible) {
|
||||||
|
print('CallService: Pending call for $phoneNumber already active, clearing');
|
||||||
|
_pendingCall = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final context = navigatorKey.currentContext;
|
||||||
|
if (context != null) {
|
||||||
|
print('CallService: Processing queued call: $phoneNumber');
|
||||||
|
currentPhoneNumber = phoneNumber;
|
||||||
|
_activeCallNumber = phoneNumber;
|
||||||
|
await _fetchContactInfo(phoneNumber);
|
||||||
|
_navigateToIncomingCallPage(context);
|
||||||
|
_pendingCall = null;
|
||||||
|
} else {
|
||||||
|
print('CallService: Context still null, retrying...');
|
||||||
|
Future.delayed(Duration(milliseconds: 500), () => _checkPendingCall());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _navigateToCallPage() {
|
||||||
|
if (_isNavigating) {
|
||||||
|
print('CallService: Navigation already in progress, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_isNavigating = true;
|
||||||
|
|
||||||
|
final context = navigatorKey.currentContext;
|
||||||
|
if (context == null) {
|
||||||
|
print('CallService: Cannot navigate to CallPage, context is null');
|
||||||
|
_isNavigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final currentRoute = ModalRoute.of(context)?.settings.name ?? 'unknown';
|
||||||
|
print('CallService: Navigating to CallPage, Visible: $_isCallPageVisible, Current Route: $currentRoute, Active Call: $_activeCallNumber, DisplayName: $currentDisplayName');
|
||||||
|
if (_isCallPageVisible && currentRoute == '/call' && _activeCallNumber == currentPhoneNumber) {
|
||||||
|
print('CallService: CallPage already visible for $_activeCallNumber, skipping navigation');
|
||||||
|
_isNavigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_isCallPageVisible && currentRoute == '/incoming_call' && _activeCallNumber == currentPhoneNumber) {
|
||||||
|
print('CallService: Popping IncomingCallPage before navigating to CallPage');
|
||||||
|
Navigator.pop(context);
|
||||||
|
_isCallPageVisible = false;
|
||||||
|
}
|
||||||
|
if (currentPhoneNumber == null) {
|
||||||
|
print('CallService: Cannot navigate to CallPage, currentPhoneNumber is null');
|
||||||
|
_isNavigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_activeCallNumber = currentPhoneNumber;
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
settings: const RouteSettings(name: '/call'),
|
settings: const RouteSettings(name: '/call'),
|
||||||
builder: (context) => CallPage(
|
builder: (context) => CallPage(
|
||||||
displayName: currentPhoneNumber!,
|
displayName: currentDisplayName ?? currentPhoneNumber!,
|
||||||
phoneNumber: currentPhoneNumber!,
|
phoneNumber: currentPhoneNumber!,
|
||||||
thumbnail: null,
|
thumbnail: currentThumbnail,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).then((_) {
|
).then((_) {
|
||||||
_isCallPageVisible = false;
|
_isCallPageVisible = false;
|
||||||
|
_isNavigating = false;
|
||||||
|
print('CallService: CallPage popped, _isCallPageVisible set to false');
|
||||||
});
|
});
|
||||||
_isCallPageVisible = true;
|
_isCallPageVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _navigateToIncomingCallPage(BuildContext context) {
|
void _navigateToIncomingCallPage(BuildContext context) {
|
||||||
if (_isCallPageVisible && ModalRoute.of(context)?.settings.name == '/incoming_call') {
|
if (_isNavigating) {
|
||||||
print('CallService: IncomingCallPage already visible, skipping navigation');
|
print('CallService: Navigation already in progress, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_isNavigating = true;
|
||||||
|
|
||||||
|
final currentRoute = ModalRoute.of(context)?.settings.name ?? 'unknown';
|
||||||
|
print('CallService: Navigating to IncomingCallPage, Visible: $_isCallPageVisible, Current Route: $currentRoute, Active Call: $_activeCallNumber, DisplayName: $currentDisplayName');
|
||||||
|
if (_isCallPageVisible && currentRoute == '/incoming_call' && _activeCallNumber == currentPhoneNumber) {
|
||||||
|
print('CallService: IncomingCallPage already visible for $_activeCallNumber, skipping navigation');
|
||||||
|
_isNavigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_isCallPageVisible && currentRoute == '/call') {
|
||||||
|
print('CallService: CallPage visible, not showing IncomingCallPage');
|
||||||
|
_isNavigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (currentPhoneNumber == null) {
|
||||||
|
print('CallService: Cannot navigate to IncomingCallPage, currentPhoneNumber is null');
|
||||||
|
_isNavigating = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print('CallService: Navigating to IncomingCallPage');
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
settings: const RouteSettings(name: '/incoming_call'),
|
settings: const RouteSettings(name: '/incoming_call'),
|
||||||
builder: (context) => IncomingCallPage(
|
builder: (context) => IncomingCallPage(
|
||||||
displayName: currentPhoneNumber!,
|
displayName: currentDisplayName ?? currentPhoneNumber!,
|
||||||
phoneNumber: currentPhoneNumber!,
|
phoneNumber: currentPhoneNumber!,
|
||||||
thumbnail: null,
|
thumbnail: currentThumbnail,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).then((_) {
|
).then((_) {
|
||||||
_isCallPageVisible = false;
|
_isCallPageVisible = false;
|
||||||
|
_isNavigating = false;
|
||||||
|
print('CallService: IncomingCallPage popped, _isCallPageVisible set to false');
|
||||||
});
|
});
|
||||||
_isCallPageVisible = true;
|
_isCallPageVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _closeCallPage(BuildContext context) {
|
void _closeCallPage() {
|
||||||
if (!_isCallPageVisible) {
|
final context = navigatorKey.currentContext;
|
||||||
print('CallService: CallPage not visible, skipping pop');
|
if (context == null) {
|
||||||
|
print('CallService: Cannot close page, context is null');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
print('CallService: Closing call page, _isCallPageVisible: $_isCallPageVisible');
|
||||||
if (Navigator.canPop(context)) {
|
if (Navigator.canPop(context)) {
|
||||||
print('CallService: Popping CallPage');
|
print('CallService: Popping call page');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
_isCallPageVisible = false;
|
_isCallPageVisible = false;
|
||||||
|
} else {
|
||||||
|
print('CallService: No page to pop');
|
||||||
}
|
}
|
||||||
|
_activeCallNumber = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> makeGsmCall(
|
Future<Map<String, dynamic>> makeGsmCall(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String phoneNumber,
|
required String phoneNumber,
|
||||||
String? displayName,
|
String? displayName,
|
||||||
Uint8List? thumbnail,
|
Uint8List? thumbnail,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
|
if (_activeCallNumber == phoneNumber && _isCallPageVisible) {
|
||||||
|
print('CallService: Call already active for $phoneNumber, skipping');
|
||||||
|
return {"status": "already_active", "message": "Call already in progress"};
|
||||||
|
}
|
||||||
currentPhoneNumber = phoneNumber;
|
currentPhoneNumber = phoneNumber;
|
||||||
print('CallService: Making GSM call to $phoneNumber');
|
currentDisplayName = displayName ?? phoneNumber;
|
||||||
|
currentThumbnail = thumbnail;
|
||||||
|
if (displayName == null || thumbnail == null) {
|
||||||
|
await _fetchContactInfo(phoneNumber);
|
||||||
|
}
|
||||||
|
print('CallService: Making GSM call to $phoneNumber, displayName: $currentDisplayName');
|
||||||
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
|
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
|
||||||
print('CallService: makeGsmCall result: $result');
|
print('CallService: makeGsmCall result: $result');
|
||||||
if (result["status"] != "calling") {
|
final resultMap = Map<String, dynamic>.from(result as Map);
|
||||||
|
if (resultMap["status"] != "calling") {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Failed to initiate call")),
|
SnackBar(content: Text("Failed to initiate call")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return resultMap;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("CallService: Error making call: $e");
|
print("CallService: Error making call: $e");
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Error making call: $e")),
|
SnackBar(content: Text("Error making call: $e")),
|
||||||
);
|
);
|
||||||
rethrow;
|
return {"status": "error", "message": e.toString()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> hangUpCall(BuildContext context) async {
|
Future<Map<String, dynamic>> hangUpCall(BuildContext context) async {
|
||||||
try {
|
try {
|
||||||
print('CallService: Hanging up call');
|
print('CallService: Hanging up call');
|
||||||
final result = await _channel.invokeMethod('hangUpCall');
|
final result = await _channel.invokeMethod('hangUpCall');
|
||||||
print('CallService: hangUpCall result: $result');
|
print('CallService: hangUpCall result: $result');
|
||||||
if (result["status"] != "ended") {
|
final resultMap = Map<String, dynamic>.from(result as Map);
|
||||||
|
if (resultMap["status"] != "ended") {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Failed to end call")),
|
SnackBar(content: Text("Failed to end call")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return resultMap;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("CallService: Error hanging up call: $e");
|
print("CallService: Error hanging up call: $e");
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Error hanging up call: $e")),
|
SnackBar(content: Text("Error hanging up call: $e")),
|
||||||
);
|
);
|
||||||
rethrow;
|
return {"status": "error", "message": e.toString()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,11 +18,7 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
List<Contact> _allContacts = [];
|
List<Contact> _allContacts = [];
|
||||||
List<Contact> _filteredContacts = [];
|
List<Contact> _filteredContacts = [];
|
||||||
final ContactService _contactService = ContactService();
|
final ContactService _contactService = ContactService();
|
||||||
|
|
||||||
// Instantiate the ObfuscateService
|
|
||||||
final ObfuscateService _obfuscateService = ObfuscateService();
|
final ObfuscateService _obfuscateService = ObfuscateService();
|
||||||
|
|
||||||
// Instantiate the CallService
|
|
||||||
final CallService _callService = CallService();
|
final CallService _callService = CallService();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -40,8 +36,13 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
void _filterContacts() {
|
void _filterContacts() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_filteredContacts = _allContacts.where((contact) {
|
_filteredContacts = _allContacts.where((contact) {
|
||||||
final phoneMatch = contact.phones.any((phone) =>
|
bool phoneMatch = contact.phones.any((phone) {
|
||||||
phone.number.replaceAll(RegExp(r'\D'), '').contains(dialedNumber));
|
final rawPhoneNumber = phone.number;
|
||||||
|
final strippedPhoneNumber = rawPhoneNumber.replaceAll(RegExp(r'\D'), '');
|
||||||
|
final strippedDialedNumber = dialedNumber.replaceAll(RegExp(r'\D'), '');
|
||||||
|
return rawPhoneNumber.contains(dialedNumber) ||
|
||||||
|
strippedPhoneNumber.contains(strippedDialedNumber);
|
||||||
|
});
|
||||||
final nameMatch = contact.displayName
|
final nameMatch = contact.displayName
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(dialedNumber.toLowerCase());
|
.contains(dialedNumber.toLowerCase());
|
||||||
@ -57,6 +58,13 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onPlusPress() {
|
||||||
|
setState(() {
|
||||||
|
dialedNumber += '+';
|
||||||
|
_filterContacts();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _onDeletePress() {
|
void _onDeletePress() {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (dialedNumber.isNotEmpty) {
|
if (dialedNumber.isNotEmpty) {
|
||||||
@ -73,7 +81,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to call a contact's number using the CallService
|
|
||||||
void _makeCall(String phoneNumber) async {
|
void _makeCall(String phoneNumber) async {
|
||||||
try {
|
try {
|
||||||
await _callService.makeGsmCall(context, phoneNumber: phoneNumber);
|
await _callService.makeGsmCall(context, phoneNumber: phoneNumber);
|
||||||
@ -82,10 +89,12 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("Error making call: $e");
|
debugPrint("Error making call: $e");
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Failed to make call: $e')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to send an SMS to a contact's number
|
|
||||||
void _launchSms(String phoneNumber) async {
|
void _launchSms(String phoneNumber) async {
|
||||||
final uri = Uri(scheme: 'sms', path: phoneNumber);
|
final uri = Uri(scheme: 'sms', path: phoneNumber);
|
||||||
if (await canLaunchUrl(uri)) {
|
if (await canLaunchUrl(uri)) {
|
||||||
@ -95,6 +104,20 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _addContact() async {
|
||||||
|
if (await FlutterContacts.requestPermission()) {
|
||||||
|
final newContact = Contact()
|
||||||
|
..phones = [Phone(dialedNumber.isNotEmpty ? dialedNumber : '')];
|
||||||
|
final updatedContact = await FlutterContacts.openExternalInsert(newContact);
|
||||||
|
if (updatedContact != null) {
|
||||||
|
_fetchContacts();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Contact added successfully!')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -103,7 +126,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
// Top half: Display contacts matching dialed number
|
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
child: Container(
|
child: Container(
|
||||||
@ -115,8 +137,8 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: _filteredContacts.isNotEmpty
|
children: [
|
||||||
? _filteredContacts.map((contact) {
|
..._filteredContacts.map((contact) {
|
||||||
final phoneNumber = contact.phones.isNotEmpty
|
final phoneNumber = contact.phones.isNotEmpty
|
||||||
? contact.phones.first.number
|
? contact.phones.first.number
|
||||||
: 'No phone number';
|
: 'No phone number';
|
||||||
@ -132,40 +154,34 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// Call button (Now using CallService)
|
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.phone,
|
icon: Icon(Icons.phone, color: Colors.green[300], size: 20),
|
||||||
color: Colors.green[300],
|
onPressed: () => _makeCall(phoneNumber),
|
||||||
size: 20),
|
|
||||||
onPressed: () {
|
|
||||||
_makeCall(phoneNumber); // Make a call using CallService
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
// Message button
|
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.message,
|
icon: Icon(Icons.message, color: Colors.blue[300], size: 20),
|
||||||
color: Colors.blue[300],
|
onPressed: () => _launchSms(phoneNumber),
|
||||||
size: 20),
|
|
||||||
onPressed: () {
|
|
||||||
_launchSms(phoneNumber);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {},
|
||||||
// Handle contact selection if needed
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}).toList()
|
}).toList(),
|
||||||
: [],
|
ListTile(
|
||||||
|
title: const Text(
|
||||||
|
'Add a contact',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
trailing: Icon(Icons.add, color: Colors.grey[600]),
|
||||||
|
onTap: _addContact,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Bottom half: Dialpad and Dialed number display with erase button
|
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
child: Container(
|
child: Container(
|
||||||
@ -173,7 +189,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// Display dialed number with erase button
|
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
@ -182,61 +197,57 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text(
|
child: Text(
|
||||||
dialedNumber,
|
dialedNumber,
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 24, color: Colors.white),
|
||||||
fontSize: 24, color: Colors.white),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
GestureDetector(
|
||||||
onPressed: _onClearPress,
|
onTap: _onDeletePress,
|
||||||
icon: const Icon(Icons.backspace,
|
onLongPress: _onClearPress,
|
||||||
color: Colors.white),
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(8.0),
|
||||||
|
child: Icon(Icons.backspace, color: Colors.white),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
// Dialpad
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
children: [
|
||||||
_buildDialButton('1'),
|
_buildDialButton('1', Colors.white),
|
||||||
_buildDialButton('2'),
|
_buildDialButton('2', Colors.white),
|
||||||
_buildDialButton('3'),
|
_buildDialButton('3', Colors.white),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
children: [
|
||||||
_buildDialButton('4'),
|
_buildDialButton('4', Colors.white),
|
||||||
_buildDialButton('5'),
|
_buildDialButton('5', Colors.white),
|
||||||
_buildDialButton('6'),
|
_buildDialButton('6', Colors.white),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
children: [
|
||||||
_buildDialButton('7'),
|
_buildDialButton('7', Colors.white),
|
||||||
_buildDialButton('8'),
|
_buildDialButton('8', Colors.white),
|
||||||
_buildDialButton('9'),
|
_buildDialButton('9', Colors.white),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
children: [
|
||||||
_buildDialButton('*'),
|
_buildDialButton('*', const Color.fromRGBO(117, 117, 117, 1)),
|
||||||
_buildDialButton('0'),
|
_buildDialButtonWithPlus('0'),
|
||||||
_buildDialButton('#'),
|
_buildDialButton('#', const Color.fromRGBO(117, 117, 117, 1)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -249,26 +260,28 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
// Add Contact Button
|
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 20.0,
|
bottom: 20.0,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: AddContactButton(),
|
child: ElevatedButton(
|
||||||
|
onPressed: dialedNumber.isNotEmpty ? () => _makeCall(dialedNumber) : null,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.green[700],
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.phone, color: Colors.white, size: 30),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Top Row with Back Arrow
|
|
||||||
Positioned(
|
Positioned(
|
||||||
top: 40.0,
|
top: 40.0,
|
||||||
left: 16.0,
|
left: 16.0,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||||
onPressed: () {
|
onPressed: () => Navigator.pop(context),
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -276,7 +289,7 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDialButton(String number) {
|
Widget _buildDialButton(String number, Color textColor) {
|
||||||
return ElevatedButton(
|
return ElevatedButton(
|
||||||
onPressed: () => _onNumberPress(number),
|
onPressed: () => _onNumberPress(number),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
@ -286,11 +299,38 @@ class _CompositionPageState extends State<CompositionPage> {
|
|||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
number,
|
number,
|
||||||
style: const TextStyle(
|
style: TextStyle(fontSize: 24, color: textColor),
|
||||||
fontSize: 24,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildDialButtonWithPlus(String number) {
|
||||||
|
return Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onLongPress: _onPlusPress,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () => _onNumberPress(number),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
number,
|
||||||
|
style: const TextStyle(fontSize: 24, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: 8,
|
||||||
|
child: Text(
|
||||||
|
'+',
|
||||||
|
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ class HistoryPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HistoryPageState extends State<HistoryPage>
|
class _HistoryPageState extends State<HistoryPage>
|
||||||
with SingleTickerProviderStateMixin {
|
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
|
||||||
List<History> histories = [];
|
List<History> histories = [];
|
||||||
bool loading = true;
|
bool loading = true;
|
||||||
int? _expandedIndex;
|
int? _expandedIndex;
|
||||||
@ -47,10 +47,13 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
// Create a MethodChannel instance.
|
// Create a MethodChannel instance.
|
||||||
static const MethodChannel _channel = MethodChannel('com.example.calllog');
|
static const MethodChannel _channel = MethodChannel('com.example.calllog');
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true; // Preserve state when switching pages
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
if (loading) {
|
if (loading && histories.isEmpty) {
|
||||||
_buildHistories();
|
_buildHistories();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,9 +157,9 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
List<Contact> contacts = contactState.contacts;
|
List<Contact> contacts = contactState.contacts;
|
||||||
|
|
||||||
List<History> callHistories = [];
|
List<History> callHistories = [];
|
||||||
// Process each log entry.
|
// Process each log entry with intermittent yields to avoid freezing.
|
||||||
for (var entry in nativeLogs) {
|
for (int i = 0; i < nativeLogs.length; i++) {
|
||||||
// Each entry is a Map with keys: number, type, date, duration.
|
final entry = nativeLogs[i];
|
||||||
final String number = entry['number'] ?? '';
|
final String number = entry['number'] ?? '';
|
||||||
if (number.isEmpty) continue;
|
if (number.isEmpty) continue;
|
||||||
|
|
||||||
@ -202,6 +205,8 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
|
|
||||||
callHistories
|
callHistories
|
||||||
.add(History(matchedContact, callDate, callType, callStatus, 1));
|
.add(History(matchedContact, callDate, callType, callStatus, 1));
|
||||||
|
// Yield every 10 iterations to avoid blocking the UI.
|
||||||
|
if (i % 10 == 0) await Future.delayed(Duration(milliseconds: 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort histories by most recent.
|
// Sort histories by most recent.
|
||||||
@ -277,6 +282,7 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context); // required due to AutomaticKeepAliveClientMixin
|
||||||
final contactState = ContactState.of(context);
|
final contactState = ContactState.of(context);
|
||||||
|
|
||||||
if (loading || contactState.loading) {
|
if (loading || contactState.loading) {
|
||||||
@ -424,7 +430,12 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
icon: const Icon(Icons.phone, color: Colors.green),
|
icon: const Icon(Icons.phone, color: Colors.green),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (contact.phones.isNotEmpty) {
|
if (contact.phones.isNotEmpty) {
|
||||||
_callService.makeGsmCall(context, phoneNumber: contact.phones.first.number);
|
await _callService.makeGsmCall(
|
||||||
|
context,
|
||||||
|
phoneNumber: contact.phones.first.number,
|
||||||
|
displayName: contact.displayName,
|
||||||
|
thumbnail: contact.thumbnail,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
|
@ -27,14 +27,13 @@ The protocol definition will include as completed:
|
|||||||
- Handshakes
|
- Handshakes
|
||||||
- Real-time data-stream encryption (and decryption)
|
- Real-time data-stream encryption (and decryption)
|
||||||
- Encrypted stream compression
|
- Encrypted stream compression
|
||||||
- Transmission over audio stream
|
- Transmission over audio stream (at least one modulation type)
|
||||||
- Minimal error correction in audio-based transmission
|
- First steps in FEC (Forward Error Correction): detecting half of transmission errors
|
||||||
- Error handling and user prevention
|
|
||||||
|
|
||||||
And should include prototype or scratches functionalities, among which:
|
And should include prototype or scratches functionalities, among which:
|
||||||
- Embedded silent data transmission (silently transmit light data during an encrypted phone call)
|
- Embedded silent data transmission (such as DTMF)
|
||||||
- On-the-fly key exchange (does not require prior key exchange, sacrifying some security)
|
- On-the-fly key exchange (does not require prior key exchange, sacrifying some security)
|
||||||
- Strong error correction
|
- Stronger FEC: detecting >80%, correcting 20% of transmission errors
|
||||||
|
|
||||||
#### The Icing dialer (based on Icing kotlin library, an Icing protocol implementation)
|
#### The Icing dialer (based on Icing kotlin library, an Icing protocol implementation)
|
||||||
|
|
||||||
@ -128,16 +127,15 @@ The remote bank advisor asks him to authenticate, making him type his password o
|
|||||||
By using the Icing protocol, not only would Jeff and the bank be assured that the informations are transmitted safely,
|
By using the Icing protocol, not only would Jeff and the bank be assured that the informations are transmitted safely,
|
||||||
but also that the call is coming from Jeff's phone and not an impersonator.
|
but also that the call is coming from Jeff's phone and not an impersonator.
|
||||||
|
|
||||||
Elise is a 42 years-old extreme reporter.
|
Elise, 42 years-old, is a journalist covering sensitive topics.
|
||||||
After interviewing Russians opposition's leader, the FSB is looking to interview her.
|
Her work draws attention from people who want to know what she's saying - and to whom.
|
||||||
She tries to stay discreet and hidden, but those measures constrains her to barely receive cellular network.
|
Forced to stay discreet, with unreliable signal and a likely monitored phone line,
|
||||||
She suspects her phone line to be monitored, so the best she can do to call safely, is to use her Icing dialer.
|
she uses Icing dialer to make secure calls without exposing herself.
|
||||||
|
|
||||||
Paul, a 22 years-old developer working for a big company, decides to go to China for vacations.
|
Paul, a 22 years-old developer, is enjoying its vacations abroad.
|
||||||
But everything goes wrong! The company's product he works on, is failling in the middle of the day and no one is
|
But everything goes wrong! The company's product he works on, is failling in the middle of the day and no one is
|
||||||
qualified to fix it. Paul doesn't have WiFi and his phone plan only covers voice calls in China.
|
qualified to fix it. Paul doesn't have WiFi and his phone plan only covers voice calls in his country.
|
||||||
With Icing dialer, he can call his collegues and help fix the
|
With Icing dialer, he can call his collegues and help fix the problem, completely safe.
|
||||||
problem, safe from potential Chinese spies.
|
|
||||||
|
|
||||||
## Evaluation Criteria
|
## Evaluation Criteria
|
||||||
### Protocol and lib
|
### Protocol and lib
|
||||||
|
Loading…
Reference in New Issue
Block a user