Android目前的版本只能旧版本升级新版本,无法升级旧版本。
Android OTA升级主要是ota_from_target_files.py这个脚本,文件目录在build/tools/releasetools,OTA升级判断版本是否可以升级,主要基于时间戳的判断,既然基于时间戳判断,只要将脚本中时间的判断注释即可。
def WriteFullOTAPackage(input_zip, output_file):
target_info = BuildInfo(OPTIONS.info_dict, OPTIONS.oem_dicts)
# We don't know what version it will be installed on top of. We expect the API
# just won't change very often. Similarly for fstab, it might have changed in
# the target build.
target_api_version = target_info["recovery_api_version"]
script = edify_generator.EdifyGenerator(target_api_version, target_info)
.......
.......
# Assertions (e.g. downgrade check, device properties check).
ts = target_info.GetBuildProp("ro.build.date.utc")
ts_text = target_info.GetBuildProp("ro.build.date")
script.AssertOlderBuild(ts, ts_text)
script.AssertOlderBuild(ts, ts_text)方法是判断时间戳,将此方法注释即可,编译OTA升级包验证,发现下载升级时提示版本不支持升级。
项目使用的Android版本是9.0,OTA升级会先下载升级包,下载升级也会判断时间戳,只能梳理下载的流程,最后发现在system/update_engine/payload_consumer/delta_performer.cc文件中判断时间戳
ErrorCode DeltaPerformer::ValidateManifest() {
// Perform assorted checks to sanity check the manifest, make sure it
// matches data from other sources, and that it is a supported version.
bool has_old_fields =
(manifest_.has_old_kernel_info() || manifest_.has_old_rootfs_info());
for (const PartitionUpdate& partition : manifest_.partitions()) {
has_old_fields = has_old_fields || partition.has_old_partition_info();
}
......
......
if (manifest_.max_timestamp() < hardware_->GetBuildTimestamp()) {
LOG(ERROR) << "The current OS build timestamp ("
<< hardware_->GetBuildTimestamp()
<< ") is newer than the maximum timestamp in the manifest ("
<< manifest_.max_timestamp() << ")";
return ErrorCode::kPayloadTimestampError;
}
// TODO(garnold) we should be adding more and more manifest checks, such as
// partition boundaries etc (see chromium-os:37661)..
return ErrorCode::kSuccess;
}
其中if判断则是时间戳判断,将此判断注释即可