 Issue 29465639:
  Issue 5309 - Subscriptions update causes ANR  (Closed) 
  Base URL: github.com:abby-sergz/libadblockplus-android.git
    
  
    Issue 29465639:
  Issue 5309 - Subscriptions update causes ANR  (Closed) 
  Base URL: github.com:abby-sergz/libadblockplus-android.git
| Left: | ||
| Right: | 
| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 195 | 
| 196 private void initRequests() | 196 private void initRequests() | 
| 197 { | 197 { | 
| 198 androidWebRequest = new AndroidWebRequest(engine.elemhideEnabled, true); | 198 androidWebRequest = new AndroidWebRequest(engine.elemhideEnabled, true); | 
| 199 engine.webRequest = androidWebRequest; | 199 engine.webRequest = androidWebRequest; | 
| 200 | 200 | 
| 201 if (urlToResourceIdMap != null) | 201 if (urlToResourceIdMap != null) | 
| 202 { | 202 { | 
| 203 AndroidWebRequestResourceWrapper wrapper = new AndroidWebRequestResource Wrapper( | 203 AndroidWebRequestResourceWrapper wrapper = new AndroidWebRequestResource Wrapper( | 
| 204 context, engine.webRequest, urlToResourceIdMap, resourceStorage); | 204 context, engine.webRequest, urlToResourceIdMap, resourceStorage); | 
| 205 wrapper.setListener(engine.resourceWrapperListener); | 205 wrapper.setListener(new AndroidWebRequestResourceWrapper.Listener() | 
| 206 { | |
| 207 private AdblockEngine adblockEngine; | |
| 208 | |
| 209 AndroidWebRequestResourceWrapper.Listener init(AdblockEngine adblockEn gine) | |
| 210 { | |
| 211 this.adblockEngine = adblockEngine; | |
| 212 return this; | |
| 213 } | |
| 214 | |
| 215 @Override | |
| 216 public void onIntercepted(String url, int resourceId) | |
| 217 { | |
| 218 Log.d(TAG, "Force subscription update"); | |
| 
anton
2017/06/15 05:51:53
previously we invoked updateSubscriptions 1 time f
 
sergei
2017/06/16 11:12:09
OK, but why error (Log.e)?
 
anton
2017/06/16 11:25:12
Yes, obviously not `.e`. My bad.
 | |
| 219 if (this.adblockEngine.filterEngine != null) | |
| 
anton
2017/06/15 05:51:53
"{" required
 
sergei
2017/06/16 11:12:09
Done.
 | |
| 220 this.adblockEngine.filterEngine.updateFiltersAsync(url); | |
| 
anton
2017/06/15 05:51:53
"}" required
 
sergei
2017/06/16 11:12:08
Done.
 | |
| 221 } | |
| 222 }.init(this.engine)); | |
| 206 | 223 | 
| 207 engine.webRequest = wrapper; | 224 engine.webRequest = wrapper; | 
| 208 } | 225 } | 
| 209 } | 226 } | 
| 210 | 227 | 
| 211 private void initCallbacks() | 228 private void initCallbacks() | 
| 212 { | 229 { | 
| 213 if (engine.updateAvailableCallback != null) | 230 if (engine.updateAvailableCallback != null) | 
| 214 { | 231 { | 
| 215 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCal lback); | 232 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCal lback); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 269 | 
| 253 engine.filterEngine = new FilterEngine(engine.jsEngine, isAllowedConnectio nCallback); | 270 engine.filterEngine = new FilterEngine(engine.jsEngine, isAllowedConnectio nCallback); | 
| 254 } | 271 } | 
| 255 } | 272 } | 
| 256 | 273 | 
| 257 public static Builder builder(AppInfo appInfo, String basePath) | 274 public static Builder builder(AppInfo appInfo, String basePath) | 
| 258 { | 275 { | 
| 259 return new Builder(appInfo, basePath); | 276 return new Builder(appInfo, basePath); | 
| 260 } | 277 } | 
| 261 | 278 | 
| 262 private final AndroidWebRequestResourceWrapper.Listener resourceWrapperListene r = | |
| 263 new AndroidWebRequestResourceWrapper.Listener() | |
| 264 { | |
| 265 private static final int UPDATE_DELAY_MS = 1 * 1000; | |
| 266 | |
| 267 private final Handler handler = new Handler(Looper.getMainLooper()); | |
| 268 | |
| 269 private final Runnable forceUpdateRunnable = new Runnable() | |
| 270 { | |
| 271 public void run() { | |
| 272 // Filter Engine can be already disposed | |
| 273 if (filterEngine != null) | |
| 274 { | |
| 275 Log.d(TAG, "Force update subscriptions"); | |
| 276 AdblockEngine.this.updateSubscriptions(); | |
| 277 } | |
| 278 } | |
| 279 }; | |
| 280 | |
| 281 @Override | |
| 282 public void onIntercepted(String url, int resourceId) | |
| 283 { | |
| 284 // we need to force update subscriptions ASAP after preloaded one is retur ned | |
| 285 // but we should note that multiple interceptions (for main easylist and A A) and force update once only | |
| 286 | |
| 287 // adding into main thread queue to avoid concurrency issues (start update while updating) | |
| 288 // as usually onIntercepted() is invoked in background thread | |
| 289 handler.removeCallbacks(forceUpdateRunnable); | |
| 290 handler.postDelayed(forceUpdateRunnable, UPDATE_DELAY_MS); | |
| 291 | |
| 292 Log.d(TAG, "Scheduled force update in " + UPDATE_DELAY_MS); | |
| 293 } | |
| 294 }; | |
| 295 | |
| 296 public void dispose() | 279 public void dispose() | 
| 297 { | 280 { | 
| 298 Log.w(TAG, "Dispose"); | 281 Log.w(TAG, "Dispose"); | 
| 299 | 282 | 
| 300 // engines first | 283 // engines first | 
| 301 if (this.filterEngine != null) | 284 if (this.filterEngine != null) | 
| 302 { | 285 { | 
| 303 if (this.updateAvailableCallback != null) | 286 if (this.updateAvailableCallback != null) | 
| 304 { | 287 { | 
| 305 this.filterEngine.removeUpdateAvailableCallback(); | 288 this.filterEngine.removeUpdateAvailableCallback(); | 
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 sub.addToList(); | 471 sub.addToList(); | 
| 489 } | 472 } | 
| 490 finally | 473 finally | 
| 491 { | 474 { | 
| 492 sub.dispose(); | 475 sub.dispose(); | 
| 493 } | 476 } | 
| 494 } | 477 } | 
| 495 } | 478 } | 
| 496 } | 479 } | 
| 497 | 480 | 
| 498 public void updateSubscriptions() | |
| 499 { | |
| 500 for (final Subscription s : this.filterEngine.getListedSubscriptions()) | |
| 501 { | |
| 502 try | |
| 503 { | |
| 504 s.updateFilters(); | |
| 505 } | |
| 506 finally | |
| 507 { | |
| 508 s.dispose(); | |
| 509 } | |
| 510 } | |
| 511 } | |
| 512 | |
| 513 public void setEnabled(final boolean enabled) | 481 public void setEnabled(final boolean enabled) | 
| 514 { | 482 { | 
| 515 this.enabled = enabled; | 483 this.enabled = enabled; | 
| 516 } | 484 } | 
| 517 | 485 | 
| 518 public boolean isEnabled() | 486 public boolean isEnabled() | 
| 519 { | 487 { | 
| 520 return enabled; | 488 return enabled; | 
| 521 } | 489 } | 
| 522 | 490 | 
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 public void setWhitelistedDomains(List<String> domains) | 638 public void setWhitelistedDomains(List<String> domains) | 
| 671 { | 639 { | 
| 672 this.whitelistedDomains = domains; | 640 this.whitelistedDomains = domains; | 
| 673 } | 641 } | 
| 674 | 642 | 
| 675 public List<String> getWhitelistedDomains() | 643 public List<String> getWhitelistedDomains() | 
| 676 { | 644 { | 
| 677 return whitelistedDomains; | 645 return whitelistedDomains; | 
| 678 } | 646 } | 
| 679 } | 647 } | 
| OLD | NEW |