simplify progress for key import operations
This commit is contained in:
@@ -90,8 +90,8 @@ public class ChangeUnlockOperation extends BaseReadWriteOperation<ChangeUnlockPa
|
||||
// It's a success, so this must be non-null now
|
||||
UncachedKeyRing ring = modifyResult.getRing();
|
||||
|
||||
SaveKeyringResult saveResult = mKeyWritableRepository
|
||||
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 70, 95, 100));
|
||||
updateProgress(R.string.progress_saving, 80, 100);
|
||||
SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(ring);
|
||||
log.add(saveResult, 1);
|
||||
|
||||
// If the save operation didn't succeed, exit here
|
||||
|
||||
@@ -146,8 +146,8 @@ public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel>
|
||||
UploadKeyringParcel exportKeyringParcel =
|
||||
new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes);
|
||||
|
||||
UploadResult uploadResult =
|
||||
new UploadOperation(mContext, mKeyRepository, mProgressable, mCancelled)
|
||||
UploadResult uploadResult = new UploadOperation(
|
||||
mContext, mKeyRepository, new ProgressScaler(mProgressable, 60, 80, 100), mCancelled)
|
||||
.execute(exportKeyringParcel, cryptoInput);
|
||||
|
||||
log.add(uploadResult, 2);
|
||||
@@ -161,8 +161,8 @@ public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel>
|
||||
}
|
||||
|
||||
// Save the new keyring.
|
||||
SaveKeyringResult saveResult = mKeyWritableRepository
|
||||
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100));
|
||||
updateProgress(R.string.progress_saving, 90, 100);
|
||||
SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(ring);
|
||||
log.add(saveResult, 1);
|
||||
|
||||
// If the save operation didn't succeed, exit here
|
||||
|
||||
@@ -129,13 +129,13 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
* contact-to-key sync i.e ContactSyncAdapterService.requestContactsSync()
|
||||
*
|
||||
* @param entries keys to import
|
||||
* @param num number of keys to import
|
||||
* @param numTotalKeys number of keys to import
|
||||
* @param hkpKeyserver contains uri of keyserver to import from, if it is an import from cloud
|
||||
* @param progressable Allows multi-threaded import to supply a progressable that ignores the
|
||||
* progress of a single key being imported
|
||||
*/
|
||||
@NonNull
|
||||
private ImportKeyResult serialKeyRingImport(Iterator<ParcelableKeyRing> entries, int num,
|
||||
private ImportKeyResult serialKeyRingImport(Iterator<ParcelableKeyRing> entries, int numTotalKeys,
|
||||
ParcelableHkpKeyserver hkpKeyserver, Progressable progressable,
|
||||
@NonNull ParcelableProxy proxy, boolean skipSave) {
|
||||
if (progressable != null) {
|
||||
@@ -143,7 +143,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
}
|
||||
|
||||
OperationLog log = new OperationLog();
|
||||
log.add(LogType.MSG_IMPORT, 0, num);
|
||||
log.add(LogType.MSG_IMPORT, 0, numTotalKeys);
|
||||
|
||||
// If there aren't even any keys, do nothing here.
|
||||
if (entries == null || !entries.hasNext()) {
|
||||
@@ -156,8 +156,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
ArrayList<CanonicalizedKeyRing> canKeyRings = new ArrayList<>();
|
||||
|
||||
boolean cancelled = false;
|
||||
int position = 0;
|
||||
double progSteps = 100.0 / num;
|
||||
int keyImportsFinished = 0;
|
||||
|
||||
KeybaseKeyserver keybaseServer = null;
|
||||
FacebookKeyserver facebookServer = null;
|
||||
@@ -316,14 +315,10 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
// and https://github.com/open-keychain/open-keychain/issues/1480
|
||||
synchronized (mKeyRepository) {
|
||||
mKeyRepository.clearLog();
|
||||
ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps),
|
||||
(int) ((position + 1) * progSteps), 100);
|
||||
if (key.isSecret()) {
|
||||
result = mKeyWritableRepository.saveSecretKeyRing(key, progressScaler,
|
||||
canKeyRings, skipSave);
|
||||
result = mKeyWritableRepository.saveSecretKeyRing(key, canKeyRings, skipSave);
|
||||
} else {
|
||||
result = mKeyWritableRepository.savePublicKeyRing(key, progressScaler,
|
||||
entry.mExpectedFingerprint, canKeyRings, skipSave);
|
||||
result = mKeyWritableRepository.savePublicKeyRing(key, entry.mExpectedFingerprint, canKeyRings, skipSave);
|
||||
}
|
||||
}
|
||||
if (!result.success()) {
|
||||
@@ -354,8 +349,10 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
Log.e(Constants.TAG, "Encountered bad key on import!", e);
|
||||
++badKeys;
|
||||
}
|
||||
|
||||
// update progress
|
||||
position++;
|
||||
keyImportsFinished += 1;
|
||||
progressable.setProgress(keyImportsFinished, numTotalKeys);
|
||||
}
|
||||
|
||||
// Special: consolidate on secret key import (cannot be cancelled!)
|
||||
|
||||
@@ -113,8 +113,8 @@ public class PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringPa
|
||||
setPreventCancel();
|
||||
|
||||
// Save the new keyring.
|
||||
SaveKeyringResult saveResult = mKeyWritableRepository
|
||||
.saveSecretKeyRing(promotedRing, new ProgressScaler(mProgressable, 60, 95, 100));
|
||||
updateProgress(R.string.progress_saving, 80, 100);
|
||||
SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(promotedRing);
|
||||
log.add(saveResult, 1);
|
||||
|
||||
// If the save operation didn't succeed, exit here
|
||||
|
||||
@@ -75,7 +75,6 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.ProgressFixedScaler;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
import org.sufficientlysecure.keychain.util.Utf8Util;
|
||||
|
||||
/**
|
||||
@@ -179,8 +178,7 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
* and need to be saved externally to be preserved past the operation.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private int saveCanonicalizedPublicKeyRing(CanonicalizedPublicKeyRing keyRing,
|
||||
Progressable progress, boolean selfCertsAreTrusted) {
|
||||
private int saveCanonicalizedPublicKeyRing(CanonicalizedPublicKeyRing keyRing, boolean selfCertsAreTrusted) {
|
||||
|
||||
// start with ok result
|
||||
int result = SaveKeyringResult.SAVED_PUBLIC;
|
||||
@@ -206,7 +204,6 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
}
|
||||
|
||||
log(LogType.MSG_IP_INSERT_SUBKEYS);
|
||||
progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(), 40, 100);
|
||||
mIndent += 1;
|
||||
{ // insert subkeys
|
||||
Uri uri = Keys.buildKeysUri(masterKeyId);
|
||||
@@ -475,7 +472,6 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
}
|
||||
mIndent -= 1;
|
||||
|
||||
progress.setProgress(LogType.MSG_IP_UID_REORDER.getMsgId(), 65, 100);
|
||||
log(LogType.MSG_IP_UID_REORDER);
|
||||
// primary before regular before revoked (see UserIdItem.compareTo)
|
||||
// this is a stable sort, so the order of keys is otherwise preserved.
|
||||
@@ -563,11 +559,9 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
}
|
||||
|
||||
log(LogType.MSG_IP_APPLY_BATCH);
|
||||
progress.setProgress(LogType.MSG_IP_APPLY_BATCH.getMsgId(), 75, 100);
|
||||
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
||||
|
||||
log(LogType.MSG_IP_SUCCESS);
|
||||
progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(), 90, 100);
|
||||
return result;
|
||||
|
||||
} catch (RemoteException e) {
|
||||
@@ -762,7 +756,7 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
* <p>
|
||||
* If you want to merge keys in-memory only and not save in database set skipSave=true.
|
||||
*/
|
||||
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, Progressable progress,
|
||||
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing,
|
||||
String expectedFingerprint,
|
||||
ArrayList<CanonicalizedKeyRing> canKeyRings,
|
||||
boolean skipSave) {
|
||||
@@ -858,13 +852,11 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
result = SaveKeyringResult.SAVED_PUBLIC
|
||||
| (alreadyExists ? SaveKeyringResult.UPDATED : 0);
|
||||
} else {
|
||||
result = saveCanonicalizedPublicKeyRing(canPublicRing, progress, canSecretRing != null);
|
||||
result = saveCanonicalizedPublicKeyRing(canPublicRing, canSecretRing != null);
|
||||
}
|
||||
|
||||
// Save the saved keyring (if any)
|
||||
if (canSecretRing != null) {
|
||||
progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100);
|
||||
|
||||
int secretResult;
|
||||
if (skipSave) {
|
||||
// skip save method, set fixed result
|
||||
@@ -887,16 +879,15 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
}
|
||||
}
|
||||
|
||||
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, Progressable progress,
|
||||
String expectedFingerprint) {
|
||||
return savePublicKeyRing(publicRing, progress, expectedFingerprint, null, false);
|
||||
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, String expectedFingerprint) {
|
||||
return savePublicKeyRing(publicRing, expectedFingerprint, null, false);
|
||||
}
|
||||
|
||||
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) {
|
||||
return savePublicKeyRing(keyRing, new ProgressScaler(), null);
|
||||
return savePublicKeyRing(keyRing, null);
|
||||
}
|
||||
|
||||
public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing, Progressable progress,
|
||||
public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing,
|
||||
ArrayList<CanonicalizedKeyRing> canKeyRings,
|
||||
boolean skipSave) {
|
||||
|
||||
@@ -996,15 +987,13 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
// skip save method, set fixed result
|
||||
publicResult = SaveKeyringResult.SAVED_PUBLIC;
|
||||
} else {
|
||||
publicResult = saveCanonicalizedPublicKeyRing(canPublicRing, progress, true);
|
||||
publicResult = saveCanonicalizedPublicKeyRing(canPublicRing, true);
|
||||
}
|
||||
|
||||
if ((publicResult & SaveKeyringResult.RESULT_ERROR) == SaveKeyringResult.RESULT_ERROR) {
|
||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null);
|
||||
}
|
||||
|
||||
progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100);
|
||||
|
||||
int result;
|
||||
if (skipSave) {
|
||||
// skip save method, set fixed result
|
||||
@@ -1023,8 +1012,8 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
}
|
||||
}
|
||||
|
||||
public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing, Progressable progress) {
|
||||
return saveSecretKeyRing(secretRing, progress, null, false);
|
||||
public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing) {
|
||||
return saveSecretKeyRing(secretRing, null, false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
Reference in New Issue
Block a user