Initial support for restoring backups and skipping SMS in registration v2.

This commit is contained in:
Nicholas Tinsley
2024-04-29 15:17:22 -04:00
committed by Greyson Parrelli
parent fd4864b3b1
commit f23476a4e9
27 changed files with 881 additions and 233 deletions

View File

@@ -64,6 +64,18 @@ sealed class NetworkResult<T> {
}
}
/**
* Returns the [Throwable] associated with the result, or null if the result is successful.
*/
fun getCause(): Throwable? {
return when (this) {
is Success -> null
is NetworkError -> exception
is StatusCodeError -> exception
is ApplicationError -> throwable
}
}
/**
* Takes the output of one [NetworkResult] and transforms it into another if the operation is successful.
* If it's a failure, the original failure will be propagated. Useful for changing the type of a result.

View File

@@ -8,6 +8,7 @@ package org.whispersystems.signalservice.api.registration
import org.whispersystems.signalservice.api.NetworkResult
import org.whispersystems.signalservice.api.account.AccountAttributes
import org.whispersystems.signalservice.api.account.PreKeyCollection
import org.whispersystems.signalservice.internal.push.BackupAuthCheckResponse
import org.whispersystems.signalservice.internal.push.PushServiceSocket
import org.whispersystems.signalservice.internal.push.RegistrationSessionMetadataResponse
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse
@@ -67,4 +68,10 @@ class RegistrationApi(
pushServiceSocket.submitRegistrationRequest(sessionId, recoveryPassword, attributes, aciPreKeys, pniPreKeys, fcmToken, skipDeviceTransfer)
}
}
fun getSvrAuthCredential(e164: String, usernamePasswords: List<String>): NetworkResult<BackupAuthCheckResponse> {
return NetworkResult.fromFetch {
pushServiceSocket.checkBackupAuthCredentials(e164, usernamePasswords)
}
}
}

View File

@@ -1137,6 +1137,11 @@ public class PushServiceSocket {
.onErrorReturn(ServiceResponse::forUnknownError);
}
public BackupAuthCheckResponse checkBackupAuthCredentials(@Nullable String number, @Nonnull List<String> passwords) throws IOException {
String response = makeServiceRequest(BACKUP_AUTH_CHECK, "POST", JsonUtil.toJson(new BackupAuthCheckRequest(number, passwords)), NO_HEADERS, UNOPINIONATED_HANDLER, Optional.empty());
return JsonUtil.fromJson(response, BackupAuthCheckResponse.class);
}
private Single<ServiceResponse<BackupAuthCheckResponse>> createBackupAuthCheckSingle(@Nonnull String path,
@Nonnull BackupAuthCheckRequest request,
@Nonnull ResponseMapper<BackupAuthCheckResponse> responseMapper)
@@ -3048,7 +3053,6 @@ public class PushServiceSocket {
}
}
private static RegistrationSessionMetadataResponse parseSessionMetadataResponse(Response response) throws IOException {
long serverDeliveredTimestamp = 0;
try {