Added compatibility WAL flags for Global.Settings
Added Settings.Global.SQLITE_COMPATIBILITY_WAL_FLAGS -
configuration flags for SQLite Compatibility WAL. Encoded as a key-value
list, separated by commas. E.g.:
compatibility_wal_supported=true, wal_syncmode=OFF
SQLiteCompatibilityWalFlags caches the value of
SQLITE_COMPATIBILITY_WAL_FLAGS on first access and keeps it through
the lifetime of the process for consistent behavior across all
connections.
Test: SQLiteCompatibilityWalFlagsTest
Test: setting put global ... + verify that dumpsys dbinfo has the new flag
Bug: 70226732
Bug: 70517616
Change-Id: Ifacbf5908c83351ebe5dea676eeb716af039fb14
diff --git a/core/tests/coretests/src/android/database/sqlite/SQLiteCompatibilityWalFlagsTest.java b/core/tests/coretests/src/android/database/sqlite/SQLiteCompatibilityWalFlagsTest.java
new file mode 100644
index 0000000..230655d
--- /dev/null
+++ b/core/tests/coretests/src/android/database/sqlite/SQLiteCompatibilityWalFlagsTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.database.sqlite;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.content.Context;
+import android.database.DatabaseUtils;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+
+/**
+ * Tests for {@link SQLiteCompatibilityWalFlags}
+ */
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class SQLiteCompatibilityWalFlagsTest {
+
+ private SQLiteDatabase mDatabase;
+
+ @After
+ public void tearDown() {
+ SQLiteCompatibilityWalFlags.reset();
+ if (mDatabase != null) {
+ mDatabase.close();
+ SQLiteDatabase.deleteDatabase(new File(mDatabase.getPath()));
+ }
+ }
+
+ @Test
+ public void testParseConfig() {
+ SQLiteCompatibilityWalFlags.init("");
+ assertFalse(SQLiteCompatibilityWalFlags.areFlagsSet());
+
+ SQLiteCompatibilityWalFlags.init(null);
+ assertFalse(SQLiteCompatibilityWalFlags.areFlagsSet());
+
+ SQLiteCompatibilityWalFlags.init("compatibility_wal_supported=false,wal_syncmode=OFF");
+ assertTrue(SQLiteCompatibilityWalFlags.areFlagsSet());
+ assertFalse(SQLiteCompatibilityWalFlags.isCompatibilityWalSupported());
+ assertEquals("OFF", SQLiteCompatibilityWalFlags.getWALSyncMode());
+
+ SQLiteCompatibilityWalFlags.init("wal_syncmode=VALUE");
+ assertTrue(SQLiteCompatibilityWalFlags.areFlagsSet());
+ assertEquals(SQLiteGlobal.isCompatibilityWalSupported(),
+ SQLiteCompatibilityWalFlags.isCompatibilityWalSupported());
+ assertEquals("VALUE", SQLiteCompatibilityWalFlags.getWALSyncMode());
+
+ SQLiteCompatibilityWalFlags.init("compatibility_wal_supported=true");
+ assertTrue(SQLiteCompatibilityWalFlags.areFlagsSet());
+ assertEquals(SQLiteGlobal.getWALSyncMode(),
+ SQLiteCompatibilityWalFlags.getWALSyncMode());
+ assertTrue(SQLiteCompatibilityWalFlags.isCompatibilityWalSupported());
+
+ SQLiteCompatibilityWalFlags.reset();
+ SQLiteCompatibilityWalFlags.init("Invalid value");
+ assertFalse(SQLiteCompatibilityWalFlags.areFlagsSet());
+ }
+
+ @Test
+ public void testApplyFlags() {
+ Context ctx = InstrumentationRegistry.getContext();
+
+ SQLiteCompatibilityWalFlags.init("compatibility_wal_supported=true,wal_syncmode=NORMAL");
+ mDatabase = SQLiteDatabase
+ .openOrCreateDatabase(ctx.getDatabasePath("SQLiteCompatibilityWalFlagsTest"), null);
+ String journalMode = DatabaseUtils.stringForQuery(mDatabase, "PRAGMA journal_mode", null);
+ assertEquals("WAL", journalMode.toUpperCase());
+ String syncMode = DatabaseUtils.stringForQuery(mDatabase, "PRAGMA synchronous", null);
+ assertEquals("Normal mode (1) is expected", "1", syncMode);
+ }
+
+
+}
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index b03f054..907a1b8 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -335,6 +335,7 @@
Settings.Global.SMS_SHORT_CODES_UPDATE_CONTENT_URL,
Settings.Global.SMS_SHORT_CODES_UPDATE_METADATA_URL,
Settings.Global.SPEED_LABEL_CACHE_EVICTION_AGE_MILLIS,
+ Settings.Global.SQLITE_COMPATIBILITY_WAL_FLAGS,
Settings.Global.STORAGE_BENCHMARK_INTERVAL,
Settings.Global.STORAGE_SETTINGS_CLOBBER_THRESHOLD,
Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,