handle modify and save errors in KeychainIntentResult

This commit is contained in:
Vincent Breitmoser 2014-08-14 17:12:17 +02:00
parent 9c03889390
commit 9af301ec77
3 changed files with 33 additions and 16 deletions

View File

@ -86,6 +86,10 @@ public class ProviderHelper {
this(context, new OperationLog(), 0);
}
public ProviderHelper(Context context, OperationLog log) {
this(context, log, 0);
}
public ProviderHelper(Context context, OperationLog log, int indent) {
mContext = context;
mContentResolver = context.getContentResolver();

View File

@ -54,6 +54,7 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult;
import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult;
import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult;
import org.sufficientlysecure.keychain.util.FileImportCache;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
@ -391,23 +392,36 @@ public class KeychainIntentService extends IntentService
}
/* Operation */
ProviderHelper providerHelper = new ProviderHelper(this);
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 10, 60, 100));
EditKeyResult result;
EditKeyResult modifyResult;
if (saveParcel.mMasterKeyId != null) {
String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE);
CanonicalizedSecretKeyRing secRing =
providerHelper.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
new ProviderHelper(this).getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
result = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase);
modifyResult = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase);
} else {
result = keyOperations.createSecretKeyRing(saveParcel);
modifyResult = keyOperations.createSecretKeyRing(saveParcel);
}
UncachedKeyRing ring = result.getRing();
// If the edit operation didn't succeed, exit here
if ( ! modifyResult.success()) {
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, modifyResult);
return;
}
providerHelper.saveSecretKeyRing(ring, new ProgressScaler(this, 60, 95, 100));
UncachedKeyRing ring = modifyResult.getRing();
// Save the keyring. The ProviderHelper is initialized with the previous log
SaveKeyringResult saveResult = new ProviderHelper(this, modifyResult.getLog())
.saveSecretKeyRing(ring, new ProgressScaler(this, 60, 95, 100));
// If the edit operation didn't succeed, exit here
if ( ! saveResult.success()) {
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
return;
}
// cache new passphrase
if (saveParcel.mNewPassphrase != null) {
@ -418,7 +432,7 @@ public class KeychainIntentService extends IntentService
setProgress(R.string.progress_done, 100, 100);
/* Output */
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
} catch (Exception e) {
sendErrorToHandler(e);
}

View File

@ -48,8 +48,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.OperationResults;
import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult;
import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
@ -408,9 +407,9 @@ public class EditKeyFragment extends LoaderFragment implements
public void handleMessage(Message message) {
switch (message.what) {
case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE:
Long expiry = (Long) message.getData().
getSerializable(EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY_DATE);
mSaveKeyringParcel.getOrCreateSubkeyChange(keyId).mExpiry = expiry;
mSaveKeyringParcel.getOrCreateSubkeyChange(keyId).mExpiry =
(Long) message.getData().getSerializable(
EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY_DATE);
break;
}
getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
@ -520,8 +519,8 @@ public class EditKeyFragment extends LoaderFragment implements
if (returnData == null) {
return;
}
final OperationResults.EditKeyResult result =
returnData.getParcelable(EditKeyResult.EXTRA_RESULT);
final OperationResultParcel result =
returnData.getParcelable(OperationResultParcel.EXTRA_RESULT);
if (result == null) {
return;
}
@ -534,7 +533,7 @@ public class EditKeyFragment extends LoaderFragment implements
// if good -> finish, return result to showkey and display there!
Intent intent = new Intent();
intent.putExtra(EditKeyResult.EXTRA_RESULT, result);
intent.putExtra(OperationResultParcel.EXTRA_RESULT, result);
getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
getActivity().finish();