diff --git a/dialer/android/.gitignore b/dialer/android/.gitignore
index e6d71b3..ebc61c7 100644
--- a/dialer/android/.gitignore
+++ b/dialer/android/.gitignore
@@ -7,6 +7,7 @@ gradle-wrapper.jar
/gradle.properties
GeneratedPluginRegistrant.java
gradle.properties
+.cxx
# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
diff --git a/dialer/android/app/src/main/AndroidManifest.xml b/dialer/android/app/src/main/AndroidManifest.xml
index e0de6a4..cc51efb 100644
--- a/dialer/android/app/src/main/AndroidManifest.xml
+++ b/dialer/android/app/src/main/AndroidManifest.xml
@@ -1,13 +1,15 @@
-
-
+
+
-
-
-
+
+
+
+
+
-
+ android:name="io.flutter.embedding.android.NormalTheme"
+ android:resource="@style/NormalTheme" />
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
\ No newline at end of file
diff --git a/dialer/android/app/src/main/kotlin/com/icing/dialer/activities/MainActivity.kt b/dialer/android/app/src/main/kotlin/com/icing/dialer/activities/MainActivity.kt
index a2397d6..53f93d7 100644
--- a/dialer/android/app/src/main/kotlin/com/icing/dialer/activities/MainActivity.kt
+++ b/dialer/android/app/src/main/kotlin/com/icing/dialer/activities/MainActivity.kt
@@ -3,52 +3,77 @@ package com.icing.dialer.activities
import android.database.Cursor
import android.os.Bundle
import android.provider.CallLog
+import android.telecom.TelecomManager
+import android.telecom.PhoneAccountHandle
+import android.telecom.PhoneAccount
+import android.content.Intent
+import android.content.ComponentName
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import com.icing.dialer.KeystoreHelper
import com.icing.dialer.services.CallService
+import com.icing.dialer.services.CallConnectionService
-class MainActivity: FlutterActivity() {
- // Existing channel for keystore operations.
+class MainActivity : FlutterActivity() {
private val KEYSTORE_CHANNEL = "com.example.keystore"
- // New channel for call log access.
private val CALLLOG_CHANNEL = "com.example.calllog"
-
private val CALL_CHANNEL = "call_service"
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ registerPhoneAccount()
+ checkAndRequestDefaultDialer()
+ }
+
+ private fun registerPhoneAccount() {
+ val telecomManager = getSystemService(TELECOM_SERVICE) as TelecomManager
+ val phoneAccountHandle = PhoneAccountHandle(
+ ComponentName(this, CallConnectionService::class.java),
+ "IcingDialerAccount"
+ )
+ val phoneAccount = PhoneAccount.builder(phoneAccountHandle, "Icing Dialer")
+ .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
+ .build()
+ telecomManager.registerPhoneAccount(phoneAccount)
+ }
+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
- // Call service channel
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALL_CHANNEL).setMethodCallHandler { call, result ->
when (call.method) {
"makeGsmCall" -> {
val phoneNumber = call.argument("phoneNumber")
if (phoneNumber != null) {
- CallService.makeGsmCall(this, phoneNumber)
- result.success("Calling $phoneNumber")
+ val success = CallService.makeGsmCall(this, phoneNumber)
+ if (success) {
+ result.success(mapOf("status" to "calling", "phoneNumber" to phoneNumber))
+ } else {
+ result.error("CALL_FAILED", "Failed to initiate call", null)
+ }
} else {
result.error("INVALID_PHONE_NUMBER", "Phone number is required", null)
}
}
"hangUpCall" -> {
- CallService.hangUpCall(this)
- result.success("Call ended")
+ val success = CallService.hangUpCall(this)
+ if (success) {
+ result.success(mapOf("status" to "ended"))
+ } else {
+ result.error("HANGUP_FAILED", "Failed to end call", null)
+ }
}
else -> result.notImplemented()
}
}
- // Set up the keystore channel.
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KEYSTORE_CHANNEL)
.setMethodCallHandler { call, result ->
- // Delegate method calls to KeystoreHelper.
KeystoreHelper(call, result).handleMethodCall()
}
- // Set up the call log channel.
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CALLLOG_CHANNEL)
.setMethodCallHandler { call, result ->
if (call.method == "getCallLogs") {
@@ -60,35 +85,38 @@ class MainActivity: FlutterActivity() {
}
}
- /**
- * Queries the Android call log and returns a list of maps.
- * Each map contains keys: "number", "type", "date", and "duration".
- */
+ private fun checkAndRequestDefaultDialer() {
+ val tm = getSystemService(TELECOM_SERVICE) as TelecomManager
+ tm.defaultDialerPackage?.let {
+ if (it != packageName) {
+ val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
+ .putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
+ startActivity(intent)
+ }
+ }
+ }
+
private fun getCallLogs(): List