aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuanpeng Ni <yuanpengni@chromium.org>2023-09-28 14:45:55 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-10-19 22:57:31 +0000
commita41d12f560e887c7ef3b24a830a7707ad3210a0f (patch)
treea8831cb8cb7976299f585e99b0e84c083f56699b
parent54ab1023f7cf5c194e728ab526cced3d20442ee8 (diff)
downloadupdate_engine-a41d12f560e887c7ef3b24a830a7707ad3210a0f.tar.gz
update_engine: Get compressed DLC manifest
Get the DLC manifest by using the libdlcservice-utils. Wrap the dlcservice::Utils in an interface class so it can be mocked or stubbed. BUG=b:255627042 TEST=FEATURES=test emerge-$B update_engine TEST=`dlcservice_util --install --id=prebuilt-sample-dlc` on DUT Cq-Depend: chromium:4915562, chromium:4902188 Change-Id: I1a3ee78b80b12abc1a7d0d5847d432ecc6720ecd Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/4904023 Commit-Queue: Yuanpeng Ni‎ <yuanpengni@chromium.org> Reviewed-by: Jae Hoon Kim <kimjae@chromium.org> Tested-by: Yuanpeng Ni‎ <yuanpengni@chromium.org>
-rw-r--r--BUILD.gn5
-rw-r--r--common/dlcservice_interface.h21
-rw-r--r--common/dlcservice_stub.cc9
-rw-r--r--common/dlcservice_stub.h13
-rw-r--r--common/system_state.h4
-rw-r--r--common/utils.cc27
-rw-r--r--common/utils.h7
-rw-r--r--cros/dlcservice_chromeos.cc11
-rw-r--r--cros/dlcservice_chromeos.h17
-rw-r--r--cros/fake_system_state.cc1
-rw-r--r--cros/fake_system_state.h9
-rw-r--r--cros/install_action.cc4
-rw-r--r--cros/install_action_test.cc48
-rw-r--r--cros/mock_dlc_utils.h45
-rw-r--r--cros/real_system_state.cc8
-rw-r--r--cros/real_system_state.h5
-rw-r--r--cros/update_attempter.cc7
-rw-r--r--cros/update_attempter_unittest.cc11
18 files changed, 186 insertions, 66 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 3239a4f5..22feb9c8 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -296,7 +296,10 @@ static_library("libupdate_engine") {
}
if (use.dlc) {
- all_dependent_pkg_deps += [ "libdlcservice-client" ]
+ all_dependent_pkg_deps += [
+ "libdlcservice-client",
+ "libdlcservice-utils",
+ ]
}
if (use.hibernate) {
diff --git a/common/dlcservice_interface.h b/common/dlcservice_interface.h
index f432525b..fcdb85c5 100644
--- a/common/dlcservice_interface.h
+++ b/common/dlcservice_interface.h
@@ -21,6 +21,9 @@
#include <string>
#include <vector>
+#include <base/files/file_path.h>
+#include <libimageloader/manifest.h>
+
namespace chromeos_update_engine {
// The abstract dlcservice interface defines the interaction with the
@@ -48,10 +51,28 @@ class DlcServiceInterface {
DlcServiceInterface() = default;
};
+class DlcUtilsInterface {
+ public:
+ DlcUtilsInterface(const DlcUtilsInterface&) = delete;
+ DlcUtilsInterface& operator=(const DlcUtilsInterface&) = delete;
+
+ virtual ~DlcUtilsInterface() = default;
+
+ virtual std::shared_ptr<imageloader::Manifest> GetDlcManifest(
+ const std::string& id, const base::FilePath& dlc_manifest_path) = 0;
+
+ protected:
+ DlcUtilsInterface() = default;
+};
+
// This factory function creates a new DlcServiceInterface instance for the
// current platform.
std::unique_ptr<DlcServiceInterface> CreateDlcService();
+// This factory function creates a new DlcUtilsInterface instance for the
+// current platform.
+std::unique_ptr<DlcUtilsInterface> CreateDlcUtils();
+
} // namespace chromeos_update_engine
#endif // UPDATE_ENGINE_COMMON_DLCSERVICE_INTERFACE_H_
diff --git a/common/dlcservice_stub.cc b/common/dlcservice_stub.cc
index 24471470..ff211808 100644
--- a/common/dlcservice_stub.cc
+++ b/common/dlcservice_stub.cc
@@ -27,6 +27,10 @@ std::unique_ptr<DlcServiceInterface> CreateDlcService() {
return std::make_unique<DlcServiceStub>();
}
+std::unique_ptr<DlcUtilsInterface> CreateDlcUtils() {
+ return std::make_unique<DlcUtilsStub>();
+}
+
bool DlcServiceStub::GetDlcsToUpdate(vector<string>* dlc_ids) {
if (dlc_ids)
dlc_ids->clear();
@@ -40,4 +44,9 @@ bool DlcServiceStub::UpdateCompleted(const vector<string>& dlc_ids) {
return true;
}
+std::shared_ptr<imageloader::Manifest> DlcUtilsStub::GetDlcManifest(
+ const std::string& id, const base::FilePath& dlc_manifest_path) {
+ return nullptr;
+}
+
} // namespace chromeos_update_engine
diff --git a/common/dlcservice_stub.h b/common/dlcservice_stub.h
index 4df0186c..2643daf4 100644
--- a/common/dlcservice_stub.h
+++ b/common/dlcservice_stub.h
@@ -17,6 +17,7 @@
#ifndef UPDATE_ENGINE_COMMON_DLCSERVICE_STUB_H_
#define UPDATE_ENGINE_COMMON_DLCSERVICE_STUB_H_
+#include <memory>
#include <string>
#include <vector>
@@ -39,6 +40,18 @@ class DlcServiceStub : public DlcServiceInterface {
bool UpdateCompleted(const std::vector<std::string>& dlc_ids) override;
};
+class DlcUtilsStub : public DlcUtilsInterface {
+ public:
+ DlcUtilsStub() = default;
+ DlcUtilsStub(const DlcUtilsStub&) = delete;
+ DlcUtilsStub& operator=(const DlcUtilsStub&) = delete;
+
+ ~DlcUtilsStub() = default;
+
+ std::shared_ptr<imageloader::Manifest> GetDlcManifest(
+ const std::string& id, const base::FilePath& dlc_manifest_path) override;
+};
+
} // namespace chromeos_update_engine
#endif // UPDATE_ENGINE_COMMON_DLCSERVICE_STUB_H_
diff --git a/common/system_state.h b/common/system_state.h
index 7d008cb2..345e79af 100644
--- a/common/system_state.h
+++ b/common/system_state.h
@@ -45,6 +45,7 @@ class BootControlInterface;
class ConnectionManagerInterface;
class CrosHealthdInterface;
class DlcServiceInterface;
+class DlcUtilsInterface;
class HardwareInterface;
class HibernateInterface;
class MetricsReporterInterface;
@@ -126,6 +127,9 @@ class SystemState {
// Returns a pointer to the DlcServiceInterface singleton.
virtual DlcServiceInterface* dlcservice() = 0;
+ // Returns a pointer to the DlcUtilsInterface singleton.
+ virtual DlcUtilsInterface* dlc_utils() = 0;
+
// Returns a pointer to the CrosHealthdInteraface singleton.
virtual CrosHealthdInterface* cros_healthd() = 0;
diff --git a/common/utils.cc b/common/utils.cc
index 518992e5..54f000c9 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -85,9 +85,6 @@ const int kGetFileFormatMaxHeaderSize = 32;
// The path to the kernel's boot_id.
const char kBootIdPath[] = "/proc/sys/kernel/random/boot_id";
-// DLC manifest file name.
-constexpr char kDlcManifestFile[] = "imageloader.json";
-
// If |path| is absolute, or explicit relative to the current working directory,
// leaves it as is. Otherwise, uses the system's temp directory, as defined by
// base::GetTempDir() and prepends it to |path|. On success stores the full
@@ -1042,30 +1039,6 @@ ErrorCode IsTimestampNewer(const std::string& old_version,
return ErrorCode::kSuccess;
}
-std::shared_ptr<imageloader::Manifest> LoadDlcManifest(
- const std::string& manifest_dir,
- const std::string& id,
- const std::string& package) {
- std::string json_str;
- auto manifest_path = base::FilePath(manifest_dir)
- .Append(id)
- .Append(package)
- .Append(kDlcManifestFile);
-
- if (!base::ReadFileToString(manifest_path, &json_str)) {
- LOG(ERROR) << "Failed to read manifest at " << manifest_path.value();
- return nullptr;
- }
-
- auto manifest = std::make_shared<imageloader::Manifest>();
- if (!manifest->ParseManifest(json_str)) {
- LOG(ERROR) << "Failed to parse manifest for DLC=" << id;
- return nullptr;
- }
-
- return manifest;
-}
-
} // namespace utils
} // namespace chromeos_update_engine
diff --git a/common/utils.h b/common/utils.h
index 6f70a63c..945aef4c 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -340,13 +340,6 @@ std::string GetExclusionName(const std::string& str_to_convert);
ErrorCode IsTimestampNewer(const std::string& old_version,
const std::string& new_version);
-// Load and parse a DLC manifest file and return a pointer to the manifest
-// object. A nullptr will be returned on failure.
-std::shared_ptr<imageloader::Manifest> LoadDlcManifest(
- const std::string& manifest_dir,
- const std::string& id,
- const std::string& package);
-
} // namespace utils
// Utility class to close a file descriptor
diff --git a/cros/dlcservice_chromeos.cc b/cros/dlcservice_chromeos.cc
index 63019579..8d23dd1d 100644
--- a/cros/dlcservice_chromeos.cc
+++ b/cros/dlcservice_chromeos.cc
@@ -18,9 +18,11 @@
#include <base/logging.h>
#include <brillo/errors/error.h>
+#include <chromeos/constants/imageloader.h>
#include <dlcservice/proto_bindings/dlcservice.pb.h>
// NOLINTNEXTLINE(build/include_alpha) "dbus-proxies.h" needs "dlcservice.pb.h"
#include <dlcservice/dbus-proxies.h>
+#include <libdlcservice/utils.h>
#include "update_engine/cros/dbus_connection.h"
@@ -39,6 +41,10 @@ std::unique_ptr<DlcServiceInterface> CreateDlcService() {
return std::make_unique<DlcServiceChromeOS>();
}
+std::unique_ptr<DlcUtilsInterface> CreateDlcUtils() {
+ return std::make_unique<DlcUtilsChromeOS>();
+}
+
bool DlcServiceChromeOS::GetDlcsToUpdate(vector<string>* dlc_ids) {
if (!dlc_ids)
return false;
@@ -75,4 +81,9 @@ bool DlcServiceChromeOS::UpdateCompleted(const vector<string>& dlc_ids) {
return true;
}
+std::shared_ptr<imageloader::Manifest> DlcUtilsChromeOS::GetDlcManifest(
+ const std::string& id, const base::FilePath& dlc_manifest_path) {
+ return utils_.GetDlcManifest(id, dlc_manifest_path);
+}
+
} // namespace chromeos_update_engine
diff --git a/cros/dlcservice_chromeos.h b/cros/dlcservice_chromeos.h
index 5a20504e..15a58332 100644
--- a/cros/dlcservice_chromeos.h
+++ b/cros/dlcservice_chromeos.h
@@ -21,6 +21,8 @@
#include <string>
#include <vector>
+#include <libdlcservice/utils.h>
+
#include "update_engine/common/dlcservice_interface.h"
namespace chromeos_update_engine {
@@ -50,6 +52,21 @@ class DlcServiceChromeOS : public DlcServiceInterface {
bool UpdateCompleted(const std::vector<std::string>& dlc_ids) override;
};
+class DlcUtilsChromeOS : public DlcUtilsInterface {
+ public:
+ DlcUtilsChromeOS() = default;
+ DlcUtilsChromeOS(const DlcUtilsChromeOS&) = delete;
+ DlcUtilsChromeOS& operator=(const DlcUtilsChromeOS&) = delete;
+
+ ~DlcUtilsChromeOS() = default;
+
+ std::shared_ptr<imageloader::Manifest> GetDlcManifest(
+ const std::string& id, const base::FilePath& dlc_manifest_path) override;
+
+ private:
+ dlcservice::Utils utils_;
+};
+
} // namespace chromeos_update_engine
#endif // UPDATE_ENGINE_CROS_DLCSERVICE_CHROMEOS_H_
diff --git a/cros/fake_system_state.cc b/cros/fake_system_state.cc
index 8ca424d6..348454cb 100644
--- a/cros/fake_system_state.cc
+++ b/cros/fake_system_state.cc
@@ -34,6 +34,7 @@ FakeSystemState::FakeSystemState()
p2p_manager_(&mock_p2p_manager_),
update_manager_(&fake_update_manager_),
call_wrapper_(&mock_call_wrapper_),
+ dlc_utils_(&mock_dlc_utils_),
device_policy_(nullptr),
fake_system_rebooted_(false) {
mock_payload_state_.Initialize();
diff --git a/cros/fake_system_state.h b/cros/fake_system_state.h
index bdf467de..e9e69561 100644
--- a/cros/fake_system_state.h
+++ b/cros/fake_system_state.h
@@ -34,6 +34,7 @@
#include "update_engine/common/mock_prefs.h"
#include "update_engine/common/system_state.h"
#include "update_engine/cros/mock_connection_manager.h"
+#include "update_engine/cros/mock_dlc_utils.h"
#include "update_engine/cros/mock_omaha_request_params.h"
#include "update_engine/cros/mock_p2p_manager.h"
#include "update_engine/cros/mock_payload_state.h"
@@ -117,6 +118,8 @@ class FakeSystemState : public SystemState {
inline DlcServiceInterface* dlcservice() override { return dlcservice_; }
+ inline DlcUtilsInterface* dlc_utils() override { return dlc_utils_; }
+
inline CrosHealthdInterface* cros_healthd() override { return cros_healthd_; }
inline CallWrapperInterface* call_wrapper() override { return call_wrapper_; }
@@ -194,6 +197,10 @@ class FakeSystemState : public SystemState {
dlcservice_ = dlcservice;
}
+ inline void set_dlc_utils(DlcUtilsInterface* dlc_utils) {
+ dlc_utils_ = dlc_utils;
+ }
+
inline void set_cros_healthd(CrosHealthdInterface* cros_healthd) {
cros_healthd_ = (cros_healthd ? cros_healthd : &fake_cros_healthd_);
}
@@ -310,6 +317,7 @@ class FakeSystemState : public SystemState {
testing::NiceMock<MockP2PManager> mock_p2p_manager_;
testing::NiceMock<MockPowerManager> mock_power_manager_;
testing::StrictMock<MockCallWrapper> mock_call_wrapper_;
+ testing::StrictMock<MockDlcUtils> mock_dlc_utils_;
// Pointers to objects that client code can override. They are initialized to
// the default implementations above.
@@ -330,6 +338,7 @@ class FakeSystemState : public SystemState {
DlcServiceInterface* dlcservice_;
CrosHealthdInterface* cros_healthd_{&fake_cros_healthd_};
CallWrapperInterface* call_wrapper_;
+ DlcUtilsInterface* dlc_utils_;
// Other object pointers (not preinitialized).
const policy::DevicePolicy* device_policy_;
diff --git a/cros/install_action.cc b/cros/install_action.cc
index 6913af7a..4388b981 100644
--- a/cros/install_action.cc
+++ b/cros/install_action.cc
@@ -31,6 +31,7 @@
#include <libimageloader/manifest.h>
#include "update_engine/common/boot_control.h"
+#include "update_engine/common/dlcservice_interface.h"
#include "update_engine/common/system_state.h"
#include "update_engine/common/utils.h"
#include "update_engine/cros/image_properties.h"
@@ -64,7 +65,8 @@ InstallAction::~InstallAction() {}
void InstallAction::PerformAction() {
LOG(INFO) << "InstallAction performing action.";
- manifest_ = utils::LoadDlcManifest(manifest_dir_, id_, kDefaultPackage);
+ manifest_ = SystemState::Get()->dlc_utils()->GetDlcManifest(
+ id_, base::FilePath(manifest_dir_));
if (!manifest_) {
LOG(ERROR) << "Could not retrieve manifest for " << id_;
processor_->ActionComplete(this, ErrorCode::kScaledInstallationError);
diff --git a/cros/install_action_test.cc b/cros/install_action_test.cc
index 5e836a21..3f252fc5 100644
--- a/cros/install_action_test.cc
+++ b/cros/install_action_test.cc
@@ -16,6 +16,7 @@
#include "update_engine/cros/install_action.h"
+#include <memory>
#include <utility>
#include <vector>
@@ -28,6 +29,7 @@
#include "update_engine/common/mock_http_fetcher.h"
#include "update_engine/common/test_utils.h"
#include "update_engine/cros/fake_system_state.h"
+#include "update_engine/cros/mock_dlc_utils.h"
namespace chromeos_update_engine {
@@ -170,6 +172,7 @@ class InstallActionTest : public ::testing::Test {
"foobar-dlc",
/*slotting=*/"",
/*manifest_dir=*/tempdir_.GetPath().Append("dlc").value());
+ FakeSystemState::Get()->set_dlc_utils(&mock_dlc_utils_);
}
base::ScopedTempDir tempdir_;
@@ -183,6 +186,8 @@ class InstallActionTest : public ::testing::Test {
brillo::FakeMessageLoop loop_{nullptr};
MockHttpFetcher* mock_http_fetcher_{nullptr};
+
+ MockDlcUtils mock_dlc_utils_;
};
class InstallActionTestSuite : public InstallActionTest,
@@ -201,12 +206,9 @@ TEST_P(InstallActionTestSuite, ManifestReadFailure) {
processor_.set_delegate(&delegate_);
processor_.EnqueueAction(std::move(install_action_));
- ASSERT_TRUE(test_utils::WriteFileString(
- tempdir_.GetPath()
- .Append("dlc/foobar-dlc/package/imageloader.json")
- .value(),
- ""));
delegate_.expected_code_ = ErrorCode::kScaledInstallationError;
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest(testing::_, testing::_))
+ .WillOnce(testing::Return(nullptr));
loop_.PostTask(
FROM_HERE,
@@ -222,11 +224,8 @@ TEST_P(InstallActionTestSuite, PerformSuccessfulTest) {
processor_.EnqueueAction(std::move(install_action_));
auto manifest = GetParam();
- ASSERT_TRUE(test_utils::WriteFileString(
- tempdir_.GetPath()
- .Append("dlc/foobar-dlc/package/imageloader.json")
- .value(),
- manifest));
+ auto manifest_ptr = std::make_shared<imageloader::Manifest>();
+ manifest_ptr->ParseManifest(manifest);
ASSERT_TRUE(test_utils::WriteFileString(
tempdir_.GetPath().Append("etc/lsb-release").value(), kProperties));
delegate_.expected_code_ = ErrorCode::kSuccess;
@@ -237,6 +236,8 @@ TEST_P(InstallActionTestSuite, PerformSuccessfulTest) {
"dlc/foobar-dlc/package",
0,
tempdir_.GetPath().Append("foobar-dlc-device").value());
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest(testing::_, testing::_))
+ .WillOnce(testing::Return(manifest_ptr));
loop_.PostTask(
FROM_HERE,
@@ -253,11 +254,8 @@ TEST_F(InstallActionTest, PerformInvalidOffsetTest) {
processor_.EnqueueAction(std::move(install_action_));
auto manifest = base::StringPrintf(kManifestTemplate, kDefaultSha, "1025");
- ASSERT_TRUE(test_utils::WriteFileString(
- tempdir_.GetPath()
- .Append("dlc/foobar-dlc/package/imageloader.json")
- .value(),
- manifest));
+ auto manifest_ptr = std::make_shared<imageloader::Manifest>();
+ manifest_ptr->ParseManifest(manifest);
ASSERT_TRUE(test_utils::WriteFileString(
tempdir_.GetPath().Append("etc/lsb-release").value(), kProperties));
delegate_.expected_code_ = ErrorCode::kScaledInstallationError;
@@ -268,6 +266,8 @@ TEST_F(InstallActionTest, PerformInvalidOffsetTest) {
"dlc/foobar-dlc/package",
0,
tempdir_.GetPath().Append("foobar-dlc-device").value());
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest(testing::_, testing::_))
+ .WillOnce(testing::Return(manifest_ptr));
loop_.PostTask(
FROM_HERE,
@@ -286,11 +286,8 @@ TEST_F(InstallActionTest, PerformInvalidShaTest) {
kManifestTemplate,
"5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10deadbeef",
kDefaultOffset);
- ASSERT_TRUE(test_utils::WriteFileString(
- tempdir_.GetPath()
- .Append("dlc/foobar-dlc/package/imageloader.json")
- .value(),
- manifest));
+ auto manifest_ptr = std::make_shared<imageloader::Manifest>();
+ manifest_ptr->ParseManifest(manifest);
ASSERT_TRUE(test_utils::WriteFileString(
tempdir_.GetPath().Append("etc/lsb-release").value(), kProperties));
delegate_.expected_code_ = ErrorCode::kScaledInstallationError;
@@ -301,6 +298,8 @@ TEST_F(InstallActionTest, PerformInvalidShaTest) {
"dlc/foobar-dlc/package",
0,
tempdir_.GetPath().Append("foobar-dlc-device").value());
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest(testing::_, testing::_))
+ .WillOnce(testing::Return(manifest_ptr));
loop_.PostTask(
FROM_HERE,
@@ -320,11 +319,8 @@ TEST_P(InstallActionTestSuite, TransferFailureFetchesFromBackup) {
mock_http_fetcher_->FailTransfer(404);
auto manifest = GetParam();
- ASSERT_TRUE(test_utils::WriteFileString(
- tempdir_.GetPath()
- .Append("dlc/foobar-dlc/package/imageloader.json")
- .value(),
- manifest));
+ auto manifest_ptr = std::make_shared<imageloader::Manifest>();
+ manifest_ptr->ParseManifest(manifest);
ASSERT_TRUE(test_utils::WriteFileString(
tempdir_.GetPath().Append("etc/lsb-release").value(), kProperties));
delegate_.expected_code_ = ErrorCode::kScaledInstallationError;
@@ -339,6 +335,8 @@ TEST_P(InstallActionTestSuite, TransferFailureFetchesFromBackup) {
"dlc/foobar-dlc/package",
0,
tempdir_.GetPath().Append("foobar-dlc-device").value());
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest(testing::_, testing::_))
+ .WillOnce(testing::Return(manifest_ptr));
loop_.PostTask(
FROM_HERE,
diff --git a/cros/mock_dlc_utils.h b/cros/mock_dlc_utils.h
new file mode 100644
index 00000000..914efe4e
--- /dev/null
+++ b/cros/mock_dlc_utils.h
@@ -0,0 +1,45 @@
+//
+// Copyright (C) 2023 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.
+//
+
+#ifndef UPDATE_ENGINE_CROS_MOCK_DLC_UTILS_H_
+#define UPDATE_ENGINE_CROS_MOCK_DLC_UTILS_H_
+
+#include <memory>
+#include <string>
+
+#include <gmock/gmock.h>
+
+#include "update_engine/common/dlcservice_interface.h"
+
+namespace chromeos_update_engine {
+
+class MockDlcUtils : public DlcUtilsInterface {
+ public:
+ MockDlcUtils() = default;
+ MockDlcUtils(const MockDlcUtils&) = delete;
+ MockDlcUtils& operator=(const MockDlcUtils&) = delete;
+
+ ~MockDlcUtils() = default;
+
+ MOCK_METHOD(std::shared_ptr<imageloader::Manifest>,
+ GetDlcManifest,
+ (const std::string& id, const base::FilePath& dlc_manifest_path),
+ (override));
+};
+
+} // namespace chromeos_update_engine
+
+#endif // UPDATE_ENGINE_CROS_DLCSERVICE_CHROMEOS_H_
diff --git a/cros/real_system_state.cc b/cros/real_system_state.cc
index 06ad4745..e484e6f4 100644
--- a/cros/real_system_state.cc
+++ b/cros/real_system_state.cc
@@ -20,12 +20,14 @@
#include <string>
#include <utility>
+#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/functional/bind.h>
#include <base/location.h>
#include <base/logging.h>
#include <base/time/time.h>
#include <brillo/message_loops/message_loop.h>
+#include <chromeos/constants/imageloader.h>
#include <chromeos/dbus/service_constants.h>
#include "update_engine/common/boot_control.h"
@@ -78,6 +80,12 @@ bool RealSystemState::Initialize() {
return false;
}
+ dlc_utils_ = CreateDlcUtils();
+ if (!dlc_utils_) {
+ LOG(ERROR) << "Error initializing the DlcUtilsInterface.";
+ return false;
+ }
+
cros_healthd_ = CreateCrosHealthd();
if (!cros_healthd_) {
LOG(ERROR) << "Error initializing the CrosHealthdInterface,";
diff --git a/cros/real_system_state.h b/cros/real_system_state.h
index c2997744..a13b2a8d 100644
--- a/cros/real_system_state.h
+++ b/cros/real_system_state.h
@@ -117,6 +117,8 @@ class RealSystemState : public SystemState {
DlcServiceInterface* dlcservice() override { return dlcservice_.get(); }
+ DlcUtilsInterface* dlc_utils() override { return dlc_utils_.get(); }
+
CrosHealthdInterface* cros_healthd() override { return cros_healthd_.get(); }
CallWrapperInterface* call_wrapper() override { return call_wrapper_.get(); }
@@ -136,6 +138,9 @@ class RealSystemState : public SystemState {
// Interface for dlcservice.
std::unique_ptr<DlcServiceInterface> dlcservice_;
+ // Interface for dlc_utils.
+ std::unique_ptr<DlcUtilsInterface> dlc_utils_;
+
// Interface for cros_healthd.
std::unique_ptr<CrosHealthdInterface> cros_healthd_;
diff --git a/cros/update_attempter.cc b/cros/update_attempter.cc
index 14a44f5e..9ce2577b 100644
--- a/cros/update_attempter.cc
+++ b/cros/update_attempter.cc
@@ -111,9 +111,6 @@ constexpr TimeDelta kBroadcastThreshold = base::Seconds(10);
const char kAUTestURLRequest[] = "autest";
const char kScheduledAUTestURLRequest[] = "autest-scheduled";
-// The default DLC package name.
-constexpr char kDlcPackage[] = "package";
-
string ConvertToString(ProcessMode op) {
switch (op) {
case ProcessMode::UPDATE:
@@ -838,8 +835,8 @@ void UpdateAttempter::CalculateDlcParams() {
}
map<string, OmahaRequestParams::AppParams> dlc_apps_params;
for (const auto& dlc_id : dlc_ids_) {
- const auto& manifest = utils::LoadDlcManifest(
- imageloader::kDlcManifestRootpath, dlc_id, kDlcPackage);
+ const auto& manifest = SystemState::Get()->dlc_utils()->GetDlcManifest(
+ dlc_id, base::FilePath(imageloader::kDlcManifestRootpath));
if (!manifest) {
LOG(ERROR) << "Unable to load the manifest for DLC '" << dlc_id
<< "', treat it as a non-critical DLC.";
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc
index f5d2f893..030d3c06 100644
--- a/cros/update_attempter_unittest.cc
+++ b/cros/update_attempter_unittest.cc
@@ -33,6 +33,7 @@
#include <brillo/message_loops/base_message_loop.h>
#include <brillo/message_loops/message_loop.h>
#include <brillo/message_loops/message_loop_utils.h>
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <policy/libpolicy.h>
#include <policy/mock_device_policy.h>
@@ -235,6 +236,7 @@ class UpdateAttempterTest : public ::testing::Test {
FakeSystemState::Get()->set_connection_manager(&mock_connection_manager);
FakeSystemState::Get()->set_update_attempter(&attempter_);
FakeSystemState::Get()->set_dlcservice(&mock_dlcservice_);
+ FakeSystemState::Get()->set_dlc_utils(&mock_dlc_utils_);
prefs_ = FakeSystemState::Get()->fake_prefs();
certificate_checker_.reset(
@@ -329,6 +331,7 @@ class UpdateAttempterTest : public ::testing::Test {
OpenSSLWrapper openssl_wrapper_;
std::unique_ptr<CertificateChecker> certificate_checker_;
MockDlcService mock_dlcservice_;
+ MockDlcUtils mock_dlc_utils_;
NiceMock<MockActionProcessor>* processor_;
NiceMock<MockConnectionManager> mock_connection_manager;
@@ -2462,6 +2465,8 @@ TEST_F(UpdateAttempterTest, SetStatusAndNotifyTest) {
}
TEST_F(UpdateAttempterTest, CalculateDlcParamsInstallTest) {
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest)
+ .WillOnce(testing::Return(nullptr));
string dlc_id = "dlc0";
attempter_.pm_ = ProcessMode::INSTALL;
attempter_.dlc_ids_ = {dlc_id};
@@ -2488,6 +2493,8 @@ TEST_F(UpdateAttempterTest, CalculateDlcParamsNoPrefFilesTest) {
EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_))
.WillOnce(
DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true)));
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest)
+ .WillOnce(testing::Return(nullptr));
attempter_.pm_ = ProcessMode::UPDATE;
attempter_.CalculateDlcParams();
@@ -2512,6 +2519,8 @@ TEST_F(UpdateAttempterTest, CalculateDlcParamsNonParseableValuesTest) {
EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_))
.WillOnce(
DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true)));
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest)
+ .WillOnce(testing::Return(nullptr));
// Write non numeric values in the metadata files.
auto active_key =
@@ -2543,6 +2552,8 @@ TEST_F(UpdateAttempterTest, CalculateDlcParamsValidValuesTest) {
EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_))
.WillOnce(
DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true)));
+ EXPECT_CALL(mock_dlc_utils_, GetDlcManifest)
+ .WillOnce(testing::Return(nullptr));
// Write numeric values in the metadata files.
auto active_key =