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/common/fake_hardware.h b/common/fake_hardware.h
index 449787b..4558c8c 100644
--- a/common/fake_hardware.h
+++ b/common/fake_hardware.h
@@ -34,21 +34,15 @@
   // false.
   static const int kPowerwashCountNotSet = -1;
 
-  FakeHardware()
-      : is_official_build_(true),
-        is_normal_boot_mode_(true),
-        is_oobe_complete_(true),
-        oobe_timestamp_(base::Time::FromTimeT(1169280000)), // Jan 20, 2007
-        hardware_class_("Fake HWID BLAH-1234"),
-        firmware_version_("Fake Firmware v1.0.1"),
-        ec_version_("Fake EC v1.0a"),
-        powerwash_count_(kPowerwashCountNotSet) {}
+  FakeHardware() = default;
 
   // HardwareInterface methods.
   bool IsOfficialBuild() const override { return is_official_build_; }
 
   bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
 
+  bool IsOOBEEnabled() const override { return is_oobe_enabled_; }
+
   bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
     if (out_time_of_oobe != nullptr)
       *out_time_of_oobe = oobe_timestamp_;
@@ -80,13 +74,17 @@
     is_normal_boot_mode_ = is_normal_boot_mode;
   }
 
+  // Sets the SetIsOOBEEnabled to |is_oobe_enabled|.
+  void SetIsOOBEEnabled(bool is_oobe_enabled) {
+    is_oobe_enabled_ = is_oobe_enabled;
+  }
+
   // Sets the IsOOBEComplete to True with the given timestamp.
   void SetIsOOBEComplete(base::Time oobe_timestamp) {
     is_oobe_complete_ = true;
     oobe_timestamp_ = oobe_timestamp;
   }
 
-  // Sets the IsOOBEComplete to False.
   void UnsetIsOOBEComplete() {
     is_oobe_complete_ = false;
   }
@@ -108,14 +106,15 @@
   }
 
  private:
-  bool is_official_build_;
-  bool is_normal_boot_mode_;
-  bool is_oobe_complete_;
-  base::Time oobe_timestamp_;
-  std::string hardware_class_;
-  std::string firmware_version_;
-  std::string ec_version_;
-  int powerwash_count_;
+  bool is_official_build_{true};
+  bool is_normal_boot_mode_{true};
+  bool is_oobe_enabled_{true};
+  bool is_oobe_complete_{true};
+  base::Time oobe_timestamp_{base::Time::FromTimeT(1169280000)}; // Jan 20, 2007
+  std::string hardware_class_{"Fake HWID BLAH-1234"};
+  std::string firmware_version_{"Fake Firmware v1.0.1"};
+  std::string ec_version_{"Fake EC v1.0a"};
+  int powerwash_count_{kPowerwashCountNotSet};
 
   DISALLOW_COPY_AND_ASSIGN(FakeHardware);
 };
diff --git a/common/hardware_interface.h b/common/hardware_interface.h
index 17ce694..e434cc9 100644
--- a/common/hardware_interface.h
+++ b/common/hardware_interface.h
@@ -44,6 +44,11 @@
   // features.
   virtual bool IsNormalBootMode() const = 0;
 
+  // Returns whether the device has an OOBE flow that the user must go through
+  // before getting non-critical updates. Use IsOOBEComplete() to determine if
+  // that flow is complete.
+  virtual bool IsOOBEEnabled() const = 0;
+
   // Returns true if the OOBE process has been completed and EULA accepted,
   // False otherwise. If True is returned, and |out_time_of_oobe| isn't null,
   // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|.
diff --git a/common/libcurl_http_fetcher.cc b/common/libcurl_http_fetcher.cc
index 5b61263..9e40eeb 100644
--- a/common/libcurl_http_fetcher.cc
+++ b/common/libcurl_http_fetcher.cc
@@ -51,7 +51,7 @@
   // be waiting on the dev server to build an image.
   if (!hardware_->IsOfficialBuild())
     low_speed_time_seconds_ = kDownloadDevModeLowSpeedTimeSeconds;
-  if (!hardware_->IsOOBEComplete(nullptr))
+  if (hardware_->IsOOBEEnabled() && !hardware_->IsOOBEComplete(nullptr))
     max_retry_count_ = kDownloadMaxRetryCountOobeNotComplete;
 }
 
diff --git a/common/mock_hardware.h b/common/mock_hardware.h
index 451af91..826b3b3 100644
--- a/common/mock_hardware.h
+++ b/common/mock_hardware.h
@@ -36,6 +36,9 @@
     ON_CALL(*this, IsNormalBootMode())
       .WillByDefault(testing::Invoke(&fake_,
             &FakeHardware::IsNormalBootMode));
+    ON_CALL(*this, IsOOBEEnabled())
+      .WillByDefault(testing::Invoke(&fake_,
+            &FakeHardware::IsOOBEEnabled));
     ON_CALL(*this, IsOOBEComplete(testing::_))
       .WillByDefault(testing::Invoke(&fake_,
             &FakeHardware::IsOOBEComplete));
@@ -64,6 +67,7 @@
   // Hardware overrides.
   MOCK_CONST_METHOD0(IsOfficialBuild, bool());
   MOCK_CONST_METHOD0(IsNormalBootMode, bool());
+  MOCK_CONST_METHOD0(IsOOBEEnabled, bool());
   MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
   MOCK_CONST_METHOD0(GetHardwareClass, std::string());
   MOCK_CONST_METHOD0(GetFirmwareVersion, std::string());