Phone Listener changed.

This commit is contained in:
jens 2021-05-15 14:22:43 +02:00
parent 3844079781
commit 0a0399c2b0
9 changed files with 190 additions and 103 deletions

View File

@ -1360,28 +1360,29 @@ public class Rule implements Comparable<Rule>
return ruleCandidates; return ruleCandidates;
} }
// public static ArrayList<Rule> findRuleCandidatesByPhoneCall() public static ArrayList<Rule> findRuleCandidatesByPhoneCall(String direction)
// { {
// ArrayList<Rule> ruleCandidates = new ArrayList<Rule>(); ArrayList<Rule> ruleCandidates = new ArrayList<Rule>();
//
// for(Rule oneRule : ruleCollection) for(Rule oneRule : ruleCollection)
// { {
// innerloop: innerloop:
// for(Trigger oneTrigger : oneRule.getTriggerSet()) for(Trigger oneTrigger : oneRule.getTriggerSet())
// { {
// if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall)
// { {
// if(oneTrigger.getTriggerParameter() == triggerParameter) String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
// { if(elements[1].equals(Trigger.triggerPhoneCallDirectionAny) || elements[1].equals(direction))
// ruleCandidates.add(oneRule); {
// break innerloop; //we don't need to search the other triggers in the same rule ruleCandidates.add(oneRule);
// } break innerloop; //we don't need to search the other triggers in the same rule
// } }
// } }
// } }
// }
// return ruleCandidates;
// } return ruleCandidates;
}
public static ArrayList<Rule> findRuleCandidatesByNfc() public static ArrayList<Rule> findRuleCandidatesByNfc()
{ {

View File

@ -7,6 +7,7 @@ import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Looper; import android.os.Looper;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -217,7 +218,7 @@ public class Rule implements Comparable<Rule>
private boolean checkBeforeSaving(Context context, boolean changeExistingRule) private boolean checkBeforeSaving(Context context, boolean changeExistingRule)
{ {
if(this.getName() == null | this.getName().length()==0) if(this.getName() == null || this.getName().length()==0)
{ {
Toast.makeText(context, context.getResources().getString(R.string.pleaseEnterValidName), Toast.LENGTH_LONG).show(); Toast.makeText(context, context.getResources().getString(R.string.pleaseEnterValidName), Toast.LENGTH_LONG).show();
return false; return false;
@ -412,13 +413,13 @@ public class Rule implements Comparable<Rule>
&& &&
Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0 Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0
) )
| ||
// Other case, start time higher than end time, timeframe goes over midnight // Other case, start time higher than end time, timeframe goes over midnight
( (
Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), oneTrigger.getTimeFrame().getTriggerTimeStop()) < 0 Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), oneTrigger.getTimeFrame().getTriggerTimeStop()) < 0
&& &&
(Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), nowTime) >= 0 (Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), nowTime) >= 0
| ||
Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0) Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0)
) )
@ -598,13 +599,29 @@ public class Rule implements Comparable<Rule>
} }
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.phoneCall)) else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.phoneCall))
{ {
if(oneTrigger.getPhoneNumber().equals("any") | oneTrigger.getPhoneNumber().equals(PhoneStatusListener.getLastPhoneNumber())) 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.triggerPhoneCallStateRinging) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_RINGING)
||
(elements[0].equals(Trigger.triggerPhoneCallStateStarted) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_OFFHOOK)
||
(elements[0].equals(Trigger.triggerPhoneCallStateStopped) && PhoneStatusListener.getCurrentState() == 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 else
{ {
@ -619,7 +636,10 @@ public class Rule implements Comparable<Rule>
} }
} }
else else
{
Miscellaneous.logEvent("i", "Rule", "Rule doesn't apply. Wrong phone number. Demanded: " + oneTrigger.getPhoneNumber() + ", got: " + PhoneStatusListener.getLastPhoneNumber(), 4); Miscellaneous.logEvent("i", "Rule", "Rule doesn't apply. Wrong phone number. Demanded: " + oneTrigger.getPhoneNumber() + ", got: " + PhoneStatusListener.getLastPhoneNumber(), 4);
return false;
}
} }
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.nfcTag)) else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.nfcTag))
{ {
@ -772,6 +792,7 @@ public class Rule implements Comparable<Rule>
} }
foundMatch = true; foundMatch = true;
break;
} }
} }
@ -840,7 +861,7 @@ public class Rule implements Comparable<Rule>
if (Looper.myLooper() == null) if (Looper.myLooper() == null)
Looper.prepare(); Looper.prepare();
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]); wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
return null; return null;
@ -870,8 +891,8 @@ public class Rule implements Comparable<Rule>
ActivityMainScreen.updateMainScreen(); ActivityMainScreen.updateMainScreen();
super.onPostExecute(result); super.onPostExecute(result);
} }
} }
/** /**
* Will activate the rule. Should be called by a separate execution thread * Will activate the rule. Should be called by a separate execution thread
* @param automationService * @param automationService
@ -879,15 +900,15 @@ public class Rule implements Comparable<Rule>
protected boolean activateInternally(AutomationService automationService, boolean force) protected boolean activateInternally(AutomationService automationService, boolean force)
{ {
boolean isActuallyToggable = isActuallyToggable(); boolean isActuallyToggable = isActuallyToggable();
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this); boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggable; boolean doToggle = ruleToggle && isActuallyToggable;
if(notLastActive | force | doToggle) if(notLastActive || force || doToggle)
{ {
String message; String message;
if(!doToggle) if(!doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName()); message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName());
else else
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName()); message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName());
Miscellaneous.logEvent("i", "Rule", message, 2); Miscellaneous.logEvent("i", "Rule", message, 2);
@ -895,7 +916,7 @@ public class Rule implements Comparable<Rule>
// Toast.makeText(automationService, message, Toast.LENGTH_LONG).show(); // Toast.makeText(automationService, message, Toast.LENGTH_LONG).show();
if(Settings.startNewThreadForRuleActivation) if(Settings.startNewThreadForRuleActivation)
publishProgress(message); publishProgress(message);
for(int i = 0; i< Rule.this.getActionSet().size(); i++) for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{ {
try try
@ -1036,7 +1057,7 @@ public class Rule implements Comparable<Rule>
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()) if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime())
{ {
Miscellaneous.logEvent("i", "Timeframe search", "Rule goes over midnight.", 5); Miscellaneous.logEvent("i", "Timeframe search", "Rule goes over midnight.", 5);
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() | searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() || searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; //if the poi is found we don't need to search the other triggers in the same rule break innerloop; //if the poi is found we don't need to search the other triggers in the same rule
@ -1307,10 +1328,10 @@ public class Rule implements Comparable<Rule>
return ruleCandidates; return ruleCandidates;
} }
public static ArrayList<Rule> findRuleCandidatesByPhoneCall(boolean triggerParameter) public static ArrayList<Rule> findRuleCandidatesByPhoneCall(String direction)
{ {
ArrayList<Rule> ruleCandidates = new ArrayList<Rule>(); ArrayList<Rule> ruleCandidates = new ArrayList<Rule>();
for(Rule oneRule : ruleCollection) for(Rule oneRule : ruleCollection)
{ {
innerloop: innerloop:
@ -1318,7 +1339,8 @@ public class Rule implements Comparable<Rule>
{ {
if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall)
{ {
if(oneTrigger.getTriggerParameter() == triggerParameter) String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
if(elements[1].equals(Trigger.triggerPhoneCallDirectionAny) || elements[1].equals(direction))
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; //we don't need to search the other triggers in the same rule break innerloop; //we don't need to search the other triggers in the same rule
@ -1326,7 +1348,7 @@ public class Rule implements Comparable<Rule>
} }
} }
} }
return ruleCandidates; return ruleCandidates;
} }

View File

@ -63,7 +63,7 @@ public class Rule implements Comparable<Rule>
{ {
this.lastExecution = lastExecution; this.lastExecution = lastExecution;
} }
public boolean isRuleToggle() public boolean isRuleToggle()
{ {
return ruleToggle; return ruleToggle;
@ -219,7 +219,7 @@ public class Rule implements Comparable<Rule>
private boolean checkBeforeSaving(Context context, boolean changeExistingRule) private boolean checkBeforeSaving(Context context, boolean changeExistingRule)
{ {
if(this.getName() == null | this.getName().length()==0) if(this.getName() == null || this.getName().length()==0)
{ {
Toast.makeText(context, context.getResources().getString(R.string.pleaseEnterValidName), Toast.LENGTH_LONG).show(); Toast.makeText(context, context.getResources().getString(R.string.pleaseEnterValidName), Toast.LENGTH_LONG).show();
return false; return false;
@ -414,13 +414,13 @@ public class Rule implements Comparable<Rule>
&& &&
Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0 Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0
) )
| ||
// Other case, start time higher than end time, timeframe goes over midnight // Other case, start time higher than end time, timeframe goes over midnight
( (
Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), oneTrigger.getTimeFrame().getTriggerTimeStop()) < 0 Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), oneTrigger.getTimeFrame().getTriggerTimeStop()) < 0
&& &&
(Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), nowTime) >= 0 (Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), nowTime) >= 0
| ||
Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0) Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0)
) )
@ -600,13 +600,29 @@ public class Rule implements Comparable<Rule>
} }
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.phoneCall)) else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.phoneCall))
{ {
if(oneTrigger.getPhoneNumber().equals("any") | oneTrigger.getPhoneNumber().equals(PhoneStatusListener.getLastPhoneNumber())) 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.triggerPhoneCallStateRinging) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_RINGING)
||
(elements[0].equals(Trigger.triggerPhoneCallStateStarted) && PhoneStatusListener.getCurrentState() == TelephonyManager.CALL_STATE_OFFHOOK)
||
(elements[0].equals(Trigger.triggerPhoneCallStateStopped) && PhoneStatusListener.getCurrentState() == 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 else
{ {
@ -621,7 +637,10 @@ public class Rule implements Comparable<Rule>
} }
} }
else else
{
Miscellaneous.logEvent("i", "Rule", "Rule doesn't apply. Wrong phone number. Demanded: " + oneTrigger.getPhoneNumber() + ", got: " + PhoneStatusListener.getLastPhoneNumber(), 4); Miscellaneous.logEvent("i", "Rule", "Rule doesn't apply. Wrong phone number. Demanded: " + oneTrigger.getPhoneNumber() + ", got: " + PhoneStatusListener.getLastPhoneNumber(), 4);
return false;
}
} }
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.nfcTag)) else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.nfcTag))
{ {
@ -872,7 +891,7 @@ public class Rule implements Comparable<Rule>
if (Looper.myLooper() == null) if (Looper.myLooper() == null)
Looper.prepare(); Looper.prepare();
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]); wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
return null; return null;
@ -915,7 +934,7 @@ public class Rule implements Comparable<Rule>
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this); boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggable; boolean doToggle = ruleToggle && isActuallyToggable;
if(notLastActive | force | doToggle) if(notLastActive || force || doToggle)
{ {
String message; String message;
if(!doToggle) if(!doToggle)
@ -1068,7 +1087,7 @@ public class Rule implements Comparable<Rule>
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()) if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime())
{ {
Miscellaneous.logEvent("i", "Timeframe search", "Rule goes over midnight.", 5); Miscellaneous.logEvent("i", "Timeframe search", "Rule goes over midnight.", 5);
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() | searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() || searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; //if the poi is found we don't need to search the other triggers in the same rule break innerloop; //if the poi is found we don't need to search the other triggers in the same rule
@ -1339,10 +1358,10 @@ public class Rule implements Comparable<Rule>
return ruleCandidates; return ruleCandidates;
} }
public static ArrayList<Rule> findRuleCandidatesByPhoneCall(boolean triggerParameter) public static ArrayList<Rule> findRuleCandidatesByPhoneCall(String direction)
{ {
ArrayList<Rule> ruleCandidates = new ArrayList<Rule>(); ArrayList<Rule> ruleCandidates = new ArrayList<Rule>();
for(Rule oneRule : ruleCollection) for(Rule oneRule : ruleCollection)
{ {
innerloop: innerloop:
@ -1350,7 +1369,8 @@ public class Rule implements Comparable<Rule>
{ {
if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall)
{ {
if(oneTrigger.getTriggerParameter() == triggerParameter) String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
if(elements[1].equals(Trigger.triggerPhoneCallDirectionAny) || elements[1].equals(direction))
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; //we don't need to search the other triggers in the same rule break innerloop; //we don't need to search the other triggers in the same rule
@ -1358,7 +1378,7 @@ public class Rule implements Comparable<Rule>
} }
} }
} }
return ruleCandidates; return ruleCandidates;
} }

View File

@ -445,7 +445,8 @@ public class AutomationService extends Service implements OnInitListener
private void stopRoutine() private void stopRoutine()
{ {
Log.i("STOP", "Stopping"); Miscellaneous.logEvent("i", "Service", "Stopping service...", 3);
// Log.i("STOP", "Stopping");
try try
{ {
myLocationProvider.stopLocationService(); myLocationProvider.stopLocationService();

View File

@ -927,7 +927,7 @@ public class XmlFileInterface
else if(newTrigger.getTriggerType() == Trigger_Enum.phoneCall) else if(newTrigger.getTriggerType() == Trigger_Enum.phoneCall)
{ {
String[] elements = triggerParameter2.split(","); String[] elements = triggerParameter2.split(",");
if(elements.length > 3 && elements.length < 3) //old format if(elements.length == 2) //old format
{ {
// 0/1/2,number // 0/1/2,number
int direction = Integer.parseInt(elements[0]); int direction = Integer.parseInt(elements[0]);

View File

@ -14,6 +14,7 @@ import com.jens.automation2.AutomationService;
import com.jens.automation2.Miscellaneous; import com.jens.automation2.Miscellaneous;
import com.jens.automation2.R; import com.jens.automation2.R;
import com.jens.automation2.Rule; import com.jens.automation2.Rule;
import com.jens.automation2.Trigger;
import com.jens.automation2.Trigger.Trigger_Enum; import com.jens.automation2.Trigger.Trigger_Enum;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,7 +34,6 @@ public class PhoneStatusListener implements AutomationListenerInterface
protected static IncomingCallsReceiver incomingCallsReceiverInstance; protected static IncomingCallsReceiver incomingCallsReceiverInstance;
protected static BroadcastReceiver outgoingCallsReceiverInstance; protected static BroadcastReceiver outgoingCallsReceiverInstance;
public static boolean isIncomingCallsReceiverActive() public static boolean isIncomingCallsReceiverActive()
{ {
return incomingCallsReceiverActive; return incomingCallsReceiverActive;
@ -78,63 +78,106 @@ public class PhoneStatusListener implements AutomationListenerInterface
{ {
// Miscellaneous.logEvent("i", "Call state", "New call state: " + String.valueOf(state), 4); // Miscellaneous.logEvent("i", "Call state", "New call state: " + String.valueOf(state), 4);
setCurrentState(state); /*
Unfortunately receivers for incoming and outgoing calls behave pretty differently:
if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number. The Outgoing-Receiver is called when starting a call (ringing)
setLastPhoneNumber(incomingNumber); It is not called when that outgoing call ends however, only the incoming receiver.
lastPhoneDirection = 1; If the last call was outgoing the state has not changed to idle this is kind of a fake alert.
*/
switch(state)
if(lastPhoneDirection == 2 && currentState != TelephonyManager.CALL_STATE_IDLE)
{ {
case TelephonyManager.CALL_STATE_IDLE: // This status update is actually for an outgoing call
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4); setCurrentState(state);
// if(currentStateIncoming == TelephonyManager.CALL_STATE_OFFHOOK)
// setCurrentStateIncoming(state); if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
// else if(currentStateOutgoing == TelephonyManager.CALL_STATE_OFFHOOK) setLastPhoneNumber(incomingNumber);
// setCurrentStateOutgoing(state);
// else switch(state)
// currentStateIncoming = state; {
// currentStateOutgoing = state; case TelephonyManager.CALL_STATE_IDLE:
break; Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
case TelephonyManager.CALL_STATE_OFFHOOK: break;
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4); case TelephonyManager.CALL_STATE_OFFHOOK:
// if(currentStateIncoming == TelephonyManager.CALL_STATE_RINGING) Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
// setCurrentStateIncoming(state); break;
// else if(currentStateOutgoing == TelephonyManager.CALL_STATE_RINGING) case TelephonyManager.CALL_STATE_RINGING:
// setCurrentStateOutgoing(state); Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), incomingNumber), 4);
break; break;
case TelephonyManager.CALL_STATE_RINGING: }
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4);
break; ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByPhoneCall(Trigger.triggerPhoneCallDirectionOutgoing);
for(int i=0; i<ruleCandidates.size(); i++)
{
AutomationService asInstance = AutomationService.getInstance();
if(asInstance != null)
if(ruleCandidates.get(i).applies(asInstance))
ruleCandidates.get(i).activate(asInstance, false);
}
} }
else
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
AutomationService asInstance = AutomationService.getInstance();
for(int i=0; i<ruleCandidates.size(); i++)
{ {
if(asInstance != null) // state != TelephonyManager.CALL_STATE_IDLE &&
if(ruleCandidates.get(i).applies(asInstance))
ruleCandidates.get(i).activate(asInstance, false); setCurrentState(state);
setLastPhoneDirection(1);
if (incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
setLastPhoneNumber(incomingNumber);
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
break;
case TelephonyManager.CALL_STATE_RINGING:
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4);
break;
}
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByPhoneCall(Trigger.triggerPhoneCallDirectionIncoming);
for (int i = 0; i < ruleCandidates.size(); i++)
{
AutomationService asInstance = AutomationService.getInstance();
if (asInstance != null)
if (ruleCandidates.get(i).applies(asInstance))
ruleCandidates.get(i).activate(asInstance, false);
}
} }
} }
} }
static void setLastPhoneDirection(int i)
{
lastPhoneDirection = i;
}
public static class OutgoingCallsReceiver extends BroadcastReceiver public static class OutgoingCallsReceiver extends BroadcastReceiver
{ {
@Override @Override
public void onReceive(Context context, Intent intent) public void onReceive(Context context, Intent intent)
{ {
lastPhoneDirection = 2; /*
// setCurrentStateOutgoing(2); // das kommt hier auch bei nur klingeln This receiver is ONLY triggered when outgoing calls ring, not when that call is established or ends.
*/
setLastPhoneDirection(2);
TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE); // TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
setCurrentState(tm.getCallState()); // int newState = tm.getCallState();
// setCurrentState(newState);
setLastPhoneNumber(intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER)); setCurrentState(TelephonyManager.CALL_STATE_RINGING);
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallFrom), getLastPhoneNumber()), 4);
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall); String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
setLastPhoneNumber(phoneNumber);
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), getLastPhoneNumber()), 4);
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByPhoneCall(Trigger.triggerPhoneCallDirectionOutgoing);
for(int i=0; i<ruleCandidates.size(); i++) for(int i=0; i<ruleCandidates.size(); i++)
{ {
AutomationService asInstance = AutomationService.getInstance(); AutomationService asInstance = AutomationService.getInstance();

View File

@ -410,7 +410,7 @@
<string name="activityDetectionRequiredProbabilityTitle">Wahrscheinlichkeit für Aktivitätserkennungen</string> <string name="activityDetectionRequiredProbabilityTitle">Wahrscheinlichkeit für Aktivitätserkennungen</string>
<string name="activityDetectionRequiredProbabilitySummary">Wahrscheinlichkeit, ab der eine Aktivität als gegeben gilt.</string> <string name="activityDetectionRequiredProbabilitySummary">Wahrscheinlichkeit, ab der eine Aktivität als gegeben gilt.</string>
<string name="incomingCallFrom">Eingehender Telefonanruf von %1$s.</string> <string name="incomingCallFrom">Eingehender Telefonanruf von %1$s.</string>
<string name="outgoingCallFrom">Ausgehender Telefonanruf von %1$s.</string> <string name="outgoingCallTo">Ausgehender Telefonanruf von %1$s.</string>
<string name="actionSpeakText">Text sprechen</string> <string name="actionSpeakText">Text sprechen</string>
<string name="textToSpeak">Zu sprechender Text</string> <string name="textToSpeak">Zu sprechender Text</string>
<string name="toggleNotAllowed">Die Umschaltfunktion ist momentan nur für Regeln erlaubt, die NFC Tags als Auslöser haben. Für weitere Informationen lesen Sie die Hilfe.</string> <string name="toggleNotAllowed">Die Umschaltfunktion ist momentan nur für Regeln erlaubt, die NFC Tags als Auslöser haben. Für weitere Informationen lesen Sie die Hilfe.</string>

View File

@ -312,7 +312,7 @@ Quindi, se si crea una regola che imposta il profilo su vibrazione nell\'interva
<string name="onOff">On/Off</string> <string name="onOff">On/Off</string>
<string name="outgoing">effettuata</string> <string name="outgoing">effettuata</string>
<string name="outgoingAdjective">effettuata</string> <string name="outgoingAdjective">effettuata</string>
<string name="outgoingCallFrom">Ultima chiamata effettuata %1$s fa.</string> <string name="outgoingCallTo">Ultima chiamata effettuata %1$s fa.</string>
<string name="overlapBetweenPois">Rilevata sovrapposizione della posizione %1$s. Ridurre il raggio almeno di %2$s metri.</string> <string name="overlapBetweenPois">Rilevata sovrapposizione della posizione %1$s. Ridurre il raggio almeno di %2$s metri.</string>
<string name="overview">Panoramica</string> <string name="overview">Panoramica</string>
<string name="parameterName">Nome parametro</string> <string name="parameterName">Nome parametro</string>

View File

@ -411,7 +411,7 @@
<string name="activityDetectionRequiredProbabilityTitle">Activity detection probability</string> <string name="activityDetectionRequiredProbabilityTitle">Activity detection probability</string>
<string name="activityDetectionRequiredProbabilitySummary">Certainty from which activities are accepted as fact.</string> <string name="activityDetectionRequiredProbabilitySummary">Certainty from which activities are accepted as fact.</string>
<string name="incomingCallFrom">Incoming telephone call from %1$s.</string> <string name="incomingCallFrom">Incoming telephone call from %1$s.</string>
<string name="outgoingCallFrom">Outgoing telephone call to %1$s.</string> <string name="outgoingCallTo">Outgoing telephone call to %1$s.</string>
<string name="actionSpeakText">Speak text</string> <string name="actionSpeakText">Speak text</string>
<string name="textToSpeak">Text to speak</string> <string name="textToSpeak">Text to speak</string>
<string name="toggleNotAllowed">Toggling is currently only allowed for rules that have NFC tags as trigger. See help for further information.</string> <string name="toggleNotAllowed">Toggling is currently only allowed for rules that have NFC tags as trigger. See help for further information.</string>