| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 final NotificationManager notificationManager = (NotificationManager ) this.proxyService | 685 while (notification != null |
| 685 .getSystemService(NOTIFICATION_SERVICE); | 686 && (notification.getType() == Type.INVALID || notification.getTy pe() == Type.QUESTION)) |
| 686 int idx = 0; | |
| 687 while (notification != null) | |
| 688 { | 687 { |
| 689 switch (notification.getType()) | |
| 690 { | |
| 691 case CRITICAL: | |
| 692 case INFORMATION: | |
| 693 notificationManager.notify(AdblockPlus.GROUPED_NOTIFICATION_ID + idx, | |
| 694 new NotificationCompat.Builder(this.proxyService.getApplic ationContext()) | |
| 695 .setSmallIcon(R.drawable.ic_stat_blocking) | |
| 696 .setContentTitle(notification.getTitle()) | |
| 697 .setContentText(notification.getMessageString()) | |
| 698 .getNotification()); | |
| 699 idx++; | |
|
Felix Dahlke
2015/02/18 15:36:55
We don't really need the index. More importantly,
René Jeschke
2015/02/18 15:42:58
Done.
| |
| 700 break; | |
| 701 default: | |
| 702 break; | |
| 703 } | |
| 704 | |
| 705 notification = AdblockPlus.getApplication().getNextNotificationToS how(); | 688 notification = AdblockPlus.getApplication().getNextNotificationToS how(); |
| 706 } | 689 } |
| 707 | 690 |
| 708 Log.d(TAG, "Received " + idx + " new notifications"); | 691 if (notification != null) |
| 692 { | |
| 693 final NotificationManager notificationManager = (NotificationManag er) this.proxyService | |
| 694 .getSystemService(NOTIFICATION_SERVICE); | |
| 695 | |
| 696 notificationManager.notify(AdblockPlus.SERVER_NOTIFICATION_ID, | |
| 697 new NotificationCompat.Builder(this.proxyService.getApplicatio nContext()) | |
| 698 .setSmallIcon(R.drawable.ic_stat_blocking) | |
| 699 .setContentTitle(notification.getTitle()) | |
| 700 .setContentText(notification.getMessageString()) | |
| 701 .getNotification()); | |
| 702 } | |
| 709 } | 703 } |
| 710 catch (Exception ex) | 704 catch (Exception ex) |
| 711 { | 705 { |
| 712 Log.e(TAG, "Polling for notifications failed: " + ex.getMessage(), e x); | 706 Log.e(TAG, "Polling for notifications failed: " + ex.getMessage(), e x); |
| 713 } | 707 } |
| 714 | 708 |
| 715 if (this.pollInterval == 0) | 709 if (this.pollInterval == 0) |
| 716 { | 710 { |
| 717 this.running = false; | 711 this.running = false; |
| 718 } | 712 } |
| 719 else | 713 else |
| 720 { | 714 { |
| 721 nextPoll = System.currentTimeMillis() + 1000L * this.pollInterval; | 715 nextPoll = System.currentTimeMillis() + 1000L * this.pollInterval; |
| 722 } | 716 } |
| 723 } | 717 } |
| 724 } | 718 } |
| 725 } | 719 } |
| 726 } | 720 } |
| 727 } | 721 } |
| LEFT | RIGHT |