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

Delta Between Two Patch Sets: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29673565: Issue 6066 - Implement 'force update' functionality for subscriptions (Closed)
Left Patch Set: Fixed typos and line length Created Jan. 19, 2018, 11:01 a.m.
Right Patch Set: Fixes Created Jan. 23, 2018, 3:12 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
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-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 25 matching lines...) Expand all
36 import java.util.HashMap; 36 import java.util.HashMap;
37 import java.util.List; 37 import java.util.List;
38 import java.util.Map; 38 import java.util.Map;
39 import java.util.Set; 39 import java.util.Set;
40 import java.util.TreeSet; 40 import java.util.TreeSet;
41 import java.util.concurrent.LinkedBlockingQueue; 41 import java.util.concurrent.LinkedBlockingQueue;
42 import java.util.concurrent.TimeUnit; 42 import java.util.concurrent.TimeUnit;
43 import java.util.concurrent.locks.ReentrantLock; 43 import java.util.concurrent.locks.ReentrantLock;
44 44
45 import org.adblockplus.adblockplussbrowser.R; 45 import org.adblockplus.adblockplussbrowser.R;
46 import org.adblockplus.sbrowser.contentblocker.util.ConnectivityUtils;
46 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; 47 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
47 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; 48 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils;
48 49
49 import android.content.Context; 50 import android.content.Context;
50 import android.content.Intent; 51 import android.content.Intent;
51 import android.content.pm.PackageInfo; 52 import android.content.pm.PackageInfo;
52 import android.content.pm.PackageManager; 53 import android.content.pm.PackageManager;
53 import android.content.pm.ResolveInfo; 54 import android.content.pm.ResolveInfo;
54 import android.net.ConnectivityManager; 55 import android.net.ConnectivityManager;
55 import android.net.NetworkInfo; 56 import android.net.NetworkInfo;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 public void run() 191 public void run()
191 { 192 {
192 final Intent intent = new Intent(); 193 final Intent intent = new Intent();
193 intent.setAction(ACTION_UPDATE); 194 intent.setAction(ACTION_UPDATE);
194 intent.setData(Uri.parse("package:" + Engine.this.serviceContext.getPack ageName())); 195 intent.setData(Uri.parse("package:" + Engine.this.serviceContext.getPack ageName()));
195 Engine.this.serviceContext.sendBroadcast(intent); 196 Engine.this.serviceContext.sendBroadcast(intent);
196 } 197 }
197 }); 198 });
198 } 199 }
199 200
200 boolean canUseInternet() 201 boolean canUseInternet(final boolean allowMetered)
201 { 202 {
202 final ConnectivityManager connManager = (ConnectivityManager) this.serviceCo ntext 203 // allow a metered connection to update default subscriptions at the first r un.
203 .getSystemService(Context.CONNECTIVITY_SERVICE); 204 // See https://issues.adblockplus.org/ticket/5237
204 final NetworkInfo current = connManager.getActiveNetworkInfo(); 205 return ConnectivityUtils.canUseInternet(serviceContext, allowMetered || wasF irstRun());
205 if (current == null)
206 {
207 return false;
208 }
209
210 if (wasFirstRun())
211 {
212 return true;
213 }
214
215 final boolean wifiOnly = "1".equals(SharedPrefsUtils.getString(
216 this.serviceContext, R.string.key_automatic_updates , "1"));
217
218 if (wifiOnly)
219 {
220 if (current.isConnected() && !current.isRoaming())
221 {
222 switch (current.getType())
223 {
224 case ConnectivityManager.TYPE_BLUETOOTH:
225 case ConnectivityManager.TYPE_ETHERNET:
226 case ConnectivityManager.TYPE_WIFI:
227 case ConnectivityManager.TYPE_WIMAX:
228 return true;
229 default:
230 return false;
231 }
232 }
233 return false;
234 }
235 return current.isConnected();
236 } 206 }
237 207
238 public void forceUpdateSubscriptions(final boolean allowMetered) 208 public void forceUpdateSubscriptions(final boolean allowMetered)
239 { 209 {
240 try 210 try
241 { 211 {
242 subscriptions.checkForUpdates(true, allowMetered); 212 subscriptions.checkForUpdates(true, allowMetered);
243 Toast.makeText(serviceContext, serviceContext.getText(R.string.updating_su bscriptions), Toast.LENGTH_LONG).show(); 213 Toast.makeText(serviceContext, serviceContext.getText(R.string.updating_su bscriptions), Toast.LENGTH_LONG).show();
244 } 214 }
245 catch (IOException e) 215 catch (IOException e)
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 { 793 {
824 void subscriptionUpdateRequested(boolean enabled); 794 void subscriptionUpdateRequested(boolean enabled);
825 void subscriptionUpdatedApplied(); 795 void subscriptionUpdatedApplied();
826 } 796 }
827 797
828 public interface SubscriptionAddedCallback 798 public interface SubscriptionAddedCallback
829 { 799 {
830 void subscriptionAdded(); 800 void subscriptionAdded();
831 } 801 }
832 } 802 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld