calendar trigger

This commit is contained in:
jens 2023-12-31 15:54:24 +01:00
parent 81a205a8db
commit 3bcf90277f

View File

@ -34,6 +34,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
public static final int AVAILABILITY_OUT_OF_OFFICE = 4; public static final int AVAILABILITY_OUT_OF_OFFICE = 4;
public static final int AVAILABILITY_WORKING_ELSEWHERE = 5; public static final int AVAILABILITY_WORKING_ELSEWHERE = 5;
public static final String calendarAlarmAction = "ALARM_FOR_CALENDAR";
static List<AndroidCalendar> calendarsCache = null; static List<AndroidCalendar> calendarsCache = null;
static List<CalendarEvent> calendarEventsCache = null; static List<CalendarEvent> calendarEventsCache = null;
@ -65,6 +66,11 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
checkForRules(context); checkForRules(context);
armOrRearmTimer(); armOrRearmTimer();
} }
else if(intent.getAction().equalsIgnoreCase(calendarAlarmAction))
{
Miscellaneous.logEvent("i", "AlarmReceiver", "Received alarm for calendar receiver.", 5);
routineAtAlarm();
}
} }
private static void checkForRules(Context context) private static void checkForRules(Context context)
@ -268,16 +274,6 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
return calendarEventsCache; return calendarEventsCache;
} }
public static class AlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Miscellaneous.logEvent("i", "AlarmReceiver", "Received alarm for calendar receiver.", 5);
routineAtAlarm();
}
}
protected static void routineAtAlarm() protected static void routineAtAlarm()
{ {
checkForRules(Miscellaneous.getAnyContext()); checkForRules(Miscellaneous.getAnyContext());
@ -296,8 +292,9 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
{ {
alarmManager = (AlarmManager) Miscellaneous.getAnyContext().getSystemService(Context.ALARM_SERVICE); alarmManager = (AlarmManager) Miscellaneous.getAnyContext().getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(Miscellaneous.getAnyContext(), AlarmReceiver.class); Intent intent = new Intent(Miscellaneous.getAnyContext(), CalendarReceiver.class);
pi = PendingIntent.getBroadcast(Miscellaneous.getAnyContext(), 0, i, 0); intent.setAction(calendarAlarmAction);
pi = PendingIntent.getBroadcast(AutomationService.getInstance(), 0, intent, 0);
} }
} }
else else
@ -341,7 +338,9 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
} }
Miscellaneous.logEvent("i", "armOrRearmTimer()", "Setting calendar alarm for " + nextWakeup.toString(), 5); Miscellaneous.logEvent("i", "armOrRearmTimer()", "Setting calendar alarm for " + nextWakeup.toString(), 5);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextWakeup.getTimeInMillis(), pi); alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi);
//alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextWakeup.getTimeInMillis(), pi);
} }
} }
else else