diff options
author | Nikita Ioffe <ioffe@google.com> | 2021-04-29 21:37:33 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-04-29 21:37:33 +0000 |
commit | 7297ac0b8116ceb8b83c37de2b5f28a9d2d1cc92 (patch) | |
tree | 455c09f3021716dec6e091cc921397172aa0013d | |
parent | ca66627b1aedb5712dfc83741078d5660e514b21 (diff) | |
parent | 9bea7904060f2f2122e5e8aa59919ea56afd58a8 (diff) | |
download | update_engine-7297ac0b8116ceb8b83c37de2b5f28a9d2d1cc92.tar.gz |
Don't call into apexservice if device uses flattened apexes am: aedfef3c2f am: e0c1d5f924 am: 9bea790406
Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1689748
Change-Id: Ic27de995e13e8de0857e96b3845269ac252e667c
-rw-r--r-- | Android.bp | 3 | ||||
-rw-r--r-- | aosp/apex_handler_android.cc | 21 | ||||
-rw-r--r-- | aosp/apex_handler_android.h | 10 | ||||
-rw-r--r-- | aosp/apex_handler_android_unittest.cc | 39 | ||||
-rw-r--r-- | aosp/daemon_state_android.cc | 11 |
5 files changed, 73 insertions, 11 deletions
@@ -348,6 +348,9 @@ cc_defaults { "libstatslog", "libutils", ], + whole_static_libs: [ + "com.android.sysprop.apex", + ], } cc_library_static { diff --git a/aosp/apex_handler_android.cc b/aosp/apex_handler_android.cc index 38ec410b..8beef966 100644 --- a/aosp/apex_handler_android.cc +++ b/aosp/apex_handler_android.cc @@ -14,10 +14,13 @@ // limitations under the License. // +#include <memory> #include <utility> #include <base/files/file_util.h> +#include <ApexProperties.sysprop.h> + #include "update_engine/aosp/apex_handler_android.h" #include "update_engine/common/utils.h" @@ -44,6 +47,14 @@ android::apex::CompressedApexInfoList CreateCompressedApexInfoList( } // namespace +std::unique_ptr<ApexHandlerInterface> CreateApexHandler() { + if (android::sysprop::ApexProperties::updatable().value_or(false)) { + return std::make_unique<ApexHandlerAndroid>(); + } else { + return std::make_unique<FlattenedApexHandlerAndroid>(); + } +} + android::base::Result<uint64_t> ApexHandlerAndroid::CalculateSize( const std::vector<ApexInfo>& apex_infos) const { // We might not need to decompress every APEX. Communicate with apexd to get @@ -86,4 +97,14 @@ android::sp<android::apex::IApexService> ApexHandlerAndroid::GetApexService() return android::interface_cast<android::apex::IApexService>(binder); } +android::base::Result<uint64_t> FlattenedApexHandlerAndroid::CalculateSize( + const std::vector<ApexInfo>& apex_infos) const { + return 0; +} + +bool FlattenedApexHandlerAndroid::AllocateSpace( + const std::vector<ApexInfo>& apex_infos) const { + return true; +} + } // namespace chromeos_update_engine diff --git a/aosp/apex_handler_android.h b/aosp/apex_handler_android.h index 00f3a80b..767f5618 100644 --- a/aosp/apex_handler_android.h +++ b/aosp/apex_handler_android.h @@ -17,6 +17,7 @@ #ifndef SYSTEM_UPDATE_ENGINE_AOSP_APEX_HANDLER_ANDROID_H_ #define SYSTEM_UPDATE_ENGINE_AOSP_APEX_HANDLER_ANDROID_H_ +#include <memory> #include <string> #include <vector> @@ -28,6 +29,8 @@ namespace chromeos_update_engine { +std::unique_ptr<ApexHandlerInterface> CreateApexHandler(); + class ApexHandlerAndroid : virtual public ApexHandlerInterface { public: android::base::Result<uint64_t> CalculateSize( @@ -38,6 +41,13 @@ class ApexHandlerAndroid : virtual public ApexHandlerInterface { android::sp<android::apex::IApexService> GetApexService() const; }; +class FlattenedApexHandlerAndroid : virtual public ApexHandlerInterface { + public: + android::base::Result<uint64_t> CalculateSize( + const std::vector<ApexInfo>& apex_infos) const; + bool AllocateSpace(const std::vector<ApexInfo>& apex_infos) const; +}; + } // namespace chromeos_update_engine #endif // SYSTEM_UPDATE_ENGINE_AOSP_APEX_HANDLER_ANDROID_H_ diff --git a/aosp/apex_handler_android_unittest.cc b/aosp/apex_handler_android_unittest.cc index 981ae9dd..847ccaad 100644 --- a/aosp/apex_handler_android_unittest.cc +++ b/aosp/apex_handler_android_unittest.cc @@ -41,7 +41,7 @@ ApexInfo CreateApexInfo(const std::string& package_name, return std::move(result); } -TEST(ApexHandlerAndroidTest, CalculateSize) { +TEST(ApexHandlerAndroidTest, CalculateSizeUpdatableApex) { ApexHandlerAndroid apex_handler; std::vector<ApexInfo> apex_infos; ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1); @@ -52,10 +52,10 @@ TEST(ApexHandlerAndroidTest, CalculateSize) { apex_infos.push_back(uncompressed_apex); auto result = apex_handler.CalculateSize(apex_infos); ASSERT_TRUE(result.ok()); - EXPECT_EQ(*result, 3u); + ASSERT_EQ(*result, 3u); } -TEST(ApexHandlerAndroidTest, AllocateSpace) { +TEST(ApexHandlerAndroidTest, AllocateSpaceUpdatableApex) { ApexHandlerAndroid apex_handler; std::vector<ApexInfo> apex_infos; ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1); @@ -64,10 +64,39 @@ TEST(ApexHandlerAndroidTest, AllocateSpace) { apex_infos.push_back(compressed_apex_1); apex_infos.push_back(compressed_apex_2); apex_infos.push_back(uncompressed_apex); - EXPECT_TRUE(apex_handler.AllocateSpace(apex_infos)); + ASSERT_TRUE(apex_handler.AllocateSpace(apex_infos)); // Should be able to pass empty list - EXPECT_TRUE(apex_handler.AllocateSpace({})); + ASSERT_TRUE(apex_handler.AllocateSpace({})); +} + +TEST(ApexHandlerAndroidTest, CalculateSizeFlattenedApex) { + FlattenedApexHandlerAndroid apex_handler; + std::vector<ApexInfo> apex_infos; + ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1); + ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2); + ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4); + apex_infos.push_back(compressed_apex_1); + apex_infos.push_back(compressed_apex_2); + apex_infos.push_back(uncompressed_apex); + auto result = apex_handler.CalculateSize(apex_infos); + ASSERT_TRUE(result.ok()); + ASSERT_EQ(*result, 0u); +} + +TEST(ApexHandlerAndroidTest, AllocateSpaceFlattenedApex) { + FlattenedApexHandlerAndroid apex_handler; + std::vector<ApexInfo> apex_infos; + ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1); + ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2); + ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4); + apex_infos.push_back(compressed_apex_1); + apex_infos.push_back(compressed_apex_2); + apex_infos.push_back(uncompressed_apex); + ASSERT_TRUE(apex_handler.AllocateSpace(apex_infos)); + + // Should be able to pass empty list + ASSERT_TRUE(apex_handler.AllocateSpace({})); } } // namespace chromeos_update_engine diff --git a/aosp/daemon_state_android.cc b/aosp/daemon_state_android.cc index fc89d73e..da49080c 100644 --- a/aosp/daemon_state_android.cc +++ b/aosp/daemon_state_android.cc @@ -65,12 +65,11 @@ bool DaemonStateAndroid::Initialize() { certificate_checker_->Init(); // Initialize the UpdateAttempter before the UpdateManager. - update_attempter_.reset( - new UpdateAttempterAndroid(this, - prefs_.get(), - boot_control_.get(), - hardware_.get(), - std::make_unique<ApexHandlerAndroid>())); + update_attempter_.reset(new UpdateAttempterAndroid(this, + prefs_.get(), + boot_control_.get(), + hardware_.get(), + CreateApexHandler())); return true; } |