Skip to content

Commit

Permalink
hardware/health: Upgrade to 2.1 via libhealth2impl
Browse files Browse the repository at this point in the history
The `libhealthservice` and `libhealthstoragedefault` helper libraries
to implement Health HALs have been removed in Android 14 QPR 3.  At
the same time a newer 2.1 HIDL HAL has been made available (which
is already deprecated too, in favour of an AIDL HAL).  Upgrade our
custom implementation - which backs up the battery cycles and learned
capacity - to leverage `libhealth2impl` and automatically implement
`[email protected]`.

Its implementation and header even describe how to upgrade away from
the old `healthd_board_*()` callback symbols.

Furthermore, the default implementation already provides a passthrough
service, which allows us to convert this service to an `impl` library
and use the builtin service (plus all the files it needs) instead.
  • Loading branch information
MarijnS95 committed Jul 8, 2024
1 parent 72741b2 commit 1c38227
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 140 deletions.
3 changes: 2 additions & 1 deletion common-treble.mk
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ PRODUCT_PACKAGES += \

# Health
PRODUCT_PACKAGES += \
[email protected]
[email protected] \
[email protected]

ifeq ($(TARGET_VIBRATOR_V1_2),true)
# QTI Haptics Vibrator
Expand Down
41 changes: 11 additions & 30 deletions hardware/health/Android.bp
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
cc_binary {
name: "[email protected]",
init_rc: ["[email protected]"],
cc_library_shared {
name: "[email protected]",

// Only vendor and recovery variants are allowed, not core.
vendor: true,
relative_install_path: "hw",
recovery_available: true,
cflags: [
"-Wall",
"-Werror",
"-Wno-unused",
"-fexceptions",
],

defaults: ["[email protected]"],

srcs: [
"HealthService.cpp",
"impl.cpp",
"CycleCountBackupRestore.cpp",
"LearnedCapacityBackupRestore.cpp",
],
static_libs: [
"[email protected]",
"[email protected]",
"libbatterymonitor",
// libhealthservice is needed for health_service_main()
"libhealthservice",
// Storage is needed by the HAL definition, use default
"libhealthstoragedefault",
],
shared_libs: [
"[email protected]",
"libbase",
"libcutils",
"libhidlbase",
"liblog",
"libutils",
],
header_libs: [
// We only need BatteryService.h
"libbatteryservice_headers",
],

vintf_fragments: [
"[email protected]",
],
// No vintf_fragments because both -impl and -service should have been
// installed.
}
74 changes: 0 additions & 74 deletions hardware/health/HealthService.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions hardware/health/[email protected]

This file was deleted.

71 changes: 71 additions & 0 deletions hardware/health/impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Entrypoint for the main HAL service.
*
* Copyright (C) 2018 The Android Open Source Project
* Copyright (C) 2019 Felix Elsner
*
* 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.
*/

#define LOG_TAG "[email protected]"

#include <batteryservice/BatteryService.h>
#include <health/utils.h>
#include <health2impl/Health.h>

#include <string_view>

#include "CycleCountBackupRestore.h"
#include "LearnedCapacityBackupRestore.h"

using ::android::hardware::health::InitHealthdConfig;
using ::android::hardware::health::V2_1::IHealth;

using namespace std::literals;

namespace device {
namespace sony {
namespace health {
using ::android::hardware::health::V2_1::HealthInfo;
using ::android::hardware::health::V2_1::implementation::Health;
using ::device::sony::health::CycleCountBackupRestore;
using ::device::sony::health::LearnedCapacityBackupRestore;

class SonyHealth : public Health {
CycleCountBackupRestore ccBackupRestore;
LearnedCapacityBackupRestore lcBackupRestore;

virtual void UpdateHealthInfo(HealthInfo *health_info) {
ccBackupRestore.Backup(health_info->legacy.legacy.batteryLevel);
lcBackupRestore.Backup();
}

public:
SonyHealth(std::unique_ptr<struct healthd_config> &&config) : Health(std::move(config)) {
ccBackupRestore.Restore();
lcBackupRestore.Restore();
}
};
} // namespace health
} // namespace sony
} // namespace device

extern "C" IHealth *HIDL_FETCH_IHealth(const char *instance) {
if (instance != "default"sv) {
return nullptr;
}
auto config = std::make_unique<healthd_config>();
InitHealthdConfig(config.get());

return new device::sony::health::SonyHealth(std::move(config));
}
11 changes: 0 additions & 11 deletions hardware/health/[email protected]

This file was deleted.

0 comments on commit 1c38227

Please sign in to comment.