| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-2014 Eyeo GmbH | 3  * Copyright (C) 2006-2014 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 80    * Cached list of recommended subscriptions. | 80    * Cached list of recommended subscriptions. | 
| 81    */ | 81    */ | 
| 82   private Subscription[] subscriptions; | 82   private Subscription[] subscriptions; | 
| 83 | 83 | 
| 84   /** | 84   /** | 
| 85    * Indicates whether filtering is enabled or not. | 85    * Indicates whether filtering is enabled or not. | 
| 86    */ | 86    */ | 
| 87   private boolean filteringEnabled = false; | 87   private boolean filteringEnabled = false; | 
| 88 | 88 | 
| 89   private ABPEngine abpEngine; | 89   private ABPEngine abpEngine; | 
| 90 | 90 | 
| 91   private static AdblockPlus instance; | 91   private static AdblockPlus instance; | 
| 92 | 92 | 
| 93   private static class ReferrerMappingCache extends LinkedHashMap<String, String
     > | 93   private static class ReferrerMappingCache extends LinkedHashMap<String, String
     > | 
| 94   { | 94   { | 
| 95     private static final long serialVersionUID = 1L; | 95     private static final long serialVersionUID = 1L; | 
| 96     private static final int MAX_SIZE = 5000; | 96     private static final int MAX_SIZE = 5000; | 
| 97 | 97 | 
| 98     public ReferrerMappingCache() | 98     public ReferrerMappingCache() | 
| 99     { | 99     { | 
| 100       super(MAX_SIZE + 1, 0.75f, true); | 100       super(MAX_SIZE + 1, 0.75f, true); | 
| 101     } | 101     } | 
| 102 | 102 | 
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 206   public static boolean isWiFiConnected(Context context) | 206   public static boolean isWiFiConnected(Context context) | 
| 207   { | 207   { | 
| 208     ConnectivityManager connectivityManager = (ConnectivityManager) context.getS
     ystemService(Context.CONNECTIVITY_SERVICE); | 208     ConnectivityManager connectivityManager = (ConnectivityManager) context.getS
     ystemService(Context.CONNECTIVITY_SERVICE); | 
| 209     NetworkInfo networkInfo = null; | 209     NetworkInfo networkInfo = null; | 
| 210     if (connectivityManager != null) | 210     if (connectivityManager != null) | 
| 211     { | 211     { | 
| 212       networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_
     WIFI); | 212       networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_
     WIFI); | 
| 213     } | 213     } | 
| 214     return networkInfo == null ? false : networkInfo.isConnected(); | 214     return networkInfo == null ? false : networkInfo.isConnected(); | 
| 215   } | 215   } | 
| 216 | 216 | 
| 217   /** | 217   /** | 
| 218    * Checks if ProxyService is running. | 218    * Checks if ProxyService is running. | 
| 219    * | 219    * | 
| 220    * @return true if service is running | 220    * @return true if service is running | 
| 221    */ | 221    */ | 
| 222   public boolean isServiceRunning() | 222   public boolean isServiceRunning() | 
| 223   { | 223   { | 
| 224     ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVIC
     E); | 224     ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVIC
     E); | 
| 225     // Actually it returns not only running services, so extra check is required | 225     // Actually it returns not only running services, so extra check is required | 
| 226     for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VAL
     UE)) | 226     for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VAL
     UE)) | 
