Commit 981685e9 authored by Saikrishna Arcot's avatar Saikrishna Arcot Committed by Albert Vaca Cintora

Avoid NPE when pluginList is still getting updated, by starting the receiving...

Avoid NPE when pluginList is still getting updated, by starting the receiving thread after the pluginList is updated.

Also have the pluginList be initialized to an empty map.

REVIEW: 130140
parent 63f8f86c
......@@ -116,7 +116,10 @@ public class BluetoothLink extends BaseLink {
super(context, deviceId, linkProvider);
this.socket = socket;
this.linkProvider = linkProvider;
receivingThread.start();
}
public void startListening() {
this.receivingThread.start();
}
@Override
......@@ -195,7 +198,8 @@ public class BluetoothLink extends BaseLink {
serverSocket.close();
int idealBufferLength = 4096;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& transferSocket.getMaxReceivePacketSize() > 0) {
idealBufferLength = transferSocket.getMaxReceivePacketSize();
}
byte[] buffer = new byte[idealBufferLength];
......
......@@ -63,11 +63,12 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
Log.i("BluetoothLinkProvider","addLink to "+deviceId);
BluetoothLink oldLink = visibleComputers.get(deviceId);
if (oldLink == link) {
Log.e("KDEConnect", "BluetoothLinkProvider: oldLink == link. This should not happen!");
Log.e("BluetoothLinkProvider", "oldLink == link. This should not happen!");
return;
}
visibleComputers.put(deviceId, link);
connectionAccepted(identityPackage, link);
link.startListening();
if (oldLink != null) {
Log.i("BluetoothLinkProvider","Removing old connection to same device");
oldLink.disconnect();
......
......@@ -144,7 +144,9 @@ public class BackgroundService extends Service {
private void registerLinkProviders() {
linkProviders.add(new LanLinkProvider(this));
// linkProviders.add(new LoopbackLinkProvider(this));
// linkProviders.add(new BluetoothLinkProvider(this));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// linkProviders.add(new BluetoothLinkProvider(this));
}
}
public ArrayList<BaseLinkProvider> getLinkProviders() {
......
......@@ -82,7 +82,7 @@ public class Device implements BaseLink.PackageReceiver {
private List<String> m_supportedPlugins = new ArrayList<>();
private final ConcurrentHashMap<String, Plugin> plugins = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, Plugin> failedPlugins = new ConcurrentHashMap<>();
private Map<String, ArrayList<String>> pluginsByIncomingInterface;
private Map<String, ArrayList<String>> pluginsByIncomingInterface = new HashMap<>();
private final SharedPreferences settings;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment