consolidate: prevent concurrent calls of step 2

This commit is contained in:
Vincent Breitmoser 2014-08-20 19:59:45 +02:00
parent 2a96912a96
commit 475293a116
4 changed files with 126 additions and 102 deletions

View File

@ -86,21 +86,26 @@ public class KeychainApplication extends Application {
setupAccountAsNeeded(this); setupAccountAsNeeded(this);
// Update keyserver list as needed // Update keyserver list as needed
Preferences prefs = Preferences.getPreferences(this); Preferences.getPreferences(this).updatePreferences();
prefs.updatePreferences();
TlsHelper.addStaticCA("pool.sks-keyservers.net", getAssets(), "sks-keyservers.netCA.cer"); TlsHelper.addStaticCA("pool.sks-keyservers.net", getAssets(), "sks-keyservers.netCA.cer");
TemporaryStorageProvider.cleanUp(this); TemporaryStorageProvider.cleanUp(this);
checkConsolidateRecovery();
}
public void checkConsolidateRecovery() {
// restart consolidate process if it has been interruped before // restart consolidate process if it has been interruped before
if (prefs.getCachedConsolidate()) { if (Preferences.getPreferences(this).getCachedConsolidate()) {
// do something which calls ProviderHelper.consolidateDatabaseStep2 with a progressable // do something which calls ProviderHelper.consolidateDatabaseStep2 with a progressable
Intent consolidateIntent = new Intent(this, ConsolidateDialogActivity.class); Intent consolidateIntent = new Intent(this, ConsolidateDialogActivity.class);
consolidateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); consolidateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(consolidateIntent); startActivity(consolidateIntent);
} }
} }
public static void setupAccountAsNeeded(Context context) { public static void setupAccountAsNeeded(Context context) {

View File

@ -961,8 +961,19 @@ public class ProviderHelper {
return consolidateDatabaseStep2(progress, true); return consolidateDatabaseStep2(progress, true);
} }
private static boolean mConsolidateCritical = false;
private ConsolidateResult consolidateDatabaseStep2(Progressable progress, boolean recovery) { private ConsolidateResult consolidateDatabaseStep2(Progressable progress, boolean recovery) {
synchronized (ProviderHelper.class) {
if (mConsolidateCritical) {
log(LogLevel.ERROR, LogType.MSG_CON_ERROR_CONCURRENT);
return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog);
}
mConsolidateCritical = true;
}
try {
Preferences prefs = Preferences.getPreferences(mContext); Preferences prefs = Preferences.getPreferences(mContext);
// Set flag that we have a cached consolidation here // Set flag that we have a cached consolidation here
@ -1011,7 +1022,8 @@ public class ProviderHelper {
return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog);
} finally { } finally {
mIndent -= 1; mIndent -= 1;
} else { }
else {
log(LogLevel.DEBUG, LogType.MSG_CON_REIMPORT_SECRET_SKIP); log(LogLevel.DEBUG, LogType.MSG_CON_REIMPORT_SECRET_SKIP);
} }
@ -1029,7 +1041,8 @@ public class ProviderHelper {
return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog);
} finally { } finally {
mIndent -= 1; mIndent -= 1;
} else { }
else {
log(LogLevel.DEBUG, LogType.MSG_CON_REIMPORT_PUBLIC_SKIP); log(LogLevel.DEBUG, LogType.MSG_CON_REIMPORT_PUBLIC_SKIP);
} }
@ -1067,6 +1080,10 @@ public class ProviderHelper {
return new ConsolidateResult(ConsolidateResult.RESULT_OK, mLog); return new ConsolidateResult(ConsolidateResult.RESULT_OK, mLog);
} finally {
mConsolidateCritical = false;
}
} }
/** /**

View File

@ -396,6 +396,7 @@ public class OperationResultParcel implements Parcelable {
MSG_CON_DELETE_PUBLIC (R.string.msg_con_delete_public), MSG_CON_DELETE_PUBLIC (R.string.msg_con_delete_public),
MSG_CON_DELETE_SECRET (R.string.msg_con_delete_secret), MSG_CON_DELETE_SECRET (R.string.msg_con_delete_secret),
MSG_CON_ERROR_BAD_STATE (R.string.msg_con_error_bad_state), MSG_CON_ERROR_BAD_STATE (R.string.msg_con_error_bad_state),
MSG_CON_ERROR_CONCURRENT(R.string.msg_con_error_concurrent),
MSG_CON_ERROR_DB (R.string.msg_con_error_db), MSG_CON_ERROR_DB (R.string.msg_con_error_db),
MSG_CON_ERROR_IO_PUBLIC (R.string.msg_con_error_io_public), MSG_CON_ERROR_IO_PUBLIC (R.string.msg_con_error_io_public),
MSG_CON_ERROR_IO_SECRET (R.string.msg_con_error_io_secret), MSG_CON_ERROR_IO_SECRET (R.string.msg_con_error_io_secret),

View File

@ -673,7 +673,8 @@
<!-- Consolidate --> <!-- Consolidate -->
<string name="msg_con">Consolidating database</string> <string name="msg_con">Consolidating database</string>
<string name="msg_con_error_bad_state">Consolidation started while no database was cached! This is probably a programming error, please file a bug report.</string> <string name="msg_con_error_bad_state">Consolidation was started while no database was cached! This is probably a programming error, please file a bug report.</string>
<string name="msg_con_error_concurrent">Consolidation aborted, already running on other thread!</string>
<string name="msg_con_save_secret">Saving secret keyrings</string> <string name="msg_con_save_secret">Saving secret keyrings</string>
<string name="msg_con_save_public">Saving public keyrings</string> <string name="msg_con_save_public">Saving public keyrings</string>
<string name="msg_con_db_clear">Clearing database</string> <string name="msg_con_db_clear">Clearing database</string>