Support 'fastboot getvar unlocked' command.
Test: fastboot getvar unlocked.
Bug: 78793464
Change-Id: Ie59c6db90a503e9a6e9ac1c416e4ee5deac60479
diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp
index 0ec0994..9914227 100644
--- a/fastboot/device/commands.cpp
+++ b/fastboot/device/commands.cpp
@@ -159,6 +159,12 @@
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 @@
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 @@
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 @@
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 @@
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);
}
diff --git a/fastboot/device/utility.cpp b/fastboot/device/utility.cpp
index 261a202..02f6f2c 100644
--- a/fastboot/device/utility.cpp
+++ b/fastboot/device/utility.cpp
@@ -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 @@
}
return partitions;
}
+
+bool GetDeviceLockStatus() {
+ std::string cmdline;
+ android::base::ReadFileToString("/proc/cmdline", &cmdline);
+ return cmdline.find("androidboot.verifiedbootstate=orange") == std::string::npos;
+}
diff --git a/fastboot/device/utility.h b/fastboot/device/utility.h
index 4f0d079..bb08f72 100644
--- a/fastboot/device/utility.h
+++ b/fastboot/device/utility.h
@@ -58,3 +58,4 @@
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();
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp
index 7535248..002e043 100644
--- a/fastboot/device/variables.cpp
+++ b/fastboot/device/variables.cpp
@@ -148,7 +148,7 @@
bool GetUnlocked(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
std::string* message) {
- *message = "yes";
+ *message = GetDeviceLockStatus() ? "no" : "yes";
return true;
}