Cleaning up main code
cleaning up main() code in fastboot.cpp to run off one task vector. The eventual goal is to just have all functionality run off this vector. Test: tested commands on raven Bug: 194686221 Change-Id: I98d0ba33091eff31ff1bc338766c3689ffb54746
This commit is contained in:
parent
1418fb8ce0
commit
76c9343339
|
@ -2192,7 +2192,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::unique_ptr<Task> reboot_task = nullptr;
|
std::vector<std::unique_ptr<Task>> tasks;
|
||||||
std::vector<std::string> args(argv, argv + argc);
|
std::vector<std::string> args(argv, argv + argc);
|
||||||
while (!args.empty()) {
|
while (!args.empty()) {
|
||||||
std::string command = next_arg(&args);
|
std::string command = next_arg(&args);
|
||||||
|
@ -2246,17 +2246,17 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
} else if (command == FB_CMD_REBOOT) {
|
} else if (command == FB_CMD_REBOOT) {
|
||||||
if (args.size() == 1) {
|
if (args.size() == 1) {
|
||||||
std::string reboot_target = next_arg(&args);
|
std::string reboot_target = next_arg(&args);
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get(), reboot_target);
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get(), reboot_target));
|
||||||
} else if (!fp->skip_reboot) {
|
} else if (!fp->skip_reboot) {
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get());
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get()));
|
||||||
}
|
}
|
||||||
if (!args.empty()) syntax_error("junk after reboot command");
|
if (!args.empty()) syntax_error("junk after reboot command");
|
||||||
} else if (command == FB_CMD_REBOOT_BOOTLOADER) {
|
} else if (command == FB_CMD_REBOOT_BOOTLOADER) {
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get(), "bootloader");
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get(), "bootloader"));
|
||||||
} else if (command == FB_CMD_REBOOT_RECOVERY) {
|
} else if (command == FB_CMD_REBOOT_RECOVERY) {
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get(), "recovery");
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get(), "recovery"));
|
||||||
} else if (command == FB_CMD_REBOOT_FASTBOOT) {
|
} else if (command == FB_CMD_REBOOT_FASTBOOT) {
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get(), "fastboot");
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get(), "fastboot"));
|
||||||
} else if (command == FB_CMD_CONTINUE) {
|
} else if (command == FB_CMD_CONTINUE) {
|
||||||
fb->Continue();
|
fb->Continue();
|
||||||
} else if (command == FB_CMD_BOOT) {
|
} else if (command == FB_CMD_BOOT) {
|
||||||
|
@ -2278,7 +2278,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str());
|
if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str());
|
||||||
|
|
||||||
FlashTask task(slot_override, pname, fname, is_vbmeta_partition(pname));
|
FlashTask task(fp->slot_override, pname, fname, is_vbmeta_partition(pname));
|
||||||
task.Run();
|
task.Run();
|
||||||
} else if (command == "flash:raw") {
|
} else if (command == "flash:raw") {
|
||||||
std::string partition = next_arg(&args);
|
std::string partition = next_arg(&args);
|
||||||
|
@ -2298,12 +2298,11 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Warning: slot set to 'all'. Secondary slots will not be flashed.\n");
|
"Warning: slot set to 'all'. Secondary slots will not be flashed.\n");
|
||||||
fp->skip_secondary = true;
|
fp->skip_secondary = true;
|
||||||
do_flashall(fp.get());
|
|
||||||
} else {
|
|
||||||
do_flashall(fp.get());
|
|
||||||
}
|
}
|
||||||
|
do_flashall(fp.get());
|
||||||
|
|
||||||
if (!fp->skip_reboot) {
|
if (!fp->skip_reboot) {
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get());
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get()));
|
||||||
}
|
}
|
||||||
} else if (command == "update") {
|
} else if (command == "update") {
|
||||||
bool slot_all = (slot_override == "all");
|
bool slot_all = (slot_override == "all");
|
||||||
|
@ -2317,7 +2316,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
do_update(filename.c_str(), fp.get());
|
do_update(filename.c_str(), fp.get());
|
||||||
if (!fp->skip_reboot) {
|
if (!fp->skip_reboot) {
|
||||||
reboot_task = std::make_unique<RebootTask>(fp.get());
|
tasks.emplace_back(std::make_unique<RebootTask>(fp.get()));
|
||||||
}
|
}
|
||||||
} else if (command == FB_CMD_SET_ACTIVE) {
|
} else if (command == FB_CMD_SET_ACTIVE) {
|
||||||
std::string slot = verify_slot(next_arg(&args), false);
|
std::string slot = verify_slot(next_arg(&args), false);
|
||||||
|
@ -2351,13 +2350,12 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
fb->CreatePartition(partition, size);
|
fb->CreatePartition(partition, size);
|
||||||
} else if (command == FB_CMD_DELETE_PARTITION) {
|
} else if (command == FB_CMD_DELETE_PARTITION) {
|
||||||
std::string partition = next_arg(&args);
|
std::string partition = next_arg(&args);
|
||||||
auto delete_task = std::make_unique<DeleteTask>(fp.get(), partition);
|
tasks.emplace_back(std::make_unique<DeleteTask>(fp.get(), partition));
|
||||||
fb->DeletePartition(partition);
|
|
||||||
} else if (command == FB_CMD_RESIZE_PARTITION) {
|
} else if (command == FB_CMD_RESIZE_PARTITION) {
|
||||||
std::string partition = next_arg(&args);
|
std::string partition = next_arg(&args);
|
||||||
std::string size = next_arg(&args);
|
std::string size = next_arg(&args);
|
||||||
std::unique_ptr<ResizeTask> resize_task =
|
std::unique_ptr<ResizeTask> resize_task =
|
||||||
std::make_unique<ResizeTask>(fp.get(), partition, size, slot_override);
|
std::make_unique<ResizeTask>(fp.get(), partition, size, fp->slot_override);
|
||||||
resize_task->Run();
|
resize_task->Run();
|
||||||
} else if (command == "gsi") {
|
} else if (command == "gsi") {
|
||||||
std::string arg = next_arg(&args);
|
std::string arg = next_arg(&args);
|
||||||
|
@ -2400,15 +2398,14 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
std::vector<std::string> partitions = {"userdata", "cache", "metadata"};
|
std::vector<std::string> partitions = {"userdata", "cache", "metadata"};
|
||||||
for (const auto& partition : partitions) {
|
for (const auto& partition : partitions) {
|
||||||
std::unique_ptr<WipeTask> wipe_task = std::make_unique<WipeTask>(fp.get(), partition);
|
tasks.emplace_back(std::make_unique<WipeTask>(fp.get(), partition));
|
||||||
wipe_task->Run();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fp->wants_set_active) {
|
if (fp->wants_set_active) {
|
||||||
fb->SetActive(next_active);
|
fb->SetActive(next_active);
|
||||||
}
|
}
|
||||||
if (reboot_task) {
|
for (auto& task : tasks) {
|
||||||
reboot_task->Run();
|
task->Run();
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Finished. Total time: %.3fs\n", (now() - start));
|
fprintf(stderr, "Finished. Total time: %.3fs\n", (now() - start));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue