diff --git a/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourSpeechCall.java b/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourSpeechCall.java index 1ecfd9d..0ee0f27 100755 --- a/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourSpeechCall.java +++ b/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourSpeechCall.java @@ -39,42 +39,48 @@ public class UeBehaviourSpeechCall extends UeBehaviour{ @Override - protected void execute() throws InterruptedException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + protected void execute() throws Exception { Context context = MainActivity.getContext(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); // Start Call log.debug("Starting Call"); CallUtil.startCall(phoneNumber); - Thread.sleep(1000); + Thread.sleep(SLEEP_PERIOD); // Wait for call to start - log.debug("Waiting for an answer"); + log.debug("Waiting call to start"); while(tm.getCallState() == TelephonyManager.CALL_STATE_RINGING){ if(super.stopExecution()) return; - super.setProgress(0.1f); + super.setProgress(0.2f); Thread.sleep(SLEEP_PERIOD); } + // Start timer log.debug("Starting call timer"); int elapsedTime = 0; int lengthMillisec = length*1000; while(elapsedTime < lengthMillisec){ if(super.stopExecution()) return; - super.setProgress((float)elapsedTime/lengthMillisec); + if(tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { + log.debug("Call ended prematurely"); + return; + } + super.setProgress((float) elapsedTime / lengthMillisec); Thread.sleep(SLEEP_PERIOD); elapsedTime += SLEEP_PERIOD; } - CallUtil.endCall(); - log.debug("Waiting for call to end"); - // Wait for call to end + // End Call + log.debug("Ending call"); + CallUtil.endCall(); + log.debug("Waiting call to end"); while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){ if(super.stopExecution()) return; - super.setProgress(0.9f); + super.setProgress(0.95f); Thread.sleep(SLEEP_PERIOD); } }