mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 18:40:19 -05:00
add more progress info from import routine
This commit is contained in:
parent
109bea7542
commit
2f0e70587d
@ -37,6 +37,7 @@ import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLo
|
|||||||
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
|
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
|
||||||
import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult;
|
import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -130,6 +131,7 @@ public class PgpImportExport {
|
|||||||
int newKeys = 0, oldKeys = 0, badKeys = 0;
|
int newKeys = 0, oldKeys = 0, badKeys = 0;
|
||||||
|
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
int progSteps = 100 / entries.size();
|
||||||
for (ParcelableKeyRing entry : entries) {
|
for (ParcelableKeyRing entry : entries) {
|
||||||
try {
|
try {
|
||||||
UncachedKeyRing key = UncachedKeyRing.decodeFromData(entry.getBytes());
|
UncachedKeyRing key = UncachedKeyRing.decodeFromData(entry.getBytes());
|
||||||
@ -149,7 +151,8 @@ public class PgpImportExport {
|
|||||||
if (key.isSecret()) {
|
if (key.isSecret()) {
|
||||||
result = mProviderHelper.saveSecretKeyRing(key);
|
result = mProviderHelper.saveSecretKeyRing(key);
|
||||||
} else {
|
} else {
|
||||||
result = mProviderHelper.savePublicKeyRing(key);
|
result = mProviderHelper.savePublicKeyRing(key,
|
||||||
|
new ProgressScaler(mProgressable, position, (position+1)*progSteps, 100));
|
||||||
}
|
}
|
||||||
if (!result.success()) {
|
if (!result.success()) {
|
||||||
badKeys += 1;
|
badKeys += 1;
|
||||||
@ -165,7 +168,6 @@ public class PgpImportExport {
|
|||||||
}
|
}
|
||||||
// update progress
|
// update progress
|
||||||
position++;
|
position++;
|
||||||
updateProgress(position / entries.size() * 100, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OperationLog log = mProviderHelper.getLog();
|
OperationLog log = mProviderHelper.getLog();
|
||||||
|
@ -29,6 +29,7 @@ import android.support.v4.util.LongSparseArray;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedPublicKey;
|
import org.sufficientlysecure.keychain.pgp.WrappedPublicKey;
|
||||||
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
|
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
|
||||||
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
|
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
|
||||||
@ -259,11 +260,29 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) {
|
||||||
|
return savePublicKeyRing(keyRing, new Progressable() {
|
||||||
|
@Override
|
||||||
|
public void setProgress(String message, int current, int total) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProgress(int resourceId, int current, int total) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProgress(int current, int total) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Saves PGPPublicKeyRing with its keys and userIds in DB
|
* Saves PGPPublicKeyRing with its keys and userIds in DB
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) {
|
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing, Progressable progress) {
|
||||||
if (keyRing.isSecret()) {
|
if (keyRing.isSecret()) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_BAD_TYPE_SECRET);
|
log(LogLevel.ERROR, LogType.MSG_IP_BAD_TYPE_SECRET);
|
||||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
||||||
@ -287,6 +306,7 @@ public class ProviderHelper {
|
|||||||
try {
|
try {
|
||||||
secretRing = getWrappedSecretKeyRing(masterKeyId).getUncached();
|
secretRing = getWrappedSecretKeyRing(masterKeyId).getUncached();
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_PRESERVING_SECRET);
|
log(LogLevel.DEBUG, LogType.MSG_IP_PRESERVING_SECRET);
|
||||||
|
progress.setProgress(LogType.MSG_IP_PRESERVING_SECRET.getMsgId(), 30, 100);
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
secretRing = null;
|
secretRing = null;
|
||||||
}
|
}
|
||||||
@ -316,6 +336,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_INSERT_SUBKEYS);
|
log(LogLevel.INFO, LogType.MSG_IP_INSERT_SUBKEYS);
|
||||||
|
progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(), 40, 100);
|
||||||
mIndent += 1;
|
mIndent += 1;
|
||||||
{ // insert subkeys
|
{ // insert subkeys
|
||||||
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
|
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
|
||||||
@ -410,6 +431,7 @@ public class ProviderHelper {
|
|||||||
log(LogLevel.INFO, LogType.MSG_IP_UID_CLASSIFYING, new String[]{
|
log(LogLevel.INFO, LogType.MSG_IP_UID_CLASSIFYING, new String[]{
|
||||||
Integer.toString(trustedKeys.size())
|
Integer.toString(trustedKeys.size())
|
||||||
});
|
});
|
||||||
|
progress.setProgress(LogType.MSG_IP_UID_CLASSIFYING.getMsgId(), 60, 100);
|
||||||
mIndent += 1;
|
mIndent += 1;
|
||||||
List<UserIdItem> uids = new ArrayList<UserIdItem>();
|
List<UserIdItem> uids = new ArrayList<UserIdItem>();
|
||||||
for (String userId : new IterableIterator<String>(
|
for (String userId : new IterableIterator<String>(
|
||||||
@ -476,6 +498,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
mIndent -= 1;
|
mIndent -= 1;
|
||||||
|
|
||||||
|
progress.setProgress(LogType.MSG_IP_UID_REORDER.getMsgId(), 80, 100);
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_UID_REORDER);
|
log(LogLevel.DEBUG, LogType.MSG_IP_UID_REORDER);
|
||||||
// primary before regular before revoked (see UserIdItem.compareTo)
|
// primary before regular before revoked (see UserIdItem.compareTo)
|
||||||
// this is a stable sort, so the order of keys is otherwise preserved.
|
// this is a stable sort, so the order of keys is otherwise preserved.
|
||||||
@ -519,6 +542,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_APPLY_BATCH);
|
log(LogLevel.DEBUG, LogType.MSG_IP_APPLY_BATCH);
|
||||||
|
progress.setProgress(LogType.MSG_IP_APPLY_BATCH.getMsgId(), 90, 100);
|
||||||
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
||||||
|
|
||||||
// Save the saved keyring (if any)
|
// Save the saved keyring (if any)
|
||||||
@ -532,6 +556,7 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
mIndent -= 1;
|
mIndent -= 1;
|
||||||
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
||||||
|
progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(), 100, 100);
|
||||||
return new SaveKeyringResult(result, mLog);
|
return new SaveKeyringResult(result, mLog);
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@ -56,6 +56,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout;
|
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout;
|
||||||
|
|
||||||
@ -121,6 +122,18 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
mViewPager = (ViewPager) findViewById(R.id.view_key_pager);
|
mViewPager = (ViewPager) findViewById(R.id.view_key_pager);
|
||||||
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.view_key_sliding_tab_layout);
|
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.view_key_sliding_tab_layout);
|
||||||
|
|
||||||
|
mSlidingTabLayout.setCustomTabColorizer(new TabColorizer() {
|
||||||
|
@Override
|
||||||
|
public int getIndicatorColor(int position) {
|
||||||
|
return position == TAB_CERTS || position == TAB_KEYS ? 0xFFFF4444 : 0xFFAA66CC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDividerColor(int position) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
int switchToTab = TAB_MAIN;
|
int switchToTab = TAB_MAIN;
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent.getExtras() != null && intent.getExtras().containsKey(EXTRA_SELECTED_TAB)) {
|
if (intent.getExtras() != null && intent.getExtras().containsKey(EXTRA_SELECTED_TAB)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user