mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Added payload to NetworkPackage
Matching KDED's implementation
This commit is contained in:
@@ -11,6 +11,10 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
@@ -35,6 +39,8 @@ public class NetworkPackage {
|
|||||||
private long mId;
|
private long mId;
|
||||||
private String mType;
|
private String mType;
|
||||||
private JSONObject mBody;
|
private JSONObject mBody;
|
||||||
|
private InputStream mPayload;
|
||||||
|
private JSONObject mPayloadTransferInfo;
|
||||||
|
|
||||||
private NetworkPackage() {
|
private NetworkPackage() {
|
||||||
}
|
}
|
||||||
@@ -43,6 +49,7 @@ public class NetworkPackage {
|
|||||||
mId = System.currentTimeMillis();
|
mId = System.currentTimeMillis();
|
||||||
mType = type;
|
mType = type;
|
||||||
mBody = new JSONObject();
|
mBody = new JSONObject();
|
||||||
|
mPayloadTransferInfo = new JSONObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
@@ -116,14 +123,17 @@ public class NetworkPackage {
|
|||||||
np.mId = jo.getLong("id");
|
np.mId = jo.getLong("id");
|
||||||
np.mType = jo.getString("type");
|
np.mType = jo.getString("type");
|
||||||
np.mBody = jo.getJSONObject("body");
|
np.mBody = jo.getJSONObject("body");
|
||||||
|
if (jo.has("payloadTransferInfo")) {
|
||||||
|
np.mPayloadTransferInfo = jo.getJSONObject("payloadTransferInfo");
|
||||||
|
} else {
|
||||||
|
np.mPayloadTransferInfo = new JSONObject();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return np;
|
return np;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void encrypt(PublicKey publicKey) throws Exception {
|
public void encrypt(PublicKey publicKey) throws Exception {
|
||||||
|
|
||||||
String serialized = serialize();
|
String serialized = serialize();
|
||||||
@@ -177,7 +187,6 @@ public class NetworkPackage {
|
|||||||
return unserialize(decryptedJson);
|
return unserialize(decryptedJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public NetworkPackage createIdentityPackage(Context context) {
|
static public NetworkPackage createIdentityPackage(Context context) {
|
||||||
|
|
||||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_IDENTITY);
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_IDENTITY);
|
||||||
@@ -208,4 +217,24 @@ public class NetworkPackage {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPayload(byte[] data) {
|
||||||
|
mPayload = new ByteArrayInputStream(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayload(InputStream stream) {
|
||||||
|
mPayload = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getPayload() {
|
||||||
|
return mPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPayload() {
|
||||||
|
return (mPayload == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPayloadTransferInfo() {
|
||||||
|
return (mPayloadTransferInfo.length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user