Lines Matching refs:device

74 static bool IsSnapshotUpdateInProgress(FastbootDevice* device) {  in IsSnapshotUpdateInProgress()  argument
75 auto hal = device->boot1_1(); in IsSnapshotUpdateInProgress()
83 static bool IsProtectedPartitionDuringMerge(FastbootDevice* device, const std::string& name) { in IsProtectedPartitionDuringMerge() argument
89 return IsSnapshotUpdateInProgress(device); in IsProtectedPartitionDuringMerge()
92 static void GetAllVars(FastbootDevice* device, const std::string& name, in GetAllVars() argument
96 if (!handlers.get(device, std::vector<std::string>(), &message)) { in GetAllVars()
99 device->WriteInfo(android::base::StringPrintf("%s:%s", name.c_str(), message.c_str())); in GetAllVars()
103 auto all_args = handlers.get_all_args(device); in GetAllVars()
106 if (!handlers.get(device, args, &message)) { in GetAllVars()
110 device->WriteInfo(android::base::StringPrintf("%s:%s:%s", name.c_str(), arg_string.c_str(), in GetAllVars()
115 bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args) { in GetVarHandler() argument
154 return device->WriteFail("Missing argument"); in GetVarHandler()
160 GetAllVars(device, name, handlers); in GetVarHandler()
162 return device->WriteOkay(""); in GetVarHandler()
168 return device->WriteFail("Unknown variable"); in GetVarHandler()
173 if (!found_variable->second.get(device, getvar_args, &message)) { in GetVarHandler()
174 return device->WriteFail(message); in GetVarHandler()
176 return device->WriteOkay(message); in GetVarHandler()
179 bool OemPostWipeData(FastbootDevice* device) { in OemPostWipeData() argument
180 auto fastboot_hal = device->fastboot_hal(); in OemPostWipeData()
193 device->WriteStatus(FastbootResult::FAIL, ret.message); in OemPostWipeData()
195 device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded"); in OemPostWipeData()
201 bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) { in EraseHandler() argument
203 return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments"); in EraseHandler()
207 return device->WriteStatus(FastbootResult::FAIL, "Erase is not allowed on locked devices"); in EraseHandler()
211 if (IsProtectedPartitionDuringMerge(device, partition_name)) { in EraseHandler()
213 return device->WriteFail(message); in EraseHandler()
217 if (!OpenPartition(device, partition_name, &handle)) { in EraseHandler()
218 return device->WriteStatus(FastbootResult::FAIL, "Partition doesn't exist"); in EraseHandler()
224 support_oem_postwipedata = OemPostWipeData(device); in EraseHandler()
228 return device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded"); in EraseHandler()
234 return device->WriteStatus(FastbootResult::FAIL, "Erasing failed"); in EraseHandler()
237 bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args) { in OemCmdHandler() argument
238 auto fastboot_hal = device->fastboot_hal(); in OemCmdHandler()
240 return device->WriteStatus(FastbootResult::FAIL, "Unable to open fastboot HAL"); in OemCmdHandler()
245 return device->WriteStatus(FastbootResult::FAIL, "Unable to do oem postwipedata userdata"); in OemCmdHandler()
251 return device->WriteStatus(FastbootResult::FAIL, "Unable to do OEM command"); in OemCmdHandler()
254 return device->WriteStatus(FastbootResult::FAIL, ret.message); in OemCmdHandler()
257 return device->WriteStatus(FastbootResult::OKAY, ret.message); in OemCmdHandler()
260 bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& args) { in DownloadHandler() argument
262 return device->WriteStatus(FastbootResult::FAIL, "size argument unspecified"); in DownloadHandler()
266 return device->WriteStatus(FastbootResult::FAIL, in DownloadHandler()
273 return device->WriteStatus(FastbootResult::FAIL, "Invalid size"); in DownloadHandler()
275 device->download_data().resize(size); in DownloadHandler()
276 if (!device->WriteStatus(FastbootResult::DATA, android::base::StringPrintf("%08x", size))) { in DownloadHandler()
280 if (device->HandleData(true, &device->download_data())) { in DownloadHandler()
281 return device->WriteStatus(FastbootResult::OKAY, ""); in DownloadHandler()
285 return device->WriteStatus(FastbootResult::FAIL, "Couldn't download data"); in DownloadHandler()
288 bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& args) { in SetActiveHandler() argument
290 return device->WriteStatus(FastbootResult::FAIL, "Missing slot argument"); in SetActiveHandler()
294 return device->WriteStatus(FastbootResult::FAIL, in SetActiveHandler()
301 return device->WriteStatus(FastbootResult::FAIL, "Bad slot suffix"); in SetActiveHandler()
305 auto boot_control_hal = device->boot_control_hal(); in SetActiveHandler()
307 return device->WriteStatus(FastbootResult::FAIL, in SetActiveHandler()
311 return device->WriteStatus(FastbootResult::FAIL, "Slot out of range"); in SetActiveHandler()
315 if (args[1] == device->GetCurrentSlot()) { in SetActiveHandler()
316 return device->WriteOkay(""); in SetActiveHandler()
320 if (auto hal11 = device->boot1_1()) { in SetActiveHandler()
323 return device->WriteFail("Cannot change slots while a snapshot update is in progress"); in SetActiveHandler()
333 device->WriteInfo( in SetActiveHandler()
346 device->set_active_slot(current_slot); in SetActiveHandler()
347 return device->WriteStatus(FastbootResult::OKAY, ""); in SetActiveHandler()
349 return device->WriteStatus(FastbootResult::FAIL, "Unable to set slot"); in SetActiveHandler()
352 bool ShutDownHandler(FastbootDevice* device, const std::vector<std::string>& /* args */) { in ShutDownHandler() argument
353 auto result = device->WriteStatus(FastbootResult::OKAY, "Shutting down"); in ShutDownHandler()
355 device->CloseDevice(); in ShutDownHandler()
360 bool RebootHandler(FastbootDevice* device, const std::vector<std::string>& /* args */) { in RebootHandler() argument
361 auto result = device->WriteStatus(FastbootResult::OKAY, "Rebooting"); in RebootHandler()
363 device->CloseDevice(); in RebootHandler()
368 bool RebootBootloaderHandler(FastbootDevice* device, const std::vector<std::string>& /* args */) { in RebootBootloaderHandler() argument
369 auto result = device->WriteStatus(FastbootResult::OKAY, "Rebooting bootloader"); in RebootBootloaderHandler()
371 device->CloseDevice(); in RebootBootloaderHandler()
376 bool RebootFastbootHandler(FastbootDevice* device, const std::vector<std::string>& /* args */) { in RebootFastbootHandler() argument
377 auto result = device->WriteStatus(FastbootResult::OKAY, "Rebooting fastboot"); in RebootFastbootHandler()
379 device->CloseDevice(); in RebootFastbootHandler()
410 bool RebootRecoveryHandler(FastbootDevice* device, const std::vector<std::string>& /* args */) { in RebootRecoveryHandler() argument
413 status = device->WriteStatus(FastbootResult::OKAY, "Rebooting to recovery"); in RebootRecoveryHandler()
415 status = device->WriteStatus(FastbootResult::FAIL, "Unable to reboot to recovery"); in RebootRecoveryHandler()
417 device->CloseDevice(); in RebootRecoveryHandler()
426 explicit PartitionBuilder(FastbootDevice* device, const std::string& partition_name);
439 PartitionBuilder::PartitionBuilder(FastbootDevice* device, const std::string& partition_name) in PartitionBuilder() argument
440 : device_(device) { in PartitionBuilder()
441 std::string slot_suffix = GetSuperSlotSuffix(device, partition_name); in PartitionBuilder()
459 bool CreatePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args) { in CreatePartitionHandler() argument
461 return device->WriteFail("Invalid partition name and size"); in CreatePartitionHandler()
465 return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices"); in CreatePartitionHandler()
471 return device->WriteFail("Invalid partition size"); in CreatePartitionHandler()
474 PartitionBuilder builder(device, partition_name); in CreatePartitionHandler()
476 return device->WriteFail("Could not open super partition"); in CreatePartitionHandler()
480 return device->WriteFail("Partition already exists"); in CreatePartitionHandler()
485 return device->WriteFail("Failed to add partition"); in CreatePartitionHandler()
489 return device->WriteFail("Not enough space for partition"); in CreatePartitionHandler()
492 return device->WriteFail("Failed to write partition table"); in CreatePartitionHandler()
494 return device->WriteOkay("Partition created"); in CreatePartitionHandler()
497 bool DeletePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args) { in DeletePartitionHandler() argument
499 return device->WriteFail("Invalid partition name and size"); in DeletePartitionHandler()
503 return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices"); in DeletePartitionHandler()
508 PartitionBuilder builder(device, partition_name); in DeletePartitionHandler()
510 return device->WriteFail("Could not open super partition"); in DeletePartitionHandler()
514 return device->WriteFail("Failed to write partition table"); in DeletePartitionHandler()
516 return device->WriteOkay("Partition deleted"); in DeletePartitionHandler()
519 bool ResizePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args) { in ResizePartitionHandler() argument
521 return device->WriteFail("Invalid partition name and size"); in ResizePartitionHandler()
525 return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices"); in ResizePartitionHandler()
531 return device->WriteFail("Invalid partition size"); in ResizePartitionHandler()
534 PartitionBuilder builder(device, partition_name); in ResizePartitionHandler()
536 return device->WriteFail("Could not open super partition"); in ResizePartitionHandler()
541 return device->WriteFail("Partition does not exist"); in ResizePartitionHandler()
549 return device->WriteFail("Not enough space to resize partition"); in ResizePartitionHandler()
552 return device->WriteFail("Failed to write partition table"); in ResizePartitionHandler()
554 return device->WriteOkay("Partition resized"); in ResizePartitionHandler()
557 void CancelPartitionSnapshot(FastbootDevice* device, const std::string& partition_name) { in CancelPartitionSnapshot() argument
558 PartitionBuilder builder(device, partition_name); in CancelPartitionSnapshot()
571 bool FlashHandler(FastbootDevice* device, const std::vector<std::string>& args) { in FlashHandler() argument
573 return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments"); in FlashHandler()
577 return device->WriteStatus(FastbootResult::FAIL, in FlashHandler()
582 if (IsProtectedPartitionDuringMerge(device, partition_name)) { in FlashHandler()
584 return device->WriteFail(message); in FlashHandler()
587 if (LogicalPartitionExists(device, partition_name)) { in FlashHandler()
588 CancelPartitionSnapshot(device, partition_name); in FlashHandler()
591 int ret = Flash(device, partition_name); in FlashHandler()
593 return device->WriteStatus(FastbootResult::FAIL, strerror(-ret)); in FlashHandler()
595 return device->WriteStatus(FastbootResult::OKAY, "Flashing succeeded"); in FlashHandler()
598 bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>& args) { in UpdateSuperHandler() argument
600 return device->WriteFail("Invalid arguments"); in UpdateSuperHandler()
604 return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices"); in UpdateSuperHandler()
608 return UpdateSuper(device, args[1], wipe); in UpdateSuperHandler()
611 bool GsiHandler(FastbootDevice* device, const std::vector<std::string>& args) { in GsiHandler() argument
613 return device->WriteFail("Invalid arguments"); in GsiHandler()
618 return device->WriteFail("Could not find GSI install"); in GsiHandler()
622 return device->WriteStatus(FastbootResult::FAIL, "No GSI is installed"); in GsiHandler()
627 return device->WriteStatus(FastbootResult::FAIL, strerror(errno)); in GsiHandler()
631 return device->WriteStatus(FastbootResult::FAIL, strerror(errno)); in GsiHandler()
634 return device->WriteStatus(FastbootResult::OKAY, "Success"); in GsiHandler()
637 bool SnapshotUpdateHandler(FastbootDevice* device, const std::vector<std::string>& args) { in SnapshotUpdateHandler() argument
640 auto hal = device->boot1_1(); in SnapshotUpdateHandler()
641 if (!hal) return device->WriteFail("Not supported"); in SnapshotUpdateHandler()
648 if (!GetSnapshotUpdateStatus(device, {}, &message)) { in SnapshotUpdateHandler()
649 return device->WriteFail("Could not determine update status"); in SnapshotUpdateHandler()
651 device->WriteInfo(message); in SnapshotUpdateHandler()
652 return device->WriteOkay(""); in SnapshotUpdateHandler()
658 return device->WriteFail("Invalid arguments"); in SnapshotUpdateHandler()
671 return device->WriteFail("No snapshot merge is in progress"); in SnapshotUpdateHandler()
676 return device->WriteFail("Unable to create SnapshotManager"); in SnapshotUpdateHandler()
679 return device->WriteFail("Unable to finish snapshot merge"); in SnapshotUpdateHandler()
682 return device->WriteFail("Invalid parameter to snapshot-update"); in SnapshotUpdateHandler()
684 return device->WriteStatus(FastbootResult::OKAY, "Success"); in SnapshotUpdateHandler()
691 static bool Fetch(FastbootDevice* device, const std::vector<std::string>& args) { in Fetch() argument
693 return device->WriteFail("Fetch is not allowed on user build"); in Fetch()
697 return device->WriteFail("Fetch is not allowed on locked devices"); in Fetch()
700 PartitionFetcher fetcher(device, args); in Fetch()
709 PartitionFetcher(FastbootDevice* device, const std::vector<std::string>& args) in PartitionFetcher() argument
710 : device_(device), args_(&args) {} in PartitionFetcher()
855 bool FetchHandler(FastbootDevice* device, const std::vector<std::string>& args) { in FetchHandler() argument
856 return PartitionFetcher::Fetch(device, args); in FetchHandler()