diff --git a/app/src/apkFlavor/java/com/jens/automation2/Rule.java b/app/src/apkFlavor/java/com/jens/automation2/Rule.java index f35c0500..824e364d 100644 --- a/app/src/apkFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/apkFlavor/java/com/jens/automation2/Rule.java @@ -609,13 +609,11 @@ public class Rule implements Comparable { //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.triggerPhoneCallStateRinging) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_RINGING) || - (elements[0].equals(Trigger.triggerPhoneCallStateStarted) && PhoneStatusListener.getLastState() == TelephonyManager.CALL_STATE_OFFHOOK) + (elements[0].equals(Trigger.triggerPhoneCallStateStarted) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_OFFHOOK) || - (elements[0].equals(Trigger.triggerPhoneCallStateStopped) && PhoneStatusListener.getLastState() == TelephonyManager.CALL_STATE_IDLE) + (elements[0].equals(Trigger.triggerPhoneCallStateStopped) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_IDLE) ) { if( @@ -1362,28 +1360,28 @@ public class Rule implements Comparable return ruleCandidates; } - public static ArrayList findRuleCandidatesByPhoneCall(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - } +// public static ArrayList findRuleCandidatesByPhoneCall() +// { +// ArrayList ruleCandidates = new ArrayList(); +// +// for(Rule oneRule : ruleCollection) +// { +// innerloop: +// for(Trigger oneTrigger : oneRule.getTriggerSet()) +// { +// if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) +// { +// if(oneTrigger.getTriggerParameter() == triggerParameter) +// { +// ruleCandidates.add(oneRule); +// break innerloop; //we don't need to search the other triggers in the same rule +// } +// } +// } +// } +// +// return ruleCandidates; +// } public static ArrayList findRuleCandidatesByNfc() { diff --git a/app/src/main/java/com/jens/automation2/ActivityManageTriggerPhoneCall.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerPhoneCall.java index c401f8c6..d120bfa2 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageTriggerPhoneCall.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerPhoneCall.java @@ -19,7 +19,7 @@ public class ActivityManageTriggerPhoneCall extends Activity ProgressDialog progressDialog = null; EditText etTriggerPhoneCallPhoneNumber; - RadioButton rbTriggerPhoneCallStateAny, rbTriggerPhoneCallStateRinging, rbTriggerPhoneCallStateStarted, rbTriggerPhoneCallStateStopped, rbTriggerPhoneCallDirectionAny, rbTriggerPhoneCallDirectionIncoming, rbTriggerPhoneCallDirectionOutgoing; + RadioButton rbTriggerPhoneCallStateRinging, rbTriggerPhoneCallStateStarted, rbTriggerPhoneCallStateStopped, rbTriggerPhoneCallDirectionAny, rbTriggerPhoneCallDirectionIncoming, rbTriggerPhoneCallDirectionOutgoing; Button bSaveTriggerPhoneCall, bTriggerPhoneCallImportFromContacts; @Override @@ -29,7 +29,6 @@ public class ActivityManageTriggerPhoneCall extends Activity setContentView(R.layout.activity_manage_trigger_phone_call); etTriggerPhoneCallPhoneNumber = (EditText)findViewById(R.id.etTriggerPhoneCallPhoneNumber); - rbTriggerPhoneCallStateAny = (RadioButton)findViewById(R.id.rbTriggerPhoneCallStateAny); rbTriggerPhoneCallStateRinging = (RadioButton)findViewById(R.id.rbTriggerPhoneCallStateRinging); rbTriggerPhoneCallStateStarted = (RadioButton)findViewById(R.id.rbTriggerPhoneCallStateStarted); rbTriggerPhoneCallStateStopped = (RadioButton)findViewById(R.id.rbTriggerPhoneCallStateStopped); @@ -46,9 +45,7 @@ public class ActivityManageTriggerPhoneCall extends Activity { String tp2Result = ""; - if(rbTriggerPhoneCallStateAny.isChecked()) - tp2Result += Trigger.triggerPhoneCallStateAny; - else if(rbTriggerPhoneCallStateRinging.isChecked()) + if(rbTriggerPhoneCallStateRinging.isChecked()) tp2Result += Trigger.triggerPhoneCallStateRinging; else if(rbTriggerPhoneCallStateStarted.isChecked()) tp2Result += Trigger.triggerPhoneCallStateStarted; @@ -101,9 +98,7 @@ public class ActivityManageTriggerPhoneCall extends Activity { String[] parts = editedPhoneCallTrigger.getTriggerParameter2().split(triggerParameter2Split); - if(parts[0].equals(Trigger.triggerPhoneCallStateAny)) - rbTriggerPhoneCallStateAny.setChecked(true); - else if(parts[0].equals(Trigger.triggerPhoneCallStateRinging)) + if(parts[0].equals(Trigger.triggerPhoneCallStateRinging)) rbTriggerPhoneCallStateRinging.setChecked(true); else if(parts[0].equals(Trigger.triggerPhoneCallStateStarted)) rbTriggerPhoneCallStateStarted.setChecked(true); diff --git a/app/src/main/java/com/jens/automation2/Trigger.java b/app/src/main/java/com/jens/automation2/Trigger.java index ca29fc34..f77be33b 100644 --- a/app/src/main/java/com/jens/automation2/Trigger.java +++ b/app/src/main/java/com/jens/automation2/Trigger.java @@ -80,7 +80,6 @@ public class Trigger public static String triggerPhoneCallStateRinging = "ringing"; public static String triggerPhoneCallStateStarted = "started"; public static String triggerPhoneCallStateStopped = "stopped"; - public static String triggerPhoneCallStateAny = "any"; public static String triggerPhoneCallDirectionIncoming = "incoming"; public static String triggerPhoneCallDirectionOutgoing = "outgoing"; public static String triggerPhoneCallDirectionAny = "any"; @@ -370,9 +369,7 @@ public class Trigger returnString.append(" "); - if(elements[0].equals(Trigger.triggerPhoneCallStateAny)) - returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.any) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.state)); - else if(elements[0].equals(Trigger.triggerPhoneCallStateRinging)) + if(elements[0].equals(Trigger.triggerPhoneCallStateRinging)) returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.ringing)); else if(elements[0].equals(Trigger.triggerPhoneCallStateStarted)) returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.started)); diff --git a/app/src/main/java/com/jens/automation2/XmlFileInterface.java b/app/src/main/java/com/jens/automation2/XmlFileInterface.java index e10a642a..6627c92b 100644 --- a/app/src/main/java/com/jens/automation2/XmlFileInterface.java +++ b/app/src/main/java/com/jens/automation2/XmlFileInterface.java @@ -260,8 +260,8 @@ public class XmlFileInterface serializer.text(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getProcessName()); else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.batteryLevel) serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getBatteryLevel())); - else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.phoneCall) - serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getPhoneDirection()) + "," + String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getPhoneNumber())); +// else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.phoneCall) +// serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getPhoneDirection()) + "," + String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getPhoneNumber())); else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.nfcTag) serializer.text(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getNfcTagId()); else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.activityDetection) @@ -275,6 +275,8 @@ public class XmlFileInterface serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getHeadphoneType())); else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.notification) serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerParameter2())); + else + serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerParameter2())); serializer.endTag(null, "TriggerParameter2"); serializer.endTag(null, "Trigger"); } @@ -925,7 +927,7 @@ public class XmlFileInterface else if(newTrigger.getTriggerType() == Trigger_Enum.phoneCall) { String[] elements = triggerParameter2.split(","); - if(elements.length < 3) //old format + if(elements.length > 3 && elements.length < 3) //old format { // 0/1/2,number int direction = Integer.parseInt(elements[0]); diff --git a/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java b/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java index bbdcb3c9..b9d53725 100644 --- a/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java @@ -1,11 +1,10 @@ package com.jens.automation2.receivers; +import android.app.Service; 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; import android.util.Log; @@ -21,11 +20,11 @@ import java.util.ArrayList; public class PhoneStatusListener implements AutomationListenerInterface { - protected static int currentStateIncoming = -1; - protected static int currentStateOutgoing = -1; +// protected static int currentStateIncoming = -1; +// 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 int currentState = -1; protected static boolean incomingCallsReceiverActive = false; protected static boolean outgoingCallsReceiverActive = false; @@ -62,9 +61,14 @@ public class PhoneStatusListener implements AutomationListenerInterface return lastPhoneNumber; } - public static int getLastState() + public static void setCurrentState(int currentState) { - return lastState; + PhoneStatusListener.currentState = currentState; + } + + public static int getCurrentState() + { + return currentState; } public static class IncomingCallsReceiver extends PhoneStateListener @@ -74,39 +78,45 @@ public class PhoneStatusListener implements AutomationListenerInterface { // Miscellaneous.logEvent("i", "Call state", "New call state: " + String.valueOf(state), 4); - lastState = state; + setCurrentState(state); if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number. setLastPhoneNumber(incomingNumber); + + lastPhoneDirection = 1; switch(state) { case TelephonyManager.CALL_STATE_IDLE: Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4); - if(currentStateIncoming == TelephonyManager.CALL_STATE_OFFHOOK) - setCurrentStateIncoming(state); - else if(currentStateOutgoing == TelephonyManager.CALL_STATE_OFFHOOK) - setCurrentStateOutgoing(state); - else - currentStateIncoming = state; - currentStateOutgoing = state; +// if(currentStateIncoming == TelephonyManager.CALL_STATE_OFFHOOK) +// setCurrentStateIncoming(state); +// else if(currentStateOutgoing == TelephonyManager.CALL_STATE_OFFHOOK) +// setCurrentStateOutgoing(state); +// else +// currentStateIncoming = state; +// currentStateOutgoing = state; break; case TelephonyManager.CALL_STATE_OFFHOOK: Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4); - if(currentStateIncoming == TelephonyManager.CALL_STATE_RINGING) - setCurrentStateIncoming(state); - else if(currentStateOutgoing == TelephonyManager.CALL_STATE_RINGING) - setCurrentStateOutgoing(state); +// if(currentStateIncoming == TelephonyManager.CALL_STATE_RINGING) +// setCurrentStateIncoming(state); +// else if(currentStateOutgoing == TelephonyManager.CALL_STATE_RINGING) +// setCurrentStateOutgoing(state); break; case TelephonyManager.CALL_STATE_RINGING: - String number = "unknown"; - if(incomingNumber != null && incomingNumber.length() > 0) - number = incomingNumber; - Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), number), 4); - - setCurrentStateIncoming(state); + Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4); break; } + + ArrayList ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall); + AutomationService asInstance = AutomationService.getInstance(); + for(int i=0; i ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall); + for(int i=0; i - -