forked from jens/Automation
Notification trigger.
This commit is contained in:
parent
864ed2111e
commit
13bcb02ffc
@ -51,9 +51,20 @@ public class Rule implements Comparable<Rule>
|
|||||||
private String name;
|
private String name;
|
||||||
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
||||||
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
||||||
|
private Calendar lastExecution;
|
||||||
|
|
||||||
private static Date lastActivatedRuleActivationTime;
|
private static Date lastActivatedRuleActivationTime;
|
||||||
|
|
||||||
|
public Calendar getLastExecution()
|
||||||
|
{
|
||||||
|
return lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastExecution(Calendar lastExecution)
|
||||||
|
{
|
||||||
|
this.lastExecution = lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRuleToggle()
|
public boolean isRuleToggle()
|
||||||
{
|
{
|
||||||
return ruleToggle;
|
return ruleToggle;
|
||||||
@ -757,40 +768,44 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||||
{
|
{
|
||||||
String app = sbn.getPackageName();
|
if(lastExecution == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
|
||||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
|
||||||
|
|
||||||
if (!myApp.equals("-1"))
|
|
||||||
{
|
{
|
||||||
if (!app.equalsIgnoreCase(myApp))
|
String app = sbn.getPackageName();
|
||||||
{
|
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myTitle.length() > 0)
|
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||||
{
|
|
||||||
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
|
||||||
{
|
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myText.length() > 0)
|
if (!myApp.equals("-1"))
|
||||||
{
|
|
||||||
if (!Miscellaneous.compare(myTextDir, myText, text))
|
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
if (!app.equalsIgnoreCase(myApp))
|
||||||
continue;
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foundMatch = true;
|
if (myTitle.length() > 0)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myText.length() > 0)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foundMatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!foundMatch)
|
if(!foundMatch)
|
||||||
@ -859,7 +874,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null)
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
|
|
||||||
activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -883,6 +898,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
*/
|
*/
|
||||||
if(wasActivated)
|
if(wasActivated)
|
||||||
{
|
{
|
||||||
|
setLastExecution(Calendar.getInstance());
|
||||||
AutomationService.updateNotification();
|
AutomationService.updateNotification();
|
||||||
ActivityMainScreen.updateMainScreen();
|
ActivityMainScreen.updateMainScreen();
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
@ -46,8 +46,19 @@ public class Rule implements Comparable<Rule>
|
|||||||
private String name;
|
private String name;
|
||||||
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
||||||
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
||||||
|
private Calendar lastExecution;
|
||||||
|
|
||||||
private static Date lastActivatedRuleActivationTime;
|
private static Date lastActivatedRuleActivationTime;
|
||||||
|
|
||||||
|
public Calendar getLastExecution()
|
||||||
|
{
|
||||||
|
return lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastExecution(Calendar lastExecution)
|
||||||
|
{
|
||||||
|
this.lastExecution = lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRuleToggle()
|
public boolean isRuleToggle()
|
||||||
{
|
{
|
||||||
@ -762,29 +773,43 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||||
{
|
{
|
||||||
String app = sbn.getPackageName();
|
if(getLastExecution() == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
|
||||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
|
||||||
|
|
||||||
if (!myApp.equals("-1"))
|
|
||||||
{
|
{
|
||||||
if (!app.equalsIgnoreCase(myApp))
|
String app = sbn.getPackageName();
|
||||||
continue;
|
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||||
}
|
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||||
|
|
||||||
if (myTitle.length() > 0)
|
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||||
{
|
|
||||||
if (!Miscellaneous.compare(myTitleDir, title, myTitle))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myText.length() > 0)
|
if (!myApp.equals("-1"))
|
||||||
{
|
{
|
||||||
if (!Miscellaneous.compare(myTextDir, text, myText))
|
if (!app.equalsIgnoreCase(myApp))
|
||||||
continue;
|
{
|
||||||
}
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foundMatch = true;
|
if (myTitle.length() > 0)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myText.length() > 0)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foundMatch = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!foundMatch)
|
if(!foundMatch)
|
||||||
@ -852,8 +877,8 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null)
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
|
|
||||||
activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -877,6 +902,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
*/
|
*/
|
||||||
if(wasActivated)
|
if(wasActivated)
|
||||||
{
|
{
|
||||||
|
setLastExecution(Calendar.getInstance());
|
||||||
AutomationService.updateNotification();
|
AutomationService.updateNotification();
|
||||||
ActivityMainScreen.updateMainScreen();
|
ActivityMainScreen.updateMainScreen();
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
@ -48,8 +48,19 @@ public class Rule implements Comparable<Rule>
|
|||||||
private String name;
|
private String name;
|
||||||
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
||||||
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
||||||
|
private Calendar lastExecution;
|
||||||
|
|
||||||
private static Date lastActivatedRuleActivationTime;
|
private static Date lastActivatedRuleActivationTime;
|
||||||
|
|
||||||
|
public Calendar getLastExecution()
|
||||||
|
{
|
||||||
|
return lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastExecution(Calendar lastExecution)
|
||||||
|
{
|
||||||
|
this.lastExecution = lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRuleToggle()
|
public boolean isRuleToggle()
|
||||||
{
|
{
|
||||||
@ -793,29 +804,43 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||||
{
|
{
|
||||||
String app = sbn.getPackageName();
|
if(getLastExecution() == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
|
||||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
|
||||||
|
|
||||||
if (!myApp.equals("-1"))
|
|
||||||
{
|
{
|
||||||
if (!app.equalsIgnoreCase(myApp))
|
String app = sbn.getPackageName();
|
||||||
continue;
|
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||||
}
|
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||||
|
|
||||||
if (myTitle.length() > 0)
|
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||||
{
|
|
||||||
if (!Miscellaneous.compare(myTitleDir, title, myTitle))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myText.length() > 0)
|
if (!myApp.equals("-1"))
|
||||||
{
|
{
|
||||||
if (!Miscellaneous.compare(myTextDir, text, myText))
|
if (!app.equalsIgnoreCase(myApp))
|
||||||
continue;
|
{
|
||||||
}
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foundMatch = true;
|
if (myTitle.length() > 0)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myText.length() > 0)
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foundMatch = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!foundMatch)
|
if(!foundMatch)
|
||||||
@ -883,8 +908,8 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null)
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
|
|
||||||
activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -908,6 +933,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
*/
|
*/
|
||||||
if(wasActivated)
|
if(wasActivated)
|
||||||
{
|
{
|
||||||
|
setLastExecution(Calendar.getInstance());
|
||||||
AutomationService.updateNotification();
|
AutomationService.updateNotification();
|
||||||
ActivityMainScreen.updateMainScreen();
|
ActivityMainScreen.updateMainScreen();
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
@ -74,7 +74,7 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
checkNotification(false, sbn);
|
checkNotification(false, sbn);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean checkNotification(boolean created, StatusBarNotification sbn)
|
synchronized boolean checkNotification(boolean created, StatusBarNotification sbn)
|
||||||
{
|
{
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
||||||
{
|
{
|
||||||
@ -89,9 +89,9 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
lastNotification.title = title;
|
lastNotification.title = title;
|
||||||
lastNotification.text = text;
|
lastNotification.text = text;
|
||||||
|
|
||||||
if(lastResponseToNotification == null || lastResponseToNotification.getTimeInMillis() < lastNotification.publishTime.getTimeInMillis())
|
// if(lastResponseToNotification == null || lastResponseToNotification.getTimeInMillis() < lastNotification.publishTime.getTimeInMillis())
|
||||||
{
|
// {
|
||||||
lastResponseToNotification = Calendar.getInstance();
|
// lastResponseToNotification = Calendar.getInstance();
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||||
@ -99,9 +99,9 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
if (ruleCandidates.get(i).applies(NotificationListener.this))
|
if (ruleCandidates.get(i).applies(NotificationListener.this))
|
||||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
Miscellaneous.logEvent("e", "NotificationCheck", "Ignoring notification as it is old.", 5);
|
// Miscellaneous.logEvent("e", "NotificationCheck", "Ignoring notification as it is old.", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user