Search in sources :

Example 21 with PushNetworkException

use of org.whispersystems.signalservice.api.push.exceptions.PushNetworkException in project Signal-Android by WhisperSystems.

the class PushNotificationReceiveJob method onRun.

@Override
public void onRun() throws IOException {
    BackgroundMessageRetriever retriever = ApplicationDependencies.getBackgroundMessageRetriever();
    boolean result = retriever.retrieveMessages(context, foregroundServiceDelayMs, new RestStrategy());
    if (result) {
        Log.i(TAG, "Successfully pulled messages.");
    } else {
        throw new PushNetworkException("Failed to pull messages.");
    }
}
Also used : PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) BackgroundMessageRetriever(org.thoughtcrime.securesms.messages.BackgroundMessageRetriever) RestStrategy(org.thoughtcrime.securesms.messages.RestStrategy)

Example 22 with PushNetworkException

use of org.whispersystems.signalservice.api.push.exceptions.PushNetworkException in project Signal-Android by WhisperSystems.

the class RecaptchaProofActivity method handleToken.

private void handleToken(@NonNull String token) {
    SimpleProgressDialog.DismissibleDialog dialog = SimpleProgressDialog.showDelayed(this, 1000, 500);
    SimpleTask.run(() -> {
        String challenge = SignalStore.rateLimit().getChallenge();
        if (Util.isEmpty(challenge)) {
            Log.w(TAG, "No challenge available?");
            return new TokenResult(true, false);
        }
        try {
            for (int i = 0; i < 3; i++) {
                try {
                    ApplicationDependencies.getSignalServiceAccountManager().submitRateLimitRecaptchaChallenge(challenge, token);
                    RateLimitUtil.retryAllRateLimitedMessages(this);
                    Log.i(TAG, "Successfully completed reCAPTCHA.");
                    return new TokenResult(true, true);
                } catch (PushNetworkException e) {
                    Log.w(TAG, "Network error during submission. Retrying.", e);
                }
            }
        } catch (IOException e) {
            Log.w(TAG, "Terminal failure during submission. Will clear state. May get a 428 later.", e);
            return new TokenResult(true, false);
        }
        return new TokenResult(false, false);
    }, result -> {
        dialog.dismiss();
        if (result.clearState) {
            Log.i(TAG, "Considering the response sufficient to clear the slate.");
            SignalStore.rateLimit().onProofAccepted();
        }
        if (!result.success) {
            Log.w(TAG, "Response was not a true success.");
            Toast.makeText(this, R.string.RecaptchaProofActivity_failed_to_submit, Toast.LENGTH_LONG).show();
        }
        finish();
    });
}
Also used : PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Aggregations

PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)22 IOException (java.io.IOException)19 Response (okhttp3.Response)13 NonSuccessfulResponseCodeException (org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException)13 Call (okhttp3.Call)12 OkHttpClient (okhttp3.OkHttpClient)11 Request (okhttp3.Request)11 ProfileKeyCredentialResponse (org.signal.zkgroup.profiles.ProfileKeyCredentialResponse)10 ReceiptCredentialResponse (org.signal.zkgroup.receipts.ReceiptCredentialResponse)10 CredentialResponse (org.whispersystems.signalservice.api.groupsv2.CredentialResponse)10 CallingResponse (org.whispersystems.signalservice.api.messages.calls.CallingResponse)10 VerifyDeviceResponse (org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse)10 StorageAuthResponse (org.whispersystems.signalservice.api.storage.StorageAuthResponse)10 DiscoveryResponse (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse)10 KeyBackupResponse (org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse)10 TokenResponse (org.whispersystems.signalservice.internal.contacts.entities.TokenResponse)10 ProfileKeyCredentialRequest (org.signal.zkgroup.profiles.ProfileKeyCredentialRequest)8 ReceiptCredentialRequest (org.signal.zkgroup.receipts.ReceiptCredentialRequest)8 ChangePhoneNumberRequest (org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest)8 DiscoveryRequest (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest)8