Skip to content

Commit

Permalink
Fix possible ConcurrentModificationException
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Jan 8, 2025
1 parent b04f054 commit feaa468
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.router.RouteSegmentResult;
import net.osmand.util.Algorithms;
import net.osmand.util.CollectionUtils;
import net.osmand.util.MapUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -140,8 +141,8 @@ public interface OsmAndCompassListener {

private final GPSInfo gpsInfo = new GPSInfo();

private final List<OsmAndLocationListener> locationListeners = new ArrayList<>();
private final List<OsmAndCompassListener> compassListeners = new ArrayList<>();
private List<OsmAndLocationListener> locationListeners = new ArrayList<>();
private List<OsmAndCompassListener> compassListeners = new ArrayList<>();
private GnssStatus.Callback gpsStatusListener;
private final float[] mRotationM = new float[9];

Expand Down Expand Up @@ -246,22 +247,22 @@ public void updateScreenOrientation(int orientation) {

public void addLocationListener(@NonNull OsmAndLocationListener listener) {
if (!locationListeners.contains(listener)) {
locationListeners.add(listener);
locationListeners = CollectionUtils.addToList(locationListeners, listener);
}
}

public void removeLocationListener(@NonNull OsmAndLocationListener listener) {
locationListeners.remove(listener);
locationListeners = CollectionUtils.removeFromList(locationListeners, listener);
}

public void addCompassListener(@NonNull OsmAndCompassListener listener) {
if (!compassListeners.contains(listener)) {
compassListeners.add(listener);
compassListeners = CollectionUtils.addToList(compassListeners, listener);
}
}

public void removeCompassListener(@NonNull OsmAndCompassListener listener) {
compassListeners.remove(listener);
compassListeners = CollectionUtils.removeFromList(compassListeners, listener);
}

private void addLocationSourceListener() {
Expand Down Expand Up @@ -488,9 +489,9 @@ private float getAngle(float sinA, float cosA) {
return MapUtils.unifyRotationTo360((float) (Math.atan2(sinA, cosA) * 180 / Math.PI));
}

private void updateLocation(net.osmand.Location loc) {
for (OsmAndLocationListener l : locationListeners) {
l.updateLocation(loc);
private void updateLocation(net.osmand.Location location) {
for (OsmAndLocationListener listener : locationListeners) {
listener.updateLocation(location);
}
}

Expand Down

0 comments on commit feaa468

Please sign in to comment.