Fix non-critical updates on boards without an OOBE flow.

A recent change in the policy made update_engine to ignore available
updates if the OOBE flow is not completed and the update is not
critical. Nevertheless, some custom boards don't have a OOBE flow as
Chromebooks do and set is_oobe_enabled=false in the policy manager.
These board were not getting regular updates because the OOBE flow is
considered not completed in those cases.

This patch moves the is_oobe_enabled flag to the HardwareInterface class
together with the IsOOBEComplete() method and updates the callers to
check the IsOOBEEnabled() value before.

Bug: 28460247
Bug: 28553821
TEST=Added unittest for the disabled and not complete case.

Change-Id: Ifd3ac2dc5e7a43f6c24eb014b7e3eacad22e3ab3
diff --git a/update_manager/real_config_provider.cc b/update_manager/real_config_provider.cc
index 2d17a7f..97e624e 100644
--- a/update_manager/real_config_provider.cc
+++ b/update_manager/real_config_provider.cc
@@ -16,47 +16,13 @@
 
 #include "update_engine/update_manager/real_config_provider.h"
 
-#include <base/files/file_path.h>
-#include <base/logging.h>
-#include <brillo/key_value_store.h>
-
-#include "update_engine/common/constants.h"
-#include "update_engine/common/utils.h"
 #include "update_engine/update_manager/generic_variables.h"
 
-using brillo::KeyValueStore;
-
-namespace {
-
-const char* kConfigFilePath = "/etc/update_manager.conf";
-
-// Config options:
-const char* kConfigOptsIsOOBEEnabled = "is_oobe_enabled";
-
-}  // namespace
-
 namespace chromeos_update_manager {
 
 bool RealConfigProvider::Init() {
-  KeyValueStore store;
-
-  if (hardware_->IsNormalBootMode()) {
-    store.Load(base::FilePath(root_prefix_ + kConfigFilePath));
-  } else {
-    if (store.Load(base::FilePath(root_prefix_ +
-                                  chromeos_update_engine::kStatefulPartition +
-                                  kConfigFilePath))) {
-      LOG(INFO) << "UpdateManager Config loaded from stateful partition.";
-    } else {
-      store.Load(base::FilePath(root_prefix_ + kConfigFilePath));
-    }
-  }
-
-  bool is_oobe_enabled;
-  if (!store.GetBoolean(kConfigOptsIsOOBEEnabled, &is_oobe_enabled))
-    is_oobe_enabled = true;  // Default value.
-  var_is_oobe_enabled_.reset(
-      new ConstCopyVariable<bool>(kConfigOptsIsOOBEEnabled, is_oobe_enabled));
+  var_is_oobe_enabled_.reset(new ConstCopyVariable<bool>(
+      "is_oobe_enabled", hardware_->IsOOBEEnabled()));
 
   return true;
 }
diff --git a/update_manager/real_config_provider.h b/update_manager/real_config_provider.h
index 4de910c..e79ae60 100644
--- a/update_manager/real_config_provider.h
+++ b/update_manager/real_config_provider.h
@@ -18,7 +18,6 @@
 #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_CONFIG_PROVIDER_H_
 
 #include <memory>
-#include <string>
 
 #include "update_engine/common/hardware_interface.h"
 #include "update_engine/update_manager/config_provider.h"
@@ -41,22 +40,10 @@
   }
 
  private:
-  friend class UmRealConfigProviderTest;
-
-  // Used for testing. Sets the root prefix, which is by default "". Call this
-  // method before calling Init() in order to mock out the place where the files
-  // are being read from.
-  void SetRootPrefix(const std::string& prefix) {
-    root_prefix_ = prefix;
-  }
-
   std::unique_ptr<ConstCopyVariable<bool>> var_is_oobe_enabled_;
 
   chromeos_update_engine::HardwareInterface* hardware_;
 
-  // Prefix to prepend to the file paths. Useful for testing.
-  std::string root_prefix_;
-
   DISALLOW_COPY_AND_ASSIGN(RealConfigProvider);
 };
 
diff --git a/update_manager/real_config_provider_unittest.cc b/update_manager/real_config_provider_unittest.cc
deleted file mode 100644
index 2d7dc0d..0000000
--- a/update_manager/real_config_provider_unittest.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-//
-// Copyright (C) 2014 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.
-//
-
-#include "update_engine/update_manager/real_config_provider.h"
-
-#include <memory>
-
-#include <base/files/file_util.h>
-#include <base/files/scoped_temp_dir.h>
-#include <gtest/gtest.h>
-
-#include "update_engine/common/constants.h"
-#include "update_engine/common/fake_hardware.h"
-#include "update_engine/common/test_utils.h"
-#include "update_engine/update_manager/umtest_utils.h"
-
-using base::TimeDelta;
-using chromeos_update_engine::test_utils::WriteFileString;
-using std::string;
-using std::unique_ptr;
-
-namespace chromeos_update_manager {
-
-class UmRealConfigProviderTest : public ::testing::Test {
- protected:
-  void SetUp() override {
-    ASSERT_TRUE(root_dir_.CreateUniqueTempDir());
-    provider_.reset(new RealConfigProvider(&fake_hardware_));
-    provider_->SetRootPrefix(root_dir_.path().value());
-  }
-
-  void WriteStatefulConfig(const string& config) {
-    base::FilePath kFile(root_dir_.path().value()
-                         + chromeos_update_engine::kStatefulPartition
-                         + "/etc/update_manager.conf");
-    ASSERT_TRUE(base::CreateDirectory(kFile.DirName()));
-    ASSERT_TRUE(WriteFileString(kFile.value(), config));
-  }
-
-  void WriteRootfsConfig(const string& config) {
-    base::FilePath kFile(root_dir_.path().value()
-                         + "/etc/update_manager.conf");
-    ASSERT_TRUE(base::CreateDirectory(kFile.DirName()));
-    ASSERT_TRUE(WriteFileString(kFile.value(), config));
-  }
-
-  unique_ptr<RealConfigProvider> provider_;
-  chromeos_update_engine::FakeHardware fake_hardware_;
-  TimeDelta default_timeout_ = TimeDelta::FromSeconds(1);
-  base::ScopedTempDir root_dir_;
-};
-
-TEST_F(UmRealConfigProviderTest, InitTest) {
-  EXPECT_TRUE(provider_->Init());
-  EXPECT_NE(nullptr, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, NoFileFoundReturnsDefault) {
-  EXPECT_TRUE(provider_->Init());
-  UmTestUtils::ExpectVariableHasValue(true, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, DontReadStatefulInNormalMode) {
-  fake_hardware_.SetIsNormalBootMode(true);
-  WriteStatefulConfig("is_oobe_enabled=false");
-
-  EXPECT_TRUE(provider_->Init());
-  UmTestUtils::ExpectVariableHasValue(true, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, ReadStatefulInDevMode) {
-  fake_hardware_.SetIsNormalBootMode(false);
-  WriteRootfsConfig("is_oobe_enabled=true");
-  // Since the stateful is present, this should read that one.
-  WriteStatefulConfig("is_oobe_enabled=false");
-
-  EXPECT_TRUE(provider_->Init());
-  UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, ReadRootfsIfStatefulNotFound) {
-  fake_hardware_.SetIsNormalBootMode(false);
-  WriteRootfsConfig("is_oobe_enabled=false");
-
-  EXPECT_TRUE(provider_->Init());
-  UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_enabled());
-}
-
-}  // namespace chromeos_update_manager