Only prevent boot image downgrade if sysprop set.
Only return timestamp error if ro.build.ab_update.gki.prevent_downgrade_version is set.
Otherwise, log warning message and continue the update.
This allows devices that does not support GKI updates to install OTA packages where
the boot image has a lower version than the existing, which is supported before.
Bug: 162623577
Test: apply OTA on devices with and without sysprop set
Change-Id: Ie98fb49ffaae1aa60fc94766f53a6fbbae519a5b
diff --git a/hardware_android.cc b/hardware_android.cc
index 4894522..fc6e1dc 100644
--- a/hardware_android.cc
+++ b/hardware_android.cc
@@ -23,6 +23,7 @@
#include <string>
#include <string_view>
+#include <android/sysprop/GkiProperties.sysprop.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <base/files/file_util.h>
@@ -261,7 +262,10 @@
PLOG(ERROR) << "Unable to call uname()";
return ErrorCode::kError;
}
- return IsKernelUpdateValid(buf.release, new_version);
+ bool prevent_downgrade =
+ android::sysprop::GkiProperties::prevent_downgrade_version().value_or(
+ false);
+ return IsKernelUpdateValid(buf.release, new_version, prevent_downgrade);
}
const auto old_version = GetPartitionBuildDate(partition_name);
@@ -278,7 +282,8 @@
}
ErrorCode HardwareAndroid::IsKernelUpdateValid(const string& old_release,
- const string& new_release) {
+ const string& new_release,
+ bool prevent_downgrade) {
// Check that the package either contain an empty version (indicating that the
// new build does not use GKI), or a valid GKI kernel release.
std::optional<KernelRelease> new_kernel_release;
@@ -296,10 +301,17 @@
auto old_kernel_release =
KernelRelease::Parse(old_release, true /* allow_suffix */);
- return android::kver::IsKernelUpdateValid(old_kernel_release,
- new_kernel_release)
- ? ErrorCode::kSuccess
- : ErrorCode::kPayloadTimestampError;
+ bool is_update_valid = android::kver::IsKernelUpdateValid(old_kernel_release,
+ new_kernel_release);
+
+ if (!is_update_valid) {
+ if (prevent_downgrade) {
+ return ErrorCode::kPayloadTimestampError;
+ }
+ LOG(WARNING) << "Boot version downgrade detected, allowing update because "
+ << "prevent_downgrade_version sysprop is not set.";
+ }
+ return ErrorCode::kSuccess;
}
} // namespace chromeos_update_engine