mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 14:45:08 +00:00
Fixed some potential concurrent modification exceptions
# Conflicts: # src/org/kde/kdeconnect/Device.java
This commit is contained in:
@@ -23,10 +23,11 @@ package org.kde.kdeconnect.Backends;
|
|||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public abstract class BaseLinkProvider {
|
public abstract class BaseLinkProvider {
|
||||||
|
|
||||||
private final ArrayList<ConnectionReceiver> connectionReceivers = new ArrayList<>();
|
private final CopyOnWriteArrayList<ConnectionReceiver> connectionReceivers = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
public interface ConnectionReceiver {
|
public interface ConnectionReceiver {
|
||||||
void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
||||||
|
@@ -53,6 +53,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class Device implements BaseLink.PackageReceiver {
|
public class Device implements BaseLink.PackageReceiver {
|
||||||
|
|
||||||
@@ -64,6 +65,37 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
private int notificationId;
|
private int notificationId;
|
||||||
private int protocolVersion;
|
private int protocolVersion;
|
||||||
|
|
||||||
|
private DeviceType deviceType;
|
||||||
|
private PairStatus pairStatus;
|
||||||
|
private final CopyOnWriteArrayList<PairingCallback> pairingCallback = new CopyOnWriteArrayList<>();
|
||||||
|
private Timer pairingTimer;
|
||||||
|
|
||||||
|
private final CopyOnWriteArrayList<BaseLink> links = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
private ArrayList<String> incomingCapabilities;
|
||||||
|
private ArrayList<String> outgoingCapabilities;
|
||||||
|
|
||||||
|
private final HashMap<String, Plugin> plugins = new HashMap<>();
|
||||||
|
private final HashMap<String, Plugin> failedPlugins = new HashMap<>();
|
||||||
|
|
||||||
|
private ArrayList<String> unsupportedPlugins = new ArrayList<>();
|
||||||
|
private HashSet<String> supportedIncomingInterfaces = new HashSet<>();
|
||||||
|
|
||||||
|
HashMap<String, ArrayList<String>> pluginsByIncomingInterface;
|
||||||
|
HashMap<String, ArrayList<String>> pluginsByOutgoingInterface;
|
||||||
|
|
||||||
|
private final SharedPreferences settings;
|
||||||
|
|
||||||
|
public ArrayList<String> getUnsupportedPlugins() {
|
||||||
|
return unsupportedPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final CopyOnWriteArrayList<PluginsChangedListener> pluginsChangedListeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
public interface PluginsChangedListener {
|
||||||
|
void onPluginsChanged(Device device);
|
||||||
|
}
|
||||||
|
|
||||||
public enum PairStatus {
|
public enum PairStatus {
|
||||||
NotPaired,
|
NotPaired,
|
||||||
Requested,
|
Requested,
|
||||||
@@ -616,8 +648,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
||||||
|
|
||||||
//Make a copy to avoid concurrent modification exception if the original list changes
|
//Make a copy to avoid concurrent modification exception if the original list changes
|
||||||
ArrayList<BaseLink> mLinks = new ArrayList<>(links);
|
for (final BaseLink link : links) {
|
||||||
for (final BaseLink link : mLinks) {
|
|
||||||
if (link == null) continue; //Since we made a copy, maybe somebody destroyed the link in the meanwhile
|
if (link == null) continue; //Since we made a copy, maybe somebody destroyed the link in the meanwhile
|
||||||
if (useEncryption) {
|
if (useEncryption) {
|
||||||
link.sendPackageEncrypted(np, callback, publicKey);
|
link.sendPackageEncrypted(np, callback, publicKey);
|
||||||
@@ -628,7 +659,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!callback.success) {
|
if (!callback.success) {
|
||||||
Log.e("KDE/sendPackage", "No device link (of "+mLinks.size()+" available) could send the package "+np.getType()+". Package lost!");
|
Log.e("KDE/sendPackage", "No device link (of "+links.size()+" available) could send the package. Package "+np.getType()+" to " + name + " lost!");
|
||||||
backtrace.printStackTrace();
|
backtrace.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,12 +816,6 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
return failedPlugins;
|
return failedPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface PluginsChangedListener {
|
|
||||||
void onPluginsChanged(Device device);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ArrayList<PluginsChangedListener> pluginsChangedListeners = new ArrayList<>();
|
|
||||||
|
|
||||||
public void addPluginsChangedListener(PluginsChangedListener listener) {
|
public void addPluginsChangedListener(PluginsChangedListener listener) {
|
||||||
pluginsChangedListeners.add(listener);
|
pluginsChangedListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user