Skip to content

Commit c76a698

Browse files
- fixes and improvements;
1 parent 67258f9 commit c76a698

16 files changed

+179
-118
lines changed

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ android {
4242
dependencies {
4343
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4444
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
45-
implementation platform('com.google.firebase:firebase-bom:29.0.1')
45+
46+
implementation platform('com.google.firebase:firebase-bom:29.0.3')
4647
implementation 'com.google.firebase:firebase-messaging-ktx'
47-
// implementation 'com.google.firebase:firebase-analytics-ktx'
4848
}

android/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,17 @@
1313
android:taskAffinity="com.connectycube.flutter.connectycube_flutter_call_kit.INCOMING_CALL_AFFINITY"
1414
android:theme="@android:style/Theme.Holo.NoActionBar"
1515
android:turnScreenOn="true" />
16+
<service
17+
android:name=".background_isolates.ConnectycubeFlutterBgPerformingService"
18+
android:permission="android.permission.BIND_JOB_SERVICE"
19+
android:exported="false"/>
20+
<service
21+
android:name=".ConnectycubeFCMService"
22+
android:exported="false">
23+
<intent-filter>
24+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
25+
</intent-filter>
26+
</service>
27+
1628
</application>
1729
</manifest>

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ConnectycubeFCMService : FirebaseMessagingService() {
5858
if (callOpponentsString != null) {
5959
callOpponents = ArrayList(callOpponentsString.split(',').map { it.toInt() })
6060
}
61-
val userInfo = data["user_info"] ?: ""
61+
val userInfo = data["user_info"] ?: "{}"
6262

6363
if (callType == null || callInitiatorId == null || callInitiatorName == null || callOpponents.isEmpty()) {
6464
return

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
4141
this.applicationContext = flutterPluginBinding.applicationContext
4242
ContextHolder.applicationContext = this.applicationContext
4343
this.methodChannel =
44-
MethodChannel(flutterPluginBinding.binaryMessenger, "connectycube_flutter_call_kit")
44+
MethodChannel(
45+
flutterPluginBinding.binaryMessenger,
46+
"connectycube_flutter_call_kit.methodChannel"
47+
)
4548
this.methodChannel.setMethodCallHandler(this)
4649

4750
this.eventChannel =
@@ -70,22 +73,9 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
7073
"Fetching FCM registration token failed",
7174
task.exception
7275
)
73-
return@OnCompleteListener
74-
}
75-
76-
val token = task.result
77-
val tokenStringId = applicationContext?.resources?.getIdentifier(
78-
"msg_token_fmt",
79-
"string",
80-
applicationContext?.packageName
81-
)
82-
if (tokenStringId != null && tokenStringId != 0) {
83-
val msg = applicationContext?.getString(tokenStringId, token)
84-
Log.d("ConnectycubeFlutterCallKitPlugin", "Received FCM token $msg")
85-
result.success(msg)
76+
result.error("error", "Fetching FCM registration token failed", null)
8677
} else {
87-
Log.d("ConnectycubeFlutterCallKitPlugin", "Error while receiving FCM token")
88-
result.success(null)
78+
result.success(task.result)
8979
}
9080
})
9181
}
@@ -127,9 +117,9 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
127117

128118
saveBackgroundHandler(applicationContext, pluginCallbackHandle)
129119

130-
if(REJECTED_IN_BACKGROUND == userCallbackHandleName){
120+
if (REJECTED_IN_BACKGROUND == userCallbackHandleName) {
131121
saveBackgroundRejectHandler(applicationContext, userCallbackHandle)
132-
} else if (ACCEPTED_IN_BACKGROUND == userCallbackHandleName){
122+
} else if (ACCEPTED_IN_BACKGROUND == userCallbackHandleName) {
133123
saveBackgroundAcceptHandler(applicationContext, userCallbackHandle)
134124
}
135125

@@ -177,6 +167,24 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
177167
}
178168
}
179169

