Keystore2: Stop using WAL mode

WAL mode attempts to open an additional file for use as a shared memory
mechanism. If storage is too full, then the database fails to open.
Remove the use of WAL mode so that keystore can perform read-only
transactions on the database and startup even on a full disk.

Disabling WAL mode shows about a 5% performance drop on a synthetic test
that creates and destroys 5000 AES keys.

Bug: 190142197
Test: keystore2_test
Change-Id: I9b1cb7e6398e07fa9f02f0ba4e9eb48313c06472
Merged-In: I9b1cb7e6398e07fa9f02f0ba4e9eb48313c06472
diff --git a/keystore2/vpnprofilestore/lib.rs b/keystore2/vpnprofilestore/lib.rs
index df2731a..baa632f 100644
--- a/keystore2/vpnprofilestore/lib.rs
+++ b/keystore2/vpnprofilestore/lib.rs
@@ -22,7 +22,7 @@
     BinderFeatures, ExceptionCode, Result as BinderResult, Status as BinderStatus, Strong,
     ThreadState,
 };
-use anyhow::{anyhow, Context, Result};
+use anyhow::{Context, Result};
 use keystore2::{async_task::AsyncTask, legacy_blob::LegacyBlobLoader, utils::watchdog as wd};
 use rusqlite::{
     params, Connection, OptionalExtension, Transaction, TransactionBehavior, NO_PARAMS,
@@ -30,22 +30,14 @@
 use std::{
     collections::HashSet,
     path::{Path, PathBuf},
-    sync::Once,
 };
 
-static DB_SET_WAL_MODE: Once = Once::new();
-
 struct DB {
     conn: Connection,
 }
 
 impl DB {
     fn new(db_file: &Path) -> Result<Self> {
-        DB_SET_WAL_MODE.call_once(|| {
-            log::info!("Setting VpnProfileStore database to WAL mode first time since boot.");
-            Self::set_wal_mode(&db_file).expect("In vpnprofilestore: Could not set WAL mode.");
-        });
-
         let mut db = Self {
             conn: Connection::open(db_file).context("Failed to initialize SQLite connection.")?,
         };
@@ -54,18 +46,6 @@
         Ok(db)
     }
 
-    fn set_wal_mode(db_file: &Path) -> Result<()> {
-        let conn = Connection::open(db_file)
-            .context("In VpnProfileStore set_wal_mode: Failed to open DB.")?;
-        let mode: String = conn
-            .pragma_update_and_check(None, "journal_mode", &"WAL", |row| row.get(0))
-            .context("In VpnProfileStore set_wal_mode: Failed to set journal_mode")?;
-        match mode.as_str() {
-            "wal" => Ok(()),
-            _ => Err(anyhow!("Unable to set WAL mode, db is still in {} mode.", mode)),
-        }
-    }
-
     fn with_transaction<T, F>(&mut self, behavior: TransactionBehavior, f: F) -> Result<T>
     where
         F: Fn(&Transaction) -> Result<T>,