mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
refactored KeychainService
This commit is contained in:
parent
5726698763
commit
0499b1f056
@ -165,8 +165,6 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
|
|
||||||
private KeyImportAccumulator mKeyImportAccumulator;
|
private KeyImportAccumulator mKeyImportAccumulator;
|
||||||
|
|
||||||
private KeychainService mKeychainService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return null;
|
return null;
|
||||||
@ -177,7 +175,6 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(final Intent intent, int flags, int startId) {
|
public int onStartCommand(final Intent intent, int flags, int startId) {
|
||||||
mKeychainService = this;
|
|
||||||
|
|
||||||
if (ACTION_CANCEL.equals(intent.getAction())) {
|
if (ACTION_CANCEL.equals(intent.getAction())) {
|
||||||
mActionCanceled.set(true);
|
mActionCanceled.set(true);
|
||||||
@ -214,7 +211,7 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
|
|
||||||
Log.logDebugBundle(data, "EXTRA_DATA");
|
Log.logDebugBundle(data, "EXTRA_DATA");
|
||||||
|
|
||||||
ProviderHelper providerHelper = new ProviderHelper(mKeychainService);
|
ProviderHelper providerHelper = new ProviderHelper(KeychainService.this);
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
@ -225,9 +222,9 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
// Operation
|
// Operation
|
||||||
ConsolidateResult result;
|
ConsolidateResult result;
|
||||||
if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
|
if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
|
||||||
result = providerHelper.consolidateDatabaseStep2(mKeychainService);
|
result = providerHelper.consolidateDatabaseStep2(KeychainService.this);
|
||||||
} else {
|
} else {
|
||||||
result = providerHelper.consolidateDatabaseStep1(mKeychainService);
|
result = providerHelper.consolidateDatabaseStep1(KeychainService.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -290,8 +287,8 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper,
|
PgpDecryptVerify op = new PgpDecryptVerify(KeychainService.this, providerHelper,
|
||||||
mKeychainService);
|
KeychainService.this);
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes)
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes)
|
||||||
.setSignedLiteralData(true)
|
.setSignedLiteralData(true)
|
||||||
@ -336,7 +333,7 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
boolean isSecret = data.getBoolean(DELETE_IS_SECRET);
|
boolean isSecret = data.getBoolean(DELETE_IS_SECRET);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
DeleteOperation op = new DeleteOperation(mKeychainService, providerHelper, mKeychainService);
|
DeleteOperation op = new DeleteOperation(KeychainService.this, providerHelper, KeychainService.this);
|
||||||
DeleteResult result = op.execute(masterKeyIds, isSecret);
|
DeleteResult result = op.execute(masterKeyIds, isSecret);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -351,8 +348,8 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
EditKeyOperation op = new EditKeyOperation(mKeychainService, providerHelper,
|
EditKeyOperation op = new EditKeyOperation(KeychainService.this, providerHelper,
|
||||||
mKeychainService, mActionCanceled);
|
KeychainService.this, mActionCanceled);
|
||||||
OperationResult result = op.execute(saveParcel, cryptoInput);
|
OperationResult result = op.execute(saveParcel, cryptoInput);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -369,7 +366,7 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
PromoteKeyOperation op = new PromoteKeyOperation(
|
PromoteKeyOperation op = new PromoteKeyOperation(
|
||||||
mKeychainService, providerHelper, mKeychainService,
|
KeychainService.this, providerHelper, KeychainService.this,
|
||||||
mActionCanceled);
|
mActionCanceled);
|
||||||
PromoteKeyResult result = op.execute(keyRingId, cardAid, subKeyIds);
|
PromoteKeyResult result = op.execute(keyRingId, cardAid, subKeyIds);
|
||||||
|
|
||||||
@ -390,7 +387,7 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||||
mKeychainService, providerHelper, mKeychainService);
|
KeychainService.this, providerHelper, KeychainService.this);
|
||||||
ExportResult result;
|
ExportResult result;
|
||||||
if (outputFile != null) {
|
if (outputFile != null) {
|
||||||
result = importExportOperation.exportToFile(masterKeyIds, exportSecret, outputFile);
|
result = importExportOperation.exportToFile(masterKeyIds, exportSecret, outputFile);
|
||||||
@ -441,8 +438,8 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
HkpKeyserver server = new HkpKeyserver(keyServer);
|
HkpKeyserver server = new HkpKeyserver(keyServer);
|
||||||
|
|
||||||
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(mKeychainService,
|
ImportExportOperation importExportOperation = new ImportExportOperation(KeychainService.this,
|
||||||
providerHelper, mKeychainService);
|
providerHelper, KeychainService.this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
importExportOperation.uploadKeyRingToServer(server, keyring, getProxyFromBundle(data));
|
importExportOperation.uploadKeyRingToServer(server, keyring, getProxyFromBundle(data));
|
||||||
@ -496,7 +493,7 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
// contextualize the exception, if necessary
|
// contextualize the exception, if necessary
|
||||||
String message;
|
String message;
|
||||||
if (e instanceof PgpGeneralMsgIdException) {
|
if (e instanceof PgpGeneralMsgIdException) {
|
||||||
e = ((PgpGeneralMsgIdException) e).getContextualized(mKeychainService);
|
e = ((PgpGeneralMsgIdException) e).getContextualized(KeychainService.this);
|
||||||
message = e.getMessage();
|
message = e.getMessage();
|
||||||
} else {
|
} else {
|
||||||
message = e.getMessage();
|
message = e.getMessage();
|
||||||
@ -580,11 +577,11 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
ProviderHelper providerHelper, Proxy proxy) {
|
ProviderHelper providerHelper, Proxy proxy) {
|
||||||
Log.d(Constants.TAG, "serial key import starting");
|
Log.d(Constants.TAG, "serial key import starting");
|
||||||
ParcelableFileCache<ParcelableKeyRing> cache =
|
ParcelableFileCache<ParcelableKeyRing> cache =
|
||||||
new ParcelableFileCache<>(mKeychainService, "key_import.pcl");
|
new ParcelableFileCache<>(KeychainService.this, "key_import.pcl");
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||||
mKeychainService, providerHelper, mKeychainService,
|
KeychainService.this, providerHelper, KeychainService.this,
|
||||||
mActionCanceled);
|
mActionCanceled);
|
||||||
// Either list or cache must be null, no guarantees otherwise.
|
// Either list or cache must be null, no guarantees otherwise.
|
||||||
ImportKeyResult result = keyList != null
|
ImportKeyResult result = keyList != null
|
||||||
@ -602,7 +599,7 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
keyServer, final Proxy proxy) {
|
keyServer, final Proxy proxy) {
|
||||||
Log.d(Constants.TAG, "Multi-threaded key import starting");
|
Log.d(Constants.TAG, "Multi-threaded key import starting");
|
||||||
if (keyListIterator != null) {
|
if (keyListIterator != null) {
|
||||||
mKeyImportAccumulator = new KeyImportAccumulator(totKeys, mKeychainService);
|
mKeyImportAccumulator = new KeyImportAccumulator(totKeys, KeychainService.this);
|
||||||
setProgress(0, totKeys);
|
setProgress(0, totKeys);
|
||||||
|
|
||||||
final int maxThreads = 200;
|
final int maxThreads = 200;
|
||||||
@ -621,8 +618,8 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
ImportKeyResult result = null;
|
ImportKeyResult result = null;
|
||||||
try {
|
try {
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||||
mKeychainService,
|
KeychainService.this,
|
||||||
new ProviderHelper(mKeychainService),
|
new ProviderHelper(KeychainService.this),
|
||||||
mKeyImportAccumulator.getImportProgressable(),
|
mKeyImportAccumulator.getImportProgressable(),
|
||||||
mActionCanceled);
|
mActionCanceled);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user