mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Add NonNull annotations to Link classes
This commit is contained in:
@@ -8,6 +8,7 @@ package org.kde.kdeconnect.Backends;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
@@ -20,18 +21,17 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public abstract class BaseLink {
|
public abstract class BaseLink {
|
||||||
|
|
||||||
protected final Context context;
|
|
||||||
|
|
||||||
public interface PacketReceiver {
|
public interface PacketReceiver {
|
||||||
void onPacketReceived(NetworkPacket np);
|
void onPacketReceived(@NonNull NetworkPacket np);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final Context context;
|
||||||
private final BaseLinkProvider linkProvider;
|
private final BaseLinkProvider linkProvider;
|
||||||
private final String deviceId;
|
private final String deviceId;
|
||||||
private final ArrayList<PacketReceiver> receivers = new ArrayList<>();
|
private final ArrayList<PacketReceiver> receivers = new ArrayList<>();
|
||||||
protected PrivateKey privateKey;
|
protected PrivateKey privateKey;
|
||||||
|
|
||||||
protected BaseLink(Context context, String deviceId, BaseLinkProvider linkProvider) {
|
protected BaseLink(@NonNull Context context, @NonNull String deviceId, @NonNull BaseLinkProvider linkProvider) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.linkProvider = linkProvider;
|
this.linkProvider = linkProvider;
|
||||||
this.deviceId = deviceId;
|
this.deviceId = deviceId;
|
||||||
@@ -39,13 +39,13 @@ public abstract class BaseLink {
|
|||||||
|
|
||||||
/* To be implemented by each link for pairing handlers */
|
/* To be implemented by each link for pairing handlers */
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
public abstract BasePairingHandler getPairingHandler(Device device, BasePairingHandler.PairingHandlerCallback callback);
|
public abstract BasePairingHandler getPairingHandler(@NonNull Device device, @NonNull BasePairingHandler.PairingHandlerCallback callback);
|
||||||
|
|
||||||
public String getDeviceId() {
|
public String getDeviceId() {
|
||||||
return deviceId;
|
return deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrivateKey(PrivateKey key) {
|
public void setPrivateKey(@NonNull PrivateKey key) {
|
||||||
privateKey = key;
|
privateKey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,15 +53,15 @@ public abstract class BaseLink {
|
|||||||
return linkProvider;
|
return linkProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPacketReceiver(PacketReceiver pr) {
|
public void addPacketReceiver(@NonNull PacketReceiver pr) {
|
||||||
receivers.add(pr);
|
receivers.add(pr);
|
||||||
}
|
}
|
||||||
public void removePacketReceiver(PacketReceiver pr) {
|
public void removePacketReceiver(@NonNull PacketReceiver pr) {
|
||||||
receivers.remove(pr);
|
receivers.remove(pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Should be called from a background thread listening for packets
|
//Should be called from a background thread listening for packets
|
||||||
protected void packetReceived(NetworkPacket np) {
|
protected void packetReceived(@NonNull NetworkPacket np) {
|
||||||
for(PacketReceiver pr : receivers) {
|
for(PacketReceiver pr : receivers) {
|
||||||
pr.onPacketReceived(np);
|
pr.onPacketReceived(np);
|
||||||
}
|
}
|
||||||
@@ -73,5 +73,5 @@ public abstract class BaseLink {
|
|||||||
|
|
||||||
//TO OVERRIDE, should be sync. If sendPayloadFromSameThread is false, it should only block to send the packet but start a separate thread to send the payload.
|
//TO OVERRIDE, should be sync. If sendPayloadFromSameThread is false, it should only block to send the packet but start a separate thread to send the payload.
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public abstract boolean sendPacket(NetworkPacket np, Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) throws IOException;
|
public abstract boolean sendPacket(@NonNull NetworkPacket np, @NonNull Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) throws IOException;
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@@ -137,7 +138,7 @@ public class BluetoothLink extends BaseLink {
|
|||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
@Override
|
@Override
|
||||||
public boolean sendPacket(NetworkPacket np, Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) throws IOException {
|
public boolean sendPacket(@NonNull NetworkPacket np, @NonNull Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) throws IOException {
|
||||||
// sendPayloadFromSameThread is ignored, we always send from the same thread!
|
// sendPayloadFromSameThread is ignored, we always send from the same thread!
|
||||||
|
|
||||||
/*if (!isConnected()) {
|
/*if (!isConnected()) {
|
||||||
|
@@ -9,6 +9,7 @@ package org.kde.kdeconnect.Backends.LanBackend;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -131,7 +132,7 @@ public class LanLink extends BaseLink {
|
|||||||
//Blocking, do not call from main thread
|
//Blocking, do not call from main thread
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
@Override
|
@Override
|
||||||
public boolean sendPacket(NetworkPacket np, final Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
|
public boolean sendPacket(@NonNull NetworkPacket np, @NonNull final Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
|
||||||
if (socket == null) {
|
if (socket == null) {
|
||||||
Log.e("KDE/sendPacket", "Not yet connected");
|
Log.e("KDE/sendPacket", "Not yet connected");
|
||||||
callback.onFailure(new NotYetConnectedException());
|
callback.onFailure(new NotYetConnectedException());
|
||||||
|
@@ -8,6 +8,7 @@ package org.kde.kdeconnect.Backends.LoopbackBackend;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import org.kde.kdeconnect.Backends.BaseLink;
|
import org.kde.kdeconnect.Backends.BaseLink;
|
||||||
@@ -34,7 +35,7 @@ public class LoopbackLink extends BaseLink {
|
|||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
@Override
|
@Override
|
||||||
public boolean sendPacket(NetworkPacket in, Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
|
public boolean sendPacket(@NonNull NetworkPacket in, @NonNull Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
|
||||||
packetReceived(in);
|
packetReceived(in);
|
||||||
if (in.hasPayload()) {
|
if (in.hasPayload()) {
|
||||||
callback.onPayloadProgressChanged(0);
|
callback.onPayloadProgressChanged(0);
|
||||||
|
@@ -93,7 +93,7 @@ public class Device implements BaseLink.PacketReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface PluginsChangedListener {
|
public interface PluginsChangedListener {
|
||||||
void onPluginsChanged(Device device);
|
void onPluginsChanged(@NonNull Device device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PairStatus {
|
public enum PairStatus {
|
||||||
@@ -626,22 +626,22 @@ public class Device implements BaseLink.PacketReceiver {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
public void sendPacket(NetworkPacket np) {
|
public void sendPacket(@NonNull NetworkPacket np) {
|
||||||
sendPacket(np, -1, defaultCallback);
|
sendPacket(np, -1, defaultCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
public void sendPacket(NetworkPacket np, int replaceID) {
|
public void sendPacket(@NonNull NetworkPacket np, int replaceID) {
|
||||||
sendPacket(np, replaceID, defaultCallback);
|
sendPacket(np, replaceID, defaultCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public boolean sendPacketBlocking(NetworkPacket np) {
|
public boolean sendPacketBlocking(@NonNull NetworkPacket np) {
|
||||||
return sendPacketBlocking(np, defaultCallback);
|
return sendPacketBlocking(np, defaultCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
public void sendPacket(final NetworkPacket np, final SendPacketStatusCallback callback) {
|
public void sendPacket(@NonNull final NetworkPacket np, @NonNull final SendPacketStatusCallback callback) {
|
||||||
sendPacket(np, -1, callback);
|
sendPacket(np, -1, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,7 +652,7 @@ public class Device implements BaseLink.PacketReceiver {
|
|||||||
* @param callback A callback for success/failure
|
* @param callback A callback for success/failure
|
||||||
*/
|
*/
|
||||||
@AnyThread
|
@AnyThread
|
||||||
public void sendPacket(final NetworkPacket np, int replaceID, final SendPacketStatusCallback callback) {
|
public void sendPacket(@NonNull final NetworkPacket np, int replaceID, @NonNull final SendPacketStatusCallback callback) {
|
||||||
if (packetQueue == null) {
|
if (packetQueue == null) {
|
||||||
callback.onFailure(new Exception("Device disconnected!"));
|
callback.onFailure(new Exception("Device disconnected!"));
|
||||||
} else {
|
} else {
|
||||||
@@ -675,7 +675,7 @@ public class Device implements BaseLink.PacketReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public boolean sendPacketBlocking(final NetworkPacket np, final SendPacketStatusCallback callback) {
|
public boolean sendPacketBlocking(@NonNull final NetworkPacket np, @NonNull final SendPacketStatusCallback callback) {
|
||||||
return sendPacketBlocking(np, callback, false);
|
return sendPacketBlocking(np, callback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,7 +691,7 @@ public class Device implements BaseLink.PacketReceiver {
|
|||||||
* @see BaseLink#sendPacket(NetworkPacket, SendPacketStatusCallback)
|
* @see BaseLink#sendPacket(NetworkPacket, SendPacketStatusCallback)
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public boolean sendPacketBlocking(final NetworkPacket np, final SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
|
public boolean sendPacketBlocking(@NonNull final NetworkPacket np, @NonNull final SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (!m_outgoingCapabilities.contains(np.getType()) && !NetworkPacket.protocolPacketTypes.contains(np.getType())) {
|
if (!m_outgoingCapabilities.contains(np.getType()) && !NetworkPacket.protocolPacketTypes.contains(np.getType())) {
|
||||||
|
Reference in New Issue
Block a user