summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.bp5
-rw-r--r--CleanSpec.mk8
-rw-r--r--OWNERS3
-rw-r--r--applypatch/Android.bp7
-rw-r--r--applypatch/applypatch.cpp2
-rw-r--r--applypatch/vendor_flash_recovery.rc3
-rw-r--r--boot_control/Android.bp1
-rw-r--r--boot_control/include/libboot_control/libboot_control.h8
-rw-r--r--boot_control/libboot_control.cpp21
-rw-r--r--bootloader_message/include/bootloader_message/bootloader_message.h4
-rw-r--r--edify/Android.bp1
-rw-r--r--minadbd/Android.bp4
-rw-r--r--minadbd/minadbd_services.cpp18
-rw-r--r--otautil/Android.bp1
-rw-r--r--recovery.cpp87
-rw-r--r--recovery_utils/Android.bp49
-rw-r--r--recovery_utils/battery_utils.cpp89
-rw-r--r--recovery_utils/include/recovery_utils/battery_utils.h33
-rw-r--r--recovery_utils/roots.cpp6
-rw-r--r--tests/unit/battery_utils_test.cpp27
-rw-r--r--updater/updater_main.cpp21
-rw-r--r--updater_sample/OWNERS2
22 files changed, 291 insertions, 109 deletions
diff --git a/Android.bp b/Android.bp
index a9a08a1a9..aefcabe86 100644
--- a/Android.bp
+++ b/Android.bp
@@ -58,7 +58,6 @@ cc_defaults {
],
shared_libs: [
- "android.hardware.health@2.0",
"libbase",
"libbootloader_message",
"libcrypto",
@@ -75,9 +74,6 @@ cc_defaults {
"libminui",
"librecovery_utils",
"libotautil",
-
- // external dependencies
- "libhealthhalutils",
],
}
@@ -106,6 +102,7 @@ cc_binary {
defaults: [
"libinstall_defaults",
"librecovery_defaults",
+ "librecovery_utils_defaults",
],
srcs: [
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 0980a35f3..d4e9e437b 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -61,6 +61,14 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/priv-app/SystemUpdaterSample
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib*/libbrotli.so)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib*/libbz.so)
+# Move recovery resources from /system to /vendor.
+$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/bin/applypatch)
+$(call add-clean-step, rm -r $(PRODUCT_OUT)/symbols/system/bin/applypatch)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/PACKAGING/target_files_intermediates/*-target_files-*/SYSTEM/bin/applypatch)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/PACKAGING/target_files_intermediates/*-target_files-*/SYSTEM/bin/install-recovery.sh)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/PACKAGING/target_files_intermediates/*-target_files-*/SYSTEM/etc/recovery-resource.dat)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/PACKAGING/target_files_intermediates/*-target_files-*/SYSTEM/recovery-from-boot.p)
+
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
diff --git a/OWNERS b/OWNERS
index b3f11dcd6..fe1c33d4b 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1,4 @@
enh@google.com
-tbao@google.com
+nhdo@google.com
xunchang@google.com
+zhaojiac@google.com
diff --git a/applypatch/Android.bp b/applypatch/Android.bp
index 55d185201..13a962584 100644
--- a/applypatch/Android.bp
+++ b/applypatch/Android.bp
@@ -31,6 +31,7 @@ cc_library_static {
name: "libapplypatch",
host_supported: true,
+ vendor_available: true,
defaults: [
"applypatch_defaults",
@@ -69,6 +70,7 @@ cc_library_static {
cc_library_static {
name: "libapplypatch_modes",
+ vendor_available: true,
defaults: [
"applypatch_defaults",
@@ -92,6 +94,7 @@ cc_library_static {
cc_binary {
name: "applypatch",
+ vendor: true,
defaults: [
"applypatch_defaults",
@@ -120,6 +123,10 @@ cc_binary {
"libz",
"libziparchive",
],
+
+ init_rc: [
+ "vendor_flash_recovery.rc",
+ ],
}
cc_library_host_static {
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
index 336860cb9..adda6976d 100644
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -279,7 +279,7 @@ bool PatchPartition(const Partition& target, const Partition& source, const Valu
}
FileContents source_file;
- if (ReadPartitionToBuffer(source, &source_file, true)) {
+ if (ReadPartitionToBuffer(source, &source_file, backup_source)) {
return GenerateTarget(target, source_file, patch, bonus, backup_source);
}
diff --git a/applypatch/vendor_flash_recovery.rc b/applypatch/vendor_flash_recovery.rc
new file mode 100644
index 000000000..37a7c2be7
--- /dev/null
+++ b/applypatch/vendor_flash_recovery.rc
@@ -0,0 +1,3 @@
+service vendor_flash_recovery /vendor/bin/install-recovery.sh
+ class main
+ oneshot
diff --git a/boot_control/Android.bp b/boot_control/Android.bp
index f6a6ceddd..b2e68dfd4 100644
--- a/boot_control/Android.bp
+++ b/boot_control/Android.bp
@@ -28,6 +28,7 @@ cc_defaults {
],
shared_libs: [
+ "android.hardware.boot@1.1",
"libbase",
"liblog",
],
diff --git a/boot_control/include/libboot_control/libboot_control.h b/boot_control/include/libboot_control/libboot_control.h
index 6582d0244..34a9affe1 100644
--- a/boot_control/include/libboot_control/libboot_control.h
+++ b/boot_control/include/libboot_control/libboot_control.h
@@ -18,11 +18,15 @@
#include <string>
+#include <android/hardware/boot/1.1/IBootControl.h>
+
namespace android {
namespace bootable {
// Helper library to implement the IBootControl HAL using the misc partition.
class BootControl {
+ using MergeStatus = ::android::hardware::boot::V1_1::MergeStatus;
+
public:
bool Init();
unsigned int GetNumberSlots();
@@ -34,6 +38,10 @@ class BootControl {
bool IsSlotBootable(unsigned int slot);
const char* GetSuffix(unsigned int slot);
bool IsSlotMarkedSuccessful(unsigned int slot);
+ bool SetSnapshotMergeStatus(MergeStatus status);
+ MergeStatus GetSnapshotMergeStatus();
+
+ bool IsValidSlot(unsigned int slot);
const std::string& misc_device() const {
return misc_device_;
diff --git a/boot_control/libboot_control.cpp b/boot_control/libboot_control.cpp
index 89cf8786a..e3bff9ff3 100644
--- a/boot_control/libboot_control.cpp
+++ b/boot_control/libboot_control.cpp
@@ -34,6 +34,8 @@
namespace android {
namespace bootable {
+using ::android::hardware::boot::V1_1::MergeStatus;
+
// The number of boot attempts that should be made from a new slot before
// rolling back to the previous slot.
constexpr unsigned int kDefaultBootAttempts = 7;
@@ -327,6 +329,25 @@ bool BootControl::IsSlotMarkedSuccessful(unsigned int slot) {
return bootctrl.slot_info[slot].successful_boot && bootctrl.slot_info[slot].tries_remaining;
}
+bool BootControl::IsValidSlot(unsigned int slot) {
+ return slot < kMaxNumSlots && slot < num_slots_;
+}
+
+bool BootControl::SetSnapshotMergeStatus(MergeStatus status) {
+ bootloader_control bootctrl;
+ if (!LoadBootloaderControl(misc_device_, &bootctrl)) return false;
+
+ bootctrl.merge_status = (unsigned int)status;
+ return UpdateAndSaveBootloaderControl(misc_device_, &bootctrl);
+}
+
+MergeStatus BootControl::GetSnapshotMergeStatus() {
+ bootloader_control bootctrl;
+ if (!LoadBootloaderControl(misc_device_, &bootctrl)) return MergeStatus::UNKNOWN;
+
+ return (MergeStatus)bootctrl.merge_status;
+}
+
const char* BootControl::GetSuffix(unsigned int slot) {
if (slot >= kMaxNumSlots || slot >= num_slots_) {
return nullptr;
diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h
index 5c0a450fc..b78783083 100644
--- a/bootloader_message/include/bootloader_message/bootloader_message.h
+++ b/bootloader_message/include/bootloader_message/bootloader_message.h
@@ -163,8 +163,10 @@ struct bootloader_control {
uint8_t nb_slot : 3;
// Number of times left attempting to boot recovery.
uint8_t recovery_tries_remaining : 3;
+ // Status of any pending snapshot merge of dynamic partitions.
+ uint8_t merge_status : 3;
// Ensure 4-bytes alignment for slot_info field.
- uint8_t reserved0[2];
+ uint8_t reserved0[1];
// Per-slot information. Up to 4 slots.
struct slot_metadata slot_info[4];
// Reserved for further use.
diff --git a/edify/Android.bp b/edify/Android.bp
index 42947eb4e..73048d21c 100644
--- a/edify/Android.bp
+++ b/edify/Android.bp
@@ -16,6 +16,7 @@ cc_library_static {
name: "libedify",
host_supported: true,
+ vendor_available: true,
srcs: [
"expr.cpp",
diff --git a/minadbd/Android.bp b/minadbd/Android.bp
index 071712599..b7075e670 100644
--- a/minadbd/Android.bp
+++ b/minadbd/Android.bp
@@ -40,6 +40,7 @@ cc_library {
defaults: [
"minadbd_defaults",
+ "librecovery_utils_defaults",
],
srcs: [
@@ -48,6 +49,7 @@ cc_library {
],
static_libs: [
+ "librecovery_utils",
"libotautil",
],
@@ -97,6 +99,7 @@ cc_test {
defaults: [
"minadbd_defaults",
+ "librecovery_utils_defaults",
],
srcs: [
@@ -107,6 +110,7 @@ cc_test {
static_libs: [
"libminadbd_services",
"libfusesideload",
+ "librecovery_utils",
"libotautil",
"libadbd",
],
diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp
index cabcdaa09..eb91fb3e4 100644
--- a/minadbd/minadbd_services.cpp
+++ b/minadbd/minadbd_services.cpp
@@ -44,6 +44,7 @@
#include "fuse_adb_provider.h"
#include "fuse_sideload.h"
#include "minadbd/types.h"
+#include "recovery_utils/battery_utils.h"
#include "services.h"
#include "sysdeps.h"
@@ -160,7 +161,10 @@ static void RescueInstallHostService(unique_fd sfd, const std::string& args) {
// If given an empty string, dumps all the supported properties (analogous to `adb shell getprop`)
// in lines, e.g. "[prop]: [value]".
static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
+ constexpr const char* kRescueBatteryLevelProp = "rescue.battery_level";
static const std::set<std::string> kGetpropAllowedProps = {
+ // clang-format off
+ kRescueBatteryLevelProp,
"ro.build.date.utc",
"ro.build.fingerprint",
"ro.build.flavor",
@@ -170,18 +174,28 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
"ro.build.version.incremental",
"ro.product.device",
"ro.product.vendor.device",
+ // clang-format on
};
+
+ auto query_prop = [](const std::string& key) {
+ if (key == kRescueBatteryLevelProp) {
+ auto battery_info = GetBatteryInfo();
+ return std::to_string(battery_info.capacity);
+ }
+ return android::base::GetProperty(key, "");
+ };
+
std::string result;
if (prop.empty()) {
for (const auto& key : kGetpropAllowedProps) {
- auto value = android::base::GetProperty(key, "");
+ auto value = query_prop(key);
if (value.empty()) {
continue;
}
result += "[" + key + "]: [" + value + "]\n";
}
} else if (kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end()) {
- result = android::base::GetProperty(prop, "") + "\n";
+ result = query_prop(prop) + "\n";
}
if (result.empty()) {
result = "\n";
diff --git a/otautil/Android.bp b/otautil/Android.bp
index c8f974688..3b3f9cbc4 100644
--- a/otautil/Android.bp
+++ b/otautil/Android.bp
@@ -16,6 +16,7 @@ cc_library_static {
name: "libotautil",
host_supported: true,
+ vendor_available: true,
recovery_available: true,
defaults: [
diff --git a/recovery.cpp b/recovery.cpp
index 8f8f7dc02..633734285 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -42,7 +42,6 @@
#include <android-base/strings.h>
#include <cutils/properties.h> /* for property_list */
#include <fs_mgr/roots.h>
-#include <healthhalutils/HealthHalUtils.h>
#include <ziparchive/zip_archive.h>
#include "bootloader_message/bootloader_message.h"
@@ -59,6 +58,7 @@
#include "otautil/sysutil.h"
#include "recovery_ui/screen_ui.h"
#include "recovery_ui/ui.h"
+#include "recovery_utils/battery_utils.h"
#include "recovery_utils/logging.h"
#include "recovery_utils/roots.h"
@@ -453,74 +453,17 @@ static void print_property(const char* key, const char* name, void* /* cookie */
printf("%s=%s\n", key, name);
}
-static bool is_battery_ok(int* required_battery_level) {
- using android::hardware::health::V1_0::BatteryStatus;
- using android::hardware::health::V2_0::get_health_service;
- using android::hardware::health::V2_0::IHealth;
- using android::hardware::health::V2_0::Result;
- using android::hardware::health::V2_0::toString;
-
- android::sp<IHealth> health = get_health_service();
-
- static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10;
- int wait_second = 0;
- while (true) {
- auto charge_status = BatteryStatus::UNKNOWN;
-
- if (health == nullptr) {
- LOG(WARNING) << "no health implementation is found, assuming defaults";
- } else {
- health
- ->getChargeStatus([&charge_status](auto res, auto out_status) {
- if (res == Result::SUCCESS) {
- charge_status = out_status;
- }
- })
- .isOk(); // should not have transport error
- }
-
- // Treat unknown status as charged.
- bool charged = (charge_status != BatteryStatus::DISCHARGING &&
- charge_status != BatteryStatus::NOT_CHARGING);
-
- Result res = Result::UNKNOWN;
- int32_t capacity = INT32_MIN;
- if (health != nullptr) {
- health
- ->getCapacity([&res, &capacity](auto out_res, auto out_capacity) {
- res = out_res;
- capacity = out_capacity;
- })
- .isOk(); // should not have transport error
- }
-
- LOG(INFO) << "charge_status " << toString(charge_status) << ", charged " << charged
- << ", status " << toString(res) << ", capacity " << capacity;
- // At startup, the battery drivers in devices like N5X/N6P take some time to load
- // the battery profile. Before the load finishes, it reports value 50 as a fake
- // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
- // to finish loading the battery profile earlier than 10 seconds after kernel startup.
- if (res == Result::SUCCESS && capacity == 50) {
- if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) {
- sleep(1);
- wait_second++;
- continue;
- }
- }
- // If we can't read battery percentage, it may be a device without battery. In this
- // situation, use 100 as a fake battery percentage.
- if (res != Result::SUCCESS) {
- capacity = 100;
- }
-
- // GmsCore enters recovery mode to install package when having enough battery percentage.
- // Normally, the threshold is 40% without charger and 20% with charger. So we should check
- // battery with a slightly lower limitation.
- static constexpr int BATTERY_OK_PERCENTAGE = 20;
- static constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
- *required_battery_level = charged ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE;
- return capacity >= *required_battery_level;
- }
+static bool IsBatteryOk(int* required_battery_level) {
+ // GmsCore enters recovery mode to install package when having enough battery percentage.
+ // Normally, the threshold is 40% without charger and 20% with charger. So we check the battery
+ // level against a slightly lower limit.
+ constexpr int BATTERY_OK_PERCENTAGE = 20;
+ constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
+
+ auto battery_info = GetBatteryInfo();
+ *required_battery_level =
+ battery_info.charging ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE;
+ return battery_info.capacity >= *required_battery_level;
}
// Set the retry count to |retry_count| in BCB.
@@ -713,12 +656,10 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri
// to log the update attempt since update_package is non-NULL.
save_current_log = true;
- int required_battery_level;
- if (retry_count == 0 && !is_battery_ok(&required_battery_level)) {
+ if (int required_battery_level; retry_count == 0 && !IsBatteryOk(&required_battery_level)) {
ui->Print("battery capacity is not enough for installing package: %d%% needed\n",
required_battery_level);
- // Log the error code to last_install when installation skips due to
- // low battery.
+ // 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 (retry_count == 0 && bootreason_in_blacklist()) {
diff --git a/recovery_utils/Android.bp b/recovery_utils/Android.bp
index 271d0799d..bf79a2e87 100644
--- a/recovery_utils/Android.bp
+++ b/recovery_utils/Android.bp
@@ -12,6 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+cc_defaults {
+ name: "librecovery_utils_defaults",
+
+ defaults: [
+ "recovery_defaults",
+ ],
+
+ shared_libs: [
+ "android.hardware.health@2.0",
+ "libbase",
+ "libext4_utils",
+ "libfs_mgr",
+ "libhidlbase",
+ "libselinux",
+ "libutils",
+ ],
+
+ static_libs: [
+ "libotautil",
+
+ // External dependencies.
+ "libfstab",
+ "libhealthhalutils",
+ ],
+}
+
// A utility lib that's local to recovery (in contrast, libotautil is exposed to device-specific
// recovery_ui lib as well as device-specific updater).
cc_library_static {
@@ -20,39 +46,27 @@ cc_library_static {
recovery_available: true,
defaults: [
- "recovery_defaults",
+ "librecovery_utils_defaults",
],
srcs: [
+ "battery_utils.cpp",
"logging.cpp",
"parse_install_logs.cpp",
"roots.cpp",
"thermalutil.cpp",
],
- shared_libs: [
- "libbase",
- "libext4_utils",
- "libfs_mgr",
- "libselinux",
+ header_libs: [
+ "libvold_headers",
],
export_include_dirs: [
"include",
],
- include_dirs: [
- "system/vold",
- ],
-
- static_libs: [
- "libotautil",
-
- // external dependency
- "libfstab",
- ],
-
export_static_lib_headers: [
+ // roots.h includes <fstab/fstab.h>.
"libfstab",
],
@@ -61,6 +75,7 @@ cc_library_static {
visibility: [
"//bootable/recovery",
"//bootable/recovery/install",
+ "//bootable/recovery/minadbd",
"//bootable/recovery/tests",
],
}
diff --git a/recovery_utils/battery_utils.cpp b/recovery_utils/battery_utils.cpp
new file mode 100644
index 000000000..323f52537
--- /dev/null
+++ b/recovery_utils/battery_utils.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 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 "recovery_utils/battery_utils.h"
+
+#include <stdint.h>
+#include <unistd.h>
+
+#include <android-base/logging.h>
+#include <healthhalutils/HealthHalUtils.h>
+
+BatteryInfo GetBatteryInfo() {
+ using android::hardware::health::V1_0::BatteryStatus;
+ using android::hardware::health::V2_0::get_health_service;
+ using android::hardware::health::V2_0::IHealth;
+ using android::hardware::health::V2_0::Result;
+ using android::hardware::health::V2_0::toString;
+
+ android::sp<IHealth> health = get_health_service();
+
+ int wait_second = 0;
+ while (true) {
+ auto charge_status = BatteryStatus::UNKNOWN;
+
+ if (health == nullptr) {
+ LOG(WARNING) << "No health implementation is found; assuming defaults";
+ } else {
+ health
+ ->getChargeStatus([&charge_status](auto res, auto out_status) {
+ if (res == Result::SUCCESS) {
+ charge_status = out_status;
+ }
+ })
+ .isOk(); // should not have transport error
+ }
+
+ // Treat unknown status as on charger. See hardware/interfaces/health/1.0/types.hal for the
+ // meaning of the return values.
+ bool charging = (charge_status != BatteryStatus::DISCHARGING &&
+ charge_status != BatteryStatus::NOT_CHARGING);
+
+ Result res = Result::UNKNOWN;
+ int32_t capacity = INT32_MIN;
+ if (health != nullptr) {
+ health
+ ->getCapacity([&res, &capacity](auto out_res, auto out_capacity) {
+ res = out_res;
+ capacity = out_capacity;
+ })
+ .isOk(); // should not have transport error
+ }
+
+ LOG(INFO) << "charge_status " << toString(charge_status) << ", charging " << charging
+ << ", status " << toString(res) << ", capacity " << capacity;
+
+ constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10;
+ // At startup, the battery drivers in devices like N5X/N6P take some time to load
+ // the battery profile. Before the load finishes, it reports value 50 as a fake
+ // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
+ // to finish loading the battery profile earlier than 10 seconds after kernel startup.
+ if (res == Result::SUCCESS && capacity == 50) {
+ if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) {
+ sleep(1);
+ wait_second++;
+ continue;
+ }
+ }
+ // If we can't read battery percentage, it may be a device without battery. In this
+ // situation, use 100 as a fake battery percentage.
+ if (res != Result::SUCCESS) {
+ capacity = 100;
+ }
+
+ return BatteryInfo{ charging, capacity };
+ }
+}
diff --git a/recovery_utils/include/recovery_utils/battery_utils.h b/recovery_utils/include/recovery_utils/battery_utils.h
new file mode 100644
index 000000000..a95f71dca
--- /dev/null
+++ b/recovery_utils/include/recovery_utils/battery_utils.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+struct BatteryInfo {
+ // Whether the device is on charger. Note that the value will be `true` if the battery status is
+ // unknown (BATTERY_STATUS_UNKNOWN).
+ bool charging;
+
+ // The remaining battery capacity percentage (i.e. between 0 and 100). See getCapacity in
+ // hardware/interfaces/health/2.0/IHealth.hal. Returns 100 in case it fails to read a value from
+ // the health HAL.
+ int32_t capacity;
+};
+
+// Returns the battery status for OTA installation purpose.
+BatteryInfo GetBatteryInfo();
diff --git a/recovery_utils/roots.cpp b/recovery_utils/roots.cpp
index f717ec208..fe3a07aa2 100644
--- a/recovery_utils/roots.cpp
+++ b/recovery_utils/roots.cpp
@@ -54,7 +54,11 @@ void load_volume_table() {
}
fstab.emplace_back(FstabEntry{
- .mount_point = "/tmp", .fs_type = "ramdisk", .blk_device = "ramdisk", .length = 0 });
+ .blk_device = "ramdisk",
+ .mount_point = "/tmp",
+ .fs_type = "ramdisk",
+ .length = 0,
+ });
std::cout << "recovery filesystem table" << std::endl << "=========================" << std::endl;
for (size_t i = 0; i < fstab.size(); ++i) {
diff --git a/tests/unit/battery_utils_test.cpp b/tests/unit/battery_utils_test.cpp
new file mode 100644
index 000000000..55639fdb5
--- /dev/null
+++ b/tests/unit/battery_utils_test.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2019 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 agree 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 <android-base/logging.h>
+#include <gtest/gtest.h>
+
+#include "recovery_utils/battery_utils.h"
+
+TEST(BatteryInfoTest, GetBatteryInfo) {
+ auto info = GetBatteryInfo();
+ // 0 <= capacity <= 100
+ ASSERT_LE(0, info.capacity);
+ ASSERT_LE(info.capacity, 100);
+}
diff --git a/updater/updater_main.cpp b/updater/updater_main.cpp
index 055a8ac76..33d5b5b47 100644
--- a/updater/updater_main.cpp
+++ b/updater/updater_main.cpp
@@ -22,6 +22,7 @@
#include <android-base/logging.h>
#include <android-base/parseint.h>
+#include <openssl/crypto.h>
#include <selinux/android.h>
#include <selinux/label.h>
#include <selinux/selinux.h>
@@ -56,22 +57,28 @@ int main(int argc, char** argv) {
// (which is redirected to recovery.log).
android::base::InitLogging(argv, &UpdaterLogger);
+ // Run the libcrypto KAT(known answer tests) based self tests.
+ if (BORINGSSL_self_test() != 1) {
+ LOG(ERROR) << "Failed to run the boringssl self tests";
+ return EXIT_FAILURE;
+ }
+
if (argc != 4 && argc != 5) {
LOG(ERROR) << "unexpected number of arguments: " << argc;
- return 1;
+ return EXIT_FAILURE;
}
char* version = argv[1];
if ((version[0] != '1' && version[0] != '2' && version[0] != '3') || version[1] != '\0') {
// We support version 1, 2, or 3.
LOG(ERROR) << "wrong updater binary API; expected 1, 2, or 3; got " << argv[1];
- return 1;
+ return EXIT_FAILURE;
}
int fd;
if (!android::base::ParseInt(argv[2], &fd)) {
LOG(ERROR) << "Failed to parse fd in " << argv[2];
- return 1;
+ return EXIT_FAILURE;
}
std::string package_name = argv[3];
@@ -82,7 +89,7 @@ int main(int argc, char** argv) {
is_retry = true;
} else {
LOG(ERROR) << "unexpected argument: " << argv[4];
- return 1;
+ return EXIT_FAILURE;
}
}
@@ -98,12 +105,12 @@ int main(int argc, char** argv) {
Updater updater(std::make_unique<UpdaterRuntime>(sehandle));
if (!updater.Init(fd, package_name, is_retry)) {
- return 1;
+ return EXIT_FAILURE;
}
if (!updater.RunUpdate()) {
- return 1;
+ return EXIT_FAILURE;
}
- return 0;
+ return EXIT_SUCCESS;
} \ No newline at end of file
diff --git a/updater_sample/OWNERS b/updater_sample/OWNERS
deleted file mode 100644
index 5c1c3706c..000000000
--- a/updater_sample/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-zhaojiac@google.com
-zhomart@google.com