get rid of two consolidate number preferences

This commit is contained in:
Vincent Breitmoser 2014-10-03 03:37:08 +02:00
parent a91468565f
commit 04c8d42436
5 changed files with 32 additions and 56 deletions

View File

@ -80,8 +80,6 @@ public final class Constants {
public static final String FIRST_TIME = "firstTime";
public static final String SHOW_ADVANCED_TABS = "showAdvancedTabs";
public static final String CACHED_CONSOLIDATE = "cachedConsolidate";
public static final String CACHED_CONSOLIDATE_SECRETS = "cachedConsolidateSecrets";
public static final String CACHED_CONSOLIDATE_PUBLICS = "cachedConsolidatePublics";
public static final String SEARCH_KEYSERVER = "search_keyserver_pref";
public static final String SEARCH_KEYBASE = "search_keybase_pref";
public static final String USE_DEFAULT_YUBIKEY_PIN = "useDefaultYubikeyPin";

View File

@ -925,8 +925,6 @@ public class ProviderHelper {
return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog);
}
Preferences.getPreferences(mContext).setCachedConsolidateNumSecrets(cursor.getCount());
ParcelableFileCache<ParcelableKeyRing> cache =
new ParcelableFileCache<ParcelableKeyRing>(mContext, "consolidate_secret.pcl");
cache.writeCache(cursor.getCount(), new Iterator<ParcelableKeyRing>() {
@ -987,8 +985,6 @@ public class ProviderHelper {
return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog);
}
Preferences.getPreferences(mContext).setCachedConsolidateNumPublics(cursor.getCount());
ParcelableFileCache<ParcelableKeyRing> cache =
new ParcelableFileCache<ParcelableKeyRing>(mContext, "consolidate_public.pcl");
cache.writeCache(cursor.getCount(), new Iterator<ParcelableKeyRing>() {
@ -1057,16 +1053,8 @@ public class ProviderHelper {
try {
Preferences prefs = Preferences.getPreferences(mContext);
// Set flag that we have a cached consolidation here
int numSecrets = prefs.getCachedConsolidateNumSecrets();
int numPublics = prefs.getCachedConsolidateNumPublics();
if (recovery) {
if (numSecrets >= 0 && numPublics >= 0) {
log(LogType.MSG_CON_RECOVER, numSecrets, numPublics);
} else {
log(LogType.MSG_CON_RECOVER_UNKNOWN);
}
log(LogType.MSG_CON_RECOVER);
mIndent += 1;
}
@ -1084,14 +1072,24 @@ public class ProviderHelper {
ParcelableFileCache<ParcelableKeyRing> cachePublic =
new ParcelableFileCache<ParcelableKeyRing>(mContext, "consolidate_public.pcl");
// 3. Re-Import secret keyrings from cache
if (numSecrets > 0) try {
// Set flag that we have a cached consolidation here
try {
Iterator<ParcelableKeyRing> itSecrets = cacheSecret.readCache(false);
int numSecrets = cacheSecret.getNumEntries();
log(LogType.MSG_CON_REIMPORT_SECRET, numSecrets);
mIndent += 1;
// 3. Re-Import secret keyrings from cache
if (numSecrets > 0) {
new PgpImportExport(mContext, this,
new ProgressFixedScaler(progress, 10, 25, 100, R.string.progress_con_reimport))
.importKeyRings(cacheSecret.readCache(false), numSecrets);
.importKeyRings(itSecrets, numSecrets);
} else {
log(LogType.MSG_CON_REIMPORT_SECRET_SKIP);
}
} catch (IOException e) {
Log.e(Constants.TAG, "error importing secret", e);
log(LogType.MSG_CON_ERROR_SECRET);
@ -1099,18 +1097,25 @@ public class ProviderHelper {
} finally {
mIndent -= 1;
}
else {
log(LogType.MSG_CON_REIMPORT_SECRET_SKIP);
}
// 4. Re-Import public keyrings from cache
if (numPublics > 0) try {
try {
Iterator<ParcelableKeyRing> itPublics = cachePublic.readCache();
int numPublics = cachePublic.getNumEntries();
log(LogType.MSG_CON_REIMPORT_PUBLIC, numPublics);
mIndent += 1;
// 4. Re-Import public keyrings from cache
if (numPublics > 0) {
new PgpImportExport(mContext, this,
new ProgressFixedScaler(progress, 25, 99, 100, R.string.progress_con_reimport))
.importKeyRings(cachePublic.readCache(false), numPublics);
.importKeyRings(itPublics, numPublics);
} else {
log(LogType.MSG_CON_REIMPORT_PUBLIC_SKIP);
}
} catch (IOException e) {
Log.e(Constants.TAG, "error importing public", e);
log(LogType.MSG_CON_ERROR_PUBLIC);
@ -1118,9 +1123,6 @@ public class ProviderHelper {
} finally {
mIndent -= 1;
}
else {
log(LogType.MSG_CON_REIMPORT_PUBLIC_SKIP);
}
log(LogType.MSG_CON_CRITICAL_OUT);
Preferences.getPreferences(mContext).setCachedConsolidate(false);

View File

@ -439,7 +439,6 @@ public abstract class OperationResult implements Parcelable {
MSG_CON_ERROR_PUBLIC (LogLevel.ERROR, R.string.msg_con_error_public),
MSG_CON_ERROR_SECRET (LogLevel.ERROR, R.string.msg_con_error_secret),
MSG_CON_RECOVER (LogLevel.DEBUG, R.plurals.msg_con_recover),
MSG_CON_RECOVER_UNKNOWN (LogLevel.DEBUG, R.string.msg_con_recover_unknown),
MSG_CON_REIMPORT_PUBLIC (LogLevel.DEBUG, R.plurals.msg_con_reimport_public),
MSG_CON_REIMPORT_PUBLIC_SKIP (LogLevel.DEBUG, R.string.msg_con_reimport_public_skip),
MSG_CON_REIMPORT_SECRET (LogLevel.DEBUG, R.plurals.msg_con_reimport_secret),

View File

@ -177,26 +177,6 @@ public class Preferences {
editor.commit();
}
public int getCachedConsolidateNumPublics() {
return mSharedPreferences.getInt(Pref.CACHED_CONSOLIDATE_PUBLICS, -1);
}
public void setCachedConsolidateNumPublics(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(Pref.CACHED_CONSOLIDATE_PUBLICS, value);
editor.commit();
}
public int getCachedConsolidateNumSecrets() {
return mSharedPreferences.getInt(Pref.CACHED_CONSOLIDATE_SECRETS, -1);
}
public void setCachedConsolidateNumSecrets(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(Pref.CACHED_CONSOLIDATE_SECRETS, value);
editor.commit();
}
public boolean isFirstTime() {
return mSharedPreferences.getBoolean(Constants.Pref.FIRST_TIME, true);
}

View File

@ -790,10 +790,7 @@
<string name="msg_con_error_io_secret">"IO error writing secret keys to cache!"</string>
<string name="msg_con_error_public">"Error reimporting public keys!"</string>
<string name="msg_con_error_secret">"Error reimporting secret keys!"</string>
<plurals name="msg_con_recover">
<item quantity="one">"Recovering consolidation with %1$d secret and %2$d public keys"</item>
<item quantity="other">"Recovering consolidation with %1$d secret and %2$d public keys"</item>
</plurals>
<string name="msg_con_recover">"Recovering consolidation"</string>
<string name="msg_con_recover_unknown">"Recovering from unknown state"</string>
<plurals name="msg_con_reimport_public">
<item quantity="one">"Reimporting one public key"</item>