Added fallback for answering call and also added progress to call behaviours

This commit is contained in:
Ziver Koc 2014-08-11 13:13:40 +02:00
parent 0a05a6b69c
commit e9018290c9
4 changed files with 33 additions and 23 deletions

View file

@ -38,8 +38,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest> </manifest>

View file

@ -24,7 +24,7 @@ public class UeBehaviourReceiveCall extends UeBehaviour{
@Override @Override
protected void execute() throws InterruptedException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { protected void execute() throws Exception {
Context context = MainActivity.getContext(); Context context = MainActivity.getContext();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
@ -32,14 +32,18 @@ public class UeBehaviourReceiveCall extends UeBehaviour{
while(tm.getCallState() != TelephonyManager.CALL_STATE_RINGING ){ while(tm.getCallState() != TelephonyManager.CALL_STATE_RINGING ){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress(0.2f);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
} }
log.debug("Phone is ringing, answering call"); log.debug("Phone is ringing, answering call");
Thread.sleep(1000);
CallUtil.answerCall();
// Wait for call to end // Wait for call to end
while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){ while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress(0.6f);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
} }
log.debug("Call has ended"); log.debug("Call has ended");

View file

@ -52,6 +52,7 @@ public class UeBehaviourSpeechCall extends UeBehaviour{
while(tm.getCallState() != TelephonyManager.CALL_STATE_OFFHOOK){ while(tm.getCallState() != TelephonyManager.CALL_STATE_OFFHOOK){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress(0.1f);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
} }
@ -71,6 +72,7 @@ public class UeBehaviourSpeechCall extends UeBehaviour{
while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){ while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress(0.9f);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
} }
} }

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.view.KeyEvent;
import com.ericsson.uecontrol.gui.MainActivity; import com.ericsson.uecontrol.gui.MainActivity;
@ -39,9 +40,11 @@ public class CallUtil {
} }
private static void answerCall() throws Exception { public static void answerCall() throws Exception {
Context context = MainActivity.getContext();
log.debug("Answering Speech Call"); log.debug("Answering Speech Call");
try {
Object telephonyService = getTelephonyServiceAidl(); Object telephonyService = getTelephonyServiceAidl();
Class c = Class.forName(telephonyService.getClass().getName()); Class c = Class.forName(telephonyService.getClass().getName());
// Silence ringer // Silence ringer
@ -52,8 +55,9 @@ public class CallUtil {
m = c.getDeclaredMethod("answerRingingCall"); m = c.getDeclaredMethod("answerRingingCall");
m.setAccessible(true); m.setAccessible(true);
m.invoke(telephonyService); m.invoke(telephonyService);
}catch (Exception e){
log.debug("Using fallback call solution");
/* Fallback Solution
// Simulate a press of the headset button to pick up the call // Simulate a press of the headset button to pick up the call
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON); Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK)); buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
@ -63,7 +67,7 @@ public class CallUtil {
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON); Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK)); buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
*/ }
} }