| 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 | 
| 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 12  * GNU General Public License for more details. | 12  * GNU General Public License for more details. | 
| 13  * | 13  * | 
| 14  * You should have received a copy of the GNU General Public License | 14  * You should have received a copy of the GNU General Public License | 
| 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| 16  */ | 16  */ | 
| 17 | 17 | 
| 18 package org.adblockplus.android; | 18 package org.adblockplus.android; | 
| 19 | 19 | 
| 20 import java.io.BufferedReader; | 20 import java.io.BufferedReader; | 
| 21 import java.io.File; | 21 import java.io.File; | 
| 22 import java.io.FileNotFoundException; | 22 import java.io.FileNotFoundException; | 
| 23 import java.io.IOException; | 23 import java.io.IOException; | 
| 24 import java.io.InputStream; | 24 import java.io.InputStream; | 
| 25 import java.io.InputStreamReader; | 25 import java.io.InputStreamReader; | 
| 26 import java.util.ArrayList; |  | 
| 27 import java.util.Calendar; | 26 import java.util.Calendar; | 
| 28 import java.util.LinkedHashMap; |  | 
| 29 import java.util.List; | 27 import java.util.List; | 
| 30 import java.util.Map; |  | 
| 31 import java.util.TimeZone; | 28 import java.util.TimeZone; | 
| 32 import java.util.regex.Pattern; | 29 import java.util.regex.Pattern; | 
| 33 | 30 | 
| 34 import org.adblockplus.android.updater.AlarmReceiver; | 31 import org.adblockplus.android.updater.AlarmReceiver; | 
| 35 import org.apache.commons.lang.StringUtils; | 32 import org.apache.commons.lang.StringUtils; | 
| 36 | 33 | 
| 37 import android.app.ActivityManager; | 34 import android.app.ActivityManager; | 
| 38 import android.app.ActivityManager.RunningServiceInfo; | 35 import android.app.ActivityManager.RunningServiceInfo; | 
| 39 import android.app.AlarmManager; | 36 import android.app.AlarmManager; | 
| 40 import android.app.Application; | 37 import android.app.Application; | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 70   public static final int UPDATE_NOTIFICATION_ID = R.string.app_name + 1; | 67   public static final int UPDATE_NOTIFICATION_ID = R.string.app_name + 1; | 
| 71   /** | 68   /** | 
| 72    * Broadcasted when filtering is enabled or disabled. | 69    * Broadcasted when filtering is enabled or disabled. | 
| 73    */ | 70    */ | 
| 74   public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.andro
     id.filtering.status"; | 71   public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.andro
     id.filtering.status"; | 
| 75   /** | 72   /** | 
| 76    * Broadcasted when subscription status changes. | 73    * Broadcasted when subscription status changes. | 
| 77    */ | 74    */ | 
| 78   public static final String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.an
     droid.subscription.status"; | 75   public static final String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.an
     droid.subscription.status"; | 
| 79   /** | 76   /** | 
| 80    * Broadcasted when filter match check is performed. |  | 
| 81    */ |  | 
| 82   public static final String BROADCAST_FILTER_MATCHES = "org.adblockplus.android
     .filter.matches"; |  | 
