Phone Listener changed.

This commit is contained in:
jens 2021-05-14 20:07:46 +02:00
parent e988cedf7c
commit 191ad904a3
3 changed files with 42 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Looper;
import android.service.notification.StatusBarNotification;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
@ -601,13 +602,31 @@ public class Rule implements Comparable<Rule>
}
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.phoneCall))
{
if(oneTrigger.getPhoneNumber().equals("any") || PhoneStatusListener.getLastPhoneNumber().matches(oneTrigger.getPhoneNumber()))
String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
// state dir number
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || PhoneStatusListener.getLastPhoneNumber().matches(elements[2]))
{
if(PhoneStatusListener.isInACall() == oneTrigger.getTriggerParameter())
//if(PhoneStatusListener.isInACall() == oneTrigger.getTriggerParameter())
if(
elements[0].equals(Trigger.triggerPhoneCallStateAny)
||
(elements[0].equals(Trigger.triggerPhoneCallStateRinging) && PhoneStatusListener.getLastState() == TelephonyManager.CALL_STATE_RINGING)
||
(elements[0].equals(Trigger.triggerPhoneCallStateStarted) && PhoneStatusListener.getLastState() == TelephonyManager.CALL_STATE_OFFHOOK)
||
(elements[0].equals(Trigger.triggerPhoneCallStateStopped) && PhoneStatusListener.getLastState() == TelephonyManager.CALL_STATE_IDLE)
)
{
if(oneTrigger.getPhoneDirection() == 0 || (oneTrigger.getPhoneDirection() == PhoneStatusListener.getLastPhoneDirection()))
if(
elements[1].equals(Trigger.triggerPhoneCallDirectionAny)
||
(elements[1].equals(Trigger.triggerPhoneCallDirectionIncoming) && PhoneStatusListener.getLastPhoneDirection() == 1)
||
(elements[1].equals(Trigger.triggerPhoneCallDirectionOutgoing) && PhoneStatusListener.getLastPhoneDirection() == 2)
)
{
// Everything's allright
// Trigger conditions are met
}
else
{

View File

@ -928,8 +928,9 @@ public class XmlFileInterface
if(elements.length < 3) //old format
{
// 0/1/2,number
int direction = Integer.parseInt(triggerParameter2.substring(0, 1));
String number = triggerParameter2.substring(2);
int direction = Integer.parseInt(elements[0]);
String number = elements[1];
newTrigger.setPhoneDirection(direction);
newTrigger.setPhoneNumber(number);

View File

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.provider.Telephony;
import android.telecom.Call;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
@ -24,6 +25,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
protected static int currentStateOutgoing = -1;
protected static String lastPhoneNumber="";
protected static int lastPhoneDirection = -1; //0=incoming, 1=outgoing
protected static int lastState = -1;
protected static boolean incomingCallsReceiverActive = false;
protected static boolean outgoingCallsReceiverActive = false;
@ -59,7 +61,12 @@ public class PhoneStatusListener implements AutomationListenerInterface
{
return lastPhoneNumber;
}
public static int getLastState()
{
return lastState;
}
public static class IncomingCallsReceiver extends PhoneStateListener
{
@Override
@ -67,6 +74,8 @@ public class PhoneStatusListener implements AutomationListenerInterface
{
// Miscellaneous.logEvent("i", "Call state", "New call state: " + String.valueOf(state), 4);
lastState = state;
if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
setLastPhoneNumber(incomingNumber);
@ -106,7 +115,9 @@ public class PhoneStatusListener implements AutomationListenerInterface
@Override
public void onReceive(Context context, Intent intent)
{
setCurrentStateOutgoing(2);
lastState = TelephonyManager.CALL_STATE_RINGING;
lastPhoneDirection = 2;
setCurrentStateOutgoing(2); // das kommt hier auch bei nur klingeln
setLastPhoneNumber(intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallFrom), getLastPhoneNumber()), 4);
}
@ -236,7 +247,9 @@ public class PhoneStatusListener implements AutomationListenerInterface
return currentStateOutgoing;
}
/*
Apps that redirect outgoing calls should use the android.telecom.CallRedirectionService API. Apps that perform call screening should use the android.telecom.CallScreeningService API.
*/
public static void startPhoneStatusListener(AutomationService automationService)
{