Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/android/ProxyService.java

Issue 5327480814567424: Issue 1108 - Support notifications (Closed)
Left Patch Set: Removed markAsShown() Created Feb. 18, 2015, 2:46 p.m.
Right Patch Set: Only one Notification displayed now Created Feb. 18, 2015, 3:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/android/CrashHandler.java ('k') | src/org/adblockplus/android/Utils.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android; 18 package org.adblockplus.android;
19 19
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.net.InetAddress; 21 import java.net.InetAddress;
22 import java.net.ServerSocket; 22 import java.net.ServerSocket;
23 import java.net.UnknownHostException; 23 import java.net.UnknownHostException;
24 import java.util.Properties; 24 import java.util.Properties;
25 25
26 import org.adblockplus.android.configurators.ProxyConfigurator; 26 import org.adblockplus.android.configurators.ProxyConfigurator;
27 import org.adblockplus.android.configurators.ProxyConfigurators; 27 import org.adblockplus.android.configurators.ProxyConfigurators;
28 import org.adblockplus.android.configurators.ProxyRegistrationType; 28 import org.adblockplus.android.configurators.ProxyRegistrationType;
29 import org.adblockplus.libadblockplus.Notification.Type;
29 import org.apache.commons.lang.StringUtils; 30 import org.apache.commons.lang.StringUtils;
30 31
31 import sunlabs.brazil.server.Server; 32 import sunlabs.brazil.server.Server;
32 import sunlabs.brazil.util.Base64; 33 import sunlabs.brazil.util.Base64;
33 import android.annotation.SuppressLint; 34 import android.annotation.SuppressLint;
34 import android.app.Notification; 35 import android.app.Notification;
35 import android.app.NotificationManager; 36 import android.app.NotificationManager;
36 import android.app.PendingIntent; 37 import android.app.PendingIntent;
37 import android.app.Service; 38 import android.app.Service;
38 import android.content.BroadcastReceiver; 39 import android.content.BroadcastReceiver;
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (this.notificationWatcher != null) 619 if (this.notificationWatcher != null)
619 { 620 {
620 this.notificationWatcher.stop(); 621 this.notificationWatcher.stop();
621 this.notificationWatcher = null; 622 this.notificationWatcher = null;
622 } 623 }
623 } 624 }
624 625
625 private static class NotificationWatcher implements Runnable 626 private static class NotificationWatcher implements Runnable
626 { 627 {
627 public static final int DEFAULT_POLL_DELAY = 3 * 60; /* seconds */ 628 public static final int DEFAULT_POLL_DELAY = 3 * 60; /* seconds */
628 public static final int DEFAULT_POLL_INTERVALS = 0; /* seconds */ 629 public static final int DEFAULT_POLL_INTERVAL = 0; /* seconds */
Felix Dahlke 2015/02/18 14:55:04 Should be POLL_INTERVAL now, huh?
René Jeschke 2015/02/18 15:01:25 Done.
629 630
630 private final ProxyService proxyService; 631 private final ProxyService proxyService;
631 private final int pollDelay; 632 private final int pollDelay;
632 private final int pollInterval; 633 private final int pollInterval;
633 634
634 volatile boolean running = true; 635 volatile boolean running = true;
635 636
636 public NotificationWatcher(final ProxyService proxyService, final int firstP ollInterval, 637 public NotificationWatcher(final ProxyService proxyService, final int pollDe lay,
637 final int nextPollIntervals) 638 final int pollInterval)
638 { 639 {
639 this.proxyService = proxyService; 640 this.proxyService = proxyService;
640 this.pollDelay = Math.max(0, firstPollInterval); 641 this.pollDelay = Math.max(0, pollDelay);
Felix Dahlke 2015/02/18 14:55:04 Might as well rename the parameters while at it :P
René Jeschke 2015/02/18 15:01:25 Done.
641 this.pollInterval = Math.max(0, nextPollIntervals); 642 this.pollInterval = Math.max(0, pollInterval);
642 } 643 }
643 644
644 public NotificationWatcher(final ProxyService proxyService) 645 public NotificationWatcher(final ProxyService proxyService)
645 { 646 {
646 this(proxyService, DEFAULT_POLL_DELAY, DEFAULT_POLL_INTERVALS); 647 this(proxyService, DEFAULT_POLL_DELAY, DEFAULT_POLL_INTERVAL);
647 } 648 }
648 649
649 protected void stop() 650 protected void stop()
650 { 651 {
651 this.running = false; 652 this.running = false;
652 } 653 }
653 654
654 @Override 655 @Override
655 public void run() 656 public void run()
656 { 657 {
(...skipping 14 matching lines...) Expand all
671 catch (InterruptedException ex) 672 catch (InterruptedException ex)
672 { 673 {
673 break; 674 break;
674 } 675 }
675 676
676 if (System.currentTimeMillis() >= nextPoll && this.running) 677 if (System.currentTimeMillis() >= nextPoll && this.running)
677 { 678 {
678 try 679 try
679 { 680 {
680 Log.d(TAG, "Polling for notifications"); 681 Log.d(TAG, "Polling for notifications");
681 org.adblockplus.libadblockplus.Notification notification = AdblockPl us.getApplication() 682 org.adblockplus.libadblockplus.Notification notification =
682 .getNextNotificationToShow(); 683 AdblockPlus.getApplication().getNextNotificationToShow();
683 684
684 int idx = 0; 685 while (notification != null
685 while (notification != null) 686 && (notification.getType() == Type.INVALID || notification.getTy pe() == Type.QUESTION))
Felix Dahlke 2015/02/18 14:55:04 Maybe, just while we're at it, we should ignore qu
René Jeschke 2015/02/18 15:01:25 Stayed a 'while', ignoring QUESTION/INVALID now.
686 { 687 {
687 Notification notif = new NotificationCompat.Builder( 688 notification = AdblockPlus.getApplication().getNextNotificationToS how();
688 this.proxyService.getApplicationContext()) 689 }
689 .setSmallIcon(R.drawable.ic_stat_blocking) 690
690 .setContentTitle(notification.getTitle()) 691 if (notification != null)
691 .setContentText(notification.getMessageString()) 692 {
692 .getNotification();
693
694 final NotificationManager notificationManager = (NotificationManag er) this.proxyService 693 final NotificationManager notificationManager = (NotificationManag er) this.proxyService
695 .getSystemService(NOTIFICATION_SERVICE); 694 .getSystemService(NOTIFICATION_SERVICE);
696 notificationManager.notify(AdblockPlus.GROUPED_NOTIFICATION_ID + i dx, notif); 695
697 696 notificationManager.notify(AdblockPlus.SERVER_NOTIFICATION_ID,
698 idx++; 697 new NotificationCompat.Builder(this.proxyService.getApplicatio nContext())
699 notification = AdblockPlus.getApplication().getNextNotificationToS how(); 698 .setSmallIcon(R.drawable.ic_stat_blocking)
699 .setContentTitle(notification.getTitle())
700 .setContentText(notification.getMessageString())
701 .getNotification());
700 } 702 }
701
702 Log.d(TAG, "Received " + idx + " new notifications");
703 } 703 }
704 catch (Exception ex) 704 catch (Exception ex)
705 { 705 {
706 Log.e(TAG, "Polling for notifications failed: " + ex.getMessage(), e x); 706 Log.e(TAG, "Polling for notifications failed: " + ex.getMessage(), e x);
707 } 707 }
708 708
709 if (this.pollInterval == 0) 709 if (this.pollInterval == 0)
710 { 710 {
711 this.running = false; 711 this.running = false;
712 } 712 }
713 else 713 else
714 { 714 {
715 nextPoll = System.currentTimeMillis() + 1000L * this.pollInterval; 715 nextPoll = System.currentTimeMillis() + 1000L * this.pollInterval;
716 } 716 }
717 } 717 }
718 } 718 }
719 } 719 }
720 } 720 }
721 } 721 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld