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

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29673565: Issue 6066 - Implement 'force update' functionality for subscriptions (Closed)
Patch Set: Fixed typos and line length Created Jan. 19, 2018, 11:01 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 import android.content.pm.PackageManager; 52 import android.content.pm.PackageManager;
53 import android.content.pm.ResolveInfo; 53 import android.content.pm.ResolveInfo;
54 import android.net.ConnectivityManager; 54 import android.net.ConnectivityManager;
55 import android.net.NetworkInfo; 55 import android.net.NetworkInfo;
56 import android.net.Uri; 56 import android.net.Uri;
57 import android.os.Handler; 57 import android.os.Handler;
58 import android.os.Looper; 58 import android.os.Looper;
59 import android.text.TextUtils; 59 import android.text.TextUtils;
60 import android.text.format.DateUtils; 60 import android.text.format.DateUtils;
61 import android.util.Log; 61 import android.util.Log;
62 import android.widget.Toast;
62 63
63 public final class Engine 64 public final class Engine
64 { 65 {
65 private static final String TAG = Engine.class.getSimpleName(); 66 private static final String TAG = Engine.class.getSimpleName();
66 67
67 public static final String USER_FILTERS_TITLE = "__filters"; 68 public static final String USER_FILTERS_TITLE = "__filters";
68 public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; 69 public static final String USER_EXCEPTIONS_TITLE = "__exceptions";
69 70
70 public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; 71 public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser";
71 public static final String EASYLIST_URL = "https://easylist-downloads.adblockp lus.org/easylist.txt"; 72 public static final String EASYLIST_URL = "https://easylist-downloads.adblockp lus.org/easylist.txt";
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return true; 228 return true;
228 default: 229 default:
229 return false; 230 return false;
230 } 231 }
231 } 232 }
232 return false; 233 return false;
233 } 234 }
234 return current.isConnected(); 235 return current.isConnected();
235 } 236 }
236 237
238 public void forceUpdateSubscriptions(final boolean allowMetered)
239 {
240 try
241 {
242 subscriptions.checkForUpdates(true, allowMetered);
243 Toast.makeText(serviceContext, serviceContext.getText(R.string.updating_su bscriptions), Toast.LENGTH_LONG).show();
244 }
245 catch (IOException e)
246 {
247 Log.e(TAG, "Failed checking for updates", e);
248 }
249 }
250
237 public List<SubscriptionInfo> getListedSubscriptions() 251 public List<SubscriptionInfo> getListedSubscriptions()
238 { 252 {
239 return this.subscriptions.getSubscriptions(this); 253 return this.subscriptions.getSubscriptions(this);
240 } 254 }
241 255
242 public void changeSubscriptionState(final String id, final boolean enabled) 256 public void changeSubscriptionState(final String id, final boolean enabled)
243 { 257 {
244 if (this.subscriptionUpdateCallback != null) 258 if (this.subscriptionUpdateCallback != null)
245 { 259 {
246 subscriptionUpdateCallback.subscriptionUpdateRequested(enabled); 260 subscriptionUpdateCallback.subscriptionUpdateRequested(enabled);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 Log.d(TAG, "Unhandled type: " + event.getType()); 696 Log.d(TAG, "Unhandled type: " + event.getType());
683 break; 697 break;
684 } 698 }
685 } 699 }
686 700
687 final long currentTime = System.currentTimeMillis(); 701 final long currentTime = System.currentTimeMillis();
688 if (currentTime > nextUpdateCheck) 702 if (currentTime > nextUpdateCheck)
689 { 703 {
690 nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL; 704 nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL;
691 705
692 this.engine.subscriptions.checkForUpdates(); 706 this.engine.subscriptions.checkForUpdates(false, false);
693 } 707 }
694 708
695 if (currentTime > this.engine.nextUpdateBroadcast) 709 if (currentTime > this.engine.nextUpdateBroadcast)
696 { 710 {
697 this.engine.nextUpdateBroadcast = Long.MAX_VALUE; 711 this.engine.nextUpdateBroadcast = Long.MAX_VALUE;
698 Log.d(TAG, "Sending update broadcast"); 712 Log.d(TAG, "Sending update broadcast");
699 this.engine.writeFileAndSendUpdateBroadcast(); 713 this.engine.writeFileAndSendUpdateBroadcast();
700 } 714 }
701 } 715 }
702 finally 716 finally
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 this.id = id; 783 this.id = id;
770 this.responseCode = responseCode; 784 this.responseCode = responseCode;
771 this.response = response; 785 this.response = response;
772 if (headers != null) 786 if (headers != null)
773 { 787 {
774 this.headers.putAll(headers); 788 this.headers.putAll(headers);
775 } 789 }
776 } 790 }
777 } 791 }
778 792
779 public void enqueueDownload(final Subscription sub, final boolean forced) thro ws IOException 793 public void enqueueDownload(final Subscription sub, final boolean forced,
794 final boolean allowMetered) throws IOException
780 { 795 {
781 if (sub.getURL() != null && sub.shouldUpdate(forced)) 796 if (sub.getURL() != null && sub.shouldUpdate(forced))
782 { 797 {
783 final HashMap<String, String> headers = new HashMap<>(); 798 final HashMap<String, String> headers = new HashMap<>();
784 if (sub.isMetaDataValid() && sub.isFiltersValid()) 799 if (sub.isMetaDataValid() && sub.isFiltersValid())
785 { 800 {
786 final String lastModified = sub.getMeta(Subscription.KEY_HTTP_LAST_MODIF IED); 801 final String lastModified = sub.getMeta(Subscription.KEY_HTTP_LAST_MODIF IED);
787 if (!TextUtils.isEmpty(lastModified)) 802 if (!TextUtils.isEmpty(lastModified))
788 { 803 {
789 headers.put("If-Modified-Since", lastModified); 804 headers.put("If-Modified-Since", lastModified);
790 } 805 }
791 final String etag = sub.getMeta(Subscription.KEY_HTTP_ETAG); 806 final String etag = sub.getMeta(Subscription.KEY_HTTP_ETAG);
792 if (!TextUtils.isEmpty(etag)) 807 if (!TextUtils.isEmpty(etag))
793 { 808 {
794 headers.put("If-None-Match", etag); 809 headers.put("If-None-Match", etag);
795 } 810 }
796 } 811 }
797 Log.d(TAG, headers.toString()); 812 Log.d(TAG, headers.toString());
798 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers); 813 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers, allowMetered);
799 } 814 }
800 } 815 }
801 816
802 public void connectivityChanged() 817 public void connectivityChanged()
803 { 818 {
804 this.downloader.connectivityChanged(); 819 this.downloader.connectivityChanged();
805 } 820 }
806 821
807 public interface SubscriptionUpdateCallback 822 public interface SubscriptionUpdateCallback
808 { 823 {
809 void subscriptionUpdateRequested(boolean enabled); 824 void subscriptionUpdateRequested(boolean enabled);
810 void subscriptionUpdatedApplied(); 825 void subscriptionUpdatedApplied();
811 } 826 }
812 827
813 public interface SubscriptionAddedCallback 828 public interface SubscriptionAddedCallback
814 { 829 {
815 void subscriptionAdded(); 830 void subscriptionAdded();
816 } 831 }
817 } 832 }
OLDNEW

Powered by Google App Engine
This is Rietveld