some cleanup and documentation

This commit is contained in:
Vincent Breitmoser
2015-07-06 00:10:54 +02:00
parent 7e83900d6c
commit 539379a629
5 changed files with 61 additions and 46 deletions

View File

@@ -26,6 +26,7 @@ import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
import android.support.annotation.NonNull;
import android.support.v4.util.LongSparseArray;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
@@ -725,7 +726,7 @@ public class ProviderHelper {
LongSparseArray<WrappedSignature> trustedCerts = new LongSparseArray<>();
@Override
public int compareTo(UserPacketItem o) {
public int compareTo(@NonNull UserPacketItem o) {
// revoked keys always come last!
//noinspection DoubleNegation
if ((selfRevocation != null) != (o.selfRevocation != null)) {
@@ -1126,6 +1127,7 @@ public class ProviderHelper {
}
});
cursor.close();
} catch (IOException e) {
Log.e(Constants.TAG, "error saving secret", e);
@@ -1187,6 +1189,7 @@ public class ProviderHelper {
}
});
cursor.close();
} catch (IOException e) {
Log.e(Constants.TAG, "error saving public", e);

View File

@@ -23,6 +23,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -385,14 +386,18 @@ public class CreateKeyFinalFragment extends Fragment {
}
public void handleResult(ExportResult result) {
// TODO: ExportOperation UPLOAD_KEYSERVER needs logs!
// TODO: then merge logs here!
//saveKeyResult.getLog().add(result, 0);
Activity activity = getActivity();
if (activity == null) {
return;
}
saveKeyResult.getLog().add(result, 0);
Intent data = new Intent();
data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult);
getActivity().setResult(Activity.RESULT_OK, data);
getActivity().finish();
activity.setResult(Activity.RESULT_OK, data);
activity.finish();
}
@Override

View File

@@ -210,7 +210,7 @@ public class ViewKeyYubiKeyFragment
}
@Override
protected void onCryptoOperationResult(PromoteKeyResult result) {
public void onCryptoOperationSuccess(PromoteKeyResult result) {
result.createNotify(getActivity()).show();
}
}

View File

@@ -20,56 +20,88 @@ package org.sufficientlysecure.keychain.ui.base;
import android.content.Intent;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.service.KeychainService;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
/**
* All fragments executing crypto operations need to extend this class.
/** This is a base class for fragments which implement a cryptoOperation.
*
* Subclasses of this class can call the cryptoOperation method to execute an
* operation in KeychainService which takes a parcelable of type T as its input
* and returns an OperationResult of type S as a result.
*
* The input (of type T) is not given directly to the cryptoOperation method,
* but must be provided by the overriden createOperationInput method to be
* available upon request during execution of the cryptoOperation.
*
* After running cryptoOperation, one of the onCryptoOperation*() methods will
* be called, depending on the success status of the operation. The subclass
* must override at least onCryptoOperationSuccess to proceed after a
* successful operation.
*
* @see KeychainService
*
*/
public abstract class CryptoOperationFragment<T extends Parcelable, S extends OperationResult>
extends Fragment implements CryptoOperationHelper.Callback<T, S> {
private CryptoOperationHelper<T, S> mOperationHelper;
final private CryptoOperationHelper<T, S> mOperationHelper;
public CryptoOperationFragment() {
mOperationHelper = new CryptoOperationHelper<>(this, this);
}
public void setProgressMessageResource(int id) {
mOperationHelper.setProgressMessageResource(id);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mOperationHelper.handleActivityResult(requestCode, resultCode, data);
}
@Override
public abstract T createOperationInput();
/** Starts execution of the cryptographic operation.
*
* During this process, the createOperationInput() method will be called,
* this input will be handed to KeychainService, where it is executed in
* the appropriate *Operation class. If the result is a PendingInputResult,
* it is handled accordingly. Otherwise, it is returned in one of the
* onCryptoOperation* callbacks.
*/
protected void cryptoOperation() {
cryptoOperation(new CryptoInputParcel());
mOperationHelper.cryptoOperation();
}
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
cryptoOperation(cryptoInput, true);
mOperationHelper.cryptoOperation(cryptoInput);
}
protected void cryptoOperation(CryptoInputParcel cryptoInput, boolean showProgress) {
mOperationHelper.cryptoOperation(cryptoInput, showProgress);
}
@Override @Nullable
/** Creates input for the crypto operation. Called internally after the
* crypto operation is started by a call to cryptoOperation(). Silently
* cancels operation if this method returns null. */
public abstract T createOperationInput();
/** Returns false, indicating that we did not handle progress ourselves. */
public boolean onCryptoSetProgress(String msg, int progress, int max) {
return false;
}
public void setProgressMessageResource(int id) {
mOperationHelper.setProgressMessageResource(id);
}
@Override
/** Called when the cryptoOperation() was successful. No default behavior
* here, this should always be implemented by a subclass! */
abstract public void onCryptoOperationSuccess(S result);
@Override
public void onCryptoOperationError(S result) {
onCryptoOperationResult(result);
result.createNotify(getActivity()).show();
}
@@ -77,19 +109,4 @@ public abstract class CryptoOperationFragment<T extends Parcelable, S extends Op
public void onCryptoOperationCancelled() {
}
@Override
public void onCryptoOperationSuccess(S result) {
onCryptoOperationResult(result);
}
/**
* To be overriden by subclasses, if desired. Provides a way to access the method by the
* same name in CryptoOperationHelper, if super.onCryptoOperationSuccess and
* super.onCryptoOperationError are called at the start of the respective functions in the
* subclass overriding them
*
* @param result
*/
protected void onCryptoOperationResult(S result) {
}
}

View File

@@ -84,8 +84,6 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
/**
* If OperationHelper is being integrated into an activity
*
* @param activity
*/
public CryptoOperationHelper(FragmentActivity activity, Callback<T, S> callback, int progressMessageString) {
mActivity = activity;
@@ -96,8 +94,6 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
/**
* if OperationHelper is being integrated into a fragment
*
* @param fragment
*/
public CryptoOperationHelper(Fragment fragment, Callback<T, S> callback, int progressMessageString) {
mFragment = fragment;
@@ -108,8 +104,6 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
/**
* if OperationHelper is being integrated into a fragment with default message for the progress dialog
*
* @param fragment
*/
public CryptoOperationHelper(Fragment fragment, Callback<T, S> callback) {
mFragment = fragment;
@@ -178,10 +172,6 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
/**
* Attempts the result of an activity started by this helper. Returns true if requestCode is
* recognized, false otherwise.
*
* @param requestCode
* @param resultCode
* @param data
* @return true if requestCode was recognized, false otherwise
*/
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {