use of sugar.free.sightparser.error.DisconnectedError in project SightRemote by TebbeUbben.
the class PairingEstablisher method onInboundMessage.
@Override
public void onInboundMessage(Object message, final Pipeline pipeline) throws Exception {
if (message instanceof ConnectionResponse) {
KeyRequest keyRequest = new KeyRequest();
keyRequest.setRandomBytes(getRandomBytes());
keyRequest.setPreMasterKey(keyToBytes(getKeyPair().getPublicKey()));
pipeline.setStatus(Status.EXCHANGING_KEYS);
pipeline.send(keyRequest);
} else if (message instanceof KeyResponse) {
KeyResponse keyResponse = (KeyResponse) message;
pipeline.setDerivedKeys(Cryptograph.deriveKeys(Cryptograph.decryptRSA(getKeyPair().getPrivateKey(), keyResponse.getPreMasterSecret()), getRandomBytes(), keyResponse.getRandomData()));
VerifyDisplayRequest verifyDisplayRequest = new VerifyDisplayRequest();
pipeline.setStatus(Status.WAITING_FOR_CODE_CONFIRMATION);
pipeline.send(verifyDisplayRequest);
} else if (message instanceof VerifyDisplayResponse) {
VerifyConfirmRequest verifyConfirmRequest = new VerifyConfirmRequest();
verifyConfirmRequest.setPairingStatus(PairingStatus.CONFIRMED);
pipeline.send(verifyConfirmRequest);
} else if (message instanceof VerifyConfirmResponse) {
VerifyConfirmResponse verifyConfirmResponse = (VerifyConfirmResponse) message;
PairingStatus pairingStatus = verifyConfirmResponse.getPairingStatus();
if (pairingStatus == PairingStatus.REJECTED) {
pipeline.setStatus(Status.CODE_REJECTED);
throw new DisconnectedError();
} else if (pairingStatus == PairingStatus.CONFIRMED) {
pipeline.setStatus(Status.APP_BINDING);
pipeline.send(new BindMessage());
} else if (pairingStatus == PairingStatus.PENDING) {
timer.schedule(new TimerTask() {
@Override
public void run() {
VerifyConfirmRequest verifyConfirmRequest = new VerifyConfirmRequest();
verifyConfirmRequest.setPairingStatus(PairingStatus.CONFIRMED);
pipeline.send(verifyConfirmRequest);
}
}, 2000);
}
} else if (message instanceof BindMessage) {
pipeline.setStatus(Status.CONNECTED);
}
}
use of sugar.free.sightparser.error.DisconnectedError in project SightRemote by TebbeUbben.
the class StatusActivity method onError.
@Override
public void onError(Exception e) {
if (!(e instanceof CancelledException) && !(e instanceof DisconnectedError)) {
Snackbar snackbar = Snackbar.make(getRootView(), R.string.error, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.retry, view -> taskRunnerRunnable.run());
showSnackbar(snackbar);
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
}
}
use of sugar.free.sightparser.error.DisconnectedError in project SightRemote by TebbeUbben.
the class Pipeline method send.
public void send(Object message) {
if (message instanceof Exception) {
Exception exception = (Exception) message;
Log.d("SightService", "EXCEPTION: " + exception.getClass().getName() + ": " + exception.getMessage());
if (!(exception instanceof DisconnectedError))
Answers.getInstance().logCustom(new CustomEvent("Exception In Pipeline").putCustomAttribute("Message", exception.getClass().getSimpleName() + ": " + exception.getMessage()));
}
for (Handler handler : handlers) {
if (handler instanceof OutboundHandler) {
OutboundHandler outboundHandler = (OutboundHandler) handler;
try {
outboundHandler.onOutboundMessage(message, this);
} catch (IOException e) {
setStatus(Status.DISCONNECTED);
} catch (Exception e) {
send(e);
}
}
}
}
use of sugar.free.sightparser.error.DisconnectedError in project SightRemote by TebbeUbben.
the class Pipeline method receive.
public void receive(Object message) {
if (message instanceof Exception) {
Exception exception = (Exception) message;
Log.d("SightService", "EXCEPTION: " + exception.getClass().getName() + ": " + exception.getMessage());
if (!(exception instanceof DisconnectedError))
Answers.getInstance().logCustom(new CustomEvent("Exception In Pipeline").putCustomAttribute("Message", exception.getClass().getSimpleName() + ": " + exception.getMessage()));
}
for (Handler handler : handlers) {
if (handler instanceof InboundHandler) {
InboundHandler inboundHandler = (InboundHandler) handler;
try {
inboundHandler.onInboundMessage(message, this);
} catch (IOException e) {
setStatus(Status.DISCONNECTED);
} catch (Exception e) {
receive(e);
}
}
}
}
use of sugar.free.sightparser.error.DisconnectedError in project SightRemote by TebbeUbben.
the class RequestWorker method onOutboundMessage.
@Override
public void onOutboundMessage(Object message, Pipeline pipeline) throws Exception {
synchronized (messageRequests) {
if (messageRequests.size() == 0)
return;
if (message instanceof DisconnectedError) {
for (MessageRequest messageRequest : messageRequests) {
sendError(messageRequest, (Exception) message);
messageRequests.remove(messageRequest);
}
return;
}
MessageRequest messageRequest = messageRequests.get(0);
if (messageRequest.getMessageStatus() == MessageStatus.PENDING && message instanceof Exception)
sendError(messageRequest, (Exception) message);
}
}
Aggregations