mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 21:27:40 +00:00
Fixes to the new sendPackage logic
This commit is contained in:
parent
bda6e3cb7f
commit
3d415c5959
@ -60,6 +60,7 @@ public class LanLink extends BaseLink {
|
||||
//Blocking, do not call from main thread
|
||||
private void sendPackageInternal(NetworkPackage np, final Device.SendPackageStatusCallback callback, PublicKey key) {
|
||||
if (session == null) {
|
||||
Log.e("sendPackage", "Not yet connected");
|
||||
callback.sendFailure(new NotYetConnectedException());
|
||||
return;
|
||||
}
|
||||
@ -86,6 +87,7 @@ public class LanLink extends BaseLink {
|
||||
WriteFuture future = session.write(np.serialize());
|
||||
future.awaitUninterruptibly();
|
||||
if (!future.isWritten()) {
|
||||
Log.e("sendPackage", "!future.isWritten()");
|
||||
callback.sendFailure(future.getException());
|
||||
return;
|
||||
}
|
||||
@ -99,6 +101,7 @@ public class LanLink extends BaseLink {
|
||||
timeout.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.e("sendPackage","Timeout");
|
||||
try { server.close(); } catch (Exception e) { }
|
||||
callback.sendFailure(new TimeoutException("Timed out waiting for other end to establish a connection to receive the payload."));
|
||||
}
|
||||
@ -122,6 +125,7 @@ public class LanLink extends BaseLink {
|
||||
}
|
||||
Log.i("LanLink", "Finished sending payload");
|
||||
} catch (Exception e) {
|
||||
Log.e("sendPackage", "Exception: "+e);
|
||||
callback.sendFailure(e);
|
||||
return;
|
||||
} finally {
|
||||
@ -135,7 +139,9 @@ public class LanLink extends BaseLink {
|
||||
callback.sendSuccess();
|
||||
|
||||
} catch (Exception e) {
|
||||
callback.sendFailure(e);
|
||||
if (callback != null) {
|
||||
callback.sendFailure(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
||||
import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
import org.kde.kdeconnect.UserInterface.CustomDevicesActivity;
|
||||
|
||||
@ -66,15 +67,26 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
@Override
|
||||
public void sessionClosed(IoSession session) throws Exception {
|
||||
|
||||
LanLink brokenLink = nioSessions.get(session.getId());
|
||||
final LanLink brokenLink = nioSessions.get(session.getId());
|
||||
if (brokenLink != null) {
|
||||
nioSessions.remove(session.getId());
|
||||
connectionLost(brokenLink);
|
||||
brokenLink.disconnect();
|
||||
String deviceId = brokenLink.getDeviceId();
|
||||
if (visibleComputers.get(deviceId) == brokenLink) {
|
||||
visibleComputers.remove(deviceId);
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//Wait a bit before emiting connectionLost, in case the same device re-appears
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) { }
|
||||
connectionLost(brokenLink);
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -169,10 +181,19 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
@Override
|
||||
public void run() {
|
||||
NetworkPackage np2 = NetworkPackage.createIdentityPackage(context);
|
||||
link.sendPackage(np2,null);
|
||||
link.sendPackage(np2,new Device.SendPackageStatusCallback() {
|
||||
@Override
|
||||
protected void onSuccess() {
|
||||
nioSessions.put(session.getId(), link);
|
||||
addLink(identityPackage, link);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFailure(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
nioSessions.put(session.getId(), link);
|
||||
addLink(identityPackage, link);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class LoopbackLink extends BaseLink {
|
||||
String s = in.serialize();
|
||||
NetworkPackage out= NetworkPackage.unserialize(s);
|
||||
if (key != null) {
|
||||
out.decrypt(privateKey);
|
||||
out = out.decrypt(privateKey);
|
||||
}
|
||||
packageReceived(out);
|
||||
if (in.hasPayload()) {
|
||||
|
@ -544,7 +544,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
}
|
||||
|
||||
if (!callback.success) {
|
||||
Log.e("sendPackage", "No device link could send the package. package lost!");
|
||||
Log.e("sendPackage", "No device link (of "+mLinks.size()+" available) could send the package. Package lost!");
|
||||
backtrace.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -215,6 +215,7 @@ public class NetworkPackage {
|
||||
|
||||
NetworkPackage encrypted = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_ENCRYPTED);
|
||||
encrypted.set("data", chunks);
|
||||
encrypted.setPayload(mPayload, mPayloadSize);
|
||||
return encrypted;
|
||||
|
||||
}
|
||||
@ -233,7 +234,9 @@ public class NetworkPackage {
|
||||
decryptedJson += decryptedChunk;
|
||||
}
|
||||
|
||||
return unserialize(decryptedJson);
|
||||
NetworkPackage decrypted = unserialize(decryptedJson);
|
||||
decrypted.setPayload(mPayload, mPayloadSize);
|
||||
return decrypted;
|
||||
}
|
||||
|
||||
static public NetworkPackage createIdentityPackage(Context context) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user