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); this(context, new OperationLog(), 0);
} }
public ProviderHelper(Context context, OperationLog log) {
this(context, log, 0);
}
public ProviderHelper(Context context, OperationLog log, int indent) { public ProviderHelper(Context context, OperationLog log, int indent) {
mContext = context; mContext = context;
mContentResolver = context.getContentResolver(); 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.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult;
import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; 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.FileImportCache;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -391,23 +392,36 @@ public class KeychainIntentService extends IntentService
} }
/* Operation */ /* Operation */
ProviderHelper providerHelper = new ProviderHelper(this);
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 10, 60, 100)); PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 10, 60, 100));
EditKeyResult result; EditKeyResult modifyResult;
if (saveParcel.mMasterKeyId != null) { if (saveParcel.mMasterKeyId != null) {
String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE); String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE);
CanonicalizedSecretKeyRing secRing = 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 { } 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 // cache new passphrase
if (saveParcel.mNewPassphrase != null) { if (saveParcel.mNewPassphrase != null) {
@ -418,7 +432,7 @@ public class KeychainIntentService extends IntentService
setProgress(R.string.progress_done, 100, 100); setProgress(R.string.progress_done, 100, 100);
/* Output */ /* Output */
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
} catch (Exception e) { } catch (Exception e) {
sendErrorToHandler(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.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.OperationResults; import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
@ -408,9 +407,9 @@ public class EditKeyFragment extends LoaderFragment implements
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE: case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE:
Long expiry = (Long) message.getData(). mSaveKeyringParcel.getOrCreateSubkeyChange(keyId).mExpiry =
getSerializable(EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY_DATE); (Long) message.getData().getSerializable(
mSaveKeyringParcel.getOrCreateSubkeyChange(keyId).mExpiry = expiry; EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY_DATE);
break; break;
} }
getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad(); getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
@ -520,8 +519,8 @@ public class EditKeyFragment extends LoaderFragment implements
if (returnData == null) { if (returnData == null) {
return; return;
} }
final OperationResults.EditKeyResult result = final OperationResultParcel result =
returnData.getParcelable(EditKeyResult.EXTRA_RESULT); returnData.getParcelable(OperationResultParcel.EXTRA_RESULT);
if (result == null) { if (result == null) {
return; return;
} }
@ -534,7 +533,7 @@ public class EditKeyFragment extends LoaderFragment implements
// if good -> finish, return result to showkey and display there! // if good -> finish, return result to showkey and display there!
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(EditKeyResult.EXTRA_RESULT, result); intent.putExtra(OperationResultParcel.EXTRA_RESULT, result);
getActivity().setResult(EditKeyActivity.RESULT_OK, intent); getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
getActivity().finish(); getActivity().finish();