#include <cutils/android_get_control_file.h>
#include <fs_mgr.h>
#endif
+#ifdef ENABLE_JSON
#include <jsonpb/jsonpb.h>
+#endif
#include <liblp/builder.h>
#include <liblp/liblp.h>
+#ifdef ENABLE_JSON
#include "dynamic_partitions_device_info.pb.h"
+#endif
using namespace android;
using namespace android::fs_mgr;
"\n"
"Options:\n"
" -s, --slot=N Slot number or suffix.\n"
+#ifdef ENABLE_JSON
" -j, --json Print in JSON format.\n"
+#endif
" -d, --dump-metadata-size\n"
" Print the space reserved for metadata to stdout\n"
" in bytes.\n"
return s;
}
+#ifdef ENABLE_JSON
// Merge proto with information from metadata.
static bool MergeMetadata(const LpMetadata* metadata,
DynamicPartitionsDeviceInfoProto* proto) {
cout << *error_or_json;
return EX_OK;
}
+#endif
static int DumpMetadataSize(const LpMetadata& metadata, std::ostream& cout) {
auto super_device = GetMetadataSuperBlockDevice(metadata);
{ "all", no_argument, nullptr, 'a' },
{ "slot", required_argument, nullptr, 's' },
{ "help", no_argument, nullptr, 'h' },
+#ifdef ENABLE_JSON
{ "json", no_argument, nullptr, 'j' },
+#endif
{ "dump-metadata-size", no_argument, nullptr, 'd' },
{ "is-super-empty", no_argument, nullptr, 'e' },
{ nullptr, 0, nullptr, 0 },
int rv;
int index;
+#ifdef ENABLE_JSON
bool json = false;
+#endif
bool dump_metadata_size = false;
bool dump_all = false;
std::optional<uint32_t> slot;
case 'd':
dump_metadata_size = true;
break;
+#ifdef ENABLE_JSON
case 'j':
json = true;
break;
+#endif
case '?':
case ':':
return usage(argc, argv, cerr);
cerr << "Cannot specify both --all and --slot.\n";
return usage(argc, argv, cerr);
}
+#ifdef ENABLE_JSON
if (json) {
cerr << "Cannot specify both --all and --json.\n";
return usage(argc, argv, cerr);
}
-
+#endif
// When dumping everything always start from the first slot.
slot = 0;
}
auto pt = ReadDeviceOrFile(super_path, slot.value());
+#ifdef ENABLE_JSON
// --json option doesn't require metadata to be present.
if (json) {
return PrintJson(pt.get(), cout, cerr);
}
-
+#endif
+
if (!pt) {
cerr << "Failed to read metadata.\n";
return EX_NOINPUT;