Compare commits

..

16 Commits

Author SHA1 Message Date
0d6322a714 fix: not showing call UI on long press
All checks were successful
/ mirror (push) Successful in 4s
/ build-stealth (push) Successful in 8m21s
/ build (push) Successful in 8m30s
2025-03-14 15:59:54 +02:00
da0c5d1991 feat: call page UI
Some checks failed
/ mirror (push) Waiting to run
/ build (push) Has been cancelled
/ build-stealth (push) Has been cancelled
2025-03-14 15:57:47 +02:00
3129e51eb4 Add CallPage for initiating calls with contact details (#37)
Demo call page avec les features de base:
- Haut parleur
- Couper/activer micro
- keypad
- raccrocher
- Display Icing state (toucher pour switch l'état)

S'active en faisant un appui long sur le bouton d'appel depuis les détails du contact.
Compatible avec l'obfuscation des contacts.

Co-authored-by: AlexisDanlos <91090088+AlexisDanlos@users.noreply.github.com>
Reviewed-on: #37
Co-authored-by: alexis <alexis.danlos@epitech.eu>
Co-committed-by: alexis <alexis.danlos@epitech.eu>
2025-03-14 15:54:26 +02:00
2894dce1bc feat: can call and receive call
All checks were successful
/ mirror (push) Successful in 5s
/ build-stealth (push) Successful in 8m45s
/ build (push) Successful in 8m47s
2025-03-14 15:40:28 +02:00
5704fa1607 feat: APP IS DEFAULT DIALER
All checks were successful
/ mirror (push) Successful in 5s
/ build-stealth (push) Successful in 8m46s
/ build (push) Successful in 8m39s
2025-03-14 00:21:21 +02:00
e4ad9726ae rebase
All checks were successful
/ mirror (push) Successful in 5s
/ build (push) Successful in 8m33s
/ build-stealth (push) Successful in 8m35s
2025-03-13 22:45:14 +02:00
26316cf971 feat: call page UI
Some checks failed
/ mirror (push) Successful in 5s
/ build (push) Failing after 4m3s
/ build-stealth (push) Failing after 4m3s
2025-03-13 22:35:40 +02:00
98f199f450 Add CallPage for initiating calls with contact details (#37)
Demo call page avec les features de base:
- Haut parleur
- Couper/activer micro
- keypad
- raccrocher
- Display Icing state (toucher pour switch l'état)

S'active en faisant un appui long sur le bouton d'appel depuis les détails du contact.
Compatible avec l'obfuscation des contacts.

Co-authored-by: AlexisDanlos <91090088+AlexisDanlos@users.noreply.github.com>
Reviewed-on: #37
Co-authored-by: alexis <alexis.danlos@epitech.eu>
Co-committed-by: alexis <alexis.danlos@epitech.eu>
2025-03-13 22:29:39 +02:00
5529a6e038 feat: request perm in flutter, wait for perm before trying to become main dialer
All checks were successful
/ build (push) Successful in 8m35s
/ build-stealth (push) Successful in 8m33s
/ mirror (push) Successful in 5s
2025-03-05 16:04:05 +01:00
c886e29d75 feat: perms & UI methodchannel
All checks were successful
/ mirror (push) Successful in 5s
/ build-stealth (push) Successful in 8m24s
/ build (push) Successful in 8m24s
2025-03-04 18:44:55 +01:00
24dc5a9bbe feat: update flutter UI via methodchannel, permissions via flutter at startup 2025-03-04 18:43:48 +01:00
b042a68a8e fix: makeGsmCall in historypage
All checks were successful
/ mirror (push) Successful in 7s
/ build-stealth (push) Successful in 8m29s
/ build (push) Successful in 8m30s
2025-03-04 14:23:02 +01:00
9bfb55821d fix: search bar upgrade (#42)
Some checks failed
/ mirror (push) Successful in 4s
/ build (push) Has been cancelled
/ build-stealth (push) Has been cancelled
Reviewed-on: #42
Co-authored-by: Florian Griffon <florian.griffon@epitech.eu>
Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
2025-03-04 14:22:06 +01:00
b7ebacec85 cicd-stealth (#40)
Reviewed-on: #40
Co-authored-by: ange <ange@yw5n.com>
Co-committed-by: ange <ange@yw5n.com>
2025-03-04 14:22:06 +01:00
ef78e4c17d fix: call correctly in history page (#41)
Reviewed-on: #41
Co-authored-by: Florian Griffon <florian.griffon@epitech.eu>
Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
2025-03-04 14:22:06 +01:00
7c7a4f28f4 feat: call page UI
Some checks failed
/ build (push) Failing after 5s
/ mirror (push) Successful in 5s
2025-03-04 14:20:56 +01:00
9 changed files with 263 additions and 611 deletions

View File

@ -12,8 +12,6 @@
<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"
@ -29,14 +27,9 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data <meta-data
android:name="io.flutter.embedding.android.NormalTheme" android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" android:resource="@style/NormalTheme" />
/>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
@ -89,11 +82,6 @@
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
</application> </application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries> <queries>
<intent> <intent>
<action android:name="android.intent.action.PROCESS_TEXT" /> <action android:name="android.intent.action.PROCESS_TEXT" />

View File

@ -6,6 +6,7 @@ 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
@ -25,76 +26,23 @@ 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")
wasPhoneLocked = intent.getBooleanExtra("wasPhoneLocked", false) Log.d(TAG, "Waiting for Flutter to signal permissions")
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)
} }
@ -112,66 +60,37 @@ class MainActivity : FlutterActivity() {
} }
} }
"hangUpCall" -> { "hangUpCall" -> {
val success = MyInCallService.currentCall?.let { val success = CallService.hangUpCall(this)
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 {
Log.w(TAG, "No active call to hang up") result.error("HANGUP_FAILED", "Failed to end call", null)
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) it.answer(0) // 0 for default video state (audio-only)
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)
}
else -> result.notImplemented() else -> result.notImplemented()
} }
} }
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KEYSTORE_CHANNEL) MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KEYSTORE_CHANNEL)
.setMethodCallHandler { call, result -> .setMethodCallHandler { call, result -> KeystoreHelper(call, result).handleMethodCall() }
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()
} }
@ -190,6 +109,8 @@ 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)
@ -227,18 +148,6 @@ 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(
@ -262,25 +171,4 @@ 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")
}
}
}
}
}
} }

