rns-nativecall 0.3.2 → 0.3.3

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.
@@ -2,6 +2,7 @@ package com.rnsnativecall
2
2
 
3
3
  import android.app.ActivityManager
4
4
  import android.content.Context
5
+ import android.content.Intent
5
6
  import android.os.Handler
6
7
  import android.os.Looper
7
8
  import com.google.firebase.messaging.FirebaseMessagingService
@@ -11,23 +12,48 @@ class CallMessagingService : FirebaseMessagingService() {
11
12
 
12
13
  override fun onMessageReceived(remoteMessage: RemoteMessage) {
13
14
  val data = remoteMessage.data
15
+ val context = applicationContext
14
16
 
15
- if (isAppInForeground(applicationContext)) {
16
- // 1. App is OPEN: Send to JS immediately (No delay)
17
+ if (isAppInForeground(context)) {
17
18
  CallModule.sendEventToJS("onCallReceived", data)
18
19
  } else {
19
- // 2. App is CLOSED/BACKGROUND: Delay the system pill by 18 seconds
20
+ // 1. START WAKING THE APP IMMEDIATELY
21
+ // We launch the "AcceptCallActivity" with a special flag
22
+ // OR just trigger the Bridge via an Intent.
23
+ wakeUpReactContext(context, data)
24
+
25
+ // 2. Start the 18-second "Safety" timer
20
26
  val handler = Handler(Looper.getMainLooper())
21
27
  handler.postDelayed({
22
- // Re-check: If the user opened the app during these 18 seconds,
23
- // we might want to cancel the pill.
24
- if (!isAppInForeground(applicationContext)) {
25
- NativeCallManager.handleIncomingPush(applicationContext, data)
28
+ // Re-check: If the bridge woke up and the user navigated in-app,
29
+ // isAppInForeground will now be true.
30
+ if (!isAppInForeground(context)) {
31
+ NativeCallManager.handleIncomingPush(context, data)
26
32
  }
27
33
  }, 18000)
28
34
  }
29
35
  }
30
36
 
37
+ private fun wakeUpReactContext(context: Context, data: Map<String, String>) {
38
+ try {
39
+ // We use the Launch Intent to trigger the splash/main activity boot sequence
40
+ // but we don't bring it to the front yet (it stays in background process)
41
+ val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
42
+ launchIntent?.apply {
43
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
44
+ // Add a hidden flag so your Splash screen knows it's a "silent boot"
45
+ putExtra("silent_wake", true)
46
+ data.forEach { (key, value) -> putExtra(key, value) }
47
+ }
48
+
49
+ // This starts the process and the React Native Bridge
50
+ // Note: On Android 10+, this won't show the UI, but it WILL start the process.
51
+ context.startActivity(launchIntent)
52
+ } catch (e: Exception) {
53
+ // Log error
54
+ }
55
+ }
56
+
31
57
  private fun isAppInForeground(context: Context): Boolean {
32
58
  val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
33
59
  val appProcesses = activityManager.runningAppProcesses ?: return false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "RNS nativecall component with native Android/iOS for handling native call ui, when app is not open or open.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",