| OLD | NEW |
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 Loading... |
| 36 import java.util.List; | 36 import java.util.List; |
| 37 import java.util.Map; | 37 import java.util.Map; |
| 38 import java.util.Set; | 38 import java.util.Set; |
| 39 import java.util.TreeSet; | 39 import java.util.TreeSet; |
| 40 import java.util.concurrent.LinkedBlockingQueue; | 40 import java.util.concurrent.LinkedBlockingQueue; |
| 41 import java.util.concurrent.TimeUnit; | 41 import java.util.concurrent.TimeUnit; |
| 42 import java.util.concurrent.locks.ReentrantLock; | 42 import java.util.concurrent.locks.ReentrantLock; |
| 43 import java.util.regex.Pattern; | 43 import java.util.regex.Pattern; |
| 44 | 44 |
| 45 import org.adblockplus.adblockplussbrowser.R; | 45 import org.adblockplus.adblockplussbrowser.R; |
| 46 import org.adblockplus.sbrowser.contentblocker.MainPreferences; | |
| 47 | 46 |
| 48 import android.content.Context; | 47 import android.content.Context; |
| 49 import android.content.Intent; | 48 import android.content.Intent; |
| 50 import android.content.SharedPreferences; | 49 import android.content.SharedPreferences; |
| 51 import android.content.pm.PackageInfo; | 50 import android.content.pm.PackageInfo; |
| 52 import android.content.pm.PackageManager; | 51 import android.content.pm.PackageManager; |
| 53 import android.content.pm.ResolveInfo; | 52 import android.content.pm.ResolveInfo; |
| 54 import android.net.ConnectivityManager; | 53 import android.net.ConnectivityManager; |
| 55 import android.net.NetworkInfo; | 54 import android.net.NetworkInfo; |
| 56 import android.net.Uri; | 55 import android.net.Uri; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; | 104 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; |
| 106 | 105 |
| 107 private final ReentrantLock accessLock = new ReentrantLock(); | 106 private final ReentrantLock accessLock = new ReentrantLock(); |
| 108 private DefaultSubscriptions defaultSubscriptions; | 107 private DefaultSubscriptions defaultSubscriptions; |
| 109 private Subscriptions subscriptions; | 108 private Subscriptions subscriptions; |
| 110 private JSONPrefs jsonPrefs; | 109 private JSONPrefs jsonPrefs; |
| 111 private AppInfo appInfo; | 110 private AppInfo appInfo; |
| 112 private LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueu
e<EngineEvent>(); | 111 private LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueu
e<EngineEvent>(); |
| 113 private Thread handlerThread; | 112 private Thread handlerThread; |
| 114 private Downloader downloader; | 113 private Downloader downloader; |
| 114 private SubscriptionUpdateCallback subscriptionUpdateCallback; |
| 115 private final Context serviceContext; | 115 private final Context serviceContext; |
| 116 private boolean wasFirstRun = false; | 116 private boolean wasFirstRun = false; |
| 117 private long nextUpdateBroadcast = Long.MAX_VALUE; | 117 private long nextUpdateBroadcast = Long.MAX_VALUE; |
| 118 | 118 |
| 119 private Engine(final Context context) | 119 private Engine(final Context context) |
| 120 { | 120 { |
| 121 this.serviceContext = context; | 121 this.serviceContext = context; |
| 122 } | 122 } |
| 123 | 123 |
| 124 public String getPrefsDefault(final String key) | 124 public String getPrefsDefault(final String key) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 catch (PackageManager.NameNotFoundException e) | 183 catch (PackageManager.NameNotFoundException e) |
| 184 { | 184 { |
| 185 // Should never happen, as checkAAStatusAndProceed() should not be called
if the user | 185 // Should never happen, as checkAAStatusAndProceed() should not be called
if the user |
| 186 // has no compatible SBrowser installed. Nevertheless we have to handle th
e Exception. | 186 // has no compatible SBrowser installed. Nevertheless we have to handle th
e Exception. |
| 187 Log.d(TAG, "No compatible Samsung Browser found.", e); | 187 Log.d(TAG, "No compatible Samsung Browser found.", e); |
| 188 return false; | 188 return false; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 public void setSubscriptionUpdateCallback(final SubscriptionUpdateCallback sub
scriptionUpdateCallback) |
| 193 { |
| 194 this.subscriptionUpdateCallback = subscriptionUpdateCallback; |
| 195 } |
| 196 |
| 192 public void requestUpdateBroadcast() | 197 public void requestUpdateBroadcast() |
| 193 { | 198 { |
| 194 this.lock(); | 199 this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATIO
N_DELAY_MILLIS; |
| 195 try | |
| 196 { | |
| 197 this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINAT
ION_DELAY_MILLIS; | |
| 198 } | |
| 199 finally | |
| 200 { | |
| 201 this.unlock(); | |
| 202 } | |
| 203 } | 200 } |
| 204 | 201 |
| 205 private void writeFileAndSendUpdateBroadcast() | 202 private void writeFileAndSendUpdateBroadcast() |
| 206 { | 203 { |
| 207 createAndWriteFile(); | 204 createAndWriteFile(); |
| 208 | 205 |
| 209 runOnUiThread(new Runnable() | 206 runOnUiThread(new Runnable() |
| 210 { | 207 { |
| 211 @Override | 208 @Override |
| 212 public void run() | 209 public void run() |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return false; | 246 return false; |
| 250 } | 247 } |
| 251 } | 248 } |
| 252 return false; | 249 return false; |
| 253 } | 250 } |
| 254 return current.isConnected(); | 251 return current.isConnected(); |
| 255 } | 252 } |
| 256 | 253 |
| 257 public List<SubscriptionInfo> getListedSubscriptions() | 254 public List<SubscriptionInfo> getListedSubscriptions() |
| 258 { | 255 { |
| 259 this.lock(); | 256 return this.subscriptions.getSubscriptions(this); |
| 260 try | |
| 261 { | |
| 262 return this.subscriptions.getSubscriptions(this); | |
| 263 } | |
| 264 finally | |
| 265 { | |
| 266 this.unlock(); | |
| 267 } | |
| 268 } | 257 } |
| 269 | 258 |
| 270 public void changeSubscriptionState(final String id, final boolean enabled) | 259 public void changeSubscriptionState(final String id, final boolean enabled) |
| 271 { | 260 { |
| 261 if (this.subscriptionUpdateCallback != null) |
| 262 { |
| 263 this.subscriptionUpdateCallback.subscriptionUpdateRequested(enabled); |
| 264 } |
| 272 this.engineEvents.add(new ChangeEnabledStateEvent(id, enabled)); | 265 this.engineEvents.add(new ChangeEnabledStateEvent(id, enabled)); |
| 273 } | 266 } |
| 274 | 267 |
| 268 public void subscriptionStateChanged() { |
| 269 if (this.subscriptionUpdateCallback != null) |
| 270 { |
| 271 this.subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| 272 } |
| 273 } |
| 274 |
| 275 void downloadFinished(final String id, final int responseCode, final String re
sponse, | 275 void downloadFinished(final String id, final int responseCode, final String re
sponse, |
| 276 final Map<String, String> headers) | 276 final Map<String, String> headers) |
| 277 { | 277 { |
| 278 this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response,
headers)); | 278 this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response,
headers)); |
| 279 } | 279 } |
| 280 | 280 |
| 281 private void createAndWriteFile() | 281 private void createAndWriteFile() |
| 282 { | 282 { |
| 283 this.lock(); | 283 this.lock(); |
| 284 try | 284 try |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 } | 799 } |
| 800 Log.d(TAG, headers.toString()); | 800 Log.d(TAG, headers.toString()); |
| 801 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(),
headers); | 801 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(),
headers); |
| 802 } | 802 } |
| 803 } | 803 } |
| 804 | 804 |
| 805 public void connectivityChanged() | 805 public void connectivityChanged() |
| 806 { | 806 { |
| 807 this.downloader.connectivityChanged(); | 807 this.downloader.connectivityChanged(); |
| 808 } | 808 } |
| 809 |
| 810 public interface SubscriptionUpdateCallback |
| 811 { |
| 812 void subscriptionUpdateRequested(boolean enabled); |
| 813 void subscriptionUpdatedApplied(); |
| 814 } |
| 809 } | 815 } |
| OLD | NEW |