View File

@ -1,17 +1,8 @@
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.os.Build
import android.telecom.Call import android.telecom.Call
import android.telecom.InCallService import android.telecom.InCallService
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() {
@ -19,9 +10,6 @@ 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 val callCallback = object : Call.Callback() { private val callCallback = object : Call.Callback() {
@ -38,22 +26,12 @@ 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()
} }
} }
} }
@ -65,32 +43,22 @@ class MyInCallService : InCallService() {
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" else -> "dialing" // Default for outgoing
} }
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)
} }
override fun onCallRemoved(call: Call) { override fun onCallRemoved(call: Call) {
super.onCallRemoved(call) super.onCallRemoved(call)
Log.d(TAG, "Call removed: ${call.details.handle}, wasPhoneLocked: $wasPhoneLocked") Log.d(TAG, "Call removed: ${call.details.handle}")
call.unregisterCallback(callCallback) call.unregisterCallback(callCallback)
channel?.invokeMethod("callRemoved", mapOf( channel?.invokeMethod("callRemoved", mapOf("callId" to call.details.handle.toString()))
"callId" to call.details.handle.toString(),
"wasPhoneLocked" to wasPhoneLocked
))
currentCall = null currentCall = null
cancelNotification()
} }
override fun onCallAudioStateChanged(state: android.telecom.CallAudioState) { override fun onCallAudioStateChanged(state: android.telecom.CallAudioState) {
@ -98,59 +66,4 @@ class MyInCallService : InCallService() {
Log.d(TAG, "Audio state changed: route=${state.route}") Log.d(TAG, "Audio state changed: route=${state.route}")
channel?.invokeMethod("audioStateChanged", mapOf("route" to state.route)) channel?.invokeMethod("audioStateChanged", mapOf("route" to state.route))
} }
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")
}
} }

View File

