@qusaieilouti99/call-manager 0.1.92 → 0.1.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,7 @@ import org.json.JSONObject
37
37
  import java.util.concurrent.ConcurrentHashMap
38
38
  import java.util.concurrent.CopyOnWriteArrayList
39
39
  import java.util.concurrent.atomic.AtomicBoolean
40
-
40
+ import android.app.KeyguardManager
41
41
  /**
42
42
  * Core call‐management engine. Manages self-managed telecom calls,
43
43
  * audio routing, UI notifications, etc.
@@ -916,47 +916,89 @@ object CallEngine {
916
916
  }
917
917
  }
918
918
 
919
- // **SAMSUNG FIX**: Enhanced showIncomingCallUI method
920
919
  private fun showIncomingCallUI(callId: String, callerName: String, callType: String) {
921
920
  val context = requireContext()
922
921
  Log.d(TAG, "Showing incoming call UI for $callId")
923
- createNotificationChannel()
924
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
925
922
 
926
- // **CRITICAL**: Use Android's SYSTEM overlay approach for Samsung
923
+ // **SIMPLE LOGIC**: If locked -> overlay, if unlocked -> notification
924
+ if (isDeviceLocked(context)) {
925
+ Log.d(TAG, "Device is locked - using overlay approach")
926
+ showCallActivityOverlay(context, callId, callerName, callType)
927
+ } else {
928
+ Log.d(TAG, "Device is unlocked - using standard notification")
929
+ showStandardNotification(context, callId, callerName, callType)
930
+ }
931
+
932
+ playRingtone()
933
+ setInitialAudioRoute(callType)
934
+ }
935
+
936
+ /**
937
+ * Simple check if device is locked
938
+ */
939
+ private fun isDeviceLocked(context: Context): Boolean {
940
+ val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
941
+ val isLocked = keyguardManager.isKeyguardLocked
942
+ Log.d(TAG, "Device locked status: $isLocked")
943
+ return isLocked
944
+ }
945
+
946
+ /**
947
+ * Shows the call activity directly as overlay (when device is locked)
948
+ */
949
+ private fun showCallActivityOverlay(context: Context, callId: String, callerName: String, callType: String) {
927
950
  val overlayIntent = Intent(context, CallActivity::class.java).apply {
928
951
  addFlags(
929
952
  Intent.FLAG_ACTIVITY_NEW_TASK or
930
953
  Intent.FLAG_ACTIVITY_CLEAR_TASK or
931
954
  Intent.FLAG_ACTIVITY_NO_ANIMATION or
932
- Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS or
933
- Intent.FLAG_ACTIVITY_MULTIPLE_TASK
955
+ Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
934
956
  )
935
957
  putExtra("callId", callId)
936
958
  putExtra("callerName", callerName)
937
959
  putExtra("callType", callType)
960
+ putExtra("LOCK_SCREEN_MODE", true) // Flag to identify lock screen mode
938
961
  }
939
962
 
940
- // **SAMSUNG SPECIFIC**: Launch immediately via system overlay
941
963
  try {
942
- // First, wake up the screen using PowerManager
964
+ // Wake the screen when device is locked
943
965
  val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
944
966
  val wakeLock = powerManager.newWakeLock(
945
967
  PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
946
- "CallEngine:IncomingCallWake"
968
+ "CallEngine:LockScreenWake"
947
969
  )
948
- wakeLock.acquire(5000) // 5 seconds
970
+ wakeLock.acquire(5000)
949
971
 
950
- // Then launch the activity
972
+ // Launch the activity overlay
951
973
  context.startActivity(overlayIntent)
952
- Log.d(TAG, "Successfully launched CallActivity with screen wake")
974
+ Log.d(TAG, "Successfully launched CallActivity overlay for locked device")
975
+
976
+ // **NO NOTIFICATION** when using overlay
977
+
953
978
  } catch (e: Exception) {
954
- Log.e(TAG, "Failed to launch CallActivity: ${e.message}")
979
+ Log.e(TAG, "Overlay failed, falling back to notification: ${e.message}")
980
+ // If overlay fails, fall back to notification
981
+ showStandardNotification(context, callId, callerName, callType)
982
+ }
983
+ }
984
+
985
+ /**
986
+ * Shows standard notification with full-screen intent (when device is unlocked)
987
+ */
988
+ private fun showStandardNotification(context: Context, callId: String, callerName: String, callType: String) {
989
+ createNotificationChannel()
990
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
991
+
992
+ val fullScreenIntent = Intent(context, CallActivity::class.java).apply {
993
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
994
+ putExtra("callId", callId)
995
+ putExtra("callerName", callerName)
996
+ putExtra("callType", callType)
997
+ // No lock screen flag - standard notification mode
955
998
  }
956
999
 
957
- // Create notification as backup
958
1000
  val fullScreenPendingIntent = PendingIntent.getActivity(
959
- context, callId.hashCode(), overlayIntent,
1001
+ context, callId.hashCode(), fullScreenIntent,
960
1002
  PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
961
1003
  )
962
1004
 
@@ -1016,8 +1058,6 @@ object CallEngine {
1016
1058
  }
1017
1059
 
1018
1060
  notificationManager.notify(NOTIF_ID, notification)
1019
- playRingtone()
1020
- setInitialAudioRoute(callType)
1021
1061
  }
1022
1062
 
1023
1063
  fun cancelIncomingCallUI() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusaieilouti99/call-manager",
3
- "version": "0.1.92",
3
+ "version": "0.1.94",
4
4
  "description": "Call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",