Search in sources :

Example 1 with DisconnectedError

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);
    }
}
Also used : PairingStatus(sugar.free.sightparser.authlayer.PairingStatus) KeyResponse(sugar.free.sightparser.authlayer.KeyResponse) TimerTask(java.util.TimerTask) VerifyDisplayResponse(sugar.free.sightparser.authlayer.VerifyDisplayResponse) VerifyConfirmRequest(sugar.free.sightparser.authlayer.VerifyConfirmRequest) KeyRequest(sugar.free.sightparser.authlayer.KeyRequest) VerifyDisplayRequest(sugar.free.sightparser.authlayer.VerifyDisplayRequest) DisconnectedError(sugar.free.sightparser.error.DisconnectedError) VerifyConfirmResponse(sugar.free.sightparser.authlayer.VerifyConfirmResponse) ConnectionResponse(sugar.free.sightparser.authlayer.ConnectionResponse) BindMessage(sugar.free.sightparser.applayer.messages.connection.BindMessage)

Example 2 with DisconnectedError

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);
    }
}
Also used : CancelledException(sugar.free.sightparser.error.CancelledException) DisconnectedError(sugar.free.sightparser.error.DisconnectedError) Snackbar(android.support.design.widget.Snackbar)

Example 3 with DisconnectedError

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);
            }
        }
    }
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) DisconnectedError(sugar.free.sightparser.error.DisconnectedError) IOException(java.io.IOException) IOException(java.io.IOException)

Example 4 with DisconnectedError

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);
            }
        }
    }
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) DisconnectedError(sugar.free.sightparser.error.DisconnectedError) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with DisconnectedError

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);
    }
}
Also used : MessageRequest(sugar.free.sightparser.handling.MessageRequest) DisconnectedError(sugar.free.sightparser.error.DisconnectedError)

Aggregations

DisconnectedError (sugar.free.sightparser.error.DisconnectedError)6 CustomEvent (com.crashlytics.android.answers.CustomEvent)2 IOException (java.io.IOException)2 MessageRequest (sugar.free.sightparser.handling.MessageRequest)2 Snackbar (android.support.design.widget.Snackbar)1 ArrayList (java.util.ArrayList)1 TimerTask (java.util.TimerTask)1 Service (sugar.free.sightparser.applayer.descriptors.Service)1 AppLayerMessage (sugar.free.sightparser.applayer.messages.AppLayerMessage)1 ActivateServiceMessage (sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage)1 BindMessage (sugar.free.sightparser.applayer.messages.connection.BindMessage)1 ServiceChallengeMessage (sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage)1 ConnectionResponse (sugar.free.sightparser.authlayer.ConnectionResponse)1 KeyRequest (sugar.free.sightparser.authlayer.KeyRequest)1 KeyResponse (sugar.free.sightparser.authlayer.KeyResponse)1 PairingStatus (sugar.free.sightparser.authlayer.PairingStatus)1 VerifyConfirmRequest (sugar.free.sightparser.authlayer.VerifyConfirmRequest)1 VerifyConfirmResponse (sugar.free.sightparser.authlayer.VerifyConfirmResponse)1 VerifyDisplayRequest (sugar.free.sightparser.authlayer.VerifyDisplayRequest)1 VerifyDisplayResponse (sugar.free.sightparser.authlayer.VerifyDisplayResponse)1