Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
- Fix repeated ESM Scheduler when created an event with a time window.
Browse files Browse the repository at this point in the history
  • Loading branch information
denzilferreira committed Mar 10, 2019
1 parent 7f66dd5 commit 97035e9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions aware-core/src/main/java/com/aware/utils/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,6 @@ private boolean is_trigger(Schedule schedule) {
schedule_data_cursor.close();

// This is a scheduled task on a specific timestamp.
// NOTE: Once triggered, it's deleted from the database automatically.
if (schedule.getTimer() != -1 && last_triggered == 0) { //not been triggered yet
Calendar schedulerTimer = Calendar.getInstance();
schedulerTimer.setTimeInMillis(schedule.getTimer());
Expand All @@ -834,6 +833,8 @@ private boolean is_trigger(Schedule schedule) {
+ "\n Time to trigger: " + Converters.readable_elapsed(schedule.getTimer() - now.getTimeInMillis()));
return false;
}
} else if (schedule.getTimer() != -1 && last_triggered != 0) {
return false; //already triggered, do nothing.
}

Calendar previous = null;
Expand Down Expand Up @@ -1176,7 +1177,7 @@ private void performAction(Schedule schedule) {

if (schedule.getTimer() != -1) {

removeSchedule(getApplicationContext(), schedule.getScheduleID());
//removeSchedule(getApplicationContext(), schedule.getScheduleID());

//Check if this scheduler is a random and it is the last time it was triggered, re-schedule new randoms
if (schedule.getRandom().length() > 0 && schedule.getScheduleID().contains("_last") && schedule.getScheduleID().contains("_random_")) {
Expand All @@ -1188,17 +1189,17 @@ private void performAction(Schedule schedule) {
//recreate random scheduler for tomorrow
Scheduler.rescheduleRandom(getApplicationContext(), schedule);
}
}

} else {
ContentValues data = new ContentValues();
data.put(Scheduler_Provider.Scheduler_Data.LAST_TRIGGERED, System.currentTimeMillis());
ContentValues data = new ContentValues();
data.put(Scheduler_Provider.Scheduler_Data.LAST_TRIGGERED, System.currentTimeMillis());

if (getApplicationContext().getResources().getBoolean(R.bool.standalone)) {
getContentResolver().update(Scheduler_Provider.Scheduler_Data.CONTENT_URI, data, Scheduler_Provider.Scheduler_Data.SCHEDULE_ID + " LIKE '" + schedule.getScheduleID() + "' AND (" + Scheduler_Provider.Scheduler_Data.PACKAGE_NAME + " LIKE '" + getPackageName() + "' OR " + Scheduler_Provider.Scheduler_Data.PACKAGE_NAME + " LIKE 'com.aware.phone')", null);
} else {
getContentResolver().update(Scheduler_Provider.Scheduler_Data.CONTENT_URI, data, Scheduler_Provider.Scheduler_Data.SCHEDULE_ID + " LIKE '" + schedule.getScheduleID() + "' AND " + Scheduler_Provider.Scheduler_Data.PACKAGE_NAME + " LIKE '" + getPackageName() + "'", null);
}
if (getApplicationContext().getResources().getBoolean(R.bool.standalone)) {
getContentResolver().update(Scheduler_Provider.Scheduler_Data.CONTENT_URI, data, Scheduler_Provider.Scheduler_Data.SCHEDULE_ID + " LIKE '" + schedule.getScheduleID() + "' AND (" + Scheduler_Provider.Scheduler_Data.PACKAGE_NAME + " LIKE '" + getPackageName() + "' OR " + Scheduler_Provider.Scheduler_Data.PACKAGE_NAME + " LIKE 'com.aware.phone')", null);
} else {
getContentResolver().update(Scheduler_Provider.Scheduler_Data.CONTENT_URI, data, Scheduler_Provider.Scheduler_Data.SCHEDULE_ID + " LIKE '" + schedule.getScheduleID() + "' AND " + Scheduler_Provider.Scheduler_Data.PACKAGE_NAME + " LIKE '" + getPackageName() + "'", null);
}

} catch (JSONException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 97035e9

Please sign in to comment.