summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-10-07 15:30:27 +0200
committerArne Schwabe <arne@rfc2549.org>2021-10-07 15:30:27 +0200
commit706f3d28ab839369d0036299c4ee77d12b776a9a (patch)
treedcfa9d2701790da6841933f169ce48be4ed40ef1
parentaeae23169a270e083b1e560e33c6cfd33981c9f6 (diff)
Fix concurrent access on TrafficHistory lists
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java20
1 files changed, 10 insertions, 10 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java b/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java
index 6ba35066..3d6e6850 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java
@@ -23,9 +23,9 @@ public class TrafficHistory implements Parcelable {
public static final long PERIODS_TO_KEEP = 5;
public static final int TIME_PERIOD_MINTUES = 60 * 1000;
public static final int TIME_PERIOD_HOURS = 3600 * 1000;
- private LinkedList<TrafficDatapoint> trafficHistorySeconds = new LinkedList<>();
- private LinkedList<TrafficDatapoint> trafficHistoryMinutes = new LinkedList<>();
- private LinkedList<TrafficDatapoint> trafficHistoryHours = new LinkedList<>();
+ private final LinkedList<TrafficDatapoint> trafficHistorySeconds = new LinkedList<>();
+ private final LinkedList<TrafficDatapoint> trafficHistoryMinutes = new LinkedList<>();
+ private final LinkedList<TrafficDatapoint> trafficHistoryHours = new LinkedList<>();
private TrafficDatapoint lastSecondUsedForMinute;
private TrafficDatapoint lastMinuteUsedForHours;
@@ -93,16 +93,16 @@ public class TrafficHistory implements Parcelable {
}
- public LinkedList<TrafficDatapoint> getHours() {
- return trafficHistoryHours;
+ public synchronized LinkedList<TrafficDatapoint> getHours() {
+ return new LinkedList<>(trafficHistoryHours);
}
- public LinkedList<TrafficDatapoint> getMinutes() {
- return trafficHistoryMinutes;
+ public synchronized LinkedList<TrafficDatapoint> getMinutes() {
+ return new LinkedList<>(trafficHistoryMinutes);
}
- public LinkedList<TrafficDatapoint> getSeconds() {
- return trafficHistorySeconds;
+ public synchronized LinkedList<TrafficDatapoint> getSeconds() {
+ return new LinkedList<>(trafficHistorySeconds);
}
public static LinkedList<TrafficDatapoint> getDummyList() {
@@ -162,7 +162,7 @@ public class TrafficHistory implements Parcelable {
return diff;
}
- private void addDataPoint(TrafficDatapoint tdp) {
+ private synchronized void addDataPoint(TrafficDatapoint tdp) {
trafficHistorySeconds.add(tdp);
if (lastSecondUsedForMinute == null) {