170+
"updateConfig" -> {
171+
try {
172+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
173+
call.arguments as Map<String, Any>
174+
val ringtone = arguments["ringtone"] as String?
175+
val icon = arguments["icon"] as String?
176+
val color = arguments["color"] as String?
177+
178+
putString(applicationContext!!, "ringtone", ringtone)
179+
putString(applicationContext!!, "icon", icon)
180+
putString(applicationContext!!, "color", color)
181+
182+
result.success(null)
183+
} catch (e: Exception) {
184+
result.error("ERROR", e.message, "")
185+
}
186+
}
187+
180188
"reportCallAccepted" -> {
181189
try {
182190
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
@@ -416,6 +424,7 @@ fun saveBackgroundAcceptHandler(applicationContext: Context?, callbackId: Long)
416424
// ignore
417425
}
418426
}
427+
419428
fun getBackgroundAcceptHandler(applicationContext: Context?): Long {
420429
if (applicationContext == null) return -1L
421430

@@ -496,7 +505,7 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl
496505

497506
val parameters = HashMap<String, Any?>()
498507
parameters["event"] = "voipToken"
499-
parameters["voipToken"] = token
508+
parameters["args"] = { "voipToken" to token }
500509

501510
events?.success(parameters)
502511
return
@@ -516,6 +525,8 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl
516525
intent.getIntegerArrayListExtra(EXTRA_CALL_OPPONENTS)?.joinToString(separator = ",")
517526
callEventMap["user_info"] = intent.getStringExtra(EXTRA_CALL_USER_INFO)
518527

528+
Log.d("ConnectycubeFlutterCallKitPlugin", "callEventMap: $callEventMap")
529+
519530
val callbackData = HashMap<String, Any?>()
520531
callbackData["args"] = callEventMap
521532

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/IncomingCallActivity.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.os.Looper
1111
import android.text.TextUtils
1212
import android.view.View
1313
import android.view.WindowManager
14+
import android.widget.ImageView
1415
import android.widget.TextView
1516
import androidx.annotation.Nullable
1617
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@@ -126,6 +127,21 @@ class IncomingCallActivity : Activity() {
126127
findViewById(resources.getIdentifier("call_type_txt", "id", packageName))
127128
callSubTitleTxt.text =
128129
String.format(CALL_TYPE_PLACEHOLDER, if (callType == 1) "Video" else "Audio")
130+
val avatarImg: ImageView =
131+
findViewById(resources.getIdentifier("avatar_img", "id", packageName))
132+
133+
val defaultImgResId = resources.getIdentifier("connectycube_place_holder", "drawable", packageName)
134+
val customAvatarResName = com.connectycube.flutter.connectycube_flutter_call_kit.utils.getString(this, "icon")
135+
if (TextUtils.isEmpty(customAvatarResName)){
136+
avatarImg.setImageResource(defaultImgResId)
137+
} else {
138+
val imgResourceId = resources.getIdentifier(customAvatarResName, "drawable", packageName)
139+
if (imgResourceId != 0){
140+
avatarImg.setImageResource(imgResourceId)
141+
} else {
142+
avatarImg.setImageResource(defaultImgResId)
143+
}
144+
}
129145
}
130146

131147
// calls from layout file

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/NotificationsManager.kt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import android.content.Intent
88
import android.content.pm.PackageManager
99
import android.graphics.Color
1010
import android.media.AudioAttributes
11-
import android.media.RingtoneManager
1211
import android.net.Uri
1312
import android.os.Build
1413
import android.os.Bundle
14+
import android.provider.Settings
15+
import android.text.TextUtils
16+
import android.util.Log
1517
import androidx.core.app.NotificationCompat
1618
import androidx.core.app.NotificationManagerCompat
1719
import com.connectycube.flutter.connectycube_flutter_call_kit.utils.getColorizedText
20+
import com.connectycube.flutter.connectycube_flutter_call_kit.utils.getString
1821

1922
const val CALL_CHANNEL_ID = "calls_channel_id"
2023
const val CALL_CHANNEL_NAME = "Calls"
@@ -40,10 +43,18 @@ fun showCallNotification(
4043
PendingIntent.FLAG_UPDATE_CURRENT
4144
)
4245

43-
val ringtone: Uri = RingtoneManager.getActualDefaultRingtoneUri(
44-
context.applicationContext,
45-
RingtoneManager.TYPE_RINGTONE
46-
)
46+
var ringtone: Uri
47+
48+
val customRingtone = getString(context, "ringtone")
49+
Log.d("NotificationsManager", "customRingtone $customRingtone")
50+
if (!TextUtils.isEmpty(customRingtone)) {
51+
ringtone = Uri.parse("android.resource://" + context.packageName + "/raw/" + customRingtone)
52+
Log.d("NotificationsManager", "ringtone 1 $ringtone")
53+
} else {
54+
ringtone = Settings.System.DEFAULT_RINGTONE_URI
55+
}
56+
57+
Log.d("NotificationsManager", "ringtone 2 $ringtone")
4758

4859
val callTypeTitle =
4960
String.format(CALL_TYPE_PLACEHOLDER, if (callType == 1) "Video" else "Audio")
@@ -295,15 +306,21 @@ fun setNotificationSmallIcon(context: Context, notificationBuilder: Notification
295306

296307
fun setNotificationColor(context: Context, notificationBuilder: NotificationCompat.Builder) {
297308
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
298-
val accentID = context.resources.getIdentifier(
299-
"call_notification_color_accent",
300-
"color",
301-
context.packageName
302-
)
303-
if (accentID != 0) {
304-
notificationBuilder.color = context.resources.getColor(accentID, null)
309+
val color = getString(context, "color")
310+
311+
if (!TextUtils.isEmpty(color)) {
312+
notificationBuilder.color = Color.parseColor(color)
305313
} else {
306-
notificationBuilder.color = Color.parseColor("#4CAF50")
314+
val accentID = context.resources.getIdentifier(
315+
"call_notification_color_accent",
316+
"color",
317+
context.packageName
318+
)
319+
if (accentID != 0) {
320+
notificationBuilder.color = context.resources.getColor(accentID, null)
321+
} else {
322+
notificationBuilder.color = Color.parseColor("#4CAF50")
323+
}
307324
}
308325
}
309326
}

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/ConnectycubeFlutterBgPerformingService.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class ConnectycubeFlutterBgPerformingService : JobIntentService() {
8787
fun enqueueMessageProcessing(context: Context, callEventIntent: Intent) {
8888
enqueueWork(
8989
context,
90-
FlutterConnectycubeBackgroundExecutor::class.java,
90+
ConnectycubeFlutterBgPerformingService::class.java,
9191
2022,
9292
callEventIntent,
9393
true
@@ -120,13 +120,12 @@ class ConnectycubeFlutterBgPerformingService : JobIntentService() {
120120
* Called once the Dart isolate (`flutterBackgroundExecutor`) has finished initializing.
121121
*
122122
*
123-
* Invoked by [ConnectycubeFlutterCallKitPlugin] when it receives the `FirebaseMessaging.initialized` message. Processes all messaging events that came in while the
124-
* isolate was starting.
123+
* Invoked by [ConnectycubeFlutterCallKitPlugin] .
125124
*/
126125
/* package */
127126
@SuppressLint("LongLogTag")
128127
fun onInitialized() {
129-
Log.i(TAG, "FlutterFirebaseMessagingBackgroundService started!")
128+
Log.i(TAG, "ConnectycubeFlutterBgPerformingService started!")
130129
synchronized(messagingQueue) {
131130

132131
// Handle all the message events received before the Dart isolate was

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class FlutterConnectycubeBackgroundExecutor : MethodCallHandler {
6363
result.notImplemented()
6464
}
6565
} catch (e: Exception) {
66-
result.error("error", "Flutter FCM error: " + e.localizedMessage, null)
66+
result.error("error", "Flutter ConnectycubeCallKit error: " + e.localizedMessage, null)
6767
}
6868
}
6969

@@ -260,7 +260,7 @@ class FlutterConnectycubeBackgroundExecutor : MethodCallHandler {
260260
private fun initializeMethodChannel(isolate: BinaryMessenger) {
261261
// backgroundChannel is the channel responsible for receiving the following messages from
262262
// the background isolate that was setup by this plugin method call:
263-
// - "FirebaseBackgroundMessaging#initialized"
263+
// - "onBackgroundHandlerInitialized"
264264
//
265265
// This channel is also responsible for sending requests from Android to Dart to execute Dart
266266
// callbacks in the background isolate.

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/JobIntentService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ abstract class JobIntentService : Service() {
503503
we.ensureJobId(jobId)
504504

505505
// Can throw on API 26+ if useWakefulService=true and app is NOT whitelisted.
506-
// One example is when an FCM high priority message is received the system will
506+
// One example is when a hight priority job is received the system will
507507
// temporarily whitelist the app. However it is possible that it does not end up getting
508508
// whitelisted so we need to catch this and fall back to a job service.
509509
try {

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/utils/ContextHolder.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.connectycube.flutter.connectycube_flutter_call_kit.utils
22

3-
import android.app.ActivityManager
4-
import android.app.ActivityManager.RunningAppProcessInfo
5-
import android.app.KeyguardManager
63
import android.content.Context
74

85

0 commit comments

Comments
 (0)