summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Ioffe <ioffe@google.com>2021-04-28 13:54:14 +0100
committerNikita Ioffe <ioffe@google.com>2021-04-29 18:56:49 +0000
commitaedfef3c2f2834645654833bae6fd1daf6ca1040 (patch)
tree47d4777cf3a961cb97b9bd9856f98f64f759233d
parent741c2d4da7dfb6e97bf7819e48b19e3214b5c09b (diff)
Don't call into apexservice if device uses flattened apexes
If device doesn't support updatable apexes (a.k.a. uses flattened apexes), then it won't have compressed apexes, so there is no need calling into apexd. Test: atest update_engine_unittests:ApexHandlerAndroidTest Test: build and flash aosp_cf_x86_phone_noapex-userdebug Test: m dist Test: python3 system/update_engine/scripts/update_device.py --file out/target/product/vsoc_x86_noapex/aosp_cf_x86_phone_noapex-ota-eng.ioffe.zip Test: checked OTA was successfully staged Bug: 185862111 Change-Id: Ibf9db757f3af37d23fb8248108b2b6d22c95dec7
-rw-r--r--Android.bp3
-rw-r--r--aosp/apex_handler_android.cc21
-rw-r--r--aosp/apex_handler_android.h10
-rw-r--r--aosp/apex_handler_android_unittest.cc39
-rw-r--r--aosp/daemon_state_android.cc11
5 files changed, 73 insertions, 11 deletions
diff --git a/Android.bp b/Android.bp
index dab97110..11c03b4e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -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;
}