add pseudo-static id property to CryptoOperationHelper
This commit is contained in:
@@ -53,7 +53,7 @@ public class ConsolidateDialogActivity extends FragmentActivity
|
|||||||
|
|
||||||
mRecovery = recovery;
|
mRecovery = recovery;
|
||||||
|
|
||||||
mConsolidateOpHelper = new CryptoOperationHelper<>(this, this, R.string.progress_importing);
|
mConsolidateOpHelper = new CryptoOperationHelper<>(1, this, this, R.string.progress_importing);
|
||||||
mConsolidateOpHelper.cryptoOperation();
|
mConsolidateOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mCreateOpHelper = new CryptoOperationHelper<>(this, createKeyCallback, R.string.progress_building_key);
|
mCreateOpHelper = new CryptoOperationHelper<>(1, this, createKeyCallback, R.string.progress_building_key);
|
||||||
mCreateOpHelper.cryptoOperation();
|
mCreateOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
mMoveToCardOpHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_modify);
|
mMoveToCardOpHelper = new CryptoOperationHelper<>(2, this, callback, R.string.progress_modify);
|
||||||
mMoveToCardOpHelper.cryptoOperation();
|
mMoveToCardOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +443,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mUploadOpHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_uploading);
|
mUploadOpHelper = new CryptoOperationHelper<>(3, this, callback, R.string.progress_uploading);
|
||||||
mUploadOpHelper.cryptoOperation();
|
mUploadOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mImportOpHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_importing);
|
mImportOpHelper = new CryptoOperationHelper<>(1, this, callback, R.string.progress_importing);
|
||||||
|
|
||||||
mImportOpHelper.cryptoOperation();
|
mImportOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
|||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -399,7 +398,7 @@ public class ImportKeysActivity extends BaseNfcActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
mOperationHelper = new CryptoOperationHelper<ImportKeyringParcel, ImportKeyResult>(
|
mOperationHelper = new CryptoOperationHelper<ImportKeyringParcel, ImportKeyResult>(
|
||||||
this, this, R.string.progress_importing
|
1, this, this, R.string.progress_importing
|
||||||
);
|
);
|
||||||
|
|
||||||
ImportKeysListFragment.LoaderState ls = mListFragment.getLoaderState();
|
ImportKeysListFragment.LoaderState ls = mListFragment.getLoaderState();
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public class ImportKeysProxyActivity extends FragmentActivity
|
|||||||
|
|
||||||
mKeyList = keyRings;
|
mKeyList = keyRings;
|
||||||
|
|
||||||
mImportOpHelper = new CryptoOperationHelper<>(this, this, R.string.progress_importing);
|
mImportOpHelper = new CryptoOperationHelper<>(1, this, this, R.string.progress_importing);
|
||||||
|
|
||||||
mImportOpHelper.cryptoOperation();
|
mImportOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -568,7 +568,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
mKeyserver = cloudPrefs.keyserver;
|
mKeyserver = cloudPrefs.keyserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
mImportOpHelper = new CryptoOperationHelper<>(this,
|
mImportOpHelper = new CryptoOperationHelper<>(1, this,
|
||||||
this, R.string.progress_updating);
|
this, R.string.progress_updating);
|
||||||
mImportOpHelper.cryptoOperation();
|
mImportOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
@@ -605,7 +605,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
};
|
};
|
||||||
|
|
||||||
mConsolidateOpHelper =
|
mConsolidateOpHelper =
|
||||||
new CryptoOperationHelper<>(this, callback, R.string.progress_importing);
|
new CryptoOperationHelper<>(2, this, callback, R.string.progress_importing);
|
||||||
|
|
||||||
mConsolidateOpHelper.cryptoOperation();
|
mConsolidateOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public class SafeSlingerActivity extends BaseActivity
|
|||||||
cache.writeCache(it.size(), it.iterator());
|
cache.writeCache(it.size(), it.iterator());
|
||||||
|
|
||||||
mOperationHelper =
|
mOperationHelper =
|
||||||
new CryptoOperationHelper(this, this, R.string.progress_importing);
|
new CryptoOperationHelper(1, this, this, R.string.progress_importing);
|
||||||
|
|
||||||
mKeyList = null;
|
mKeyList = null;
|
||||||
mKeyserver = null;
|
mKeyserver = null;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class UploadKeyActivity extends BaseActivity
|
|||||||
String server = (String) mKeyServerSpinner.getSelectedItem();
|
String server = (String) mKeyServerSpinner.getSelectedItem();
|
||||||
mKeyserver = server;
|
mKeyserver = server;
|
||||||
|
|
||||||
mUploadOpHelper = new CryptoOperationHelper(this, this, R.string.progress_uploading);
|
mUploadOpHelper = new CryptoOperationHelper(1, this, this, R.string.progress_uploading);
|
||||||
mUploadOpHelper.cryptoOperation();
|
mUploadOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ import org.sufficientlysecure.keychain.util.Preferences;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class ViewKeyActivity extends BaseNfcActivity implements
|
public class ViewKeyActivity extends BaseNfcActivity implements
|
||||||
LoaderManager.LoaderCallbacks<Cursor>,
|
LoaderManager.LoaderCallbacks<Cursor>,
|
||||||
@@ -154,7 +154,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
mProviderHelper = new ProviderHelper(this);
|
mProviderHelper = new ProviderHelper(this);
|
||||||
mOperationHelper = new CryptoOperationHelper<>(this, this, null);
|
mOperationHelper = new CryptoOperationHelper<>(1, this, this, null);
|
||||||
|
|
||||||
setTitle(null);
|
setTitle(null);
|
||||||
|
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
|
|||||||
|
|
||||||
mProofVerifyDetail.setVisibility(View.GONE);
|
mProofVerifyDetail.setVisibility(View.GONE);
|
||||||
|
|
||||||
mKeybaseOpHelper = new CryptoOperationHelper<>(this, this,
|
mKeybaseOpHelper = new CryptoOperationHelper<>(1, this, this,
|
||||||
R.string.progress_verifying_signature);
|
R.string.progress_verifying_signature);
|
||||||
mKeybaseOpHelper.cryptoOperation();
|
mKeybaseOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,23 +56,11 @@ abstract class CryptoOperationFragment<T extends Parcelable, S extends Operation
|
|||||||
final private CryptoOperationHelper<T, S> mOperationHelper;
|
final private CryptoOperationHelper<T, S> mOperationHelper;
|
||||||
|
|
||||||
public CryptoOperationFragment(Integer initialProgressMsg) {
|
public CryptoOperationFragment(Integer initialProgressMsg) {
|
||||||
mOperationHelper = new CryptoOperationHelper<>(this, this, initialProgressMsg);
|
mOperationHelper = new CryptoOperationHelper<>(1, this, this, initialProgressMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoOperationFragment() {
|
public CryptoOperationFragment() {
|
||||||
mOperationHelper = new CryptoOperationHelper<>(this, this, R.string.progress_processing);
|
mOperationHelper = new CryptoOperationHelper<>(1, this, this, R.string.progress_processing);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
mOperationHelper.onRestoreInstanceState(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
mOperationHelper.onSaveInstanceState(outState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,13 +26,11 @@ import android.os.Bundle;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||||
@@ -54,8 +52,6 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class CryptoOperationHelper<T extends Parcelable, S extends OperationResult> {
|
public class CryptoOperationHelper<T extends Parcelable, S extends OperationResult> {
|
||||||
|
|
||||||
public static final String ARG_REQUESTED_CODE = "requested_code";
|
|
||||||
|
|
||||||
public interface Callback<T extends Parcelable, S extends OperationResult> {
|
public interface Callback<T extends Parcelable, S extends OperationResult> {
|
||||||
T createOperationInput();
|
T createOperationInput();
|
||||||
|
|
||||||
@@ -68,14 +64,18 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
boolean onCryptoSetProgress(String msg, int progress, int max);
|
boolean onCryptoSetProgress(String msg, int progress, int max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
// request codes from CryptoOperationHelper are created essentially
|
||||||
public static final int REQUEST_CODE_NFC = 0x00008002;
|
// a static property, used to identify requestCodes meant for this
|
||||||
public static final int REQUEST_CODE_ENABLE_ORBOT = 0x00008004;
|
// particular helper. a request code looks as follows:
|
||||||
|
// (id << 9) + (1<<8) + REQUEST_CODE_X
|
||||||
|
// that is, starting from LSB, there are 8 bits request code, 1
|
||||||
|
// fixed bit set, then 7 bit operator-id code. the first two
|
||||||
|
// summands are stored in the mId for easy operation.
|
||||||
|
private final int mId;
|
||||||
|
|
||||||
// keeps track of request code used to start an activity from this CryptoOperationHelper.
|
public static final int REQUEST_CODE_PASSPHRASE = 1;
|
||||||
// this is necessary when multiple CryptoOperationHelpers are used in the same fragment/activity
|
public static final int REQUEST_CODE_NFC = 2;
|
||||||
// otherwise all CryptoOperationHandlers may respond to the same onActivityResult
|
public static final int REQUEST_CODE_ENABLE_ORBOT = 3;
|
||||||
private int mRequestedCode = -1;
|
|
||||||
|
|
||||||
private Integer mProgressMessageResource;
|
private Integer mProgressMessageResource;
|
||||||
|
|
||||||
@@ -88,7 +88,9 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
/**
|
/**
|
||||||
* If OperationHelper is being integrated into an activity
|
* If OperationHelper is being integrated into an activity
|
||||||
*/
|
*/
|
||||||
public CryptoOperationHelper(FragmentActivity activity, Callback<T, S> callback, Integer progressMessageString) {
|
public CryptoOperationHelper(int id, FragmentActivity activity, Callback<T, S> callback,
|
||||||
|
Integer progressMessageString) {
|
||||||
|
mId = (id << 9) + (1<<8);
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mUseFragment = false;
|
mUseFragment = false;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
@@ -98,24 +100,14 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
/**
|
/**
|
||||||
* if OperationHelper is being integrated into a fragment
|
* if OperationHelper is being integrated into a fragment
|
||||||
*/
|
*/
|
||||||
public CryptoOperationHelper(Fragment fragment, Callback<T, S> callback, Integer progressMessageString) {
|
public CryptoOperationHelper(int id, Fragment fragment, Callback<T, S> callback, Integer progressMessageString) {
|
||||||
|
mId = (id << 9) + (1<<8);
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
mUseFragment = true;
|
mUseFragment = true;
|
||||||
mProgressMessageResource = progressMessageString;
|
mProgressMessageResource = progressMessageString;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
outState.putInt(ARG_REQUESTED_CODE, mRequestedCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRestoreInstanceState(@Nullable Bundle state) {
|
|
||||||
if (state == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mRequestedCode = state.getInt(ARG_REQUESTED_CODE, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgressMessageResource(int id) {
|
public void setProgressMessageResource(int id) {
|
||||||
mProgressMessageResource = id;
|
mProgressMessageResource = id;
|
||||||
}
|
}
|
||||||
@@ -133,11 +125,10 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
case NFC_SIGN: {
|
case NFC_SIGN: {
|
||||||
Intent intent = new Intent(activity, NfcOperationActivity.class);
|
Intent intent = new Intent(activity, NfcOperationActivity.class);
|
||||||
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||||
mRequestedCode = REQUEST_CODE_NFC;
|
|
||||||
if (mUseFragment) {
|
if (mUseFragment) {
|
||||||
mFragment.startActivityForResult(intent, mRequestedCode);
|
mFragment.startActivityForResult(intent, mId + REQUEST_CODE_NFC);
|
||||||
} else {
|
} else {
|
||||||
activity.startActivityForResult(intent, mRequestedCode);
|
activity.startActivityForResult(intent, mId + REQUEST_CODE_NFC);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -146,11 +137,10 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
case PASSPHRASE_SYMMETRIC: {
|
case PASSPHRASE_SYMMETRIC: {
|
||||||
Intent intent = new Intent(activity, PassphraseDialogActivity.class);
|
Intent intent = new Intent(activity, PassphraseDialogActivity.class);
|
||||||
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||||
mRequestedCode = REQUEST_CODE_PASSPHRASE;
|
|
||||||
if (mUseFragment) {
|
if (mUseFragment) {
|
||||||
mFragment.startActivityForResult(intent, mRequestedCode);
|
mFragment.startActivityForResult(intent, mId + REQUEST_CODE_PASSPHRASE);
|
||||||
} else {
|
} else {
|
||||||
activity.startActivityForResult(intent, mRequestedCode);
|
activity.startActivityForResult(intent, mId + REQUEST_CODE_PASSPHRASE);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -158,11 +148,10 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
case ENABLE_ORBOT: {
|
case ENABLE_ORBOT: {
|
||||||
Intent intent = new Intent(activity, OrbotRequiredDialogActivity.class);
|
Intent intent = new Intent(activity, OrbotRequiredDialogActivity.class);
|
||||||
intent.putExtra(OrbotRequiredDialogActivity.EXTRA_CRYPTO_INPUT, cryptoInputParcel);
|
intent.putExtra(OrbotRequiredDialogActivity.EXTRA_CRYPTO_INPUT, cryptoInputParcel);
|
||||||
mRequestedCode = REQUEST_CODE_ENABLE_ORBOT;
|
|
||||||
if (mUseFragment) {
|
if (mUseFragment) {
|
||||||
mFragment.startActivityForResult(intent, mRequestedCode);
|
mFragment.startActivityForResult(intent, mId + REQUEST_CODE_ENABLE_ORBOT);
|
||||||
} else {
|
} else {
|
||||||
activity.startActivityForResult(intent, mRequestedCode);
|
activity.startActivityForResult(intent, mId + REQUEST_CODE_ENABLE_ORBOT);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -181,13 +170,13 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
Log.d(Constants.TAG, "received activity result in OperationHelper");
|
Log.d(Constants.TAG, "received activity result in OperationHelper");
|
||||||
|
|
||||||
if (mRequestedCode != requestCode) {
|
if ((requestCode & mId) != mId) {
|
||||||
// this wasn't meant for us to handle
|
// this wasn't meant for us to handle
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
// reset mRequestedCode because we have finished what we started
|
|
||||||
mRequestedCode = -1;
|
|
||||||
}
|
}
|
||||||
|
// filter out mId from requestCode
|
||||||
|
requestCode ^= mId;
|
||||||
|
|
||||||
if (resultCode == Activity.RESULT_CANCELED) {
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
mCallback.onCryptoOperationCancelled();
|
mCallback.onCryptoOperationCancelled();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ public class DeleteKeyDialogFragment extends DialogFragment
|
|||||||
mHasSecret = hasSecret;
|
mHasSecret = hasSecret;
|
||||||
|
|
||||||
mDeleteOpHelper = new CryptoOperationHelper<>
|
mDeleteOpHelper = new CryptoOperationHelper<>
|
||||||
(DeleteKeyDialogFragment.this, DeleteKeyDialogFragment.this,
|
(1, DeleteKeyDialogFragment.this, DeleteKeyDialogFragment.this,
|
||||||
R.string.progress_deleting);
|
R.string.progress_deleting);
|
||||||
mDeleteOpHelper.cryptoOperation();
|
mDeleteOpHelper.cryptoOperation();
|
||||||
// do NOT dismiss here, it'll give
|
// do NOT dismiss here, it'll give
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class ExportHelper
|
|||||||
mMasterKeyIds = masterKeyIds; // if masterKeyIds is null it means export all
|
mMasterKeyIds = masterKeyIds; // if masterKeyIds is null it means export all
|
||||||
|
|
||||||
CryptoOperationHelper<ExportKeyringParcel, ExportResult> exportOpHelper =
|
CryptoOperationHelper<ExportKeyringParcel, ExportResult> exportOpHelper =
|
||||||
new CryptoOperationHelper<>(mActivity, this, R.string.progress_exporting);
|
new CryptoOperationHelper<>(1, mActivity, this, R.string.progress_exporting);
|
||||||
exportOpHelper.cryptoOperation();
|
exportOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user