introduce EditKeyResult with transient UncachedKeyRing (half-baked!)
This commit is contained in:
@@ -24,6 +24,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.Parcelable;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
@@ -53,6 +54,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
|
||||
import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult;
|
||||
import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.util.InputData;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@@ -333,38 +335,36 @@ public class KeychainIntentService extends IntentService
|
||||
/* Operation */
|
||||
ProviderHelper providerHelper = new ProviderHelper(this);
|
||||
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 10, 50, 100));
|
||||
try {
|
||||
OperationLog log = new OperationLog();
|
||||
UncachedKeyRing ring;
|
||||
if (saveParcel.mMasterKeyId != null) {
|
||||
String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE);
|
||||
WrappedSecretKeyRing secRing =
|
||||
providerHelper.getWrappedSecretKeyRing(saveParcel.mMasterKeyId);
|
||||
EditKeyResult result;
|
||||
|
||||
ring = keyOperations.modifySecretKeyRing(secRing, saveParcel,
|
||||
passphrase, log, 0);
|
||||
} else {
|
||||
ring = keyOperations.createSecretKeyRing(saveParcel, log, 0);
|
||||
}
|
||||
if (saveParcel.mMasterKeyId != null) {
|
||||
String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE);
|
||||
WrappedSecretKeyRing secRing =
|
||||
providerHelper.getWrappedSecretKeyRing(saveParcel.mMasterKeyId);
|
||||
|
||||
providerHelper.saveSecretKeyRing(ring, new ProgressScaler(this, 10, 95, 100));
|
||||
result = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase);
|
||||
} else {
|
||||
result = keyOperations.createSecretKeyRing(saveParcel);
|
||||
}
|
||||
|
||||
// cache new passphrase
|
||||
if (saveParcel.mNewPassphrase != null) {
|
||||
PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(),
|
||||
saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserIdWithFallback());
|
||||
}
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
sendErrorToHandler(e);
|
||||
UncachedKeyRing ring = result.getRing();
|
||||
|
||||
providerHelper.saveSecretKeyRing(ring, new ProgressScaler(this, 10, 95, 100));
|
||||
|
||||
// cache new passphrase
|
||||
if (saveParcel.mNewPassphrase != null) {
|
||||
PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(),
|
||||
saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserIdWithFallback());
|
||||
}
|
||||
|
||||
setProgress(R.string.progress_done, 100, 100);
|
||||
|
||||
/* Output */
|
||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
|
||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
|
||||
} else if (ACTION_DELETE_FILE_SECURELY.equals(action)) {
|
||||
try {
|
||||
/* Input */
|
||||
@@ -624,6 +624,12 @@ public class KeychainIntentService extends IntentService
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessageToHandler(Integer arg1, OperationResultParcel data) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(OperationResultParcel.EXTRA_RESULT, data);
|
||||
sendMessageToHandler(arg1, null, bundle);
|
||||
}
|
||||
|
||||
private void sendMessageToHandler(Integer arg1, Bundle data) {
|
||||
sendMessageToHandler(arg1, null, data);
|
||||
}
|
||||
|
||||
@@ -144,20 +144,45 @@ public class OperationResultParcel implements Parcelable {
|
||||
color = Style.GREEN;
|
||||
}
|
||||
|
||||
str = activity.getString(R.string.import_error);
|
||||
str = "operation succeeded!";
|
||||
// str = activity.getString(R.string.import_error);
|
||||
|
||||
} else {
|
||||
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
str = activity.getString(R.string.import_error);
|
||||
|
||||
str = "operation failed";
|
||||
// str = activity.getString(R.string.import_error);
|
||||
|
||||
}
|
||||
|
||||
boolean button = getLog() != null && !getLog().isEmpty();
|
||||
SuperCardToast toast = new SuperCardToast(activity,
|
||||
SuperToast.Type.STANDARD, Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
|
||||
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(duration);
|
||||
toast.setIndeterminate(duration == 0);
|
||||
toast.setSwipeToDismiss(true);
|
||||
// If we have a log and it's non-empty, show a View Log button
|
||||
if (button) {
|
||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
||||
activity.getResources().getString(R.string.view_log));
|
||||
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
new SuperToast.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, Parcelable token) {
|
||||
Intent intent = new Intent(
|
||||
activity, LogDisplayActivity.class);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResultParcel.this);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
return toast;
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class OperationResults {
|
||||
// If we have a log and it's non-empty, show a View Log button
|
||||
if (button) {
|
||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
||||
activity.getResources().getString(R.string.import_view_log));
|
||||
activity.getResources().getString(R.string.view_log));
|
||||
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
@@ -167,6 +167,18 @@ public abstract class OperationResults {
|
||||
|
||||
public static class EditKeyResult extends OperationResultParcel {
|
||||
|
||||
private transient UncachedKeyRing mRing;
|
||||
|
||||
public EditKeyResult(int result, OperationLog log,
|
||||
UncachedKeyRing ring) {
|
||||
super(result, log);
|
||||
mRing = ring;
|
||||
}
|
||||
|
||||
public UncachedKeyRing getRing() {
|
||||
return mRing;
|
||||
}
|
||||
|
||||
public EditKeyResult(Parcel source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user