Added fallback for answering call and also added progress to call behaviours
This commit is contained in:
parent
0a05a6b69c
commit
e9018290c9
4 changed files with 33 additions and 23 deletions
|
|
@ -38,8 +38,8 @@
|
|||
<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_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<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.WRITE_EXTERNAL_STORAGE" />
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class UeBehaviourReceiveCall 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);
|
||||
|
||||
|
|
@ -32,14 +32,18 @@ public class UeBehaviourReceiveCall extends UeBehaviour{
|
|||
while(tm.getCallState() != TelephonyManager.CALL_STATE_RINGING ){
|
||||
if(super.stopExecution())
|
||||
return;
|
||||
super.setProgress(0.2f);
|
||||
Thread.sleep(SLEEP_PERIOD);
|
||||
}
|
||||
log.debug("Phone is ringing, answering call");
|
||||
Thread.sleep(1000);
|
||||
CallUtil.answerCall();
|
||||
|
||||
// Wait for call to end
|
||||
while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){
|
||||
if(super.stopExecution())
|
||||
return;
|
||||
super.setProgress(0.6f);
|
||||
Thread.sleep(SLEEP_PERIOD);
|
||||
}
|
||||
log.debug("Call has ended");
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public class UeBehaviourSpeechCall extends UeBehaviour{
|
|||
while(tm.getCallState() != TelephonyManager.CALL_STATE_OFFHOOK){
|
||||
if(super.stopExecution())
|
||||
return;
|
||||
super.setProgress(0.1f);
|
||||
Thread.sleep(SLEEP_PERIOD);
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +72,7 @@ public class UeBehaviourSpeechCall extends UeBehaviour{
|
|||
while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){
|
||||
if(super.stopExecution())
|
||||
return;
|
||||
super.setProgress(0.9f);
|
||||
Thread.sleep(SLEEP_PERIOD);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
|||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.ericsson.uecontrol.gui.MainActivity;
|
||||
|
||||
|
|
@ -39,31 +40,34 @@ public class CallUtil {
|
|||
}
|
||||
|
||||
|
||||
private static void answerCall() throws Exception {
|
||||
public static void answerCall() throws Exception {
|
||||
Context context = MainActivity.getContext();
|
||||
log.debug("Answering Speech Call");
|
||||
|
||||
Object telephonyService = getTelephonyServiceAidl();
|
||||
Class c = Class.forName(telephonyService.getClass().getName());
|
||||
// Silence ringer
|
||||
Method m = c.getDeclaredMethod("silenceRinger");
|
||||
m.setAccessible(true);
|
||||
m.invoke(telephonyService);
|
||||
// Answer Call
|
||||
m = c.getDeclaredMethod("answerRingingCall");
|
||||
m.setAccessible(true);
|
||||
m.invoke(telephonyService);
|
||||
try {
|
||||
Object telephonyService = getTelephonyServiceAidl();
|
||||
Class c = Class.forName(telephonyService.getClass().getName());
|
||||
// Silence ringer
|
||||
Method m = c.getDeclaredMethod("silenceRinger");
|
||||
m.setAccessible(true);
|
||||
m.invoke(telephonyService);
|
||||
// Answer Call
|
||||
m = c.getDeclaredMethod("answerRingingCall");
|
||||
m.setAccessible(true);
|
||||
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
|
||||
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
||||
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
|
||||
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
|
||||
// Simulate a press of the headset button to pick up the call
|
||||
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
||||
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
|
||||
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
|
||||
|
||||
// froyo and beyond trigger on buttonUp instead of buttonDown
|
||||
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
||||
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
|
||||
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
|
||||
*/
|
||||
// froyo and beyond trigger on buttonUp instead of buttonDown
|
||||
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
||||
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
|
||||
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue