Compare commits

..

No commits in common. "619f348a2819d195412904c8a768e8af2968902b" and "9bf353ea3ac7230d9afee00d7d55135a744cfcb4" have entirely different histories.

4 changed files with 146 additions and 129 deletions

View File

@ -351,10 +351,7 @@ public class Rule implements Comparable<Rule>
if(applies(context)) if(applies(context))
{ {
if(hasNotAppliedSinceLastExecution()) if(hasNotAppliedSinceLastExecution())
{
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
return true; return true;
}
else else
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4); Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
} }
@ -437,7 +434,7 @@ public class Rule implements Comparable<Rule>
Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler);
// without this line the debugger will - for some reason - skip all breakpoints in this class // without this line debugger will - for some reason - skip all breakpoints in this class
if(android.os.Debug.isDebuggerConnected()) if(android.os.Debug.isDebuggerConnected())
android.os.Debug.waitForDebugger(); android.os.Debug.waitForDebugger();
@ -445,7 +442,7 @@ public class Rule implements Comparable<Rule>
Looper.prepare(); Looper.prepare();
setLastExecution(Calendar.getInstance()); setLastExecution(Calendar.getInstance());
wasActivated = activateInternally((AutomationService)params[0]); wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
return null; return null;
} }
@ -480,57 +477,66 @@ public class Rule implements Comparable<Rule>
* 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
*/ */
protected boolean activateInternally(AutomationService automationService) protected boolean activateInternally(AutomationService automationService, boolean force)
{ {
boolean isActuallyToggleable = isActuallyToggable(); boolean isActuallyToggable = isActuallyToggable();
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this); boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggleable; boolean doToggle = ruleToggle && isActuallyToggable;
String message; //if(notLastActive || force || doToggle)
if(!doToggle) // if(force || doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName()); // {
else String message;
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName()); if(!doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName());
else
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName());
Miscellaneous.logEvent("i", "Rule", message, 2);
// automationService.speak(message);
// Toast.makeText(automationService, message, Toast.LENGTH_LONG).show();
if(Settings.startNewThreadForRuleActivation)
publishProgress(message);
Miscellaneous.logEvent("i", "Rule", message, 2); for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try
{
Rule.this.getActionSet().get(i).run(automationService, doToggle);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1);
}
}
if(Settings.startNewThreadForRuleActivation) // Keep log of last x rule activations (Settings)
publishProgress(message);
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try try
{ {
Rule.this.getActionSet().get(i).run(automationService, doToggle); Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization
Rule.lastActivatedRuleActivationTime = new Date();
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize)
ruleRunHistory.remove(ruleRunHistory.size()-1);
String history = "";
for(Rule rule : ruleRunHistory)
history += rule.getName() + ", ";
if(history.length() > 0)
history = history.substring(0, history.length()-2);
Miscellaneous.logEvent("i", "Rule history", "Most recent first: " + history, 4);
} }
catch(Exception e) catch(Exception e)
{ {
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1); Miscellaneous.logEvent("e", "Rule history error", Log.getStackTraceString(e), 3);
} }
}
// Keep log of last x rule activations (Settings) Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
try // }
{ // else
Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization // {
Rule.lastActivatedRuleActivationTime = new Date(); // Miscellaneous.logEvent("i", "Rule", "Request to activate rule " + Rule.this.getName() + ", but it is the last one that was activated. Won't do it again.", 3);
// return false;
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize) // }
ruleRunHistory.remove(ruleRunHistory.size()-1);
String history = "";
for(Rule rule : ruleRunHistory)
history += rule.getName() + ", ";
if(history.length() > 0)
history = history.substring(0, history.length()-2);
Miscellaneous.logEvent("i", "Rule history", "Most recent first: " + history, 4);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "Rule history error", Log.getStackTraceString(e), 3);
}
Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
return true; return true;
} }

View File

@ -348,10 +348,7 @@ public class Rule implements Comparable<Rule>
if(applies(context)) if(applies(context))
{ {
if(hasNotAppliedSinceLastExecution()) if(hasNotAppliedSinceLastExecution())
{
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
return true; return true;
}
else else
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4); Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
} }
@ -417,7 +414,7 @@ public class Rule implements Comparable<Rule>
Looper.prepare(); Looper.prepare();
setLastExecution(Calendar.getInstance()); setLastExecution(Calendar.getInstance());
wasActivated = activateInternally((AutomationService)params[0]); wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
return null; return null;
} }
@ -452,57 +449,66 @@ public class Rule implements Comparable<Rule>
* 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
*/ */
protected boolean activateInternally(AutomationService automationService) protected boolean activateInternally(AutomationService automationService, boolean force)
{ {
boolean isActuallyToggleable = isActuallyToggable(); boolean isActuallyToggable = isActuallyToggable();
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this); boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggleable; boolean doToggle = ruleToggle && isActuallyToggable;
String message; //if(notLastActive || force || doToggle)
if(!doToggle) // if(force || doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName()); // {
else String message;
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName()); if(!doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName());
else
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName());
Miscellaneous.logEvent("i", "Rule", message, 2);
// automationService.speak(message);
// Toast.makeText(automationService, message, Toast.LENGTH_LONG).show();
if(Settings.startNewThreadForRuleActivation)
publishProgress(message);
Miscellaneous.logEvent("i", "Rule", message, 2); for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try
{
Rule.this.getActionSet().get(i).run(automationService, doToggle);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1);
}
}
if(Settings.startNewThreadForRuleActivation) // Keep log of last x rule activations (Settings)
publishProgress(message);
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try try
{ {
Rule.this.getActionSet().get(i).run(automationService, doToggle); Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization
Rule.lastActivatedRuleActivationTime = new Date();
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize)
ruleRunHistory.remove(ruleRunHistory.size()-1);
String history = "";
for(Rule rule : ruleRunHistory)
history += rule.getName() + ", ";
if(history.length() > 0)
history = history.substring(0, history.length()-2);
Miscellaneous.logEvent("i", "Rule history", "Most recent first: " + history, 4);
} }
catch(Exception e) catch(Exception e)
{ {
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1); Miscellaneous.logEvent("e", "Rule history error", Log.getStackTraceString(e), 3);
} }
}
// Keep log of last x rule activations (Settings) Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
try // }
{ // else
Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization // {
Rule.lastActivatedRuleActivationTime = new Date(); // Miscellaneous.logEvent("i", "Rule", "Request to activate rule " + Rule.this.getName() + ", but it is the last one that was activated. Won't do it again.", 3);
// return false;
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize) // }
ruleRunHistory.remove(ruleRunHistory.size()-1);
String history = "";
for(Rule rule : ruleRunHistory)
history += rule.getName() + ", ";
if(history.length() > 0)
history = history.substring(0, history.length()-2);
Miscellaneous.logEvent("i", "Rule history", "Most recent first: " + history, 4);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "Rule history error", Log.getStackTraceString(e), 3);
}
Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
return true; return true;
} }

