jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/335169 )
Change subject: [Facepalm] Correctly set interval for notification polling. ...................................................................... [Facepalm] Correctly set interval for notification polling. In my ongoing testing of our notifications, I've been noticing that our polling task doesn't actually repeat like we tell it to. After hours of fruitless debugging, I noticed that we were passing in the raw integer resource ID, instead of the actual integer dimension. Therefore, we were inadvertently setting a repeat interval of 2132897234 or something similar. The same for the number-of-days timeout for the polling task to stop itself. This patch switches to the much-more-correct scheme of using the getInteger() method of retrieving the integer dimension, instead of using the resource ID. I suspect that our "testing" of notifications has worked so far because after editing a description we call startPollTask() which effectively queues the task for immediate execution. (This patch also cleans up the code a bit.) Change-Id: I5e0f6b0bb3813763133f891b9475abb232dee62a --- M app/src/main/java/org/wikipedia/notifications/NotificationPollBroadcastReceiver.java 1 file changed, 14 insertions(+), 17 deletions(-) Approvals: Niedzielski: Looks good to me, approved jenkins-bot: Verified diff --git a/app/src/main/java/org/wikipedia/notifications/NotificationPollBroadcastReceiver.java b/app/src/main/java/org/wikipedia/notifications/NotificationPollBroadcastReceiver.java index c808fc8..c1474c3 100644 --- a/app/src/main/java/org/wikipedia/notifications/NotificationPollBroadcastReceiver.java +++ b/app/src/main/java/org/wikipedia/notifications/NotificationPollBroadcastReceiver.java @@ -23,15 +23,13 @@ public class NotificationPollBroadcastReceiver extends BroadcastReceiver { public static final String ACTION_POLL = "action_notification_poll"; - private static final long POLL_INTERVAL_MILLIS - = TimeUnit.MINUTES.toMillis(R.integer.notification_poll_interval_minutes); - @Override public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), ACTION_POLL)) { if (User.isLoggedIn() - && lastDescriptionEditedWithin(R.integer.notification_poll_timeout_days)) { + && lastDescriptionEditedWithin(context.getResources() + .getInteger(R.integer.notification_poll_timeout_days))) { pollNotifications(context); } else { stopPollTask(context); @@ -41,23 +39,22 @@ } public void startPollTask(@NonNull Context context) { - Intent alarmIntent = new Intent(context, NotificationPollBroadcastReceiver.class); - boolean isAlarmUp = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE) != null; - if (!isAlarmUp) { - AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - alarmIntent.setAction(ACTION_POLL); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); - alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, - SystemClock.elapsedRealtime(), POLL_INTERVAL_MILLIS, pendingIntent); - } + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime(), + context.getResources().getInteger(R.integer.notification_poll_interval_minutes), + getAlarmPendingIntent(context)); } public void stopPollTask(@NonNull Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - Intent alarmIntent = new Intent(context, NotificationPollBroadcastReceiver.class); - alarmIntent.setAction(ACTION_POLL); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); - alarmManager.cancel(pendingIntent); + alarmManager.cancel(getAlarmPendingIntent(context)); + } + + @NonNull private PendingIntent getAlarmPendingIntent(@NonNull Context context) { + Intent intent = new Intent(context, NotificationPollBroadcastReceiver.class); + intent.setAction(ACTION_POLL); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } private void pollNotifications(@NonNull final Context context) { -- To view, visit https://gerrit.wikimedia.org/r/335169 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5e0f6b0bb3813763133f891b9475abb232dee62a Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits