Support 'fastboot getvar unlocked' command.
Test: fastboot getvar unlocked. Bug: 78793464 Change-Id: Ie59c6db90a503e9a6e9ac1c416e4ee5deac60479
This commit is contained in:
parent
6590255dbb
commit
dca328d55c
4 changed files with 32 additions and 1 deletions
|
@ -159,6 +159,12 @@ bool FlashHandler(FastbootDevice* device, const std::vector<std::string>& args)
|
|||
if (args.size() < 2) {
|
||||
return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments");
|
||||
}
|
||||
|
||||
if (GetDeviceLockStatus()) {
|
||||
return device->WriteStatus(FastbootResult::FAIL,
|
||||
"Flashing is not allowed on locked devices");
|
||||
}
|
||||
|
||||
int ret = Flash(device, args[1]);
|
||||
if (ret < 0) {
|
||||
return device->WriteStatus(FastbootResult::FAIL, strerror(-ret));
|
||||
|
@ -304,6 +310,10 @@ bool CreatePartitionHandler(FastbootDevice* device, const std::vector<std::strin
|
|||
return device->WriteFail("Invalid partition name and size");
|
||||
}
|
||||
|
||||
if (GetDeviceLockStatus()) {
|
||||
return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices");
|
||||
}
|
||||
|
||||
uint64_t partition_size;
|
||||
std::string partition_name = args[1];
|
||||
if (!android::base::ParseUint(args[2].c_str(), &partition_size)) {
|
||||
|
@ -344,6 +354,10 @@ bool DeletePartitionHandler(FastbootDevice* device, const std::vector<std::strin
|
|||
return device->WriteFail("Invalid partition name and size");
|
||||
}
|
||||
|
||||
if (GetDeviceLockStatus()) {
|
||||
return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices");
|
||||
}
|
||||
|
||||
PartitionBuilder builder(device);
|
||||
if (!builder.Valid()) {
|
||||
return device->WriteFail("Could not open super partition");
|
||||
|
@ -360,6 +374,10 @@ bool ResizePartitionHandler(FastbootDevice* device, const std::vector<std::strin
|
|||
return device->WriteFail("Invalid partition name and size");
|
||||
}
|
||||
|
||||
if (GetDeviceLockStatus()) {
|
||||
return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices");
|
||||
}
|
||||
|
||||
uint64_t partition_size;
|
||||
std::string partition_name = args[1];
|
||||
if (!android::base::ParseUint(args[2].c_str(), &partition_size)) {
|
||||
|
@ -388,6 +406,11 @@ bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>&
|
|||
if (args.size() < 2) {
|
||||
return device->WriteFail("Invalid arguments");
|
||||
}
|
||||
|
||||
if (GetDeviceLockStatus()) {
|
||||
return device->WriteStatus(FastbootResult::FAIL, "Command not available on locked devices");
|
||||
}
|
||||
|
||||
bool wipe = (args.size() >= 3 && args[2] == "wipe");
|
||||
return UpdateSuper(device, args[1], wipe);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <fs_mgr_dm_linear.h>
|
||||
#include <liblp/liblp.h>
|
||||
|
@ -159,3 +160,9 @@ std::vector<std::string> ListPartitions(FastbootDevice* device) {
|
|||
}
|
||||
return partitions;
|
||||
}
|
||||
|
||||
bool GetDeviceLockStatus() {
|
||||
std::string cmdline;
|
||||
android::base::ReadFileToString("/proc/cmdline", &cmdline);
|
||||
return cmdline.find("androidboot.verifiedbootstate=orange") == std::string::npos;
|
||||
}
|
||||
|
|
|
@ -58,3 +58,4 @@ bool LogicalPartitionExists(const std::string& name, const std::string& slot_suf
|
|||
bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHandle* handle);
|
||||
bool GetSlotNumber(const std::string& slot, android::hardware::boot::V1_0::Slot* number);
|
||||
std::vector<std::string> ListPartitions(FastbootDevice* device);
|
||||
bool GetDeviceLockStatus();
|
||||
|
|
|
@ -148,7 +148,7 @@ bool GetMaxDownloadSize(FastbootDevice* /* device */, const std::vector<std::str
|
|||
|
||||
bool GetUnlocked(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
|
||||
std::string* message) {
|
||||
*message = "yes";
|
||||
*message = GetDeviceLockStatus() ? "no" : "yes";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue