diff options
author | 2022-03-07 18:08:32 +0000 | |
---|---|---|
committer | 2022-03-07 18:08:32 +0000 | |
commit | c1f9ae3c7ed18a8528ff7d0eb55e096413ad0238 (patch) | |
tree | b5a21dc469b74174baf80099773ccf5beeea7b56 | |
parent | de49d24993aaa5628ec04df989149be43ee85c1a (diff) | |
parent | 39f6d00b731c8e043d984c4f508e72b1f9fc54a6 (diff) |
odrefresh: Stop refreshing artifacts on new Android versions. am: 39f6d00b73
Original change: https://android-review.googlesource.com/c/platform/art/+/1980107
Change-Id: I4b0b14bbd98a1b474cf6ce23bbd58f9928fea450
-rw-r--r-- | odrefresh/Android.bp | 1 | ||||
-rw-r--r-- | odrefresh/odr_common.cc | 12 | ||||
-rw-r--r-- | odrefresh/odr_common.h | 5 | ||||
-rw-r--r-- | odrefresh/odr_common_test.cc | 34 | ||||
-rw-r--r-- | odrefresh/odrefresh.h | 6 | ||||
-rw-r--r-- | odrefresh/odrefresh_main.cc | 6 |
6 files changed, 61 insertions, 3 deletions
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp index 04d65b94c3..8fee83a38a 100644 --- a/odrefresh/Android.bp +++ b/odrefresh/Android.bp @@ -182,6 +182,7 @@ art_cc_defaults { header_libs: ["odrefresh_headers"], srcs: [ "odr_artifacts_test.cc", + "odr_common_test.cc", "odr_compilation_log_test.cc", "odr_fs_utils_test.cc", "odr_metrics_test.cc", diff --git a/odrefresh/odr_common.cc b/odrefresh/odr_common.cc index 8f4e263f4c..c3c410e71b 100644 --- a/odrefresh/odr_common.cc +++ b/odrefresh/odr_common.cc @@ -21,6 +21,9 @@ #include <string> #include <string_view> +#include "android-base/logging.h" +#include "android-base/parseint.h" + namespace art { namespace odrefresh { @@ -36,5 +39,14 @@ std::string QuotePath(std::string_view path) { return Concatenate({"'", path, "'"}); } +bool ShouldDisableRefresh(const std::string& sdk_version_str) { + int sdk_version = 0; + if (!android::base::ParseInt(sdk_version_str, &sdk_version)) { + LOG(ERROR) << "Invalid SDK version string \"" << sdk_version_str << "\""; + return false; + } + return sdk_version >= 32; +} + } // namespace odrefresh } // namespace art diff --git a/odrefresh/odr_common.h b/odrefresh/odr_common.h index 7aad354d79..c7680e2612 100644 --- a/odrefresh/odr_common.h +++ b/odrefresh/odr_common.h @@ -30,6 +30,11 @@ std::string Concatenate(std::initializer_list<std::string_view> args); // Quotes a path with single quotes ('). std::string QuotePath(std::string_view path); +// Returns true if there is no need to load existing artifacts that are already up-to-date and write +// them back. See `OnDeviceRefresh::RefreshExistingArtifacts` for more details. Takes a string from +// `ro.build.version.sdk`, which represents the SDK version. +bool ShouldDisableRefresh(const std::string& sdk_version_str); + } // namespace odrefresh } // namespace art diff --git a/odrefresh/odr_common_test.cc b/odrefresh/odr_common_test.cc new file mode 100644 index 0000000000..976b3f0666 --- /dev/null +++ b/odrefresh/odr_common_test.cc @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "odr_common.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace art { +namespace odrefresh { + +TEST(OdrCommonTest, ShouldDisableRefresh) { + EXPECT_TRUE(ShouldDisableRefresh("32")); + EXPECT_TRUE(ShouldDisableRefresh("33")); + EXPECT_FALSE(ShouldDisableRefresh("31")); + EXPECT_FALSE(ShouldDisableRefresh("")); + EXPECT_FALSE(ShouldDisableRefresh("invalid")); +} + +} // namespace odrefresh +} // namespace art diff --git a/odrefresh/odrefresh.h b/odrefresh/odrefresh.h index 4558344fed..58da57a1cd 100644 --- a/odrefresh/odrefresh.h +++ b/odrefresh/odrefresh.h @@ -114,9 +114,9 @@ class OnDeviceRefresh final { android::base::Result<void> CleanupArtifactDirectory( const std::vector<std::string>& artifacts_to_keep) const; - // Loads artifacts to memory and writes them back. This essentially removes the existing artifacts - // from fs-verity so that odsign will not encounter "file exists" error when it adds the existing - // artifacts to fs-verity. + // Loads artifacts to memory and writes them back. This is a workaround for old versions of + // odsign, which encounters "file exists" error when it adds existing artifacts to fs-verity. This + // function essentially removes existing artifacts from fs-verity to avoid the error. android::base::Result<void> RefreshExistingArtifacts() const; // Checks whether all boot classpath artifacts are present. Returns true if all are present, false diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc index 6dbe3722dc..c2298f038c 100644 --- a/odrefresh/odrefresh_main.cc +++ b/odrefresh/odrefresh_main.cc @@ -41,6 +41,7 @@ using ::art::odrefresh::OdrConfig; using ::art::odrefresh::OdrMetrics; using ::art::odrefresh::OnDeviceRefresh; using ::art::odrefresh::QuotePath; +using ::art::odrefresh::ShouldDisableRefresh; using ::art::odrefresh::ZygoteKind; void UsageMsgV(const char* fmt, va_list ap) { @@ -168,6 +169,11 @@ int InitializeConfig(int argc, char** argv, OdrConfig* config) { config->SetSystemServerCompilerFilter(filter); } + if (ShouldDisableRefresh( + android::base::GetProperty("ro.build.version.sdk", /*default_value=*/""))) { + config->SetRefresh(false); + } + return n; } |