mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-07-13 17:23:56 +01:00
+41
-3
@@ -380,7 +380,7 @@ public class PushServiceSocket {
|
||||
|
||||
body.put("client", androidSmsRetriever ? "android-2021-03" : "android");
|
||||
|
||||
try (Response response = makeServiceRequest(path, "POST", jsonRequestBody(JsonUtil.toJson(body)), headers, new RegistrationSessionResponseHandler(), Optional.empty(), false)) {
|
||||
try (Response response = makeServiceRequest(path, "POST", jsonRequestBody(JsonUtil.toJson(body)), headers, new RegistrationCodeRequestResponseHandler(), Optional.empty(), false)) {
|
||||
return parseSessionMetadataResponse(response);
|
||||
}
|
||||
}
|
||||
@@ -389,7 +389,7 @@ public class PushServiceSocket {
|
||||
String path = String.format(VERIFICATION_CODE_PATH, sessionId);
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("code", verificationCode);
|
||||
try (Response response = makeServiceRequest(path, "PUT", jsonRequestBody(JsonUtil.toJson(body)), NO_HEADERS, new RegistrationCodeRequestResponseHandler(), Optional.empty(), false)) {
|
||||
try (Response response = makeServiceRequest(path, "PUT", jsonRequestBody(JsonUtil.toJson(body)), NO_HEADERS, new RegistrationCodeSubmissionResponseHandler(), Optional.empty(), false)) {
|
||||
return parseSessionMetadataResponse(response);
|
||||
}
|
||||
}
|
||||
@@ -2572,6 +2572,44 @@ public class PushServiceSocket {
|
||||
|
||||
private static class RegistrationSessionResponseHandler implements ResponseCodeHandler {
|
||||
|
||||
@Override
|
||||
public void handle(int responseCode, ResponseBody body) throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
|
||||
if (responseCode == 403) {
|
||||
throw new IncorrectRegistrationRecoveryPasswordException();
|
||||
} else if (responseCode == 404) {
|
||||
throw new NoSuchSessionException();
|
||||
} else if (responseCode == 409) {
|
||||
RegistrationSessionMetadataJson response;
|
||||
try {
|
||||
response = JsonUtil.fromJson(body.string(), RegistrationSessionMetadataJson.class);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Unable to read response body.", e);
|
||||
throw new NonSuccessfulResponseCodeException(409);
|
||||
}
|
||||
if (response.pushChallengedRequired()) {
|
||||
throw new PushChallengeRequiredException();
|
||||
} else if (response.captchaRequired()) {
|
||||
throw new CaptchaRequiredException();
|
||||
} else {
|
||||
throw new HttpConflictException();
|
||||
}
|
||||
} else if (responseCode == 502) {
|
||||
VerificationCodeFailureResponseBody response;
|
||||
try {
|
||||
response = JsonUtil.fromJson(body.string(), VerificationCodeFailureResponseBody.class);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Unable to read response body.", e);
|
||||
throw new NonSuccessfulResponseCodeException(responseCode);
|
||||
}
|
||||
throw new ExternalServiceFailureException(response.getPermanentFailure(), response.getReason());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class RegistrationCodeRequestResponseHandler implements ResponseCodeHandler {
|
||||
|
||||
@Override
|
||||
public void handle(int responseCode, ResponseBody body) throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
|
||||
@@ -2642,7 +2680,7 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
private static class RegistrationCodeRequestResponseHandler implements ResponseCodeHandler {
|
||||
private static class RegistrationCodeSubmissionResponseHandler implements ResponseCodeHandler {
|
||||
@Override
|
||||
public void handle(int responseCode, ResponseBody body) throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user