Commit eb41d94f by Sebastián Katzer

Prevent endless trigger loop [fixes #1463]

parent 45b5d887
......@@ -25,6 +25,8 @@ import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import java.util.Calendar;
import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification;
......@@ -35,6 +37,7 @@ import de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver;
import static android.content.Context.POWER_SERVICE;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static java.util.Calendar.MINUTE;
/**
* The alarm receiver is triggered when a scheduled alarm is fired. This class
......@@ -69,13 +72,18 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
notification.show();
if (options.isInfiniteTrigger()) {
manager.schedule(new Request(options), this.getClass());
}
if (!isUpdate) {
LocalNotification.fireEvent("trigger", notification);
}
if (!options.isInfiniteTrigger())
return;
Calendar cal = Calendar.getInstance();
cal.add(MINUTE, 1);
Request req = new Request(options, cal.getTime());
manager.schedule(req, this.getClass());
}
/**
......
......@@ -64,7 +64,7 @@ public final class Request {
private Date triggerDate;
/**
* Constructor
* Create a request with a base date specified through the passed options.
*
* @param options The options spec.
*/
......@@ -77,6 +77,20 @@ public final class Request {
}
/**
* Create a request with a base date specified via base argument.
*
* @param options The options spec.
* @param base The base date from where to calculate the next trigger.
*/
public Request(Options options, Date base) {
this.options = options;
this.spec = options.getTrigger();
this.count = Math.max(spec.optInt("count"), 1);
this.trigger = buildTrigger();
this.triggerDate = trigger.getNextTriggerDate(base);
}
/**
* Gets the options spec.
*/
public Options getOptions() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment