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

Side by Side Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29453722: Noissue - Lint adjustments and optimizations (Closed)
Patch Set: Adjusting HashSet initialization in Subscription Created July 19, 2017, 4:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 import android.content.Intent; 49 import android.content.Intent;
50 import android.content.pm.PackageInfo; 50 import android.content.pm.PackageInfo;
51 import android.content.pm.PackageManager; 51 import android.content.pm.PackageManager;
52 import android.content.pm.ResolveInfo; 52 import android.content.pm.ResolveInfo;
53 import android.net.ConnectivityManager; 53 import android.net.ConnectivityManager;
54 import android.net.NetworkInfo; 54 import android.net.NetworkInfo;
55 import android.net.Uri; 55 import android.net.Uri;
56 import android.os.Handler; 56 import android.os.Handler;
57 import android.os.Looper; 57 import android.os.Looper;
58 import android.text.TextUtils; 58 import android.text.TextUtils;
59 import android.text.format.DateUtils;
59 import android.util.Log; 60 import android.util.Log;
60 61
61 public final class Engine 62 public final class Engine
62 { 63 {
63 private static final String TAG = Engine.class.getSimpleName(); 64 private static final String TAG = Engine.class.getSimpleName();
64 65
65 public static final String USER_FILTERS_TITLE = "__filters"; 66 public static final String USER_FILTERS_TITLE = "__filters";
66 public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; 67 public static final String USER_EXCEPTIONS_TITLE = "__exceptions";
67 68
68 public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; 69 public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser";
69 public static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrowse r.contentBlocker.ACTION_SETTING"; 70 private static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrows er.contentBlocker.ACTION_SETTING";
70 public static final String ACTION_UPDATE = "com.samsung.android.sbrowser.conte ntBlocker.ACTION_UPDATE"; 71 private static final String ACTION_UPDATE = "com.samsung.android.sbrowser.cont entBlocker.ACTION_UPDATE";
71 public static final String EASYLIST_URL = "https://easylist-downloads.adblockp lus.org/easylist.txt"; 72 private static final String EASYLIST_URL = "https://easylist-downloads.adblock plus.org/easylist.txt";
72 73
73 public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_except ionsurl"; 74 public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_except ionsurl";
74 75
75 // The value below specifies an interval of [x, 2*x[, where x = 76 // The value below specifies an interval of [x, 2*x[, where x =
76 // INITIAL_UPDATE_CHECK_DELAY_SECONDS 77 // INITIAL_UPDATE_CHECK_DELAY
77 private static final long INITIAL_UPDATE_CHECK_DELAY_SECONDS = 5; 78 private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN _MILLIS;
78 private static final long UPDATE_CHECK_INTERVAL_MINUTES = 30; 79 private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MIL LIS;
79 private static final long BROADCAST_COMBINATION_DELAY_MILLIS = 2500; 80 private static final long BROADCAST_COMBINATION_DELAY = 2500;
80
81 public static final long MILLIS_PER_SECOND = 1000;
82 public static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND;
83 public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
84 public static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR;
85 81
86 private static final int NO_FLAG = 0; 82 private static final int NO_FLAG = 0;
87 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; 83 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000;
88 84
89 private final ReentrantLock accessLock = new ReentrantLock(); 85 private final ReentrantLock accessLock = new ReentrantLock();
90 private DefaultSubscriptions defaultSubscriptions; 86 private DefaultSubscriptions defaultSubscriptions;
91 private Subscriptions subscriptions; 87 private Subscriptions subscriptions;
92 private JSONPrefs jsonPrefs; 88 private JSONPrefs jsonPrefs;
93 private AppInfo appInfo; 89 private AppInfo appInfo;
94 private LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueu e<>(); 90 private final LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlocki ngQueue<>();
95 private Thread handlerThread; 91 private Thread handlerThread;
96 private Downloader downloader; 92 private Downloader downloader;
97 private SubscriptionUpdateCallback subscriptionUpdateCallback; 93 private SubscriptionUpdateCallback subscriptionUpdateCallback;
98 private final Context serviceContext; 94 private final Context serviceContext;
99 private boolean wasFirstRun = false; 95 private boolean wasFirstRun = false;
100 private long nextUpdateBroadcast = Long.MAX_VALUE; 96 private long nextUpdateBroadcast = Long.MAX_VALUE;
101 97
102 private Engine(final Context context) 98 private Engine(final Context context)
103 { 99 {
104 this.serviceContext = context; 100 this.serviceContext = context;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 168 }
173 } 169 }
174 170
175 public void setSubscriptionUpdateCallback(final SubscriptionUpdateCallback sub scriptionUpdateCallback) 171 public void setSubscriptionUpdateCallback(final SubscriptionUpdateCallback sub scriptionUpdateCallback)
176 { 172 {
177 this.subscriptionUpdateCallback = subscriptionUpdateCallback; 173 this.subscriptionUpdateCallback = subscriptionUpdateCallback;
178 } 174 }
179 175
180 public void requestUpdateBroadcast() 176 public void requestUpdateBroadcast()
181 { 177 {
182 this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATIO N_DELAY_MILLIS; 178 this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATIO N_DELAY;
183 } 179 }
184 180
185 private void writeFileAndSendUpdateBroadcast() 181 private void writeFileAndSendUpdateBroadcast()
186 { 182 {
187 createAndWriteFile(); 183 createAndWriteFile();
188 184
189 runOnUiThread(new Runnable() 185 runOnUiThread(new Runnable()
190 { 186 {
191 @Override 187 @Override
192 public void run() 188 public void run()
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 415 }
420 416
421 Log.d(TAG, "Added " + additional + " additional default/built-in subscript ions"); 417 Log.d(TAG, "Added " + additional + " additional default/built-in subscript ions");
422 engine.subscriptions.persistSubscriptions(); 418 engine.subscriptions.persistSubscriptions();
423 } 419 }
424 420
425 engine.handlerThread = new Thread(new EventHandler(engine)); 421 engine.handlerThread = new Thread(new EventHandler(engine));
426 engine.handlerThread.setDaemon(true); 422 engine.handlerThread.setDaemon(true);
427 engine.handlerThread.start(); 423 engine.handlerThread.start();
428 424
429 engine.downloader = Downloader.create(context, engine); 425 engine.downloader = Downloader.create(engine);
430 426
431 final File cachedFilterFile = getCachedFilterFile(context); 427 final File cachedFilterFile = getCachedFilterFile(context);
432 if (cachedFilterFile == null || !cachedFilterFile.exists()) 428 if (cachedFilterFile == null || !cachedFilterFile.exists())
433 { 429 {
434 engine.writeFileAndSendUpdateBroadcast(); 430 engine.writeFileAndSendUpdateBroadcast();
435 } 431 }
436 432
437 return engine; 433 return engine;
438 } 434 }
439 435
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 { 597 {
602 this.engine = engine; 598 this.engine = engine;
603 } 599 }
604 600
605 @Override 601 @Override
606 public void run() 602 public void run()
607 { 603 {
608 Log.d(TAG, "Handler thread started"); 604 Log.d(TAG, "Handler thread started");
609 boolean interrupted = false; 605 boolean interrupted = false;
610 long nextUpdateCheck = System.currentTimeMillis() 606 long nextUpdateCheck = System.currentTimeMillis()
611 + (long) ((1 + Math.random()) * INITIAL_UPDATE_CHECK_DELAY_SECONDS * M ILLIS_PER_SECOND); 607 + (long) ((1 + Math.random()) * INITIAL_UPDATE_CHECK_DELAY);
612 while (!interrupted) 608 while (!interrupted)
613 { 609 {
614 try 610 try
615 { 611 {
616 final EngineEvent event = this.engine.engineEvents.poll(100, TimeUnit. MILLISECONDS); 612 final EngineEvent event = this.engine.engineEvents.poll(100, TimeUnit. MILLISECONDS);
617 engine.lock(); 613 engine.lock();
618 try 614 try
619 { 615 {
620 if (event != null) 616 if (event != null)
621 { 617 {
(...skipping 17 matching lines...) Expand all
639 } 635 }
640 default: 636 default:
641 Log.d(TAG, "Unhandled type: " + event.getType()); 637 Log.d(TAG, "Unhandled type: " + event.getType());
642 break; 638 break;
643 } 639 }
644 } 640 }
645 641
646 final long currentTime = System.currentTimeMillis(); 642 final long currentTime = System.currentTimeMillis();
647 if (currentTime > nextUpdateCheck) 643 if (currentTime > nextUpdateCheck)
648 { 644 {
649 nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL_MINUTES * MI LLIS_PER_MINUTE; 645 nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL;
650 646
651 this.engine.subscriptions.checkForUpdates(); 647 this.engine.subscriptions.checkForUpdates();
652 } 648 }
653 649
654 if (currentTime > this.engine.nextUpdateBroadcast) 650 if (currentTime > this.engine.nextUpdateBroadcast)
655 { 651 {
656 this.engine.nextUpdateBroadcast = Long.MAX_VALUE; 652 this.engine.nextUpdateBroadcast = Long.MAX_VALUE;
657 Log.d(TAG, "Sending update broadcast"); 653 Log.d(TAG, "Sending update broadcast");
658 this.engine.writeFileAndSendUpdateBroadcast(); 654 this.engine.writeFileAndSendUpdateBroadcast();
659 } 655 }
(...skipping 21 matching lines...) Expand all
681 { 677 {
682 public enum EngineEventType 678 public enum EngineEventType
683 { 679 {
684 CHANGE_ENABLED_STATE, 680 CHANGE_ENABLED_STATE,
685 FORCE_DOWNLOAD, 681 FORCE_DOWNLOAD,
686 DOWNLOAD_FINISHED 682 DOWNLOAD_FINISHED
687 } 683 }
688 684
689 private final EngineEventType type; 685 private final EngineEventType type;
690 686
691 protected EngineEvent(final EngineEventType type) 687 EngineEvent(final EngineEventType type)
692 { 688 {
693 this.type = type; 689 this.type = type;
694 } 690 }
695 691
696 public EngineEventType getType() 692 public EngineEventType getType()
697 { 693 {
698 return this.type; 694 return this.type;
699 } 695 }
700 } 696 }
701 697
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 { 758 {
763 this.downloader.connectivityChanged(); 759 this.downloader.connectivityChanged();
764 } 760 }
765 761
766 public interface SubscriptionUpdateCallback 762 public interface SubscriptionUpdateCallback
767 { 763 {
768 void subscriptionUpdateRequested(boolean enabled); 764 void subscriptionUpdateRequested(boolean enabled);
769 void subscriptionUpdatedApplied(); 765 void subscriptionUpdatedApplied();
770 } 766 }
771 } 767 }
OLDNEW

Powered by Google App Engine
This is Rietveld