Skip to content

Commit ea9131c

Browse files
committed
Merge GetDefaultAvb() into the default constructor of Avb
No callers need this class to be in a `std::unique_ptr`. If they did, they can still use `std::make_unique<Avb>()` to achieve the same outcome. Bug: b/436367852
1 parent 3075877 commit ea9131c

File tree

9 files changed

+16
-48
lines changed

9 files changed

+16
-48
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/boot_config.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ Result<void> PrepareBootEnvImage(
192192
const off_t boot_env_size_bytes =
193193
AlignToPowerOf2(kMaxAvbMetadataSize + 4096, PARTITION_SIZE_SHIFT);
194194

195-
std::unique_ptr<Avb> avbtool = GetDefaultAvb();
196-
CF_EXPECT(avbtool->AddHashFooter(tmp_boot_env_image_path, "uboot_env",
197-
boot_env_size_bytes));
195+
CF_EXPECT(Avb().AddHashFooter(tmp_boot_env_image_path, "uboot_env",
196+
boot_env_size_bytes));
198197

199198
if (!FileExists(image_path) ||
200199
ReadFile(image_path) != ReadFile(tmp_boot_env_image_path)) {

base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,9 @@ bool RepackVendorBootImage(const std::string& new_ramdisk,
370370
return false;
371371
}
372372

373-
std::unique_ptr<Avb> avbtool = GetDefaultAvb();
374-
if (!avbtool) {
375-
LOG(ERROR) << "Failed to create avb object";
376-
return false;
377-
}
378373
Result<void> result =
379-
avbtool->AddHashFooter(tmp_vendor_boot_image_path, "vendor_boot",
380-
FileSize(vendor_boot_image_path));
374+
Avb().AddHashFooter(tmp_vendor_boot_image_path, "vendor_boot",
375+
FileSize(vendor_boot_image_path));
381376
if (!result.ok()) {
382377
LOG(ERROR) << result.error().Trace();
383378
return false;
@@ -476,11 +471,8 @@ void RepackGem5BootImage(
476471
// https://source.android.com/docs/core/architecture/bootloader/boot-image-header
477472
Result<std::string> ReadAndroidVersionFromBootImage(
478473
const std::string& boot_image_path) {
479-
std::unique_ptr<Avb> avb = GetDefaultAvb();
480-
CF_EXPECT(avb.get());
481-
482474
std::string boot_params =
483-
CF_EXPECTF(avb->InfoImage(boot_image_path),
475+
CF_EXPECTF(Avb().InfoImage(boot_image_path),
484476
"Failed to get avb boot data from '{}'", boot_image_path);
485477

486478
std::string os_version =

base/cvd/cuttlefish/host/commands/assemble_cvd/create_dynamic_disk_files.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,10 @@ Result<void> CreateDynamicDiskFiles(
7676
const FetcherConfig& fetcher_config, const CuttlefishConfig& config,
7777
const SystemImageDirFlag& system_image_dir) {
7878
for (const auto& instance : config.Instances()) {
79-
std::unique_ptr<Avb> avb = GetDefaultAvb();
80-
CF_EXPECT(avb.get());
81-
8279
std::optional<ChromeOsStateImage> chrome_os_state =
8380
CF_EXPECT(ChromeOsStateImage::CreateIfNecessary(instance));
8481

85-
CF_EXPECT(RepackKernelRamdisk(config, instance, *avb));
82+
CF_EXPECT(RepackKernelRamdisk(config, instance, Avb()));
8683
CF_EXPECT(VbmetaEnforceMinimumSize(instance));
8784
CF_EXPECT(BootloaderPresentCheck(instance));
8885
CF_EXPECT(Gem5ImageUnpacker(config)); // Requires RepackKernelRamdisk

base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ Result<std::optional<BootConfigPartition>> BootConfigPartition::CreateIfNeeded(
8484
const off_t bootconfig_size_bytes = AlignToPowerOf2(
8585
kMaxAvbMetadataSize + bootconfig.size(), PARTITION_SIZE_SHIFT);
8686

87-
std::unique_ptr<Avb> avbtool = GetDefaultAvb();
88-
CF_EXPECT(avbtool->AddHashFooter(bootconfig_path, "bootconfig",
89-
bootconfig_size_bytes));
87+
CF_EXPECT(Avb().AddHashFooter(bootconfig_path, "bootconfig",
88+
bootconfig_size_bytes));
9089
}
9190

9291
return BootConfigPartition(std::move(bootconfig_path));

base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_vbmeta.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ namespace cuttlefish {
3131
namespace {
3232

3333
Result<void> PrepareVBMetaImage(const std::string& path, bool has_boot_config) {
34-
std::unique_ptr<Avb> avbtool = GetDefaultAvb();
3534
std::vector<ChainPartition> chained_partitions = {ChainPartition{
3635
.name = "uboot_env",
3736
.rollback_index = "1",
@@ -44,7 +43,7 @@ Result<void> PrepareVBMetaImage(const std::string& path, bool has_boot_config) {
4443
.key_path = TestPubKeyRsa4096(),
4544
});
4645
}
47-
CF_EXPECT(avbtool->MakeVbMetaImage(path, chained_partitions, {}, {}));
46+
CF_EXPECT(Avb().MakeVbMetaImage(path, chained_partitions, {}, {}));
4847
return {};
4948
}
5049

base/cvd/cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,8 @@ Result<void> BuildVbmetaImage(const std::string& image_path,
412412
CF_EXPECT(!image_path.empty());
413413
CF_EXPECTF(FileExists(image_path), "'{}' does not exist", image_path);
414414

415-
std::unique_ptr<Avb> avbtool = GetDefaultAvb();
416-
CF_EXPECT(avbtool->MakeVbMetaImage(vbmeta_path, {}, {image_path},
417-
{"--padding_size", "4096"}));
415+
CF_EXPECT(Avb().MakeVbMetaImage(vbmeta_path, {}, {image_path},
416+
{"--padding_size", "4096"}));
418417
return {};
419418
}
420419

base/cvd/cuttlefish/host/libs/avb/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ cf_cc_library(
1919
"//cuttlefish/common/libs/utils:subprocess",
2020
"//cuttlefish/common/libs/utils:subprocess_managed_stdio",
2121
"//cuttlefish/host/libs/config:known_paths",
22-
"@fruit",
2322
],
2423
)

base/cvd/cuttlefish/host/libs/avb/avb.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <memory>
2323
#include <string>
2424

25-
#include <fruit/fruit.h>
26-
2725
#include "cuttlefish/common/libs/fs/shared_fd.h"
2826
#include "cuttlefish/common/libs/utils/files.h"
2927
#include "cuttlefish/common/libs/utils/result.h"
@@ -44,6 +42,8 @@ constexpr size_t kVbMetaMaxSize = 65536ul;
4442

4543
} // namespace
4644

45+
Avb::Avb() : Avb(AvbToolBinary(), kDefaultAlgorithm, TestKeyRsa4096()) {}
46+
4747
Avb::Avb(std::string avbtool_path, std::string algorithm, std::string key)
4848
: avbtool_path_(std::move(avbtool_path)),
4949
algorithm_(std::move(algorithm)),
@@ -155,14 +155,4 @@ Result<void> EnforceVbMetaSize(const std::string& path) {
155155
return {};
156156
}
157157

158-
std::unique_ptr<Avb> GetDefaultAvb() {
159-
return std::unique_ptr<Avb>(
160-
new Avb(AvbToolBinary(), kDefaultAlgorithm, TestKeyRsa4096()));
161-
}
162-
163-
fruit::Component<Avb> CuttlefishKeyAvbComponent() {
164-
return fruit::createComponent().registerProvider(
165-
[]() -> Avb* { return GetDefaultAvb().release(); });
166-
}
167-
168158
} // namespace cuttlefish

base/cvd/cuttlefish/host/libs/avb/avb.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020
#include <sys/types.h>
2121

2222
#include <cstdint>
23-
#include <memory>
2423
#include <string>
2524
#include <vector>
2625

27-
#include <fruit/fruit.h>
28-
2926
#include "cuttlefish/common/libs/fs/shared_fd.h"
3027
#include "cuttlefish/common/libs/utils/subprocess.h"
3128

@@ -42,6 +39,7 @@ struct ChainPartition {
4239

4340
class Avb {
4441
public:
42+
Avb();
4543
Avb(std::string avbtool_path, std::string algorithm, std::string key);
4644

4745
/**
@@ -54,7 +52,7 @@ class Avb {
5452
*/
5553
Result<void> AddHashFooter(const std::string& image_path,
5654
const std::string& partition_name,
57-
const off_t partition_size_bytes) const;
55+
off_t partition_size_bytes) const;
5856
Result<std::string> InfoImage(const std::string& image_path) const;
5957
Result<void> MakeVbMetaImage(
6058
const std::string& output_path,
@@ -65,7 +63,7 @@ class Avb {
6563
private:
6664
Command GenerateAddHashFooter(const std::string& image_path,
6765
const std::string& partition_name,
68-
const off_t partition_size_bytes) const;
66+
off_t partition_size_bytes) const;
6967
Command GenerateInfoImage(const std::string& image_path,
7068
const SharedFD& output_path) const;
7169
Command GenerateMakeVbMetaImage(
@@ -81,8 +79,4 @@ class Avb {
8179

8280
Result<void> EnforceVbMetaSize(const std::string& path);
8381

84-
std::unique_ptr<Avb> GetDefaultAvb();
85-
86-
fruit::Component<Avb> CuttlefishKeyAvbComponent();
87-
8882
} // namespace cuttlefish

0 commit comments

Comments
 (0)