| 227     { | 227     { | 
| 228       if (service.service.getClassName().equals(ProxyService.class.getCanonicalN
     ame()) && service.pid > 0) | 228       if (service.service.getClassName().equals(ProxyService.class.getCanonicalN
     ame()) && service.pid > 0) | 
| 229         return true; | 229         return true; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 254     if (subscriptions == null) | 254     if (subscriptions == null) | 
| 255       subscriptions = abpEngine.getRecommendedSubscriptions(); | 255       subscriptions = abpEngine.getRecommendedSubscriptions(); | 
| 256     return subscriptions; | 256     return subscriptions; | 
| 257   } | 257   } | 
| 258 | 258 | 
| 259   /** | 259   /** | 
| 260    * Returns list of enabled subscriptions. | 260    * Returns list of enabled subscriptions. | 
| 261    */ | 261    */ | 
| 262   public Subscription[] getListedSubscriptions() | 262   public Subscription[] getListedSubscriptions() | 
| 263   { | 263   { | 
| 264     return abpEngine.getListedSubscriptions(); | 264     return abpEngine.getListedSubscriptions(); | 
| 265   } | 265   } | 
| 266 | 266 | 
| 267   /** | 267   /** | 
| 268    * Adds provided subscription and removes previous subscriptions if any. | 268    * Adds provided subscription and removes previous subscriptions if any. | 
| 269    * | 269    * | 
| 270    * @param url | 270    * @param url | 
| 271    *          URL of subscription to add | 271    *          URL of subscription to add | 
| 272    */ | 272    */ | 
| 273   public void setSubscription(String url) | 273   public void setSubscription(String url) | 
| 274   { | 274   { | 
| 275     Subscription[] subscriptions = abpEngine.getListedSubscriptions(); |  | 
| 276     for (Subscription subscription : subscriptions) |  | 
| 277     { |  | 
| 278       abpEngine.removeSubscription(subscription.url); |  | 
| 279     } |  | 
| 280     abpEngine.addSubscription(url); |  | 
| 281   } |  | 
| 282 |  | 
| 283   /** |  | 
| 284    * Forces subscriptions refresh. |  | 
| 285    */ |  | 
| 286   public void refreshSubscriptions() |  | 
| 287   { |  | 
| 288     Subscription[] subscriptions = abpEngine.getListedSubscriptions(); | 275     Subscription[] subscriptions = abpEngine.getListedSubscriptions(); | 
| 289     for (Subscription subscription : subscriptions) | 276     for (Subscription subscription : subscriptions) | 
| 290     { | 277     { | 
|  | 278       abpEngine.removeSubscription(subscription.url); | 
|  | 279     } | 
|  | 280     abpEngine.addSubscription(url); | 
|  | 281   } | 
|  | 282 | 
|  | 283   /** | 
|  | 284    * Forces subscriptions refresh. | 
|  | 285    */ | 
|  | 286   public void refreshSubscriptions() | 
|  | 287   { | 
|  | 288     Subscription[] subscriptions = abpEngine.getListedSubscriptions(); | 
|  | 289     for (Subscription subscription : subscriptions) | 
|  | 290     { | 
| 291       abpEngine.refreshSubscription(subscription.url); | 291       abpEngine.refreshSubscription(subscription.url); | 
| 292     } | 292     } | 
| 293   } | 293   } | 
| 294 | 294 | 
| 295   /** | 295   /** | 
| 296    * Enforces subscription status update. | 296    * Enforces subscription status update. | 
| 297    * | 297    * | 
| 298    * @param url Subscription url | 298    * @param url Subscription url | 
| 299    */ | 299    */ | 
| 300   public void actualizeSubscriptionStatus(String url) | 300   public void actualizeSubscriptionStatus(String url) | 
| 301   { | 301   { | 
| 302     abpEngine.actualizeSubscriptionStatus(url); | 302     abpEngine.actualizeSubscriptionStatus(url); | 
| 303   } | 303   } | 
| 304 | 304 | 
| 305 | 305 | 
| 306   /** | 306   /** | 
| 307    * Enables or disables Acceptable Ads | 307    * Enables or disables Acceptable Ads | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 351 /* | 351 /* | 
| 352     if (!filteringEnabled) | 352     if (!filteringEnabled) | 
| 353       return null; | 353       return null; | 
| 354 | 354 | 
| 355     return abpEngine.getSelectorsForDomain(domain); | 355     return abpEngine.getSelectorsForDomain(domain); | 
| 356 */ | 356 */ | 
| 357   } | 357   } | 
| 358 | 358 | 
| 359   /** | 359   /** | 
| 360    * Checks if filters match request parameters. | 360    * Checks if filters match request parameters. | 
| 361    * | 361    * | 
| 362    * @param url | 362    * @param url | 
| 363    *          Request URL | 363    *          Request URL | 
| 364    * @param query | 364    * @param query | 
| 365    *          Request query string | 365    *          Request query string | 
| 366    * @param referrer | 366    * @param referrer | 
| 367    *          Request referrer header | 367    *          Request referrer header | 
| 368    * @param accept | 368    * @param accept | 
| 369    *          Request accept header | 369    *          Request accept header | 
| 370    * @return true if matched filter was found | 370    * @return true if matched filter was found | 
| 371    * @throws Exception | 371    * @throws Exception | 
| 372    */ | 372    */ | 
| 373   public boolean matches(String url, String query, String referrer, String accep
     t) | 373   public boolean matches(String url, String query, String referrer, String accep
     t) | 
