Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc569285 authored by Yifan Hong's avatar Yifan Hong Committed by Gerrit Code Review
Browse files

Merge "fastboot: use health AIDL HAL"

parents c034ce08 4cb88dc8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -166,8 +166,10 @@ cc_binary {
        "android.hardware.boot@1.1",
        "android.hardware.fastboot@1.1",
        "android.hardware.health@2.0",
        "android.hardware.health-V1-ndk",
        "libasyncio",
        "libbase",
        "libbinder_ndk",
        "libbootloader_message",
        "libcutils",
        "libext2_uuid",
@@ -183,8 +185,10 @@ cc_binary {
    ],

    static_libs: [
        "android.hardware.health-translate-ndk",
        "libc++fs",
        "libhealthhalutils",
        "libhealthshim",
        "libsnapshot_cow",
        "libsnapshot_nobinder",
        "update_metadata-protos",
+23 −1
Original line number Diff line number Diff line
@@ -21,10 +21,12 @@
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android/binder_manager.h>
#include <android/hardware/boot/1.0/IBootControl.h>
#include <android/hardware/fastboot/1.1/IFastboot.h>
#include <fs_mgr.h>
#include <fs_mgr/roots.h>
#include <health-shim/shim.h>
#include <healthhalutils/HealthHalUtils.h>

#include "constants.h"
@@ -32,16 +34,36 @@
#include "tcp_client.h"
#include "usb_client.h"

using std::string_literals::operator""s;
using android::fs_mgr::EnsurePathUnmounted;
using android::fs_mgr::Fstab;
using ::android::hardware::hidl_string;
using ::android::hardware::boot::V1_0::IBootControl;
using ::android::hardware::boot::V1_0::Slot;
using ::android::hardware::fastboot::V1_1::IFastboot;
using ::android::hardware::health::V2_0::get_health_service;

namespace sph = std::placeholders;

std::shared_ptr<aidl::android::hardware::health::IHealth> get_health_service() {
    using aidl::android::hardware::health::IHealth;
    using HidlHealth = android::hardware::health::V2_0::IHealth;
    using aidl::android::hardware::health::HealthShim;
    auto service_name = IHealth::descriptor + "/default"s;
    if (AServiceManager_isDeclared(service_name.c_str())) {
        ndk::SpAIBinder binder(AServiceManager_waitForService(service_name.c_str()));
        std::shared_ptr<IHealth> health = IHealth::fromBinder(binder);
        if (health != nullptr) return health;
        LOG(WARNING) << "AIDL health service is declared, but it cannot be retrieved.";
    }
    LOG(INFO) << "Unable to get AIDL health service, trying HIDL...";
    android::sp<HidlHealth> hidl_health = android::hardware::health::V2_0::get_health_service();
    if (hidl_health != nullptr) {
        return ndk::SharedRefBase::make<HealthShim>(hidl_health);
    }
    LOG(WARNING) << "No health implementation is found.";
    return nullptr;
}

FastbootDevice::FastbootDevice()
    : kCommandMap({
              {FB_CMD_SET_ACTIVE, SetActiveHandler},
+3 −3
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@
#include <utility>
#include <vector>

#include <aidl/android/hardware/health/IHealth.h>
#include <android/hardware/boot/1.0/IBootControl.h>
#include <android/hardware/boot/1.1/IBootControl.h>
#include <android/hardware/fastboot/1.1/IFastboot.h>
#include <android/hardware/health/2.0/IHealth.h>

#include "commands.h"
#include "transport.h"
@@ -57,7 +57,7 @@ class FastbootDevice {
    android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() {
        return fastboot_hal_;
    }
    android::sp<android::hardware::health::V2_0::IHealth> health_hal() { return health_hal_; }
    std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal() { return health_hal_; }

    void set_active_slot(const std::string& active_slot) { active_slot_ = active_slot; }

@@ -67,7 +67,7 @@ class FastbootDevice {
    std::unique_ptr<Transport> transport_;
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
    android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1_;
    android::sp<android::hardware::health::V2_0::IHealth> health_hal_;
    std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal_;
    android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_;
    std::vector<char> download_data_;
    std::string active_slot_;
+5 −12
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#include <android/hardware/boot/1.1/IBootControl.h>
#include <ext4_utils/ext4_utils.h>
#include <fs_mgr.h>
#include <healthhalutils/HealthHalUtils.h>
#include <liblp/liblp.h>

#include "fastboot_device.h"
@@ -120,23 +119,17 @@ bool GetVariant(FastbootDevice* device, const std::vector<std::string>& /* args
}

bool GetBatteryVoltageHelper(FastbootDevice* device, int32_t* battery_voltage) {
    using android::hardware::health::V2_0::HealthInfo;
    using android::hardware::health::V2_0::Result;
    using aidl::android::hardware::health::HealthInfo;

    auto health_hal = device->health_hal();
    if (!health_hal) {
        return false;
    }

    Result ret;
    auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) {
        *battery_voltage = info.legacy.batteryVoltage;
        ret = result;
    });
    if (!ret_val.isOk() || (ret != Result::SUCCESS)) {
        return false;
    }

    HealthInfo health_info;
    auto res = health_hal->getHealthInfo(&health_info);
    if (!res.isOk()) return false;
    *battery_voltage = health_info.batteryVoltageMillivolts;
    return true;
}