Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/android/AdblockPlus.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Adressed first batch of review issues. Created April 16, 2014, 5:36 p.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/android/AboutDialog.java ('k') | src/org/adblockplus/android/AdvancedPreferences.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 14 matching lines...) Expand all
25 import java.io.InputStreamReader; 25 import java.io.InputStreamReader;
26 import java.util.ArrayList; 26 import java.util.ArrayList;
27 import java.util.Calendar; 27 import java.util.Calendar;
28 import java.util.LinkedHashMap; 28 import java.util.LinkedHashMap;
29 import java.util.List; 29 import java.util.List;
30 import java.util.Map; 30 import java.util.Map;
31 import java.util.TimeZone; 31 import java.util.TimeZone;
32 import java.util.regex.Pattern; 32 import java.util.regex.Pattern;
33 33
34 import org.adblockplus.android.updater.AlarmReceiver; 34 import org.adblockplus.android.updater.AlarmReceiver;
35 35 import org.apache.commons.lang.StringUtils;
36 import com.github.rjeschke.neetutils.Strings;
37 36
38 import android.app.ActivityManager; 37 import android.app.ActivityManager;
39 import android.app.ActivityManager.RunningServiceInfo; 38 import android.app.ActivityManager.RunningServiceInfo;
40 import android.app.AlarmManager; 39 import android.app.AlarmManager;
41 import android.app.Application; 40 import android.app.Application;
42 import android.app.PendingIntent; 41 import android.app.PendingIntent;
43 import android.content.Context; 42 import android.content.Context;
44 import android.content.Intent; 43 import android.content.Intent;
45 import android.content.SharedPreferences; 44 import android.content.SharedPreferences;
46 import android.content.SharedPreferences.Editor; 45 import android.content.SharedPreferences.Editor;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 209 }
211 210
212 /** 211 /**
213 * Checks if ProxyService is running. 212 * Checks if ProxyService is running.
214 * 213 *
215 * @return true if service is running 214 * @return true if service is running
216 */ 215 */
217 public boolean isServiceRunning() 216 public boolean isServiceRunning()
218 { 217 {
219 final ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_ SERVICE); 218 final ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_ SERVICE);
220
221 // Actually it returns not only running services, so extra check is required 219 // Actually it returns not only running services, so extra check is required
222 for (final RunningServiceInfo service : manager.getRunningServices(Integer.M AX_VALUE)) 220 for (final RunningServiceInfo service : manager.getRunningServices(Integer.M AX_VALUE))
223 { 221 {
224 if (service.service.getClassName().equals(ProxyService.class.getCanonicalN ame()) && service.pid > 0) 222 if (service.service.getClassName().equals(ProxyService.class.getCanonicalN ame()) && service.pid > 0)
225 return true; 223 return true;
226 } 224 }
227 return false; 225 return false;
228 } 226 }
229 227
230 /** 228 /**
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 * @return A list of CSS selectors 324 * @return A list of CSS selectors
327 */ 325 */
328 public String[] getSelectorsForDomain(final String domain) 326 public String[] getSelectorsForDomain(final String domain)
329 { 327 {
330 /* We need to ignore element hiding rules here to work around two bugs: 328 /* We need to ignore element hiding rules here to work around two bugs:
331 * 1. CSS is being injected even when there's an exception rule with $elemhi de 329 * 1. CSS is being injected even when there's an exception rule with $elemhi de
332 * 2. The injected CSS causes blank pages in Chrome for Android 330 * 2. The injected CSS causes blank pages in Chrome for Android
333 * 331 *
334 * Starting with 1.1.2, we ignored element hiding rules after download anywa y, to keep the 332 * Starting with 1.1.2, we ignored element hiding rules after download anywa y, to keep the
335 * memory usage down. Doing this with libadblockplus is trickier, but would be the clean 333 * memory usage down. Doing this with libadblockplus is trickier, but would be the clean
336 * solution. 334 * solution. */
337 */
338 return null; 335 return null;
339 /* 336 /*
340 if (!filteringEnabled) 337 if (!filteringEnabled)
341 return null; 338 return null;
342 339
343 return abpEngine.getSelectorsForDomain(domain); 340 return abpEngine.getSelectorsForDomain(domain);
344 */ 341 */
345 } 342 }
346 343
347 /** 344 /**
348 * Checks if filters match request parameters. 345 * Checks if filters match request parameters.
349 * 346 *
350 * @param url 347 * @param url
351 * Request URL 348 * Request URL
352 * @param query 349 * @param query
353 * Request query string 350 * Request query string
354 * @param referrer 351 * @param referrer
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 /** 423 /**
427 * Enables or disables filtering. 424 * Enables or disables filtering.
428 */ 425 */
429 public void setFilteringEnabled(final boolean enable) 426 public void setFilteringEnabled(final boolean enable)
430 { 427 {
431 filteringEnabled = enable; 428 filteringEnabled = enable;
432 sendBroadcast(new Intent(BROADCAST_FILTERING_CHANGE).putExtra("enabled", fil teringEnabled)); 429 sendBroadcast(new Intent(BROADCAST_FILTERING_CHANGE).putExtra("enabled", fil teringEnabled));
433 } 430 }
434 431
435 /** 432 /**
436 * Starts ABP engine. It also initiates subscription refresh if it is enabled in user settings. 433 * Starts ABP engine. It also initiates subscription refresh if it is enabled
434 * in user settings.
437 */ 435 */
438 public void startEngine() 436 public void startEngine()
439 { 437 {
440 if (abpEngine == null) 438 if (abpEngine == null)
441 { 439 {
442 final File basePath = getFilesDir(); 440 final File basePath = getFilesDir();
443 abpEngine = ABPEngine.create(AdblockPlus.getApplication(), ABPEngine.gener ateAppInfo(this), basePath.getAbsolutePath()); 441 abpEngine = ABPEngine.create(AdblockPlus.getApplication(), ABPEngine.gener ateAppInfo(this), basePath.getAbsolutePath());
444 } 442 }
445 } 443 }
446 444
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 final StringBuilder out = new StringBuilder(); 512 final StringBuilder out = new StringBuilder();
515 int read; 513 int read;
516 do 514 do
517 { 515 {
518 read = reportFile.read(buffer, 0, buffer.length); 516 read = reportFile.read(buffer, 0, buffer.length);
519 if (read > 0) 517 if (read > 0)
520 out.append(buffer, 0, read); 518 out.append(buffer, 0, read);
521 } 519 }
522 while (read >= 0); 520 while (read >= 0);
523 final String report = out.toString(); 521 final String report = out.toString();
524 if (!Strings.isEmpty(report)) 522 if (StringUtils.isNotEmpty(report))
525 { 523 {
526 final Intent intent = new Intent(this, CrashReportDialog.class); 524 final Intent intent = new Intent(this, CrashReportDialog.class);
527 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
528 intent.putExtra("report", report); 526 intent.putExtra("report", report);
529 startActivity(intent); 527 startActivity(intent);
530 } 528 }
531 } 529 }
532 catch (final FileNotFoundException e) 530 catch (final FileNotFoundException e)
533 { 531 {
534 // ignore 532 // ignore
535 } 533 }
536 catch (final IOException e) 534 catch (final IOException e)
537 { 535 {
538 Log.e(TAG, e.getMessage(), e); 536 Log.e(TAG, e.getMessage(), e);
539 } 537 }
540 538
541 // Set crash handler 539 // Set crash handler
542 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); 540 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this));
543 541
544 // Initiate update check 542 // Initiate update check
545 scheduleUpdater(0); 543 scheduleUpdater(0);
546 } 544 }
547 } 545 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld