From 0431ae76894674b3a23ee5bb608dd96f3f70f490 Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Thu, 15 Jun 2023 16:28:52 -0700 Subject: [PATCH] Correct handling of journal mode changes Bug: 287126569 The SQLite database configuration is updated in a three-step process: 1. Identify the aspects that have changed by comparing the input configuration to the stored configuration. 2. Update the stored configuration. 3. Apply the stored configuration for every aspect that changed. The journal mode and sync mode did not follow this process. Both tried to identify a change to the aspect after step 2, which means that it always detected a "no change" case (after step 2, the stored configuration is identical to the input configuration). This change computes the "journal mode changed" flag and the "sync mode changed" before step 2. Test: atest * CtsDatabaseTestCases * FrameworksCoreTests:android.database.sqlite Change-Id: I64fb7867c2572ba9dc527335f56b93497f047c09 --- core/java/android/database/sqlite/SQLiteConnection.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java index 23d4d5634ac19..8323f7c0eeb50 100644 --- a/core/java/android/database/sqlite/SQLiteConnection.java +++ b/core/java/android/database/sqlite/SQLiteConnection.java @@ -580,6 +580,10 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen final int oldSize = mConfiguration.perConnectionSql.size(); final int newSize = configuration.perConnectionSql.size(); boolean perConnectionSqlChanged = newSize > oldSize; + boolean journalModeChanged = !configuration.resolveJournalMode().equalsIgnoreCase( + mConfiguration.resolveJournalMode()); + boolean syncModeChanged = + !configuration.resolveSyncMode().equalsIgnoreCase(mConfiguration.resolveSyncMode()); // Update configuration parameters. mConfiguration.updateParametersFrom(configuration); @@ -591,14 +595,10 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen setForeignKeyModeFromConfiguration(); } - boolean journalModeChanged = !configuration.resolveJournalMode().equalsIgnoreCase( - mConfiguration.resolveJournalMode()); if (journalModeChanged) { setJournalFromConfiguration(); } - boolean syncModeChanged = - !configuration.resolveSyncMode().equalsIgnoreCase(mConfiguration.resolveSyncMode()); if (syncModeChanged) { setSyncModeFromConfiguration(); }