<commit_before>package dt.call.aclient.screens;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import dt.call.aclient.CallState;
import dt.call.aclient.Const;
import dt.call.aclient.Voip.SoundEffects;
import dt.call.aclient.Voip.Voice;
import dt.call.aclient.background.async.OperatorCommand;
import dt.call.aclient.R;
import dt.call.aclient.Utils;
import dt.call.aclient.Vars;

public class CallMain extends AppCompatActivity implements View.OnClickListener, SensorEventListener
{
	private static final String WAKELOCK_INCALLA9 = "dt.call.aclient:incalla9";
	private static final String tag = "CallMain";
	public static final String DIALING_MODE = "DIALING_MODE";

	private LinearLayout micContainer, spkContainer, acceptContainer;
	private FloatingActionButton end, mic, speaker, accept;
	private Button stats;
	private boolean onSpeaker = false;
	private boolean screenShowing;
	private ImageView userImage;
	private TextView status, time, callerid;
	private int min=0, sec=0;
	private Thread timerTask;
	private BroadcastReceiver myReceiver;
	private boolean showStats = false;
	private boolean isDialing;
	private boolean selfEndedCall = false;
	private boolean finalStopRan = false;

	private AudioManager audioManager;
	private SensorManager sensorManager;
	private Sensor proximity = null;

	private final StringBuilder timeBuilder = new StringBuilder();

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_call_main);

		Vars.callEndIntentForCallMain = true;
		isDialing = getIntent().getBooleanExtra(DIALING_MODE, true);

		//allow this screen to show even when there is a password/pattern lock screen
		Window window = this.getWindow();
		window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
		window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
		window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

		//cell phone now awake. release the wakelock
		if(Vars.incomingCallLock != null)
		{
			Vars.incomingCallLock.release();
			Vars.incomingCallLock = null;
		}

		end = findViewById(R.id.call_main_end_call);
		end.setOnClickListener(this);
		micContainer = findViewById(R.id.call_main_mic_container);
		mic = findViewById(R.id.call_main_mic);
		mic.setOnClickListener(this);
		mic.setEnabled(false);
		spkContainer = findViewById(R.id.call_main_spk_container);
		speaker = findViewById(R.id.call_main_spk);
		speaker.setOnClickListener(this);
		speaker.setEnabled(false);
		acceptContainer = findViewById(R.id.call_main_accept_container);
		accept = findViewById(R.id.call_main_accept);
		accept.setOnClickListener(this);
		accept.setEnabled(!isDialing);
		stats = findViewById(R.id.call_main_stats);
		stats.setOnClickListener(this);
		status = findViewById(R.id.call_main_status); //by default ringing. change it when in a call
		callerid = findViewById(R.id.call_main_callerid);
		callerid.setText(Utils.getCallerID(Vars.callWith));
		time = findViewById(R.id.call_main_time);
		userImage = findViewById(R.id.call_main_user_image);

		sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		proximity = sensorManager != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) : null;
		audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

		timerTask = new Thread(new Runnable()
		{
			@Override
			public void run()
			{
				Utils.logcat(Const.LOGD, tag, "Timer task thread started");
				while(Vars.state != CallState.NONE)
				{
					//if the person hasn't answered after 20 seconds give up. it's probably not going to happen.
					if ((Vars.state == CallState.INIT) && (sec == Const.CALL_TIMEOUT))
					{
						new OperatorCommand().execute(OperatorCommand.END);
						onStopWrapper();
						break;
					}
					updateTime();
					updateStats();
					try
					{
						Thread.sleep(1000);
					}
					catch (InterruptedException e)
					{
						break;
					}
				}
				Utils.logcat(Const.LOGD, tag, "Timer task thread stopped");
			}
		});
		timerTask.start();<commit_msg>Use a normal thread for the ui updater like the c++ client.<commit_after>package dt.call.aclient.screens;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import dt.call.aclient.CallState;
