Fall back to memory pref if pref dir doesn't exist am: 33d180914e am: 0200e565dd am: 8a894b1100

Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1353042

Change-Id: If300861b08dd866499965b0a359d720ba4a8073c
diff --git a/daemon_state_android.cc b/daemon_state_android.cc
index c9c09b8..3376e64 100644
--- a/daemon_state_android.cc
+++ b/daemon_state_android.cc
@@ -45,17 +45,17 @@
 
   // Initialize prefs.
   base::FilePath non_volatile_path;
-  // TODO(deymo): Fall back to in-memory prefs if there's no physical directory
-  // available.
   if (!hardware_->GetNonVolatileDirectory(&non_volatile_path)) {
-    LOG(ERROR) << "Failed to get a non-volatile directory.";
-    return false;
-  }
-  Prefs* prefs = new Prefs();
-  prefs_.reset(prefs);
-  if (!prefs->Init(non_volatile_path.Append(kPrefsSubDirectory))) {
-    LOG(ERROR) << "Failed to initialize preferences.";
-    return false;
+    prefs_.reset(new MemoryPrefs());
+    LOG(WARNING)
+        << "Could not get a non-volatile directory, fall back to memory prefs";
+  } else {
+    Prefs* prefs = new Prefs();
+    prefs_.reset(prefs);
+    if (!prefs->Init(non_volatile_path.Append(kPrefsSubDirectory))) {
+      LOG(ERROR) << "Failed to initialize preferences.";
+      return false;
+    }
   }
 
   // The CertificateChecker singleton is used by the update attempter.