From d2f2ad6a3c10f1d9d908de39d19046efc53b53a0 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 23 Mar 2018 23:24:25 -0700 Subject: Move a few modules to Soong. libmounts librecovery_ui_default librecovery_ui_wear librecovery_ui_vr libverifier recovery-persist recovery-refresh They are all trivially converted. Test: mmma -j bootable/recovery Change-Id: Id783b3eec32bd15e74f42df17053732db5666675 --- Android.bp | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Android.mk | 85 +----------------------------------- 2 files changed, 145 insertions(+), 83 deletions(-) create mode 100644 Android.bp diff --git a/Android.bp b/Android.bp new file mode 100644 index 000000000..6c04504ea --- /dev/null +++ b/Android.bp @@ -0,0 +1,143 @@ +// Copyright (C) 2018 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. + +cc_defaults { + name: "recovery_defaults", + + cflags: [ + "-Wall", + "-Werror", + ], +} + +// Generic device that uses ScreenRecoveryUI. +cc_library_static { + name: "librecovery_ui_default", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "default_device.cpp", + ], +} + +// The default wear device that uses WearRecoveryUI. +cc_library_static { + name: "librecovery_ui_wear", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "wear_device.cpp", + ], +} + +// The default VR device that uses VrRecoveryUI. +cc_library_static { + name: "librecovery_ui_vr", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "vr_device.cpp", + ], +} + +cc_library_static { + name: "libmounts", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "mounts.cpp", + ], + + static_libs: [ + "libbase", + ], +} + +cc_library_static { + name: "libverifier", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "asn1_decoder.cpp", + "verifier.cpp", + ], + + static_libs: [ + "libbase", + "libcrypto", + "libcrypto_utils", + "libotautil", + ], +} + +// The dynamic executable that runs after /data mounts. +cc_binary { + name: "recovery-persist", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "recovery-persist.cpp", + "rotate_logs.cpp", + ], + + shared_libs: [ + "libbase", + "liblog", + ], + + init_rc: [ + "recovery-persist.rc", + ], +} + +// The dynamic executable that runs at init. +cc_binary { + name: "recovery-refresh", + + defaults: [ + "recovery_defaults", + ], + + srcs: [ + "recovery-refresh.cpp", + "rotate_logs.cpp", + ], + + shared_libs: [ + "libbase", + "liblog", + ], + + init_rc: [ + "recovery-refresh.rc", + ], +} diff --git a/Android.mk b/Android.mk index 5dca32a45..161dd322b 100644 --- a/Android.mk +++ b/Android.mk @@ -23,17 +23,6 @@ RECOVERY_FSTAB_VERSION := 2 # librecovery_ui_default, which uses ScreenRecoveryUI. TARGET_RECOVERY_UI_LIB ?= librecovery_ui_default -# libmounts (static library) -# =============================== -include $(CLEAR_VARS) -LOCAL_SRC_FILES := mounts.cpp -LOCAL_CFLAGS := \ - -Wall \ - -Werror -LOCAL_MODULE := libmounts -LOCAL_STATIC_LIBRARIES := libbase -include $(BUILD_STATIC_LIBRARY) - # librecovery (static library) # =============================== include $(CLEAR_VARS) @@ -49,6 +38,7 @@ ifeq ($(AB_OTA_UPDATER),true) endif LOCAL_MODULE := librecovery + LOCAL_STATIC_LIBRARIES := \ libminui \ libotautil \ @@ -72,6 +62,7 @@ LOCAL_SRC_FILES := \ LOCAL_CFLAGS := -Wall -Werror LOCAL_MODULE := librecovery_ui + LOCAL_STATIC_LIBRARIES := \ libminui \ libbase @@ -201,78 +192,6 @@ endif include $(BUILD_EXECUTABLE) -# recovery-persist (system partition dynamic executable run after /data mounts) -# =============================== -include $(CLEAR_VARS) -LOCAL_SRC_FILES := \ - recovery-persist.cpp \ - rotate_logs.cpp -LOCAL_MODULE := recovery-persist -LOCAL_SHARED_LIBRARIES := liblog libbase -LOCAL_CFLAGS := -Wall -Werror -LOCAL_INIT_RC := recovery-persist.rc -include $(BUILD_EXECUTABLE) - -# recovery-refresh (system partition dynamic executable run at init) -# =============================== -include $(CLEAR_VARS) -LOCAL_SRC_FILES := \ - recovery-refresh.cpp \ - rotate_logs.cpp -LOCAL_MODULE := recovery-refresh -LOCAL_SHARED_LIBRARIES := liblog libbase -LOCAL_CFLAGS := -Wall -Werror -LOCAL_INIT_RC := recovery-refresh.rc -include $(BUILD_EXECUTABLE) - -# libverifier (static library) -# =============================== -include $(CLEAR_VARS) -LOCAL_MODULE := libverifier -LOCAL_SRC_FILES := \ - asn1_decoder.cpp \ - verifier.cpp -LOCAL_STATIC_LIBRARIES := \ - libotautil \ - libcrypto_utils \ - libcrypto \ - libbase -LOCAL_CFLAGS := -Wall -Werror -include $(BUILD_STATIC_LIBRARY) - -# Generic device that uses ScreenRecoveryUI. -# =============================== -include $(CLEAR_VARS) -LOCAL_SRC_FILES := default_device.cpp -LOCAL_CFLAGS := -Wall -Werror - -LOCAL_MODULE := librecovery_ui_default - -include $(BUILD_STATIC_LIBRARY) - -# Wear default device -# =============================== -include $(CLEAR_VARS) -LOCAL_SRC_FILES := wear_device.cpp -LOCAL_CFLAGS := -Wall -Werror - -# Should match TARGET_RECOVERY_UI_LIB in BoardConfig.mk. -LOCAL_MODULE := librecovery_ui_wear - -include $(BUILD_STATIC_LIBRARY) - -# vr headset default device -# =============================== -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := vr_device.cpp -LOCAL_CFLAGS := -Wall -Werror - -# should match TARGET_RECOVERY_UI_LIB set in BoardConfig.mk -LOCAL_MODULE := librecovery_ui_vr - -include $(BUILD_STATIC_LIBRARY) - include \ $(LOCAL_PATH)/boot_control/Android.mk \ $(LOCAL_PATH)/minui/Android.mk \ -- cgit v1.2.3 From f39362e1848cde65fbfd6b80a53a33e5d0672cc5 Mon Sep 17 00:00:00 2001 From: Jiachen Zhao Date: Fri, 30 Mar 2018 15:24:26 -0700 Subject: Create the SystemUpdate activity class. Test: tested sample app with sideloading. Change-Id: I0d1661cea57c706b4981a4cda9f9b69fdeb69292 --- sample_updater/Android.mk | 2 + sample_updater/AndroidManifest.xml | 18 ++++-- sample_updater/res/layout/activity_main.xml | 20 +++++++ .../android/update/ui/SystemUpdateActivity.java | 68 ++++++++++++++++++++++ 4 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 sample_updater/res/layout/activity_main.xml create mode 100644 sample_updater/src/com/android/update/ui/SystemUpdateActivity.java diff --git a/sample_updater/Android.mk b/sample_updater/Android.mk index d6764bd01..2b0fcbeec 100644 --- a/sample_updater/Android.mk +++ b/sample_updater/Android.mk @@ -22,4 +22,6 @@ LOCAL_PACKAGE_NAME := SystemUpdateApp LOCAL_SDK_VERSION := system_current LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(call all-java-files-under, src) + include $(BUILD_PACKAGE) diff --git a/sample_updater/AndroidManifest.xml b/sample_updater/AndroidManifest.xml index ccee107bb..66414b5d3 100644 --- a/sample_updater/AndroidManifest.xml +++ b/sample_updater/AndroidManifest.xml @@ -14,8 +14,18 @@ limitations under the License. --> - + + + + + + + + + + + + diff --git a/sample_updater/res/layout/activity_main.xml b/sample_updater/res/layout/activity_main.xml new file mode 100644 index 000000000..bd7d68677 --- /dev/null +++ b/sample_updater/res/layout/activity_main.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/sample_updater/src/com/android/update/ui/SystemUpdateActivity.java b/sample_updater/src/com/android/update/ui/SystemUpdateActivity.java new file mode 100644 index 000000000..e57b1673c --- /dev/null +++ b/sample_updater/src/com/android/update/ui/SystemUpdateActivity.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.update.ui; + +import android.app.Activity; +import android.os.UpdateEngine; +import android.os.UpdateEngineCallback; + +/** Main update activity. */ +public class SystemUpdateActivity extends Activity { + + private UpdateEngine updateEngine; + private UpdateEngineCallbackImpl updateEngineCallbackImpl = new UpdateEngineCallbackImpl(this); + + @Override + public void onResume() { + super.onResume(); + updateEngine = new UpdateEngine(); + updateEngine.bind(updateEngineCallbackImpl); + } + + @Override + public void onPause() { + updateEngine.unbind(); + super.onPause(); + } + + void onStatusUpdate(int i, float v) { + // Handle update engine status update + } + + void onPayloadApplicationComplete(int i) { + // Handle apply payload completion + } + + private static class UpdateEngineCallbackImpl extends UpdateEngineCallback { + + private final SystemUpdateActivity activity; + + public UpdateEngineCallbackImpl(SystemUpdateActivity activity) { + this.activity = activity; + } + + @Override + public void onStatusUpdate(int i, float v) { + activity.onStatusUpdate(i, v); + } + + @Override + public void onPayloadApplicationComplete(int i) { + activity.onPayloadApplicationComplete(i); + } + } +} -- cgit v1.2.3 From a6f49bd9520e02d84026e31a53a6c98db59d91a3 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Mon, 26 Mar 2018 14:32:11 -0700 Subject: Do not skip the update installation if it's a retry We used to skip the update installation if the battery doesn't reach the threshold or the boot reason is in blacklist. Afterwards, we just cleared the BCB and reboot/shutdown the device. However, this leaves the device in a brick state if the update is a retry; because a subsequent reboot won't resume the update after the BCB gets cleared. This CL skips the battery and bootreason check on retries. An alternative solution is to conduct the check and shutdown the device without clearing the BCB on INSTALL_SKIPPED; but users who don't have context may reboot the device manually anyway. Bug: 65288661 Test: Trigger the INSTALL_SKIPPED with insufficient battery, and check the behavior with retry_count. Change-Id: I0bd8ae9cee0e35aeeec3df469a78cec9ee1b8db8 --- recovery.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 6bd291463..910cd8296 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1537,14 +1537,14 @@ int main(int argc, char **argv) { // to log the update attempt since update_package is non-NULL. modified_flash = true; - if (!is_battery_ok()) { + if (retry_count == 0 && !is_battery_ok()) { ui->Print("battery capacity is not enough for installing package, needed is %d%%\n", BATTERY_OK_PERCENTAGE); // Log the error code to last_install when installation skips due to // low battery. log_failure_code(kLowBattery, update_package); status = INSTALL_SKIPPED; - } else if (bootreason_in_blacklist()) { + } else if (retry_count == 0 && bootreason_in_blacklist()) { // Skip update-on-reboot when bootreason is kernel_panic or similar ui->Print("bootreason is in the blacklist; skip OTA installation\n"); log_failure_code(kBootreasonInBlacklist, update_package); -- cgit v1.2.3 From 9d91e898317fe19051d486fb76271a89603b5de8 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 30 Mar 2018 20:43:45 -0700 Subject: tests: Pick up testdata with LOCAL_TEST_DATA. Also push the testdata in AndroidTest.xml for `atest`. LOCAL_TEST_DATA was added in commit [1], which ships testdata next to native tests. With this CL, 1) manually sync-ing via `adb sync` and running tests with `adb shell` keep working. 2) both of 32- and 64-bit recovery_{unit,component}_test now work in APCT continuous tests. Note that 64-bit tests were failing previously in APCT, due to missing testdata. 3) `atest recovery_unit_test` works, as the testdata gets pushed to /data/local/tmp. [1] commit d07ba4e2a625a8f000d042c1953adb612bccbbe2 in https://android-review.googlesource.com/c/platform/build/+/312567. Bug: 77320514 Test: Build recovery_{unit,component,manual}_test. Setup the test via `adb sync data`. Run both of 32- and 64-bit versions on device. Test: Build and run recovery_host_test on host, for both of 32- and 64-bit versions. Test: `atest recovery_component_test` Change-Id: Ie54037726043a3a659a80030b83db1f8c1de318d --- tests/Android.mk | 50 +++++++----------------------------------- tests/AndroidTest.xml | 10 +++++---- tests/common/test_constants.h | 15 +++++-------- tests/manual/recovery_test.cpp | 12 +++++----- 4 files changed, 25 insertions(+), 62 deletions(-) diff --git a/tests/Android.mk b/tests/Android.mk index 9a71371fa..58cefd226 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -45,6 +45,8 @@ LOCAL_SRC_FILES := \ LOCAL_C_INCLUDES := bootable/recovery LOCAL_SHARED_LIBRARIES := liblog +LOCAL_TEST_DATA := \ + $(call find-test-data-in-subdirs, $(LOCAL_PATH), "*", testdata) include $(BUILD_NATIVE_TEST) # Manual tests @@ -61,25 +63,8 @@ LOCAL_SHARED_LIBRARIES := \ liblog \ libpng -resource_files := $(call find-files-in-subdirs, bootable/recovery, \ - "*_text.png", \ - res-mdpi/images \ - res-hdpi/images \ - res-xhdpi/images \ - res-xxhdpi/images \ - res-xxxhdpi/images \ - ) - -# The resource image files that will go to $OUT/data/nativetest/recovery. -testimage_out_path := $(TARGET_OUT_DATA)/nativetest/recovery -GEN := $(addprefix $(testimage_out_path)/, $(resource_files)) - -$(GEN): PRIVATE_PATH := $(LOCAL_PATH) -$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ -$(GEN): $(testimage_out_path)/% : bootable/recovery/% - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - +LOCAL_TEST_DATA := \ + $(call find-test-data-in-subdirs, bootable/recovery, "*_text.png", res-*) include $(BUILD_NATIVE_TEST) # Component tests @@ -171,29 +156,8 @@ LOCAL_STATIC_LIBRARIES := \ libBionicGtestMain \ $(tune2fs_static_libraries) -testdata_files := $(call find-subdir-files, testdata/*) - -# The testdata files that will go to $OUT/data/nativetest/recovery. -testdata_out_path := $(TARGET_OUT_DATA)/nativetest/recovery -GEN := $(addprefix $(testdata_out_path)/, $(testdata_files)) -$(GEN): PRIVATE_PATH := $(LOCAL_PATH) -$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ -$(GEN): $(testdata_out_path)/% : $(LOCAL_PATH)/% - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - -# A copy of the testdata to be packed into continuous_native_tests.zip. -testdata_continuous_zip_prefix := \ - $(call intermediates-dir-for,PACKAGING,recovery_component_test)/DATA -testdata_continuous_zip_path := $(testdata_continuous_zip_prefix)/nativetest/recovery -GEN := $(addprefix $(testdata_continuous_zip_path)/, $(testdata_files)) -$(GEN): PRIVATE_PATH := $(LOCAL_PATH) -$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ -$(GEN): $(testdata_continuous_zip_path)/% : $(LOCAL_PATH)/% - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) -LOCAL_PICKUP_FILES := $(testdata_continuous_zip_prefix) - +LOCAL_TEST_DATA := \ + $(call find-test-data-in-subdirs, $(LOCAL_PATH), "*", testdata) include $(BUILD_NATIVE_TEST) # Host tests @@ -222,4 +186,6 @@ LOCAL_STATIC_LIBRARIES := \ libBionicGtestMain LOCAL_SHARED_LIBRARIES := \ liblog +LOCAL_TEST_DATA := \ + $(call find-test-data-in-subdirs, $(LOCAL_PATH), "*", testdata) include $(BUILD_HOST_NATIVE_TEST) diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml index 3999aa57d..6b86085aa 100644 --- a/tests/AndroidTest.xml +++ b/tests/AndroidTest.xml @@ -16,16 +16,18 @@ diff --git a/tests/common/test_constants.h b/tests/common/test_constants.h index 514818e0a..b6c27a754 100644 --- a/tests/common/test_constants.h +++ b/tests/common/test_constants.h @@ -17,10 +17,10 @@ #ifndef _OTA_TEST_CONSTANTS_H #define _OTA_TEST_CONSTANTS_H -#include - #include +#include + // Zip entries in ziptest_valid.zip. static const std::string kATxtContents("abcdefghabcdefgh\n"); static const std::string kBTxtContents("abcdefgh\n"); @@ -32,14 +32,9 @@ static const std::string kATxtSha1Sum("32c96a03dc8cd20097940f351bca6261ee5a1643" // echo -n -e "abcdefgh\n" | sha1sum static const std::string kBTxtSha1Sum("e414af7161c9554089f4106d6f1797ef14a73666"); -static std::string from_testdata_base(const std::string& fname) { -#ifdef __ANDROID__ - static std::string data_root = getenv("ANDROID_DATA"); -#else - static std::string data_root = std::string(getenv("ANDROID_PRODUCT_OUT")) + "/data"; -#endif - - return data_root + "/nativetest/recovery/testdata/" + fname; +[[maybe_unused]] static std::string from_testdata_base(const std::string& fname) { + static std::string exec_dir = android::base::GetExecutableDirectory(); + return exec_dir + "/testdata/" + fname; } #endif // _OTA_TEST_CONSTANTS_H diff --git a/tests/manual/recovery_test.cpp b/tests/manual/recovery_test.cpp index 64e3b59e6..224ed5b68 100644 --- a/tests/manual/recovery_test.cpp +++ b/tests/manual/recovery_test.cpp @@ -34,7 +34,6 @@ static const std::string myFilename = "/data/misc/recovery/inject.txt"; static const std::string myContent = "Hello World\nWelcome to my recovery\n"; static const std::string kLocale = "zu"; -static const std::string kResourceTestDir = "/data/nativetest/recovery/"; // Failure is expected on systems that do not deliver either the // recovery-persist or recovery-refresh executables. Tests also require @@ -108,19 +107,20 @@ static int png_filter(const dirent* de) { return 1; } -// Find out all png files to test under /data/nativetest/recovery/. +// Find out all the PNG files to test, which stay under the same dir with the executable. static std::vector add_files() { + std::string exec_dir = android::base::GetExecutableDirectory(); std::vector files; - for (const std::string& str : image_dir) { - std::string dir_path = kResourceTestDir + str; + for (const std::string& image : image_dir) { + std::string dir_path = exec_dir + "/" + image; dirent** namelist; int n = scandir(dir_path.c_str(), &namelist, png_filter, alphasort); if (n == -1) { - printf("Failed to scan dir %s: %s\n", kResourceTestDir.c_str(), strerror(errno)); + printf("Failed to scan dir %s: %s\n", exec_dir.c_str(), strerror(errno)); return files; } if (n == 0) { - printf("No file is added for test in %s\n", kResourceTestDir.c_str()); + printf("No file is added for test in %s\n", exec_dir.c_str()); } while (n--) { -- cgit v1.2.3