import dt.call.aclient.Const;
import dt.call.aclient.Voip.SoundEffects;
import dt.call.aclient.Voip.Voice;
import dt.call.aclient.background.async.OperatorCommand;
import dt.call.aclient.R;
import dt.call.aclient.Utils;
import dt.call.aclient.Vars;

public class CallMain extends AppCompatActivity implements View.OnClickListener, SensorEventListener
{
	private static final String WAKELOCK_INCALLA9 = "dt.call.aclient:incalla9";
	private static final String tag = "CallMain";
	public static final String DIALING_MODE = "DIALING_MODE";

	private LinearLayout micContainer, spkContainer, acceptContainer;
	private FloatingActionButton end, mic, speaker, accept;
	private Button stats;
	private boolean onSpeaker = false;
	private boolean screenShowing;
	private ImageView userImage;
	private TextView status, time, callerid;
	private int min=0, sec=0;
	private Thread timerTask;
	private BroadcastReceiver myReceiver;
	private boolean showStats = false;
	private boolean isDialing;
	private boolean selfEndedCall = false;
	private boolean finalStopRan = false;

	private AudioManager audioManager;
	private SensorManager sensorManager;
	private Sensor proximity = null;

	private final StringBuilder timeBuilder = new StringBuilder();

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_call_main);

		Vars.callEndIntentForCallMain = true;
		isDialing = getIntent().getBooleanExtra(DIALING_MODE, true);

		//allow this screen to show even when there is a password/pattern lock screen
		Window window = this.getWindow();
		window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
		window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
		window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

		//cell phone now awake. release the wakelock
		if(Vars.incomingCallLock != null)
		{
			Vars.incomingCallLock.release();
			Vars.incomingCallLock = null;
		}

		end = findViewById(R.id.call_main_end_call);
		end.setOnClickListener(this);
		micContainer = findViewById(R.id.call_main_mic_container);
		mic = findViewById(R.id.call_main_mic);
		mic.setOnClickListener(this);
		mic.setEnabled(false);
		spkContainer = findViewById(R.id.call_main_spk_container);
		speaker = findViewById(R.id.call_main_spk);
		speaker.setOnClickListener(this);
		speaker.setEnabled(false);
		acceptContainer = findViewById(R.id.call_main_accept_container);
		accept = findViewById(R.id.call_main_accept);
		accept.setOnClickListener(this);
		accept.setEnabled(!isDialing);
		stats = findViewById(R.id.call_main_stats);
		stats.setOnClickListener(this);
		status = findViewById(R.id.call_main_status); //by default ringing. change it when in a call
		callerid = findViewById(R.id.call_main_callerid);
		callerid.setText(Utils.getCallerID(Vars.callWith));
		time = findViewById(R.id.call_main_time);
		userImage = findViewById(R.id.call_main_user_image);

		sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		proximity = sensorManager != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) : null;
		audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

		timerTask = new Thread(new Runnable()
		{
			@Override
			public void run()
			{
				Utils.logcat(Const.LOGD, tag, "Timer task thread started");
				while(Vars.state != CallState.NONE)
				{
					//if the person hasn't answered after 20 seconds give up. it's probably not going to happen.
					if ((Vars.state == CallState.INIT) && (sec == Const.CALL_TIMEOUT))
					{
						new OperatorCommand().execute(OperatorCommand.END);
						onStopWrapper();
						break;
					}
					updateTime();
					updateStats();
					try
					{
						Thread.sleep(1000);
					}
					catch (InterruptedException e)
					{
						break;
					}
				}
				Utils.logcat(Const.LOGD, tag, "Timer task thread stopped");
			}
		});
		timerTask.setName("CallMain_TimerTask");
		timerTask.start();
{'fraction_non_alphanumeric': 0.09740194603270137, 'fraction_numerical': 0.0020062192797672784, 'mean_word_length': 5.242955541640576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630618', 'n_tokens_mistral': 3341, 'n_tokens_neox': 3007, 'n_words': 643}