migrated delete op to KeychainNewService
This commit is contained in:
@@ -27,7 +27,10 @@ import org.sufficientlysecure.keychain.pgp.Progressable;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.DeleteKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
/** An operation which implements a high level keyring delete operation.
|
/** An operation which implements a high level keyring delete operation.
|
||||||
*
|
*
|
||||||
@@ -37,13 +40,18 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|||||||
* a list.
|
* a list.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DeleteOperation extends BaseOperation {
|
public class DeleteOperation extends BaseOperation<DeleteKeyringParcel> {
|
||||||
|
|
||||||
public DeleteOperation(Context context, ProviderHelper providerHelper, Progressable progressable) {
|
public DeleteOperation(Context context, ProviderHelper providerHelper, Progressable progressable) {
|
||||||
super(context, providerHelper, progressable);
|
super(context, providerHelper, progressable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeleteResult execute(long[] masterKeyIds, boolean isSecret) {
|
@Override
|
||||||
|
public DeleteResult execute(DeleteKeyringParcel deleteKeyringParcel,
|
||||||
|
CryptoInputParcel cryptoInputParcel) {
|
||||||
|
|
||||||
|
long[] masterKeyIds = deleteKeyringParcel.mMasterKeyIds;
|
||||||
|
boolean isSecret = deleteKeyringParcel.mIsSecret;
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.DeleteKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,6 +104,9 @@ public class KeychainNewService extends Service implements Progressable {
|
|||||||
} else if (inputParcel instanceof CertifyAction) {
|
} else if (inputParcel instanceof CertifyAction) {
|
||||||
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis,
|
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis,
|
||||||
mActionCanceled);
|
mActionCanceled);
|
||||||
|
} else if (inputParcel instanceof DeleteKeyringParcel){
|
||||||
|
Log.e("PHILIP", "delete in KeychainNewService");
|
||||||
|
op = new DeleteOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||||
} else if (inputParcel instanceof ImportKeyringParcel
|
} else if (inputParcel instanceof ImportKeyringParcel
|
||||||
|| inputParcel instanceof ExportKeyringParcel){
|
|| inputParcel instanceof ExportKeyringParcel){
|
||||||
op = new ImportExportOperation(outerThis, new ProviderHelper(outerThis),
|
op = new ImportExportOperation(outerThis, new ProviderHelper(outerThis),
|
||||||
@@ -110,10 +114,10 @@ public class KeychainNewService extends Service implements Progressable {
|
|||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Log.e("PHILIP", "exec in KeychainNewService");
|
||||||
@SuppressWarnings("unchecked") // this is unchecked, we make sure it's the correct op above!
|
@SuppressWarnings("unchecked") // this is unchecked, we make sure it's the correct op above!
|
||||||
OperationResult result = op.execute(inputParcel, cryptoInput);
|
OperationResult result = op.execute(inputParcel, cryptoInput);
|
||||||
|
Log.e("PHILIP", "result in KeychainNewService" + result);
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,12 +87,8 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
|
|
||||||
public static final String ACTION_VERIFY_KEYBASE_PROOF = Constants.INTENT_PREFIX + "VERIFY_KEYBASE_PROOF";
|
public static final String ACTION_VERIFY_KEYBASE_PROOF = Constants.INTENT_PREFIX + "VERIFY_KEYBASE_PROOF";
|
||||||
|
|
||||||
public static final String ACTION_EDIT_KEYRING = Constants.INTENT_PREFIX + "EDIT_KEYRING";
|
|
||||||
|
|
||||||
public static final String ACTION_PROMOTE_KEYRING = Constants.INTENT_PREFIX + "PROMOTE_KEYRING";
|
public static final String ACTION_PROMOTE_KEYRING = Constants.INTENT_PREFIX + "PROMOTE_KEYRING";
|
||||||
|
|
||||||
public static final String ACTION_DELETE = Constants.INTENT_PREFIX + "DELETE";
|
|
||||||
|
|
||||||
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
|
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
|
||||||
|
|
||||||
public static final String ACTION_CANCEL = Constants.INTENT_PREFIX + "CANCEL";
|
public static final String ACTION_CANCEL = Constants.INTENT_PREFIX + "CANCEL";
|
||||||
@@ -103,10 +99,6 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
public static final String KEYBASE_REQUIRED_FINGERPRINT = "keybase_required_fingerprint";
|
public static final String KEYBASE_REQUIRED_FINGERPRINT = "keybase_required_fingerprint";
|
||||||
public static final String KEYBASE_PROOF = "keybase_proof";
|
public static final String KEYBASE_PROOF = "keybase_proof";
|
||||||
|
|
||||||
// delete keyring(s)
|
|
||||||
public static final String DELETE_KEY_LIST = "delete_list";
|
|
||||||
public static final String DELETE_IS_SECRET = "delete_is_secret";
|
|
||||||
|
|
||||||
// promote key
|
// promote key
|
||||||
public static final String PROMOTE_MASTER_KEY_ID = "promote_master_key_id";
|
public static final String PROMOTE_MASTER_KEY_ID = "promote_master_key_id";
|
||||||
public static final String PROMOTE_CARD_AID = "promote_card_aid";
|
public static final String PROMOTE_CARD_AID = "promote_card_aid";
|
||||||
@@ -281,21 +273,6 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_DELETE: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
long[] masterKeyIds = data.getLongArray(DELETE_KEY_LIST);
|
|
||||||
boolean isSecret = data.getBoolean(DELETE_IS_SECRET);
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
DeleteOperation op = new DeleteOperation(KeychainService.this, providerHelper, KeychainService.this);
|
|
||||||
DeleteResult result = op.execute(masterKeyIds, isSecret);
|
|
||||||
|
|
||||||
// Result
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_PROMOTE_KEYRING: {
|
case ACTION_PROMOTE_KEYRING: {
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package org.sufficientlysecure.keychain.service.input;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public class DeleteKeyringParcel implements Parcelable {
|
||||||
|
|
||||||
|
public long[] mMasterKeyIds;
|
||||||
|
public boolean mIsSecret;
|
||||||
|
|
||||||
|
public DeleteKeyringParcel(long[] masterKeyIds, boolean isSecret) {
|
||||||
|
mMasterKeyIds = masterKeyIds;
|
||||||
|
mIsSecret = isSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DeleteKeyringParcel(Parcel in) {
|
||||||
|
mIsSecret = in.readByte() != 0x00;
|
||||||
|
mMasterKeyIds = in.createLongArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeByte((byte) (mIsSecret ? 0x01 : 0x00));
|
||||||
|
dest.writeLongArray(mMasterKeyIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<DeleteKeyringParcel> CREATOR = new Parcelable.Creator<DeleteKeyringParcel>() {
|
||||||
|
@Override
|
||||||
|
public DeleteKeyringParcel createFromParcel(Parcel in) {
|
||||||
|
return new DeleteKeyringParcel(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeleteKeyringParcel[] newArray(int size) {
|
||||||
|
return new DeleteKeyringParcel[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@@ -208,6 +208,11 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
mUseFragment ? mFragment.getFragmentManager() :
|
mUseFragment ? mFragment.getFragmentManager() :
|
||||||
mActivity.getSupportFragmentManager();
|
mActivity.getSupportFragmentManager();
|
||||||
|
|
||||||
|
if (fragmentManager == null) { // the fragment holding us has died
|
||||||
|
// fragmentManager was null when used with DialogFragments. (they close on click?)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ProgressDialogFragment progressDialogFragment =
|
ProgressDialogFragment progressDialogFragment =
|
||||||
(ProgressDialogFragment) fragmentManager.findFragmentByTag(
|
(ProgressDialogFragment) fragmentManager.findFragmentByTag(
|
||||||
ServiceProgressHandler.TAG_PROGRESS_DIALOG);
|
ServiceProgressHandler.TAG_PROGRESS_DIALOG);
|
||||||
@@ -283,7 +288,7 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onHandleResult(OperationResult result) {
|
public void onHandleResult(OperationResult result) {
|
||||||
Log.d("PHILIP", "Handling result in OperationHelper");
|
Log.d("PHILIP", "Handling result in OperationHelper " + result);
|
||||||
|
|
||||||
if (result instanceof InputPendingResult) {
|
if (result instanceof InputPendingResult) {
|
||||||
Log.d("PHILIP", "is pending result");
|
Log.d("PHILIP", "is pending result");
|
||||||
|
|||||||
@@ -33,16 +33,22 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.DeleteKeyringParcel;
|
||||||
|
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class DeleteKeyDialogFragment extends DialogFragment {
|
public class DeleteKeyDialogFragment extends DialogFragment
|
||||||
|
implements CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult> {
|
||||||
private static final String ARG_MESSENGER = "messenger";
|
private static final String ARG_MESSENGER = "messenger";
|
||||||
private static final String ARG_DELETE_MASTER_KEY_IDS = "delete_master_key_ids";
|
private static final String ARG_DELETE_MASTER_KEY_IDS = "delete_master_key_ids";
|
||||||
|
|
||||||
@@ -52,6 +58,13 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
private TextView mMainMessage;
|
private TextView mMainMessage;
|
||||||
private View mInflateView;
|
private View mInflateView;
|
||||||
|
|
||||||
|
private Messenger mMessenger;
|
||||||
|
|
||||||
|
// for CryptoOperationHelper.Callback
|
||||||
|
private long[] mMasterKeyIds;
|
||||||
|
private boolean mHasSecret;
|
||||||
|
private CryptoOperationHelper<DeleteKeyringParcel, DeleteResult> mDeleteOpHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this delete file dialog fragment
|
* Creates new instance of this delete file dialog fragment
|
||||||
*/
|
*/
|
||||||
@@ -67,10 +80,18 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
return frag;
|
return frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (mDeleteOpHelper != null) {
|
||||||
|
mDeleteOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final FragmentActivity activity = getActivity();
|
final FragmentActivity activity = getActivity();
|
||||||
final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER);
|
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||||
|
|
||||||
final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS);
|
final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS);
|
||||||
|
|
||||||
@@ -129,47 +150,16 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
|
||||||
// Send all information needed to service to import key in other thread
|
mMasterKeyIds = masterKeyIds;
|
||||||
Intent intent = new Intent(getActivity(), KeychainService.class);
|
mHasSecret = hasSecret;
|
||||||
|
|
||||||
intent.setAction(KeychainService.ACTION_DELETE);
|
mDeleteOpHelper = new CryptoOperationHelper<>
|
||||||
|
(DeleteKeyDialogFragment.this, DeleteKeyDialogFragment.this,
|
||||||
// Message is received after importing is done in KeychainService
|
R.string.progress_deleting);
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
mDeleteOpHelper.cryptoOperation();
|
||||||
@Override
|
// do NOT dismiss here, it'll give
|
||||||
public void handleMessage(Message message) {
|
// OperationHelper a null fragmentManager
|
||||||
super.handleMessage(message);
|
// dismiss();
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
|
||||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
|
||||||
try {
|
|
||||||
Message msg = Message.obtain();
|
|
||||||
msg.copyFrom(message);
|
|
||||||
messenger.send(msg);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(Constants.TAG, "messenger error", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// fill values for this action
|
|
||||||
Bundle data = new Bundle();
|
|
||||||
data.putLongArray(KeychainService.DELETE_KEY_LIST, masterKeyIds);
|
|
||||||
data.putBoolean(KeychainService.DELETE_IS_SECRET, hasSecret);
|
|
||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
|
||||||
Messenger messenger = new Messenger(saveHandler);
|
|
||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
|
||||||
|
|
||||||
// show progress dialog
|
|
||||||
saveHandler.showProgressDialog(getString(R.string.progress_deleting),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL, true);
|
|
||||||
|
|
||||||
// start service with intent
|
|
||||||
getActivity().startService(intent);
|
|
||||||
|
|
||||||
dismiss();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
@@ -183,4 +173,37 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
return builder.show();
|
return builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeleteKeyringParcel createOperationInput() {
|
||||||
|
return new DeleteKeyringParcel(mMasterKeyIds, mHasSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCryptoOperationSuccess(DeleteResult result) {
|
||||||
|
handleResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCryptoOperationCancelled() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCryptoOperationError(DeleteResult result) {
|
||||||
|
handleResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleResult(DeleteResult result) {
|
||||||
|
try {
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
data.putParcelable(OperationResult.EXTRA_RESULT, result);
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.arg1 = ServiceProgressHandler.MessageStatus.OKAY.ordinal();
|
||||||
|
msg.setData(data);
|
||||||
|
mMessenger.send(msg);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(Constants.TAG, "messenger error", e);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user