View File

@ -351,10 +351,7 @@ public class Rule implements Comparable<Rule>
if(applies(context)) if(applies(context))
{ {
if(hasNotAppliedSinceLastExecution()) if(hasNotAppliedSinceLastExecution())
{
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
return true; return true;
}
else else
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4); Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
} }
@ -436,7 +433,7 @@ public class Rule implements Comparable<Rule>
Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler);
// without this line the debugger will - for some reason - skip all breakpoints in this class // without this line debugger will - for some reason - skip all breakpoints in this class
if(android.os.Debug.isDebuggerConnected()) if(android.os.Debug.isDebuggerConnected())
android.os.Debug.waitForDebugger(); android.os.Debug.waitForDebugger();
@ -444,7 +441,7 @@ public class Rule implements Comparable<Rule>
Looper.prepare(); Looper.prepare();
setLastExecution(Calendar.getInstance()); setLastExecution(Calendar.getInstance());
wasActivated = activateInternally((AutomationService)params[0]); wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
return null; return null;
} }
@ -479,57 +476,66 @@ public class Rule implements Comparable<Rule>
* 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
*/ */
protected boolean activateInternally(AutomationService automationService) protected boolean activateInternally(AutomationService automationService, boolean force)
{ {
boolean isActuallyToggleable = isActuallyToggable(); boolean isActuallyToggable = isActuallyToggable();
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this); boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggleable; boolean doToggle = ruleToggle && isActuallyToggable;
String message; //if(notLastActive || force || doToggle)
if(!doToggle) // if(force || doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName()); // {
else String message;
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName()); if(!doToggle)
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName());
else
message = String.format(automationService.getResources().getString(R.string.ruleActivateToggle), Rule.this.getName());
Miscellaneous.logEvent("i", "Rule", message, 2);
// automationService.speak(message);
// Toast.makeText(automationService, message, Toast.LENGTH_LONG).show();
if(Settings.startNewThreadForRuleActivation)
publishProgress(message);
Miscellaneous.logEvent("i", "Rule", message, 2); for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try
{
Rule.this.getActionSet().get(i).run(automationService, doToggle);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1);
}
}
if(Settings.startNewThreadForRuleActivation) // Keep log of last x rule activations (Settings)
publishProgress(message);
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try try
{ {
Rule.this.getActionSet().get(i).run(automationService, doToggle); Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization
Rule.lastActivatedRuleActivationTime = new Date();
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize)
ruleRunHistory.remove(ruleRunHistory.size()-1);
String history = "";
for(Rule rule : ruleRunHistory)
history += rule.getName() + ", ";
if(history.length() > 0)
history = history.substring(0, history.length()-2);
Miscellaneous.logEvent("i", "Rule history", "Most recent first: " + history, 4);
} }
catch(Exception e) catch(Exception e)
{ {
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1); Miscellaneous.logEvent("e", "Rule history error", Log.getStackTraceString(e), 3);
} }
}
// Keep log of last x rule activations (Settings) Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
try // }
{ // else
Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization // {
Rule.lastActivatedRuleActivationTime = new Date(); // Miscellaneous.logEvent("i", "Rule", "Request to activate rule " + Rule.this.getName() + ", but it is the last one that was activated. Won't do it again.", 3);
// return false;
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize) // }
ruleRunHistory.remove(ruleRunHistory.size()-1);
String history = "";
for(Rule rule : ruleRunHistory)
history += rule.getName() + ", ";
if(history.length() > 0)
history = history.substring(0, history.length()-2);
Miscellaneous.logEvent("i", "Rule history", "Most recent first: " + history, 4);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "Rule history error", Log.getStackTraceString(e), 3);
}
Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
return true; return true;
} }

View File

@ -199,7 +199,6 @@ public class ActivityMainRules extends ActivityGeneric
AutomationService runContext = AutomationService.getInstance(); AutomationService runContext = AutomationService.getInstance();
if(runContext != null) if(runContext != null)
{ {
Miscellaneous.logEvent("i", "ActivityMainRules", "Initiating manual execution of rule " + ruleThisIsAbout.getName(), 3);
ruleThisIsAbout.activate(runContext, true); ruleThisIsAbout.activate(runContext, true);
break; break;
} }