22
33import android .app .ActivityManager ;
44import android .content .Intent ;
5+ import android .os .Bundle ;
56import android .os .Handler ;
67import android .os .Looper ;
78import androidx .localbroadcastmanager .content .LocalBroadcastManager ;
@@ -60,7 +61,7 @@ public void onNewToken(String token) {
6061 @ Override
6162 public void onMessageReceived (RemoteMessage remoteMessage ) {
6263 if (BuildConfig .DEBUG ) {
63- Log .d (TAG , "Bundle data : " + remoteMessage .getData ());
64+ Log .d (TAG , "VoiceFirebaseMessagingService onMessageReceived : " + remoteMessage .getMessageType ());
6465 }
6566
6667 // Check if message contains a data payload.
@@ -74,7 +75,6 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
7475 boolean valid = Voice .handleMessage (data , new MessageListener () {
7576 @ Override
7677 public void onCallInvite (final CallInvite callInvite ) {
77-
7878 // We need to run this on the main thread, as the React code assumes that is true.
7979 // Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
8080 // "Can't create handler inside thread that has not called Looper.prepare()"
@@ -93,7 +93,9 @@ public void run() {
9393 Intent launchIntent = callNotificationManager .getLaunchIntent (
9494 (ReactApplicationContext )context ,
9595 notificationId ,
96- callInvite ,
96+ callInvite .getCallSid (),
97+ callInvite .getFrom (),
98+ callInvite .getTo (),
9799 false ,
98100 appImportance
99101 );
@@ -106,28 +108,53 @@ public void run() {
106108 intent .putExtra (INCOMING_CALL_INVITE , callInvite );
107109 LocalBroadcastManager .getInstance (context ).sendBroadcast (intent );
108110 } else {
109- // Otherwise wait for construction, then handle the incoming call
110- mReactInstanceManager .addReactInstanceEventListener (new ReactInstanceManager .ReactInstanceEventListener () {
111- public void onReactContextInitialized (ReactContext context ) {
112- int appImportance = callNotificationManager .getApplicationImportance ((ReactApplicationContext )context );
113- if (BuildConfig .DEBUG ) {
114- Log .d (TAG , "CONTEXT not present appImportance = " + appImportance );
115- }
116- Intent launchIntent = callNotificationManager .getLaunchIntent ((ReactApplicationContext )context , notificationId , callInvite , true , appImportance );
117- context .startActivity (launchIntent );
118- Intent intent = new Intent (ACTION_INCOMING_CALL );
119- intent .putExtra (INCOMING_CALL_NOTIFICATION_ID , notificationId );
120- intent .putExtra (INCOMING_CALL_INVITE , callInvite );
121- LocalBroadcastManager .getInstance (context ).sendBroadcast (intent );
122- callNotificationManager .createIncomingCallNotification (
123- (ReactApplicationContext ) context , callInvite , notificationId ,
124- launchIntent );
125- }
126- });
127- if (!mReactInstanceManager .hasStartedCreatingInitialContext ()) {
128- // Construct it in the background
129- mReactInstanceManager .createReactContextInBackground ();
130- }
111+ Intent callKeepIntent = new Intent ();
112+ callKeepIntent .setAction ("com.hoxfon.HoxFon.DEV.debug.BACKGROUND_CALL" );
113+ callKeepIntent .setPackage ("com.hoxfon.HoxFon.DEV.debug" );
114+ Bundle bundle = new Bundle ();
115+ bundle .putString ("call_state" , "PENDING" );
116+ bundle .putString ("call_sid" , callInvite .getCallSid ());
117+ bundle .putString ("call_from" , callInvite .getFrom ());
118+ bundle .putString ("call_to" , callInvite .getTo ());
119+ callKeepIntent .putExtras (bundle );
120+ Log .d (TAG , "BACKGROUND onCallInvite, callKeepIntent " + callKeepIntent );
121+
122+ sendBroadcast (callKeepIntent );
123+
124+ // // Otherwise wait for construction, then handle the incoming call
125+ // mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
126+ // public void onReactContextInitialized(ReactContext context) {
127+ // int appImportance = callNotificationManager.getApplicationImportance((ReactApplicationContext)context);
128+ // if (BuildConfig.DEBUG) {
129+ // Log.d(TAG, "CONTEXT not present appImportance = " + appImportance);
130+ // }
131+ // Intent launchIntent = callNotificationManager.getLaunchIntent(
132+ // (ReactApplicationContext)context,
133+ // notificationId,
134+ // callInvite.getCallSid(),
135+ // callInvite.getFrom(),
136+ // callInvite.getTo(),
137+ // true,
138+ // appImportance
139+ // );
140+ // context.startActivity(launchIntent);
141+ // Intent intent = new Intent(ACTION_INCOMING_CALL);
142+ // intent.putExtra(INCOMING_CALL_NOTIFICATION_ID, notificationId);
143+ // intent.putExtra(INCOMING_CALL_INVITE, callInvite);
144+ // LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
145+ // callNotificationManager.createIncomingCallNotification(
146+ // (ReactApplicationContext) context,
147+ // callInvite.getCallSid(),
148+ // callInvite.getFrom(),
149+ // notificationId,
150+ // launchIntent
151+ // );
152+ // }
153+ // });
154+ // if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
155+ // // Construct it in the background
156+ // mReactInstanceManager.createReactContextInBackground();
157+ // }
131158 }
132159 }
133160 });
@@ -160,8 +187,19 @@ public void run() {
160187 */
161188 private void sendCancelledCallInviteToActivity (CancelledCallInvite cancelledCallInvite ) {
162189 SoundPoolManager .getInstance ((this )).stopRinging ();
163- Intent intent = new Intent (ACTION_CANCEL_CALL_INVITE );
164- intent .putExtra (CANCELLED_CALL_INVITE , cancelledCallInvite );
165- LocalBroadcastManager .getInstance (this ).sendBroadcast (intent );
190+ // Intent intent = new Intent(ACTION_CANCEL_CALL_INVITE);
191+ // intent.putExtra(CANCELLED_CALL_INVITE, cancelledCallInvite);
192+ // LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
193+
194+ Intent callKeepIntent = new Intent ();
195+ callKeepIntent .setAction ("com.hoxfon.react.RNTwilioVoice.BACKGROUND_CALL" );
196+ callKeepIntent .setPackage ("com.hoxfon.react.RNTwilioVoice" );
197+ Bundle bundle = new Bundle ();
198+ bundle .putString ("call_state" , "CANCELLED" );
199+ bundle .putString ("call_sid" , cancelledCallInvite .getCallSid ());
200+ bundle .putString ("call_from" , cancelledCallInvite .getFrom ());
201+ bundle .putString ("call_to" , cancelledCallInvite .getTo ());
202+ callKeepIntent .putExtras (bundle );
203+ sendBroadcast (callKeepIntent );
166204 }
167205}
0 commit comments