| 374   { | 374   { | 
| 375     final String fullUrl = !"".equals(query) ? url + "?" + query : url; | 375     final String fullUrl = !"".equals(query) ? url + "?" + query : url; | 
| 376     if (referrer != null) | 376     if (referrer != null) | 
| 377       referrerMapping.put(fullUrl, referrer); | 377       referrerMapping.put(fullUrl, referrer); | 
| 378 | 378 | 
| 379     if (!filteringEnabled) | 379     if (!filteringEnabled) | 
| 380       return false; | 380       return false; | 
| 381 | 381 | 
| 382     String contentType = null; | 382     String contentType = null; | 
| 383 | 383 | 
| 384     if (accept != null) | 384     if (accept != null) | 
| 385     { | 385     { | 
| 386       if (accept.contains("text/css")) | 386       if (accept.contains("text/css")) | 
| 387         contentType = "STYLESHEET"; | 387         contentType = "STYLESHEET"; | 
| 388       else if (accept.contains("image/*")) | 388       else if (accept.contains("image/*")) | 
| 389         contentType = "IMAGE"; | 389         contentType = "IMAGE"; | 
| 390       else if (accept.contains("text/html")) | 390       else if (accept.contains("text/html")) | 
| 391         contentType = "SUBDOCUMENT"; | 391         contentType = "SUBDOCUMENT"; | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 436   } | 436   } | 
| 437 | 437 | 
| 438   /** | 438   /** | 
| 439    * Enables or disables filtering. | 439    * Enables or disables filtering. | 
| 440    */ | 440    */ | 
| 441   public void setFilteringEnabled(boolean enable) | 441   public void setFilteringEnabled(boolean enable) | 
| 442   { | 442   { | 
| 443     filteringEnabled = enable; | 443     filteringEnabled = enable; | 
| 444     sendBroadcast(new Intent(BROADCAST_FILTERING_CHANGE).putExtra("enabled", fil
     teringEnabled)); | 444     sendBroadcast(new Intent(BROADCAST_FILTERING_CHANGE).putExtra("enabled", fil
     teringEnabled)); | 
| 445   } | 445   } | 
| 446 | 446 | 
| 447   /** | 447   /** | 
| 448    * Starts ABP engine. It also initiates subscription refresh if it is enabled | 448    * Starts ABP engine. It also initiates subscription refresh if it is enabled | 
| 449    * in user settings. | 449    * in user settings. | 
| 450    */ | 450    */ | 
| 451   public void startEngine() | 451   public void startEngine() | 
| 452   { | 452   { | 
| 453     if (abpEngine == null) | 453     if (abpEngine == null) | 
| 454     { | 454     { | 
| 455       File basePath = getFilesDir(); | 455       File basePath = getFilesDir(); | 
| 456       abpEngine = new ABPEngine(this, basePath.getAbsolutePath()); | 456       abpEngine = new ABPEngine(this, basePath.getAbsolutePath()); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 475    */ | 475    */ | 
| 476   public void checkUpdates() | 476   public void checkUpdates() | 
| 477   { | 477   { | 
| 478     abpEngine.checkUpdates(); | 478     abpEngine.checkUpdates(); | 
| 479   } | 479   } | 
| 480 | 480 | 
| 481   /** | 481   /** | 
| 482    * Sets Alarm to call updater after specified number of minutes or after one | 482    * Sets Alarm to call updater after specified number of minutes or after one | 
| 483    * day if | 483    * day if | 
| 484    * minutes are set to 0. | 484    * minutes are set to 0. | 
| 485    * | 485    * | 
| 486    * @param minutes | 486    * @param minutes | 
| 487    *          number of minutes to wait | 487    *          number of minutes to wait | 
| 488    */ | 488    */ | 
| 489   public void scheduleUpdater(int minutes) | 489   public void scheduleUpdater(int minutes) | 
| 490   { | 490   { | 
| 491     Calendar updateTime = Calendar.getInstance(); | 491     Calendar updateTime = Calendar.getInstance(); | 
| 492 | 492 | 
| 493     if (minutes == 0) | 493     if (minutes == 0) | 
| 494     { | 494     { | 
| 495       // Start update checks at 10:00 GMT... | 495       // Start update checks at 10:00 GMT... | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 552       Log.e(TAG, e.getMessage(), e); | 552       Log.e(TAG, e.getMessage(), e); | 
| 553     } | 553     } | 
| 554 | 554 | 
| 555     // Set crash handler | 555     // Set crash handler | 
| 556     Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); | 556     Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); | 
| 557 | 557 | 
| 558     // Initiate update check | 558     // Initiate update check | 
| 559     scheduleUpdater(0); | 559     scheduleUpdater(0); | 
| 560   } | 560   } | 
| 561 } | 561 } | 
| OLD | NEW | 
|---|