@ -61,16 +61,9 @@ class _CallPageState extends State<CallPage> {
void _hangUp() async { void _hangUp() async {
try { try {
final result = await _callService.hangUpCall(context); await _callService.hangUpCall(context);
print('CallPage: Hang up result: $result');
if (result["status"] == "ended" && mounted && Navigator.canPop(context)) {
Navigator.pop(context);
}
} catch (e) { } catch (e) {
print("CallPage: Error hanging up: $e"); print("Error hanging up: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Error hanging up: $e")),
);
} }
} }
@ -93,10 +86,9 @@ class _CallPageState extends State<CallPage> {
children: [ children: [
SizedBox(height: 35), SizedBox(height: 35),
ObfuscatedAvatar( ObfuscatedAvatar(
imageBytes: widget.thumbnail, imageBytes: widget.thumbnail, // Uses thumbnail if provided
radius: avatarRadius, radius: avatarRadius,
backgroundColor: backgroundColor: generateColorFromName(widget.displayName),
generateColorFromName(widget.displayName),
fallbackInitial: widget.displayName, fallbackInitial: widget.displayName,
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
@ -130,13 +122,11 @@ class _CallPageState extends State<CallPage> {
), ),
Text( Text(
widget.phoneNumber, widget.phoneNumber,
style: TextStyle( style: TextStyle(fontSize: statusFontSize, color: Colors.white70),
fontSize: statusFontSize, color: Colors.white70),
), ),
Text( Text(
'Calling...', 'Calling...',
style: TextStyle( style: TextStyle(fontSize: statusFontSize, color: Colors.white70),
fontSize: statusFontSize, color: Colors.white70),
), ),
], ],
), ),
@ -167,8 +157,7 @@ class _CallPageState extends State<CallPage> {
IconButton( IconButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: _toggleKeypad, onPressed: _toggleKeypad,
icon: icon: const Icon(Icons.close, color: Colors.white),
const Icon(Icons.close, color: Colors.white),
), ),
], ],
), ),
@ -204,8 +193,7 @@ class _CallPageState extends State<CallPage> {
child: Center( child: Center(
child: Text( child: Text(
label, label,
style: const TextStyle( style: const TextStyle(fontSize: 32, color: Colors.white),
fontSize: 32, color: Colors.white),
), ),
), ),
), ),
@ -237,8 +225,7 @@ class _CallPageState extends State<CallPage> {
), ),
Text( Text(
isMuted ? 'Unmute' : 'Mute', isMuted ? 'Unmute' : 'Mute',
style: const TextStyle( style: const TextStyle(color: Colors.white, fontSize: 14),
color: Colors.white, fontSize: 14),
), ),
], ],
), ),
@ -247,13 +234,11 @@ class _CallPageState extends State<CallPage> {
children: [ children: [
IconButton( IconButton(
onPressed: _toggleKeypad, onPressed: _toggleKeypad,
icon: const Icon(Icons.dialpad, icon: const Icon(Icons.dialpad, color: Colors.white, size: 32),
color: Colors.white, size: 32),
), ),
const Text( const Text(
'Keypad', 'Keypad',
style: TextStyle( style: TextStyle(color: Colors.white, fontSize: 14),
color: Colors.white, fontSize: 14),
), ),
], ],
), ),
@ -263,19 +248,14 @@ class _CallPageState extends State<CallPage> {
IconButton( IconButton(
onPressed: _toggleSpeaker, onPressed: _toggleSpeaker,
icon: Icon( icon: Icon(
isSpeakerOn isSpeakerOn ? Icons.volume_up : Icons.volume_off,
? Icons.volume_up color: isSpeakerOn ? Colors.amber : Colors.white,
: Icons.volume_off,
color: isSpeakerOn
? Colors.amber
: Colors.white,
size: 32, size: 32,
), ),
), ),
const Text( const Text(
'Speaker', 'Speaker',
style: TextStyle( style: TextStyle(color: Colors.white, fontSize: 14),
color: Colors.white, fontSize: 14),
), ),
], ],
), ),
@ -290,12 +270,10 @@ class _CallPageState extends State<CallPage> {
children: [ children: [
IconButton( IconButton(
onPressed: () {}, onPressed: () {},
icon: const Icon(Icons.person_add, icon: const Icon(Icons.person_add, color: Colors.white, size: 32),
color: Colors.white, size: 32),
), ),
const Text('Add Contact', const Text('Add Contact',
style: TextStyle( style: TextStyle(color: Colors.white, fontSize: 14)),
color: Colors.white, fontSize: 14)),
], ],
), ),
Column( Column(
@ -303,12 +281,10 @@ class _CallPageState extends State<CallPage> {
children: [ children: [
IconButton( IconButton(
onPressed: () {}, onPressed: () {},
icon: const Icon(Icons.sim_card, icon: const Icon(Icons.sim_card, color: Colors.white, size: 32),
color: Colors.white, size: 32),
), ),
const Text('Change SIM', const Text('Change SIM',
style: TextStyle( style: TextStyle(color: Colors.white, fontSize: 14)),
color: Colors.white, fontSize: 14)),
], ],
), ),
], ],

View File

