| Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| =================================================================== |
| --- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| +++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| @@ -54,16 +54,17 @@ import android.content.pm.PackageManager |
| import android.content.pm.ResolveInfo; |
| import android.net.ConnectivityManager; |
| import android.net.NetworkInfo; |
| import android.net.Uri; |
| import android.os.Handler; |
| import android.os.Looper; |
| import android.preference.PreferenceManager; |
| import android.text.TextUtils; |
| +import android.text.format.DateUtils; |
| import android.util.Log; |
| public final class Engine |
| { |
| private static final String TAG = Engine.class.getSimpleName(); |
| // TODO make use of this regex's |
| public static final Pattern RE_SUBSCRIPTION_HEADER = Pattern.compile( |
| @@ -77,44 +78,39 @@ public final class Engine |
| .compile("\\$(~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:=[^,\\s]+)?)*)$"); |
| public static final Pattern RE_FILTER_CSSPROPERTY = Pattern |
| .compile("\\[\\-abp\\-properties=([\"'])([^\"']+)\\1\\]"); |
| public static final String USER_FILTERS_TITLE = "__filters"; |
| public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; |
| public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; |
| - public static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrowser.contentBlocker.ACTION_SETTING"; |
| - public static final String ACTION_UPDATE = "com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE"; |
| - public static final String EASYLIST_URL = "https://easylist-downloads.adblockplus.org/easylist.txt"; |
| + private static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrowser.contentBlocker.ACTION_SETTING"; |
| + private static final String ACTION_UPDATE = "com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE"; |
| + private static final String EASYLIST_URL = "https://easylist-downloads.adblockplus.org/easylist.txt"; |
| public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_exceptionsurl"; |
| private static final String PREFS_KEY_PREVIOUS_VERSION = "key_previous_version"; |
| // The value below specifies an interval of [x, 2*x[, where x = |
| - // INITIAL_UPDATE_CHECK_DELAY_SECONDS |
| - private static final long INITIAL_UPDATE_CHECK_DELAY_SECONDS = 5; |
| - private static final long UPDATE_CHECK_INTERVAL_MINUTES = 30; |
| - private static final long BROADCAST_COMBINATION_DELAY_MILLIS = 2500; |
| - |
| - public static final long MILLIS_PER_SECOND = 1000; |
| - public static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND; |
| - public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE; |
| - public static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR; |
| + // INITIAL_UPDATE_CHECK_DELAY |
| + private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN_MILLIS; |
| + private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MILLIS; |
| + private static final long BROADCAST_COMBINATION_DELAY = 2500; |
| private static final int NO_FLAG = 0; |
| private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; |
| private final ReentrantLock accessLock = new ReentrantLock(); |
| private DefaultSubscriptions defaultSubscriptions; |
| private Subscriptions subscriptions; |
| private JSONPrefs jsonPrefs; |
| private AppInfo appInfo; |
| - private LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueue<>(); |
| + private final LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueue<>(); |
| private Thread handlerThread; |
| private Downloader downloader; |
| private final Context serviceContext; |
| private boolean wasFirstRun = false; |
| private long nextUpdateBroadcast = Long.MAX_VALUE; |
| private Engine(final Context context) |
| { |
| @@ -189,17 +185,17 @@ public final class Engine |
| } |
| } |
| public void requestUpdateBroadcast() |
| { |
| this.lock(); |
| try |
| { |
| - this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATION_DELAY_MILLIS; |
| + this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATION_DELAY; |
| } |
| finally |
| { |
| this.unlock(); |
| } |
| } |
| private void writeFileAndSendUpdateBroadcast() |
| @@ -438,17 +434,17 @@ public final class Engine |
| Log.d(TAG, "Added " + additional + " additional default/built-in subscriptions"); |
| engine.subscriptions.persistSubscriptions(); |
| } |
| engine.handlerThread = new Thread(new EventHandler(engine)); |
| engine.handlerThread.setDaemon(true); |
| engine.handlerThread.start(); |
| - engine.downloader = Downloader.create(context, engine); |
| + engine.downloader = Downloader.create(engine); |
| final File cachedFilterFile = getCachedFilterFile(context); |
| if (cachedFilterFile == null || !cachedFilterFile.exists()) |
| { |
| engine.writeFileAndSendUpdateBroadcast(); |
| } |
| return engine; |
| @@ -623,17 +619,17 @@ public final class Engine |
| } |
| @Override |
| public void run() |
| { |
| Log.d(TAG, "Handler thread started"); |
| boolean interrupted = false; |
| long nextUpdateCheck = System.currentTimeMillis() |
| - + (long) ((1 + Math.random()) * INITIAL_UPDATE_CHECK_DELAY_SECONDS * MILLIS_PER_SECOND); |
| + + (long) ((1 + Math.random()) * INITIAL_UPDATE_CHECK_DELAY); |
| while (!interrupted) |
| { |
| try |
| { |
| final EngineEvent event = this.engine.engineEvents.poll(100, TimeUnit.MILLISECONDS); |
| engine.lock(); |
| try |
| { |
| @@ -661,17 +657,17 @@ public final class Engine |
| Log.d(TAG, "Unhandled type: " + event.getType()); |
| break; |
| } |
| } |
| final long currentTime = System.currentTimeMillis(); |
| if (currentTime > nextUpdateCheck) |
| { |
| - nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL_MINUTES * MILLIS_PER_MINUTE; |
| + nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL; |
| this.engine.subscriptions.checkForUpdates(); |
| } |
| if (currentTime > this.engine.nextUpdateBroadcast) |
| { |
| this.engine.nextUpdateBroadcast = Long.MAX_VALUE; |
| Log.d(TAG, "Sending update broadcast"); |
| @@ -703,17 +699,17 @@ public final class Engine |
| { |
| CHANGE_ENABLED_STATE, |
| FORCE_DOWNLOAD, |
| DOWNLOAD_FINISHED |
| } |
| private final EngineEventType type; |
| - protected EngineEvent(final EngineEventType type) |
| + EngineEvent(final EngineEventType type) |
| { |
| this.type = type; |
| } |
| public EngineEventType getType() |
| { |
| return this.type; |
| } |