mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 05:37:43 +00:00
Add NonNull annotations to Link classes
This commit is contained in:
parent
f172ffd129
commit
62cf2d6b44
@ -8,6 +8,7 @@ package org.kde.kdeconnect.Backends;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.kde.kdeconnect.Device;
|
||||
@ -20,18 +21,17 @@ import java.util.ArrayList;
|
||||
|
||||
public abstract class BaseLink {
|
||||
|
||||
protected final Context context;
|
||||
|
||||
public interface PacketReceiver {
|
||||
void onPacketReceived(NetworkPacket np);
|
||||
void onPacketReceived(@NonNull NetworkPacket np);
|
||||
}
|
||||
|
||||
protected final Context context;
|
||||
private final BaseLinkProvider linkProvider;
|
||||
private final String deviceId;
|
||||
private final ArrayList<PacketReceiver> receivers = new ArrayList<>();
|
||||
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.linkProvider = linkProvider;
|
||||
this.deviceId = deviceId;
|
||||
@ -39,13 +39,13 @@ public abstract class BaseLink {
|
||||
|
||||
/* To be implemented by each link for pairing handlers */
|
||||
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() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setPrivateKey(PrivateKey key) {
|
||||
public void setPrivateKey(@NonNull PrivateKey key) {
|
||||
privateKey = key;
|
||||
}
|
||||
|
||||
@ -53,15 +53,15 @@ public abstract class BaseLink {
|
||||
return linkProvider;
|
||||
}
|
||||
|
||||
public void addPacketReceiver(PacketReceiver pr) {
|
||||
public void addPacketReceiver(@NonNull PacketReceiver pr) {
|
||||
receivers.add(pr);
|
||||
}
|
||||
public void removePacketReceiver(PacketReceiver pr) {
|
||||
public void removePacketReceiver(@NonNull PacketReceiver pr) {
|
||||
receivers.remove(pr);
|
||||
}
|
||||
|
||||
//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) {
|
||||
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.
|
||||
@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.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -137,7 +138,7 @@ public class BluetoothLink extends BaseLink {
|
||||
|
||||
@WorkerThread
|
||||
@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!
|
||||
|
||||
/*if (!isConnected()) {
|
||||
|
@ -9,6 +9,7 @@ package org.kde.kdeconnect.Backends.LanBackend;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@ -131,7 +132,7 @@ public class LanLink extends BaseLink {
|
||||
//Blocking, do not call from main thread
|
||||
@WorkerThread
|
||||
@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) {
|
||||
Log.e("KDE/sendPacket", "Not yet connected");
|
||||
callback.onFailure(new NotYetConnectedException());
|
||||
|
@ -8,6 +8,7 @@ package org.kde.kdeconnect.Backends.LoopbackBackend;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.kde.kdeconnect.Backends.BaseLink;
|
||||
@ -34,7 +35,7 @@ public class LoopbackLink extends BaseLink {
|
||||
|
||||
@WorkerThread
|
||||
@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);
|
||||
if (in.hasPayload()) {
|
||||
callback.onPayloadProgressChanged(0);
|
||||
|
@ -93,7 +93,7 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
}
|
||||
|
||||
public interface PluginsChangedListener {
|
||||
void onPluginsChanged(Device device);
|
||||
void onPluginsChanged(@NonNull Device device);
|
||||
}
|
||||
|
||||
public enum PairStatus {
|
||||
@ -626,22 +626,22 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
};
|
||||
|
||||
@AnyThread
|
||||
public void sendPacket(NetworkPacket np) {
|
||||
public void sendPacket(@NonNull NetworkPacket np) {
|
||||
sendPacket(np, -1, defaultCallback);
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
public void sendPacket(NetworkPacket np, int replaceID) {
|
||||
public void sendPacket(@NonNull NetworkPacket np, int replaceID) {
|
||||
sendPacket(np, replaceID, defaultCallback);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public boolean sendPacketBlocking(NetworkPacket np) {
|
||||
public boolean sendPacketBlocking(@NonNull NetworkPacket np) {
|
||||
return sendPacketBlocking(np, defaultCallback);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@ -652,7 +652,7 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
* @param callback A callback for success/failure
|
||||
*/
|
||||
@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) {
|
||||
callback.onFailure(new Exception("Device disconnected!"));
|
||||
} else {
|
||||
@ -675,7 +675,7 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@ -691,7 +691,7 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
* @see BaseLink#sendPacket(NetworkPacket, SendPacketStatusCallback)
|
||||
*/
|
||||
@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())) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user