@ -2,8 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../../services/contact_service.dart'; import '../../services/contact_service.dart';
import '../../services/obfuscate_service.dart'; import '../../services/obfuscate_service.dart'; // Import ObfuscateService
import '../../services/call_service.dart'; import '../../services/call_service.dart'; // Import the CallService
import '../contacts/widgets/add_contact_button.dart';
class CompositionPage extends StatefulWidget { class CompositionPage extends StatefulWidget {
const CompositionPage({super.key}); const CompositionPage({super.key});
@ -17,7 +18,11 @@ 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
@ -35,13 +40,8 @@ class _CompositionPageState extends State<CompositionPage> {
void _filterContacts() { void _filterContacts() {
setState(() { setState(() {
_filteredContacts = _allContacts.where((contact) { _filteredContacts = _allContacts.where((contact) {
bool phoneMatch = contact.phones.any((phone) { final phoneMatch = contact.phones.any((phone) =>
final rawPhoneNumber = phone.number; phone.number.replaceAll(RegExp(r'\D'), '').contains(dialedNumber));
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,13 +57,6 @@ class _CompositionPageState extends State<CompositionPage> {
}); });
} }
void _onPlusPress() {
setState(() {
dialedNumber += '+';
_filterContacts();
});
}
void _onDeletePress() { void _onDeletePress() {
setState(() { setState(() {
if (dialedNumber.isNotEmpty) { if (dialedNumber.isNotEmpty) {
@ -80,6 +73,7 @@ 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);
@ -88,12 +82,10 @@ 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)) {
@ -103,20 +95,6 @@ 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(
@ -125,6 +103,7 @@ 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(
@ -136,8 +115,8 @@ class _CompositionPageState extends State<CompositionPage> {
children: [ children: [
Expanded( Expanded(
child: ListView( child: ListView(
children: [ children: _filteredContacts.isNotEmpty
..._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';
@ -153,34 +132,40 @@ 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, color: Colors.green[300], size: 20), icon: Icon(Icons.phone,
onPressed: () => _makeCall(phoneNumber), color: Colors.green[300],
size: 20),
onPressed: () {
_makeCall(phoneNumber); // Make a call using CallService
},
), ),
// Message button
IconButton( IconButton(
icon: Icon(Icons.message, color: Colors.blue[300], size: 20), icon: Icon(Icons.message,
onPressed: () => _launchSms(phoneNumber), color: Colors.blue[300],
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(
@ -188,6 +173,7 @@ 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: [
@ -196,57 +182,61 @@ class _CompositionPageState extends State<CompositionPage> {
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
dialedNumber, dialedNumber,
style: const TextStyle(fontSize: 24, color: Colors.white), style: const TextStyle(
fontSize: 24, color: Colors.white),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
), ),
GestureDetector( IconButton(
onTap: _onDeletePress, onPressed: _onClearPress,
onLongPress: _onClearPress, icon: const Icon(Icons.backspace,
child: const Padding( color: Colors.white),
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.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('1', Colors.white), _buildDialButton('1'),
_buildDialButton('2', Colors.white), _buildDialButton('2'),
_buildDialButton('3', Colors.white), _buildDialButton('3'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('4', Colors.white), _buildDialButton('4'),
_buildDialButton('5', Colors.white), _buildDialButton('5'),
_buildDialButton('6', Colors.white), _buildDialButton('6'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('7', Colors.white), _buildDialButton('7'),
_buildDialButton('8', Colors.white), _buildDialButton('8'),
_buildDialButton('9', Colors.white), _buildDialButton('9'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('*', const Color.fromRGBO(117, 117, 117, 1)), _buildDialButton('*'),
_buildDialButtonWithPlus('0'), _buildDialButton('0'),
_buildDialButton('#', const Color.fromRGBO(117, 117, 117, 1)), _buildDialButton('#'),
], ],
), ),
], ],
@ -259,28 +249,26 @@ 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: ElevatedButton( child: AddContactButton(),
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: () => Navigator.pop(context), onPressed: () {
Navigator.pop(context);
},
), ),
), ),
], ],
@ -288,7 +276,7 @@ class _CompositionPageState extends State<CompositionPage> {
); );
} }
Widget _buildDialButton(String number, Color textColor) { Widget _buildDialButton(String number) {
return ElevatedButton( return ElevatedButton(
onPressed: () => _onNumberPress(number), onPressed: () => _onNumberPress(number),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
@ -298,38 +286,11 @@ class _CompositionPageState extends State<CompositionPage> {
), ),
child: Text( child: Text(
number, number,
style: TextStyle(fontSize: 24, color: textColor), style: const TextStyle(
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]),
),
),
],
);
}
} }

View File

@ -37,7 +37,7 @@ class HistoryPage extends StatefulWidget {
} }
class _HistoryPageState extends State<HistoryPage> class _HistoryPageState extends State<HistoryPage>
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
List<History> histories = []; List<History> histories = [];
bool loading = true; bool loading = true;
int? _expandedIndex; int? _expandedIndex;
@ -47,13 +47,10 @@ 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 && histories.isEmpty) { if (loading) {
_buildHistories(); _buildHistories();
} }
} }
@ -152,9 +149,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 with intermittent yields to avoid freezing. // Process each log entry.
for (int i = 0; i < nativeLogs.length; i++) { for (var entry in nativeLogs) {
final entry = nativeLogs[i]; // Each entry is a Map with keys: number, type, date, duration.
final String number = entry['number'] ?? ''; final String number = entry['number'] ?? '';
if (number.isEmpty) continue; if (number.isEmpty) continue;
@ -200,8 +197,6 @@ 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,7 +272,6 @@ 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) {

View File

@ -10,82 +10,53 @@ import '../../services/contact_service.dart';
import 'package:dialer/features/voicemail/voicemail_page.dart'; import 'package:dialer/features/voicemail/voicemail_page.dart';
import '../contacts/widgets/contact_modal.dart'; import '../contacts/widgets/contact_modal.dart';
class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
late TabController _tabController; late TabController _tabController;
List<Contact> _allContacts = []; List<Contact> _allContacts = [];
List<Contact> _contactSuggestions = []; List<Contact> _contactSuggestions = [];
final ContactService _contactService = ContactService(); final ContactService _contactService = ContactService();
final ObfuscateService _obfuscateService = ObfuscateService(); final ObfuscateService _obfuscateService = ObfuscateService();
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
late SearchController _searchBarController;
String _rawSearchInput = '';
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_tabController = TabController(length: 4, vsync: this, initialIndex: 2); // Set the TabController length to 4
_tabController = TabController(length: 4, vsync: this, initialIndex: 1);
_tabController.addListener(_handleTabIndex); _tabController.addListener(_handleTabIndex);
_searchBarController = SearchController();
_searchBarController.addListener(() {
if (_searchController.text != _searchBarController.text) {
_rawSearchInput = _searchBarController.text;
_searchController.text = _rawSearchInput;
_onSearchChanged(_searchBarController.text);
}
});
_fetchContacts(); _fetchContacts();
} }
void _fetchContacts() async { void _fetchContacts() async {
_allContacts = await _contactService.fetchContacts(); _allContacts = await _contactService.fetchContacts();
_contactSuggestions = List.from(_allContacts); setState(() {});
if (mounted) setState(() {});
} }
void _clearSearch() { void _clearSearch() {
_searchController.clear(); _searchController.clear();
_searchBarController.clear();
_rawSearchInput = '';
_onSearchChanged(''); _onSearchChanged('');
} }
void _onSearchChanged(String query) { void _onSearchChanged(String query) {
setState(() { setState(() {
if (query.isEmpty) { if (query.isEmpty) {
_contactSuggestions = List.from(_allContacts); _contactSuggestions = List.from(_allContacts); // Reset suggestions
} else { } else {
final normalizedQuery = _normalizeString(query.toLowerCase());
_contactSuggestions = _allContacts.where((contact) { _contactSuggestions = _allContacts.where((contact) {
final normalizedName = _normalizeString(contact.displayName.toLowerCase()); return contact.displayName
return normalizedName.contains(normalizedQuery); .toLowerCase()
.contains(query.toLowerCase());
}).toList(); }).toList();
} }
}); });
} }
String _normalizeString(String input) {
const accentMap = {
'àáâãäå': 'a',
'èéêë': 'e',
'ìíîï': 'i',
'òóôõö': 'o',
'ùúûü': 'u',
'ç': 'c',
'ñ': 'n',
};
String normalized = input;
accentMap.forEach((accents, base) {
for (var accent in accents.split('')) {
normalized = normalized.replaceAll(accent, base);
}
});
return normalized;
}
@override @override
void dispose() { void dispose() {
_searchController.dispose(); _searchController.dispose();
_searchBarController.dispose();
_tabController.removeListener(_handleTabIndex); _tabController.removeListener(_handleTabIndex);
_tabController.dispose(); _tabController.dispose();
super.dispose(); super.dispose();
@ -98,18 +69,19 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
void _toggleFavorite(Contact contact) async { void _toggleFavorite(Contact contact) async {
try { try {
if (await FlutterContacts.requestPermission()) { if (await FlutterContacts.requestPermission()) {
Contact? fullContact = await FlutterContacts.getContact( Contact? fullContact = await FlutterContacts.getContact(contact.id,
contact.id,
withProperties: true, withProperties: true,
withAccounts: true, withAccounts: true,
withPhoto: true, withPhoto: true,
withThumbnail: true, withThumbnail: true);
);
if (fullContact != null) { if (fullContact != null) {
fullContact.isStarred = !fullContact.isStarred; fullContact.isStarred = !fullContact.isStarred;
await FlutterContacts.updateContact(fullContact); await FlutterContacts.updateContact(fullContact);
setState(() {
// Updating the contact list after toggling the favorite
_fetchContacts(); _fetchContacts();
});
} }
} else { } else {
print("Could not fetch contact details"); print("Could not fetch contact details");
@ -128,6 +100,7 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
backgroundColor: Colors.black, backgroundColor: Colors.black,
body: Column( body: Column(
children: [ children: [
// Persistent Search Bar
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 24.0, top: 24.0,
@ -145,33 +118,35 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
border: Border.all(color: Colors.grey.shade800, width: 1), border: Border.all(color: Colors.grey.shade800, width: 1),
), ),
child: SearchAnchor( child: SearchAnchor(
searchController: _searchBarController, builder:
builder: (BuildContext context, SearchController controller) { (BuildContext context, SearchController controller) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
controller.openView(); controller.openView(); // Open the search view
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color.fromARGB(255, 30, 30, 30), color: const Color.fromARGB(255, 30, 30, 30),
borderRadius: BorderRadius.circular(12.0), borderRadius: BorderRadius.circular(12.0),
border: Border.all(color: Colors.grey.shade800, width: 1), border: Border.all(
color: Colors.grey.shade800, width: 1),
), ),
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0), padding: const EdgeInsets.symmetric(
vertical: 12.0, horizontal: 16.0),
child: Row( child: Row(
children: [ children: [
const Icon(Icons.search, color: Colors.grey, size: 24.0), const Icon(Icons.search,
color: Colors.grey, size: 24.0),
const SizedBox(width: 8.0), const SizedBox(width: 8.0),
Expanded( Text(
child: Text( _searchController.text.isEmpty
_rawSearchInput.isEmpty
? 'Search contacts' ? 'Search contacts'
: _rawSearchInput, : _searchController.text,
style: const TextStyle(color: Colors.grey, fontSize: 16.0), style: const TextStyle(
overflow: TextOverflow.ellipsis, color: Colors.grey, fontSize: 16.0),
), ),
), const Spacer(),
if (_rawSearchInput.isNotEmpty) if (_searchController.text.isNotEmpty)
GestureDetector( GestureDetector(
onTap: _clearSearch, onTap: _clearSearch,
child: const Icon( child: const Icon(
@ -186,24 +161,23 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
); );
}, },
viewOnChanged: (query) { viewOnChanged: (query) {
_onSearchChanged(query); // Update immediately
if (_searchBarController.text != query) {
_rawSearchInput = query;
_searchBarController.text = query;
_searchController.text = query;
}
_onSearchChanged(query);
}, },
suggestionsBuilder: (BuildContext context, SearchController controller) { suggestionsBuilder:
(BuildContext context, SearchController controller) {
return _contactSuggestions.map((contact) { return _contactSuggestions.map((contact) {
return ListTile( return ListTile(
key: ValueKey(contact.id), key: ValueKey(contact.id),
title: Text( title: Text(_obfuscateService.obfuscateData(contact.displayName),
_obfuscateService.obfuscateData(contact.displayName), style: const TextStyle(color: Colors.white)),
style: const TextStyle(color: Colors.white),
),
onTap: () { onTap: () {
// Clear the search text input
controller.text = '';
// Close the search view
controller.closeView(contact.displayName); controller.closeView(contact.displayName);
// Show the ContactModal when a contact is tapped
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
isScrollControlled: true, isScrollControlled: true,
@ -212,28 +186,34 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
return ContactModal( return ContactModal(
contact: contact, contact: contact,
onEdit: () async { onEdit: () async {
if (await FlutterContacts.requestPermission()) { if (await FlutterContacts
final updatedContact = await FlutterContacts .requestPermission()) {
final updatedContact =
await FlutterContacts
.openExternalEdit(contact.id); .openExternalEdit(contact.id);
if (updatedContact != null) { if (updatedContact != null) {
_fetchContacts(); _fetchContacts();
Navigator.of(context).pop(); Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
'${contact.displayName} updated successfully!'), '${contact.displayName} updated successfully!'),
), ),
); );
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar( SnackBar(
content: Text('Edit canceled or failed.'), content: Text(
'Edit canceled or failed.'),
), ),
); );
} }
} }
}, },
onToggleFavorite: () => _toggleFavorite(contact), onToggleFavorite: () =>
_toggleFavorite(contact),
isFavorite: contact.isStarred, isFavorite: contact.isStarred,
); );
}, },
@ -245,6 +225,7 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
), ),
), ),
), ),
// 3-dot menu
PopupMenuButton<String>( PopupMenuButton<String>(
icon: const Icon(Icons.more_vert, color: Colors.white), icon: const Icon(Icons.more_vert, color: Colors.white),
itemBuilder: (BuildContext context) => [ itemBuilder: (BuildContext context) => [
@ -257,7 +238,8 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
if (value == 'settings') { if (value == 'settings') {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => const SettingsPage()), MaterialPageRoute(
builder: (context) => const SettingsPage()),
); );
} }
}, },
@ -265,6 +247,7 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
], ],
), ),
), ),
// Main content with TabBarView
Expanded( Expanded(
child: Stack( child: Stack(
children: [ children: [

View File

@ -1,20 +1,24 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import '../features/call/call_page.dart'; import '../features/call/call_page.dart';
import '../features/call/incoming_call_page.dart'; import '../features/call/incoming_call_page.dart'; // Import the new page
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 bool _isCallPageVisible = false; static bool _isCallPageVisible = false;
static Map<String, dynamic>? _pendingCall;
static bool wasPhoneLocked = false;
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
CallService() { CallService() {
_channel.setMethodCallHandler((call) async { _channel.setMethodCallHandler((call) async {
print('CallService: Handling method call: ${call.method}'); final context = navigatorKey.currentContext;
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;
@ -22,86 +26,39 @@ class CallService {
currentPhoneNumber = phoneNumber.replaceFirst('tel:', ''); currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
print('CallService: Call added, number: $currentPhoneNumber, state: $state'); print('CallService: Call added, number: $currentPhoneNumber, state: $state');
if (state == "ringing") { if (state == "ringing") {
_handleIncomingCall(phoneNumber); _navigateToIncomingCallPage(context);
} else { } else {
_navigateToCallPage(); _navigateToCallPage(context);
} }
break; break;
case "callStateChanged": case "callStateChanged":
final state = call.arguments["state"] as String; final state = call.arguments["state"] as String;
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false; print('CallService: State changed to $state');
print('CallService: State changed to $state, wasPhoneLocked: $wasPhoneLocked');
if (state == "disconnected" || state == "disconnecting") { if (state == "disconnected" || state == "disconnecting") {
_closeCallPage(); _closeCallPage(context);
if (wasPhoneLocked) {
_channel.invokeMethod("callEndedFromFlutter");
}
} else if (state == "active" || state == "dialing") { } else if (state == "active" || state == "dialing") {
_navigateToCallPage(); _navigateToCallPage(context);
} else if (state == "ringing") { } else if (state == "ringing") {
final phoneNumber = call.arguments["callId"] as String; _navigateToIncomingCallPage(context);
_handleIncomingCall(phoneNumber.replaceFirst('tel:', ''));
} }
break; break;
case "callEnded": case "callEnded":
case "callRemoved": case "callRemoved":
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false; print('CallService: Call ended/removed');
print('CallService: Call ended/removed, wasPhoneLocked: $wasPhoneLocked'); _closeCallPage(context);
_closeCallPage();
if (wasPhoneLocked) {
_channel.invokeMethod("callEndedFromFlutter");
}
currentPhoneNumber = null; currentPhoneNumber = null;
break; break;
case "incomingCallFromNotification":
final phoneNumber = call.arguments["phoneNumber"] as String;
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
currentPhoneNumber = phoneNumber;
print('CallService: Incoming call from notification: $phoneNumber, wasPhoneLocked: $wasPhoneLocked');
_handleIncomingCall(phoneNumber);
break;
} }
}); });
} }
void _handleIncomingCall(String phoneNumber) { void _navigateToCallPage(BuildContext context) {
final context = navigatorKey.currentContext; if (_isCallPageVisible && ModalRoute.of(context)?.settings.name == '/call') {
if (context == null) {
print('CallService: Context is null, queuing incoming call: $phoneNumber');
_pendingCall = {"phoneNumber": phoneNumber};
Future.delayed(Duration(milliseconds: 500), () => _checkPendingCall());
} else {
_navigateToIncomingCallPage(context);
}
}
void _checkPendingCall() {
if (_pendingCall != null) {
final context = navigatorKey.currentContext;
if (context != null) {
print('CallService: Processing queued call: ${_pendingCall!["phoneNumber"]}');
currentPhoneNumber = _pendingCall!["phoneNumber"];
_navigateToIncomingCallPage(context);
_pendingCall = null;
} else {
print('CallService: Context still null, retrying...');
Future.delayed(Duration(milliseconds: 500), () => _checkPendingCall());
}
}
}
void _navigateToCallPage() {
final context = navigatorKey.currentContext;
if (context == null) {
print('CallService: Cannot navigate to CallPage, context is null');
return;
}
if (_isCallPageVisible) {
print('CallService: CallPage already visible, skipping navigation'); print('CallService: CallPage already visible, skipping navigation');
return; return;
} }
print('CallService: Navigating to CallPage'); print('CallService: Navigating to CallPage');
Navigator.push( Navigator.pushReplacement(
context, context,
MaterialPageRoute( MaterialPageRoute(
settings: const RouteSettings(name: '/call'), settings: const RouteSettings(name: '/call'),
@ -113,13 +70,12 @@ class CallService {
), ),
).then((_) { ).then((_) {
_isCallPageVisible = false; _isCallPageVisible = false;
print('CallService: CallPage popped, _isCallPageVisible set to false');
}); });
_isCallPageVisible = true; _isCallPageVisible = true;
} }
void _navigateToIncomingCallPage(BuildContext context) { void _navigateToIncomingCallPage(BuildContext context) {
if (_isCallPageVisible) { if (_isCallPageVisible && ModalRoute.of(context)?.settings.name == '/incoming_call') {
print('CallService: IncomingCallPage already visible, skipping navigation'); print('CallService: IncomingCallPage already visible, skipping navigation');
return; return;
} }
@ -136,28 +92,23 @@ class CallService {
), ),
).then((_) { ).then((_) {
_isCallPageVisible = false; _isCallPageVisible = false;
print('CallService: IncomingCallPage popped, _isCallPageVisible set to false');
}); });
_isCallPageVisible = true; _isCallPageVisible = true;
} }
void _closeCallPage() { void _closeCallPage(BuildContext context) {
final context = navigatorKey.currentContext; if (!_isCallPageVisible) {
if (context == null) { print('CallService: CallPage not visible, skipping pop');
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 call page'); print('CallService: Popping CallPage');
Navigator.pop(context); Navigator.pop(context);
_isCallPageVisible = false; _isCallPageVisible = false;
} else {
print('CallService: No page to pop');
} }
} }
Future<Map<String, dynamic>> makeGsmCall( Future<void> makeGsmCall(
BuildContext context, { BuildContext context, {
required String phoneNumber, required String phoneNumber,
String? displayName, String? displayName,
@ -168,40 +119,36 @@ class CallService {
print('CallService: Making GSM call to $phoneNumber'); print('CallService: Making GSM call to $phoneNumber');
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');
final resultMap = Map<String, dynamic>.from(result as Map); if (result["status"] != "calling") {
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")),
); );
return {"status": "error", "message": e.toString()}; rethrow;
} }
} }
Future<Map<String, dynamic>> hangUpCall(BuildContext context) async { Future<void> 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');
final resultMap = Map<String, dynamic>.from(result as Map); if (result["status"] != "ended") {
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")),
); );
return {"status": "error", "message": e.toString()}; rethrow;
} }
} }
} }

View File

@ -27,13 +27,14 @@ 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 (at least one modulation type) - Transmission over audio stream
- First steps in FEC (Forward Error Correction): detecting half of transmission errors - Minimal error correction in audio-based transmission
- 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 (such as DTMF) - Embedded silent data transmission (silently transmit light data during an encrypted phone call)
- 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)
- Stronger FEC: detecting >80%, correcting 20% of transmission errors - Strong error correction
#### The Icing dialer (based on Icing kotlin library, an Icing protocol implementation) #### The Icing dialer (based on Icing kotlin library, an Icing protocol implementation)
@ -127,15 +128,16 @@ 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, 42 years-old, is a journalist covering sensitive topics. Elise is a 42 years-old extreme reporter.
Her work draws attention from people who want to know what she's saying - and to whom. After interviewing Russians opposition's leader, the FSB is looking to interview her.
Forced to stay discreet, with unreliable signal and a likely monitored phone line, She tries to stay discreet and hidden, but those measures constrains her to barely receive cellular network.
she uses Icing dialer to make secure calls without exposing herself. She suspects her phone line to be monitored, so the best she can do to call safely, is to use her Icing dialer.
Paul, a 22 years-old developer, is enjoying its vacations abroad. Paul, a 22 years-old developer working for a big company, decides to go to China for vacations.
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 his country. qualified to fix it. Paul doesn't have WiFi and his phone plan only covers voice calls in China.
With Icing dialer, he can call his collegues and help fix the problem, completely safe. With Icing dialer, he can call his collegues and help fix the
problem, safe from potential Chinese spies.
## Evaluation Criteria ## Evaluation Criteria
### Protocol and lib ### Protocol and lib