New version prep, fix attempt in notification listener

This commit is contained in:
Jens 2024-01-24 14:00:34 +01:00
parent f7ff8a38e1
commit 0d38c8bbe0
2 changed files with 0 additions and 49 deletions

View File

@ -16,7 +16,6 @@ import com.google.android.gms.location.DetectedActivity;
import com.jens.automation2.receivers.ActivityDetectionReceiver; import com.jens.automation2.receivers.ActivityDetectionReceiver;
import com.jens.automation2.receivers.BroadcastListener; import com.jens.automation2.receivers.BroadcastListener;
import com.jens.automation2.receivers.CalendarReceiver; import com.jens.automation2.receivers.CalendarReceiver;
import com.jens.automation2.receivers.NotificationListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -380,11 +379,6 @@ public class Rule implements Comparable<Rule>
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4); Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
return true; return true;
} }
// else if(hasTriggerOfType(Trigger.Trigger_Enum.notification) && NotificationListener.mayRuleStillBeActivatedForPendingNotifications(this))
// {
// Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other notifications.", 4);
// return true;
// }
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this)) else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
{ {
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4); Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);

View File

@ -276,7 +276,6 @@ public class NotificationListener extends NotificationListenerService// implemen
cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
else else
cancelNotification(sbn.getKey()); cancelNotification(sbn.getKey());
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
@ -309,46 +308,4 @@ public class NotificationListener extends NotificationListenerService// implemen
if(!buttonFound) if(!buttonFound)
Miscellaneous.logEvent("w", "clickNotificationButton()", "Button with text \n" + buttonText + "\n could not found.", 2); Miscellaneous.logEvent("w", "clickNotificationButton()", "Button with text \n" + buttonText + "\n could not found.", 2);
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static boolean mayRuleStillBeActivatedForPendingNotifications(Rule rule)
{
for(RuleNotificationPair pair : notificationUsed)
Miscellaneous.logEvent("i", "mayRuleStillBeActivatedForPendingCalendarEvents()", "Existing pair of " + pair.rule.getName() + " and " + pair.notification, 5);
for(StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
{
for(Trigger t : rule.getTriggerSet())
{
if(t.getTriggerType().equals(Trigger.Trigger_Enum.notification) && NotificationListener.getInstance().checkNotification(true, sbn))
{
if (!hasNotificationBeenUsedInRule(rule, convertNotificationToSimpleNotification(true, sbn)))
{
/*
If there are multiple parallel calendar events and a rule has multiple
triggers of type calendar event, we don't want the rule to fire only once.
*/
if(rule.getAmountOfTriggersForType(Trigger.Trigger_Enum.notification) == 1)
{
Miscellaneous.logEvent("i", "mayRuleStillBeActivatedForPendingNotifications()", "Rule " + rule.getName() + " has not been used in conjunction with notification " + sbn, 4);
return true;
}
}
}
}
}
return false;
}
public static boolean hasNotificationBeenUsedInRule(Rule rule, SimpleNotification notification)
{
for (RuleNotificationPair executedPair : notificationUsed)
{
if (executedPair.rule.equals(rule) && executedPair.notification.equals(notification))
return true;
}
return false;
}
} }