| 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     this.subscriptionUpdateCallback = subscriptionUpdateCallback; | 
|  | 194   } | 
|  | 195 | 
| 192   public void requestUpdateBroadcast() | 196   public void requestUpdateBroadcast() | 
| 193   { | 197   { | 
| 194     this.lock(); | 198     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   } | 199   } | 
| 204 | 200 | 
| 205   private void writeFileAndSendUpdateBroadcast() | 201   private void writeFileAndSendUpdateBroadcast() | 
| 206   { | 202   { | 
| 207     createAndWriteFile(); | 203     createAndWriteFile(); | 
| 208 | 204 | 
| 209     runOnUiThread(new Runnable() | 205     runOnUiThread(new Runnable() | 
| 210     { | 206     { | 
| 211       @Override | 207       @Override | 
| 212       public void run() | 208       public void run() | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 249             return false; | 245             return false; | 
| 250         } | 246         } | 
| 251       } | 247       } | 
| 252       return false; | 248       return false; | 
| 253     } | 249     } | 
| 254     return current.isConnected(); | 250     return current.isConnected(); | 
| 255   } | 251   } | 
| 256 | 252 | 
| 257   public List<SubscriptionInfo> getListedSubscriptions() | 253   public List<SubscriptionInfo> getListedSubscriptions() | 
| 258   { | 254   { | 
| 259     this.lock(); | 255     return this.subscriptions.getSubscriptions(this); | 
| 260     try |  | 
| 261     { |  | 
| 262       return this.subscriptions.getSubscriptions(this); |  | 
| 263     } |  | 
| 264     finally |  | 
| 265     { |  | 
| 266       this.unlock(); |  | 
| 267     } |  | 
| 268   } | 256   } | 
| 269 | 257 | 
| 270   public void changeSubscriptionState(final String id, final boolean enabled) | 258   public void changeSubscriptionState(final String id, final boolean enabled) | 
| 271   { | 259   { | 
|  | 260     if (this.subscriptionUpdateCallback != null) | 
|  | 261     { | 
|  | 262       this.subscriptionUpdateCallback.subscriptionUpdateRequested(enabled); | 
|  | 263     } | 
| 272     this.engineEvents.add(new ChangeEnabledStateEvent(id, enabled)); | 264     this.engineEvents.add(new ChangeEnabledStateEvent(id, enabled)); | 
| 273   } | 265   } | 
| 274 | 266 | 
|  | 267   public void subscriptionStateChanged() { | 
|  | 268     if (this.subscriptionUpdateCallback != null) | 
|  | 269     { | 
|  | 270       this.subscriptionUpdateCallback.subscriptionUpdatedApplied(); | 
|  | 271     } | 
|  | 272   } | 
|  | 273 | 
| 275   void downloadFinished(final String id, final int responseCode, final String re
     sponse, | 274   void downloadFinished(final String id, final int responseCode, final String re
     sponse, | 
| 276       final Map<String, String> headers) | 275       final Map<String, String> headers) | 
| 277   { | 276   { | 
| 278     this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, 
     headers)); | 277     this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, 
     headers)); | 
| 279   } | 278   } | 
| 280 | 279 | 
| 281   private void createAndWriteFile() | 280   private void createAndWriteFile() | 
| 282   { | 281   { | 
| 283     this.lock(); | 282     this.lock(); | 
| 284     try | 283     try | 
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 799       } | 798       } | 
| 800       Log.d(TAG, headers.toString()); | 799       Log.d(TAG, headers.toString()); | 
| 801       this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), 
     headers); | 800       this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), 
     headers); | 
| 802     } | 801     } | 
| 803   } | 802   } | 
| 804 | 803 | 
| 805   public void connectivityChanged() | 804   public void connectivityChanged() | 
| 806   { | 805   { | 
| 807     this.downloader.connectivityChanged(); | 806     this.downloader.connectivityChanged(); | 
| 808   } | 807   } | 
|  | 808 | 
|  | 809   public interface SubscriptionUpdateCallback { | 
|  | 810     void subscriptionUpdateRequested(boolean enabled); | 
|  | 811     void subscriptionUpdatedApplied(); | 
|  | 812   } | 
| 809 } | 813 } | 
| OLD | NEW | 
|---|