added retry on upload failure
This commit is contained in:
@@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
|
||||
@@ -137,13 +138,14 @@ public class EditKeyOperation extends BaseOperation<SaveKeyringParcel> {
|
||||
new ExportKeyringParcel(saveParcel.getUploadKeyserver(), ring);
|
||||
ExportResult uploadResult =
|
||||
new ExportOperation(mContext, mProviderHelper, mProgressable)
|
||||
.execute(exportKeyringParcel, cryptoInput);
|
||||
.execute(exportKeyringParcel, cryptoInput);
|
||||
if (uploadResult.isPending()) {
|
||||
return uploadResult;
|
||||
} else if (!uploadResult.success() && saveParcel.isUploadAtomic()) {
|
||||
// if atomic, update fail implies edit operation should also fail and not save
|
||||
log.add(uploadResult, 2);
|
||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, saveParcel.mMasterKeyId);
|
||||
return new EditKeyResult(log, RequiredInputParcel.createRetryUploadOperation(),
|
||||
cryptoInput);
|
||||
} else {
|
||||
// upload succeeded or not atomic so we continue
|
||||
log.add(uploadResult, 2);
|
||||
|
||||
@@ -91,6 +91,8 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
||||
}
|
||||
|
||||
public ExportResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
||||
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream aos = null;
|
||||
OperationLog log = new OperationLog();
|
||||
@@ -119,6 +121,7 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
||||
log.add(LogType.MSG_EXPORT_ERROR_UPLOAD, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
} finally {
|
||||
mProgressable.setProgress(R.string.progress_uploading, 1, 1);
|
||||
try {
|
||||
if (aos != null) {
|
||||
aos.close();
|
||||
|
||||
@@ -20,6 +20,9 @@ package org.sufficientlysecure.keychain.operations.results;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
|
||||
public class EditKeyResult extends InputPendingResult {
|
||||
|
||||
public final Long mMasterKeyId;
|
||||
@@ -29,6 +32,12 @@ public class EditKeyResult extends InputPendingResult {
|
||||
mMasterKeyId = masterKeyId;
|
||||
}
|
||||
|
||||
public EditKeyResult(OperationLog log, RequiredInputParcel requiredInput,
|
||||
CryptoInputParcel cryptoInputParcel) {
|
||||
super(log, requiredInput, cryptoInputParcel);
|
||||
mMasterKeyId = null;
|
||||
}
|
||||
|
||||
public EditKeyResult(Parcel source) {
|
||||
super(source);
|
||||
mMasterKeyId = source.readInt() != 0 ? source.readLong() : null;
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.service.input;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class RequiredInputParcel implements Parcelable {
|
||||
|
||||
public enum RequiredInputType {
|
||||
PASSPHRASE, PASSPHRASE_SYMMETRIC, NFC_SIGN, NFC_DECRYPT, NFC_MOVE_KEY_TO_CARD, ENABLE_ORBOT,
|
||||
UPLOAD_FAIL_RETRY
|
||||
}
|
||||
|
||||
public Date mSignatureTime;
|
||||
@@ -77,6 +78,11 @@ public class RequiredInputParcel implements Parcelable {
|
||||
return mSubKeyId;
|
||||
}
|
||||
|
||||
public static RequiredInputParcel createRetryUploadOperation() {
|
||||
return new RequiredInputParcel(RequiredInputType.UPLOAD_FAIL_RETRY,
|
||||
null, null, null, 0L, 0L);
|
||||
}
|
||||
|
||||
public static RequiredInputParcel createOrbotRequiredOperation() {
|
||||
return new RequiredInputParcel(RequiredInputType.ENABLE_ORBOT, null, null, null, 0L, 0L);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
|
||||
public class UploadRetryDialogActivity extends FragmentActivity {
|
||||
|
||||
public static final String EXTRA_CRYPTO_INPUT = "extra_crypto_input";
|
||||
|
||||
public static final String RESULT_CRYPTO_INPUT = "result_crypto_input";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
UploadRetryDialogFragment.newInstance().show(getSupportFragmentManager(),
|
||||
"uploadRetryDialog");
|
||||
}
|
||||
|
||||
public static class UploadRetryDialogFragment extends DialogFragment {
|
||||
public static UploadRetryDialogFragment newInstance() {
|
||||
return new UploadRetryDialogFragment();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
ContextThemeWrapper theme = new ContextThemeWrapper(getActivity(),
|
||||
R.style.Theme_AppCompat_Light_Dialog);
|
||||
|
||||
CustomAlertDialogBuilder dialogBuilder = new CustomAlertDialogBuilder(theme);
|
||||
dialogBuilder.setTitle(R.string.retry_up_dialog_title);
|
||||
dialogBuilder.setMessage(R.string.retry_up_dialog_message);
|
||||
|
||||
dialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getActivity().setResult(RESULT_CANCELED);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
||||
dialogBuilder.setPositiveButton(R.string.retry_up_dialog_btn_reupload,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(RESULT_CRYPTO_INPUT, getActivity()
|
||||
.getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT));
|
||||
getActivity().setResult(RESULT_OK, intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
||||
return dialogBuilder.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
||||
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.UploadRetryDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@@ -76,6 +77,7 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
public static final int REQUEST_CODE_PASSPHRASE = 1;
|
||||
public static final int REQUEST_CODE_NFC = 2;
|
||||
public static final int REQUEST_CODE_ENABLE_ORBOT = 3;
|
||||
public static final int REQUEST_CODE_RETRY_UPLOAD = 4;
|
||||
|
||||
private Integer mProgressMessageResource;
|
||||
|
||||
@@ -145,6 +147,13 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
return;
|
||||
}
|
||||
|
||||
case UPLOAD_FAIL_RETRY: {
|
||||
Intent intent = new Intent(activity, UploadRetryDialogActivity.class);
|
||||
intent.putExtra(UploadRetryDialogActivity.EXTRA_CRYPTO_INPUT, cryptoInputParcel);
|
||||
startActivityForResult(intent, REQUEST_CODE_RETRY_UPLOAD);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new RuntimeException("Unhandled pending result!");
|
||||
}
|
||||
@@ -186,7 +195,6 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
CryptoInputParcel cryptoInput =
|
||||
data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
|
||||
cryptoOperation(cryptoInput);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -196,7 +204,6 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
CryptoInputParcel cryptoInput =
|
||||
data.getParcelableExtra(NfcOperationActivity.RESULT_DATA);
|
||||
cryptoOperation(cryptoInput);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -207,12 +214,22 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
data.getParcelableExtra(
|
||||
OrbotRequiredDialogActivity.RESULT_CRYPTO_INPUT);
|
||||
cryptoOperation(cryptoInput);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case REQUEST_CODE_RETRY_UPLOAD: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
CryptoInputParcel cryptoInput =
|
||||
data.getParcelableExtra(
|
||||
UploadRetryDialogActivity.RESULT_CRYPTO_INPUT);
|
||||
cryptoOperation(cryptoInput);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void dismissProgress() {
|
||||
|
||||
Reference in New Issue
Block a user