| 83   /** |  | 
| 84    * Cached list of recommended subscriptions. | 77    * Cached list of recommended subscriptions. | 
| 85    */ | 78    */ | 
| 86   private Subscription[] subscriptions; | 79   private Subscription[] subscriptions; | 
| 87   /** | 80   /** | 
| 88    * Indicates whether filtering is enabled or not. | 81    * Indicates whether filtering is enabled or not. | 
| 89    */ | 82    */ | 
| 90   private boolean filteringEnabled = false; | 83   private boolean filteringEnabled = false; | 
| 91 | 84 | 
| 92   private ABPEngine abpEngine; | 85   private ABPEngine abpEngine; | 
| 93 | 86 | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 221   public boolean isFirstRun() | 214   public boolean isFirstRun() | 
| 222   { | 215   { | 
| 223     return abpEngine.isFirstRun(); | 216     return abpEngine.isFirstRun(); | 
| 224   } | 217   } | 
| 225 | 218 | 
| 226   /** | 219   /** | 
| 227    * Returns list of known subscriptions. | 220    * Returns list of known subscriptions. | 
| 228    */ | 221    */ | 
| 229   public Subscription[] getRecommendedSubscriptions() | 222   public Subscription[] getRecommendedSubscriptions() | 
| 230   { | 223   { | 
| 231     // TODO: Why don't we re-check? |  | 
| 232     if (subscriptions == null) | 224     if (subscriptions == null) | 
| 233       subscriptions = abpEngine.getRecommendedSubscriptions(); | 225       subscriptions = abpEngine.getRecommendedSubscriptions(); | 
| 234     return subscriptions; | 226     return subscriptions; | 
| 235   } | 227   } | 
| 236 | 228 | 
| 237   /** | 229   /** | 
| 238    * Returns list of enabled subscriptions. | 230    * Returns list of enabled subscriptions. | 
| 239    */ | 231    */ | 
| 240   public Subscription[] getListedSubscriptions() | 232   public Subscription[] getListedSubscriptions() | 
| 241   { | 233   { | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 333    *          Request query string | 325    *          Request query string | 
| 334    * @param referrer | 326    * @param referrer | 
| 335    *          Request referrer header | 327    *          Request referrer header | 
| 336    * @param accept | 328    * @param accept | 
| 337    *          Request accept header | 329    *          Request accept header | 
| 338    * @return true if matched filter was found | 330    * @return true if matched filter was found | 
| 339    * @throws Exception | 331    * @throws Exception | 
| 340    */ | 332    */ | 
| 341   public boolean matches(final String url, final String query, final String refe
     rrer, final String accept) | 333   public boolean matches(final String url, final String query, final String refe
     rrer, final String accept) | 
| 342   { | 334   { | 
| 343     final String fullUrl = !"".equals(query) ? url + "?" + query : url; | 335     final String fullUrl = StringUtils.isNotEmpty(query) ? url + "?" + query : u
     rl; | 
| 344     if (referrer != null) | 336     if (referrer != null) | 
| 345       referrerMapping.add(fullUrl, referrer); | 337       referrerMapping.add(fullUrl, referrer); | 
| 346 | 338 | 
| 347     if (!filteringEnabled) | 339     if (!filteringEnabled) | 
| 348       return false; | 340       return false; | 
| 349 | 341 | 
| 350     String contentType = null; | 342     String contentType = null; | 
| 351 | 343 | 
| 352     if (accept != null) | 344     if (accept != null) | 
| 353     { | 345     { | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 369         contentType = "IMAGE"; | 361         contentType = "IMAGE"; | 
| 370       else if (RE_FONT.matcher(url).find()) | 362       else if (RE_FONT.matcher(url).find()) | 
| 371         contentType = "FONT"; | 363         contentType = "FONT"; | 
| 372       else if (RE_HTML.matcher(url).find()) | 364       else if (RE_HTML.matcher(url).find()) | 
| 373         contentType = "SUBDOCUMENT"; | 365         contentType = "SUBDOCUMENT"; | 
| 374     } | 366     } | 
| 375     if (contentType == null) | 367     if (contentType == null) | 
| 376       contentType = "OTHER"; | 368       contentType = "OTHER"; | 
| 377 | 369 | 
| 378     final List<String> referrerChain = referrerMapping.buildReferrerChain(referr
     er); | 370     final List<String> referrerChain = referrerMapping.buildReferrerChain(referr
     er); | 
| 379     Log.d("Referrer chain", fullUrl + ": " + referrerChain.toString()); |  | 
| 380     final String[] referrerChainArray = referrerChain.toArray(new String[referre
     rChain.size()]); | 371     final String[] referrerChainArray = referrerChain.toArray(new String[referre
     rChain.size()]); | 
| 381     return abpEngine.matches(fullUrl, contentType, referrerChainArray); | 372     return abpEngine.matches(fullUrl, contentType, referrerChainArray); | 
| 382   } | 373   } | 
| 383 | 374 | 
| 384   /** | 375   /** | 
| 385    * Checks if filtering is enabled. | 376    * Checks if filtering is enabled. | 
| 386    */ | 377    */ | 
| 387   public boolean isFilteringEnabled() | 378   public boolean isFilteringEnabled() | 
| 388   { | 379   { | 
| 389     return filteringEnabled; | 380     return filteringEnabled; | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 505       Log.e(TAG, e.getMessage(), e); | 496       Log.e(TAG, e.getMessage(), e); | 
| 506     } | 497     } | 
| 507 | 498 | 
| 508     // Set crash handler | 499     // Set crash handler | 
| 509     Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); | 500     Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); | 
| 510 | 501 | 
| 511     // Initiate update check | 502     // Initiate update check | 
| 512     scheduleUpdater(0); | 503     scheduleUpdater(0); | 
| 513   } | 504   } | 
| 514 } | 505 } | 
| OLD | NEW | 
|---|