Search in sources :

Example 1 with ReminderUpdateEvent

use of org.thoughtcrime.securesms.events.ReminderUpdateEvent in project Signal-Android by WhisperSystems.

the class ServiceOutageDetectionJob method onRun.

@Override
public void onRun() throws RetryLaterException {
    Log.i(TAG, "onRun()");
    long timeSinceLastCheck = System.currentTimeMillis() - TextSecurePreferences.getLastOutageCheckTime(context);
    if (timeSinceLastCheck < CHECK_TIME) {
        Log.w(TAG, "Skipping service outage check. Too soon.");
        return;
    }
    try {
        InetAddress address = InetAddress.getByName(BuildConfig.SIGNAL_SERVICE_STATUS_URL);
        Log.i(TAG, "Received outage check address: " + address.getHostAddress());
        if (IP_SUCCESS.equals(address.getHostAddress())) {
            Log.i(TAG, "Service is available.");
            TextSecurePreferences.setServiceOutage(context, false);
        } else if (IP_FAILURE.equals(address.getHostAddress())) {
            Log.w(TAG, "Service is down.");
            TextSecurePreferences.setServiceOutage(context, true);
        } else {
            Log.w(TAG, "Service status check returned an unrecognized IP address. Could be a weird network state. Prompting retry.");
            throw new RetryLaterException(new Exception("Unrecognized service outage IP address."));
        }
        TextSecurePreferences.setLastOutageCheckTime(context, System.currentTimeMillis());
        EventBus.getDefault().post(new ReminderUpdateEvent());
    } catch (UnknownHostException e) {
        throw new RetryLaterException(e);
    }
}
Also used : ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent) UnknownHostException(java.net.UnknownHostException) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) InetAddress(java.net.InetAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) UnknownHostException(java.net.UnknownHostException)

Example 2 with ReminderUpdateEvent

use of org.thoughtcrime.securesms.events.ReminderUpdateEvent in project Signal-Android by WhisperSystems.

the class ServiceOutageDetectionJob method onFailure.

@Override
public void onFailure() {
    Log.i(TAG, "Service status check could not complete. Assuming success to avoid false positives due to bad network.");
    TextSecurePreferences.setServiceOutage(context, false);
    TextSecurePreferences.setLastOutageCheckTime(context, System.currentTimeMillis());
    EventBus.getDefault().post(new ReminderUpdateEvent());
}
Also used : ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent)

Example 3 with ReminderUpdateEvent

use of org.thoughtcrime.securesms.events.ReminderUpdateEvent in project Signal-Android by WhisperSystems.

the class SignalWebSocketHealthMonitor method onStateChange.

private void onStateChange(WebSocketConnectionState connectionState, HealthState healthState) {
    executor.execute(() -> {
        switch(connectionState) {
            case CONNECTED:
                TextSecurePreferences.setUnauthorizedReceived(context, false);
                break;
            case AUTHENTICATION_FAILED:
                TextSecurePreferences.setUnauthorizedReceived(context, true);
                EventBus.getDefault().post(new ReminderUpdateEvent());
                break;
            case FAILED:
                if (SignalStore.proxy().isProxyEnabled()) {
                    Log.w(TAG, "Encountered an error while we had a proxy set! Terminating the connection to prevent retry spam.");
                    ApplicationDependencies.closeConnections();
                }
                break;
        }
        healthState.needsKeepAlive = connectionState == WebSocketConnectionState.CONNECTED;
        if (keepAliveSender == null && isKeepAliveNecessary()) {
            keepAliveSender = new KeepAliveSender();
            keepAliveSender.start();
        } else if (keepAliveSender != null && !isKeepAliveNecessary()) {
            keepAliveSender.shutdown();
            keepAliveSender = null;
        }
    });
}
Also used : ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent)

Aggregations

ReminderUpdateEvent (org.thoughtcrime.securesms.events.ReminderUpdateEvent)3 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)1