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);
}
}
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());
}
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;
}
});
}
Aggregations