mirror of
https://github.com/Evolution-X-Devices/device_google_wahoo
synced 2026-01-27 18:19:03 +00:00
Add health service for Wahoo
Bug: 68388678 Test: vts-tradefed run vts -m VtsHalHealthV2_0 Change-Id: I37c2c66d26b1af04ccfedb59a24bb4e4aa492041
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
subdirs = [
|
||||
"thermal",
|
||||
"vr",
|
||||
"vibrator",
|
||||
"wifi_offload",
|
||||
"usb",
|
||||
]
|
||||
@@ -156,3 +156,8 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/lib/hw/android.hardware.ther
|
||||
# Remove android.hardware.keymaster@4.0-service
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.keymaster@4.0-service)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.keymaster@4.0-service.rc)
|
||||
|
||||
# Health HAL 2.0
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.health@2.0-service)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.health@2.0-service.rc)
|
||||
|
||||
|
||||
49
health/Android.bp
Normal file
49
health/Android.bp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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_binary {
|
||||
name: "android.hardware.health@2.0-service.wahoo",
|
||||
init_rc: ["android.hardware.health@2.0-service.wahoo.rc"],
|
||||
proprietary: true,
|
||||
relative_install_path: "hw",
|
||||
srcs: [
|
||||
"HealthServiceCommon.cpp",
|
||||
"HealthService.cpp",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-DHEALTH_INSTANCE_NAME=\"default\"",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
"android.hardware.health@2.0-impl",
|
||||
"android.hardware.health@1.0-convert",
|
||||
"libbatterymonitor",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
"android.hardware.health@2.0",
|
||||
],
|
||||
|
||||
header_libs: ["libhealthd_headers"],
|
||||
}
|
||||
132
health/HealthService.cpp
Normal file
132
health/HealthService.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#define LOG_TAG "android.hardware.health@2.0-service.wahoo"
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <healthd/healthd.h>
|
||||
#include <health2/Health.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/strings.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using android::hardware::health::V2_0::StorageInfo;
|
||||
using android::hardware::health::V2_0::DiskStats;
|
||||
|
||||
void healthd_board_init(struct healthd_config*) {
|
||||
}
|
||||
|
||||
int healthd_board_battery_update(struct android::BatteryProperties*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char kUFSHealthFile[] = "/sys/kernel/debug/ufshcd0/dump_health_desc";
|
||||
const char kUFSHealthVersionFile[] = "/sys/kernel/debug/ufshcd0/show_hba";
|
||||
const char kDiskStatsFile[] = "/sys/block/sda/stat";
|
||||
const char kUFSName[] = "UFS0";
|
||||
|
||||
/*
|
||||
* Implementation based on system/core/storaged/storaged_info.cc
|
||||
*/
|
||||
void get_storage_info(std::vector<StorageInfo>& vec_storage_info) {
|
||||
StorageInfo storage_info = {};
|
||||
std::string buffer, version;
|
||||
|
||||
storage_info.attr.isInternal = true;
|
||||
storage_info.attr.isBootDevice = true;
|
||||
storage_info.attr.name = std::string(kUFSName);
|
||||
|
||||
if (!android::base::ReadFileToString(std::string(kUFSHealthVersionFile), &version)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> lines = android::base::Split(version, "\n");
|
||||
if (lines.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
char rev[8];
|
||||
if (sscanf(lines[6].c_str(), "hba->ufs_version = 0x%7s\n", rev) < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
storage_info.version = "ufs " + std::string(rev);
|
||||
|
||||
if (!android::base::ReadFileToString(std::string(kUFSHealthFile), &buffer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
lines = android::base::Split(buffer, "\n");
|
||||
if (lines.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < lines.size(); i++) {
|
||||
char token[32];
|
||||
uint16_t val;
|
||||
int ret;
|
||||
if ((ret = sscanf(lines[i].c_str(),
|
||||
"Health Descriptor[Byte offset 0x%*d]: %31s = 0x%hx",
|
||||
token, &val)) < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::string(token) == "bPreEOLInfo") {
|
||||
storage_info.eol = val;
|
||||
} else if (std::string(token) == "bDeviceLifeTimeEstA") {
|
||||
storage_info.lifetimeA = val;
|
||||
} else if (std::string(token) == "bDeviceLifeTimeEstB") {
|
||||
storage_info.lifetimeB = val;
|
||||
}
|
||||
}
|
||||
|
||||
vec_storage_info.resize(1);
|
||||
vec_storage_info[0] = storage_info;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation based on parse_disk_stats() in system/core/storaged_diskstats.cpp
|
||||
*/
|
||||
void get_disk_stats(std::vector<DiskStats>& vec_stats) {
|
||||
const size_t kDiskStatsSize = 11;
|
||||
struct DiskStats stats = {};
|
||||
|
||||
stats.attr.isInternal = true;
|
||||
stats.attr.isBootDevice = true;
|
||||
stats.attr.name = std::string(kUFSName);
|
||||
|
||||
|
||||
std::string buffer;
|
||||
if (!android::base::ReadFileToString(std::string(kDiskStatsFile), &buffer)) {
|
||||
LOG(ERROR) << kDiskStatsFile << ": ReadFileToString failed.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Regular diskstats entries
|
||||
std::stringstream ss(buffer);
|
||||
for (uint i = 0; i < kDiskStatsSize; ++i) {
|
||||
ss >> *(reinterpret_cast<uint64_t*>(&stats) + i);
|
||||
}
|
||||
vec_stats.resize(1);
|
||||
vec_stats[0] = stats;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
86
health/HealthServiceCommon.cpp
Normal file
86
health/HealthServiceCommon.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "health@2.0/" HEALTH_INSTANCE_NAME
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <android/hardware/health/1.0/types.h>
|
||||
#include <hal_conversion.h>
|
||||
#include <health2/Health.h>
|
||||
#include <healthd/healthd.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
using android::hardware::IPCThreadState;
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::handleTransportPoll;
|
||||
using android::hardware::setupTransportPolling;
|
||||
using android::hardware::health::V1_0::HealthInfo;
|
||||
using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;
|
||||
using android::hardware::health::V2_0::IHealth;
|
||||
using android::hardware::health::V2_0::implementation::Health;
|
||||
|
||||
extern int healthd_main(void);
|
||||
|
||||
static int gBinderFd = -1;
|
||||
|
||||
static void binder_event(uint32_t /*epevents*/) {
|
||||
if (gBinderFd >= 0) handleTransportPoll(gBinderFd);
|
||||
}
|
||||
|
||||
void healthd_mode_service_2_0_init(struct healthd_config* config) {
|
||||
LOG(INFO) << LOG_TAG << " Hal is starting up...";
|
||||
|
||||
gBinderFd = setupTransportPolling();
|
||||
|
||||
if (gBinderFd >= 0) {
|
||||
if (healthd_register_event(gBinderFd, binder_event))
|
||||
LOG(ERROR) << LOG_TAG << ": Register for binder events failed";
|
||||
}
|
||||
|
||||
android::sp<IHealth> service = Health::initInstance(config);
|
||||
CHECK_EQ(service->registerAsService(HEALTH_INSTANCE_NAME), android::OK)
|
||||
<< LOG_TAG << ": Failed to register HAL";
|
||||
|
||||
LOG(INFO) << LOG_TAG << ": Hal init done";
|
||||
}
|
||||
|
||||
int healthd_mode_service_2_0_preparetowait(void) {
|
||||
IPCThreadState::self()->flushCommands();
|
||||
return -1;
|
||||
}
|
||||
|
||||
void healthd_mode_service_2_0_heartbeat(void) {
|
||||
// noop
|
||||
}
|
||||
|
||||
void healthd_mode_service_2_0_battery_update(struct android::BatteryProperties* prop) {
|
||||
HealthInfo info;
|
||||
convertToHealthInfo(prop, info);
|
||||
Health::getImplementation()->notifyListeners(info);
|
||||
}
|
||||
|
||||
static struct healthd_mode_ops healthd_mode_service_2_0_ops = {
|
||||
.init = healthd_mode_service_2_0_init,
|
||||
.preparetowait = healthd_mode_service_2_0_preparetowait,
|
||||
.heartbeat = healthd_mode_service_2_0_heartbeat,
|
||||
.battery_update = healthd_mode_service_2_0_battery_update,
|
||||
};
|
||||
|
||||
int main() {
|
||||
healthd_mode_ops = &healthd_mode_service_2_0_ops;
|
||||
LOG(INFO) << LOG_TAG << ": Hal starting main loop...";
|
||||
return healthd_main();
|
||||
}
|
||||
4
health/android.hardware.health@2.0-service.wahoo.rc
Normal file
4
health/android.hardware.health@2.0-service.wahoo.rc
Normal file
@@ -0,0 +1,4 @@
|
||||
service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.wahoo
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
Reference in New Issue
Block a user