Skip to content

Commit

Permalink
do not reset values for incoming call. solves #572
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jan 1, 2025
1 parent 67b3169 commit acce49d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.zoffcc.applications.trifa;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.KeyguardManager;
Expand Down Expand Up @@ -1256,43 +1257,53 @@ public void run()
@Override
public boolean onTouch(View v, MotionEvent event)
{
Log.i(TAG, "accept_button:onTouch:001");
try
{
if (event.getAction() != MotionEvent.ACTION_UP)
{
Log.i(TAG, "accept_button:onTouch:002");
}
else
{
Log.i(TAG, "accept_button:onTouch:003 " + Callstate.accepted_call + " " + Callstate.friend_pubkey);
if (Callstate.accepted_call != 1)
{
Log.i(TAG, "answer button pressed");
Log.i(TAG, "accept_button:onTouch:004 " + Callstate.audio_call);

if (Callstate.audio_call)
{
int res1 = toxav_answer(tox_friend_by_public_key__wrapper(Callstate.friend_pubkey),
GLOBAL_AUDIO_BITRATE, 0);

Log.i(TAG, "accept_button:onTouch:004:001" + res1);
if (res1 != 1)
{
Log.i(TAG, "accept_button:onTouch:004:002");
return true;
}
Callstate.tox_call_state = ToxVars.TOXAV_FRIEND_CALL_STATE.TOXAV_FRIEND_CALL_STATE_SENDING_V.value;
Log.i(TAG, "accept_button:onTouch:004:003");
}
else
{
int res2 = toxav_answer(tox_friend_by_public_key__wrapper(Callstate.friend_pubkey),
GLOBAL_AUDIO_BITRATE, GLOBAL_VIDEO_BITRATE);
Log.i(TAG, "accept_button:onTouch:004:011: " + res2);

if (res2 != 1)
{
Log.i(TAG, "accept_button:onTouch:004:012");
return true;
}

Callstate.tox_call_state = ToxVars.TOXAV_FRIEND_CALL_STATE.TOXAV_FRIEND_CALL_STATE_SENDING_V.value;

Log.i(TAG, "accept_button:onTouch:004:014");
}

Callstate.accepted_call = 1;
Log.i(TAG, "accept_button:onTouch:005");

caller_avatar_view.setVisibility(View.GONE);
accept_button.setVisibility(View.GONE);
Expand All @@ -1308,8 +1319,12 @@ public boolean onTouch(View v, MotionEvent event)

Log.i(TAG, "on_call_started_actions:01");
on_call_started_actions();
Log.i(TAG, "accept_button:onTouch:006");

if (Callstate.audio_call)
{
Log.i(TAG, "accept_button:onTouch:006 " + Callstate.audio_call);

toggle_osd_view_including_cam_preview(!Callstate.audio_call);
}

Expand All @@ -1319,6 +1334,7 @@ public boolean onTouch(View v, MotionEvent event)
catch (Exception e)
{
e.printStackTrace();
Log.i(TAG, "accept_button:onTouch:006:EE01:" + e.getMessage());
}
return true;
}
Expand Down Expand Up @@ -1447,6 +1463,7 @@ else if (PREF__video_cam_resolution == 1)

public static void close_calling_activity()
{
Log.i(TAG, "reset_values:001");
Callstate.reset_values();
// close calling activity --------
ca.finish();
Expand Down Expand Up @@ -1582,6 +1599,7 @@ public static void initializeScreenshotSecurity(Activity a)
}
}

@SuppressLint("MissingSuperCall")
@Override
public void onBackPressed()
{
Expand All @@ -1602,6 +1620,7 @@ protected void onResume()
super.onResume();

tox_set_onion_active(0);
Callstate.incoming_one_on_one_call = false;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.provider.CallLog;
import android.telecom.Call;
import android.util.Log;

import static com.zoffcc.applications.trifa.CallingActivity.set_debug_text;
import static com.zoffcc.applications.trifa.TRIFAGlobals.GLOBAL_AUDIO_BITRATE;
Expand All @@ -31,10 +32,13 @@

public class Callstate
{
private static final String TAG = "trifa.Callstate";

static int state = 0; // 0 -> not in a call, 1 -> ringing/calling
static int tox_call_state = ToxVars.TOXAV_FRIEND_CALL_STATE.TOXAV_FRIEND_CALL_STATE_NONE.value;
static boolean audio_call = false;
static String friend_pubkey = "-1";
static boolean incoming_one_on_one_call = false;
static String friend_alias_name = "";
static int other_audio_enabled = 1;
static int other_video_enabled = 1;
Expand Down Expand Up @@ -79,7 +83,9 @@ static void reset_values()
Callstate.call_first_audio_frame_received = -1;
Callstate.call_start_timestamp = -1;
Callstate.call_init_timestamp = -1;
Log.i(TAG, "friend_pubkey:set:001");
Callstate.friend_pubkey = "-1";
Callstate.incoming_one_on_one_call = false;
Callstate.friend_alias_name = "";
Callstate.other_audio_enabled = 1;
Callstate.other_video_enabled = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ public static void stop_me(boolean stop_full)
Callstate.audio_group_active = false;
if (stop_full)
{
Log.i(TAG, "reset_values:003");
Callstate.reset_values();
}
ConferenceAudioActivity.conf_id = "-1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ static void on_groupaudio_ended_actions(boolean close)

public static void close_conference_audio_activity()
{
Log.i(TAG, "reset_values:002");
Callstate.reset_values();
conf_id = "-1";
conf_id_prev = "-1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private static void removeNotification()
}
}

public static void stop_me(boolean stop_full)
public static void stop_me(boolean stop_full, boolean reset_call_values)
{
ngc_running = false;
try
Expand All @@ -493,7 +493,11 @@ public static void stop_me(boolean stop_full)
Callstate.audio_ngc_group_active = false;
if (stop_full)
{
Callstate.reset_values();
if (reset_call_values)
{
Log.i(TAG, "reset_values:004");
Callstate.reset_values();
}
}
GroupGroupAudioService.group_id = "-1";
AudioRecording.global_audio_group_send_res = -999;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,10 @@ protected void onPause()
ml_is_recording = false;
ml_is_rec_ok = false;

stop_group_video(this);
// HINT: here we leave the GroupMessageListActivity
// but it could be that we are starting the CallingActivity because there is an icoming call
// then this would reset the values for the incoming call :-(
stop_group_video(this, !Callstate.incoming_one_on_one_call);
closeCamera();
MainActivity.group_message_list_fragment = null;
MainActivity.group_message_list_activity = null;
Expand Down Expand Up @@ -1708,7 +1711,7 @@ protected void onResume()
// reset update trigger timestamp
update_group_all_users_last_trigger_ts = 0;

stop_group_video(this);
stop_group_video(this, true);
closeCamera();
ngc_video_packet_last_incoming_ts = -1;
ngc_incoming_video_peer_toggle_current_index = 0;
Expand Down Expand Up @@ -3097,7 +3100,7 @@ private Size chooseOptimalSize(Size[] choices, int width, int height) {
}
}

synchronized public static void stop_group_video(final Context c)
synchronized public static void stop_group_video(final Context c, boolean reset_call_values)
{
ngc_video_showing_video_from_peer_pubkey = "-1";
NGC_Group_video_play_thread_running = false;
Expand All @@ -3109,7 +3112,7 @@ synchronized public static void stop_group_video(final Context c)
// ---- stop audio stuff
try
{
GroupGroupAudioService.stop_me(true);
GroupGroupAudioService.stop_me(true, reset_call_values);
}
catch (Exception e)
{
Expand Down Expand Up @@ -3851,7 +3854,7 @@ public void toggle_group_video(final View view)
{
if (sending_video_to_group)
{
stop_group_video(view.getContext());
stop_group_video(view.getContext(), true);
closeCamera();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ else if (position == 10)
last_video_frame_received = -1;
count_video_frame_received = 0;
count_video_frame_sent = 0;
Log.i(TAG, "friend_pubkey:set:002");
Callstate.friend_pubkey = "-1";
Callstate.audio_speaker = true;
Callstate.other_audio_enabled = 1;
Expand Down Expand Up @@ -3750,6 +3751,7 @@ public void run()
}

Callstate.state = 1;
Callstate.incoming_one_on_one_call = true;
Callstate.accepted_call = 0;
Callstate.call_first_video_frame_received = -1;
Callstate.call_first_audio_frame_received = -1;
Expand All @@ -3775,6 +3777,7 @@ public void run()
{
}
Intent intent = new Intent(context_s.getApplicationContext(), CallingActivity.class);
Log.i(TAG, "friend_pubkey:set:003");
Callstate.friend_pubkey = HelperFriend.tox_friend_get_public_key__wrapper(fn);
Callstate.friend_alias_name = get_friend_name_from_pubkey(Callstate.friend_pubkey);
Callstate.other_audio_enabled = f_audio_enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ public void run()
Callstate.accepted_call = 1; // we started the call, so it's already accepted on our side
Callstate.call_first_video_frame_received = -1;
Callstate.call_start_timestamp = -1;
Log.i(TAG, "friend_pubkey:set:004");
Callstate.friend_pubkey = tox_friend_get_public_key__wrapper(fn);
Callstate.camera_opened = false;
Callstate.audio_speaker = true;
Expand Down

0 comments on commit acce49d

Please sign in to comment.