Move slider into gs101 and <device>
from: 026342771c6642980cb4653b1ec4d857a5d8be54 Bug: 167996145 Change-Id: I2ebf7f019afed1cbe9b60dcd82581bd3a52fe109
This commit is contained in:
parent
0ef3a89b93
commit
c2b5ca99e3
308 changed files with 26964 additions and 0 deletions
59
health/Android.bp
Normal file
59
health/Android.bp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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 {
|
||||
// See: http://go/android-license-faq
|
||||
// A large-scale-change added 'default_applicable_licenses' to import
|
||||
// all of the 'license_kinds' from "//device/google/gs101:device_google_gs101_license"
|
||||
// to get the below license kinds:
|
||||
// SPDX-license-identifier-Apache-2.0
|
||||
default_applicable_licenses: [
|
||||
"//device/google/gs101:device_google_gs101_license",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "android.hardware.health@2.1-impl-gs101",
|
||||
stem: "android.hardware.health@2.0-impl-2.1-gs101",
|
||||
|
||||
proprietary: true,
|
||||
relative_install_path: "hw",
|
||||
srcs: [
|
||||
"Health.cpp",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
"android.hardware.health@1.0-convert",
|
||||
"libbatterymonitor",
|
||||
"libhealth2impl",
|
||||
"libhealthloop",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
"libpixelhealth",
|
||||
"libutils",
|
||||
"android.hardware.health@2.0",
|
||||
"android.hardware.health@2.1",
|
||||
],
|
||||
}
|
260
health/Health.cpp
Normal file
260
health/Health.cpp
Normal file
|
@ -0,0 +1,260 @@
|
|||
/*
|
||||
* 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.1-impl-gs101"
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/parseint.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android/hardware/health/2.0/types.h>
|
||||
#include <health2impl/Health.h>
|
||||
#include <health/utils.h>
|
||||
#include <hal_conversion.h>
|
||||
|
||||
#include <pixelhealth/BatteryDefender.h>
|
||||
#include <pixelhealth/BatteryMetricsLogger.h>
|
||||
#include <pixelhealth/BatteryThermalControl.h>
|
||||
#include <pixelhealth/ChargerDetect.h>
|
||||
#include <pixelhealth/DeviceHealth.h>
|
||||
#include <pixelhealth/LowBatteryShutdownMetrics.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
using android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo;
|
||||
using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;
|
||||
using android::hardware::health::V2_0::DiskStats;
|
||||
using android::hardware::health::V2_0::StorageAttribute;
|
||||
using android::hardware::health::V2_0::StorageInfo;
|
||||
using android::hardware::health::V2_0::Result;
|
||||
using ::android::hardware::health::V2_1::IHealth;
|
||||
using android::hardware::health::InitHealthdConfig;
|
||||
|
||||
using hardware::google::pixel::health::BatteryDefender;
|
||||
using hardware::google::pixel::health::BatteryMetricsLogger;
|
||||
using hardware::google::pixel::health::BatteryThermalControl;
|
||||
using hardware::google::pixel::health::DeviceHealth;
|
||||
using hardware::google::pixel::health::LowBatteryShutdownMetrics;
|
||||
using hardware::google::pixel::health::ChargerDetect;
|
||||
|
||||
#define FG_DIR "/sys/class/power_supply/battery"
|
||||
constexpr char kBatteryResistance[] {FG_DIR "/resistance"};
|
||||
constexpr char kBatteryOCV[] {FG_DIR "/voltage_ocv"};
|
||||
constexpr char kVoltageAvg[] {FG_DIR "/voltage_now"};
|
||||
|
||||
static BatteryDefender battDefender;
|
||||
static BatteryThermalControl battThermalControl(
|
||||
"dev/thermal/tz-by-name/soc/mode");
|
||||
static BatteryMetricsLogger battMetricsLogger(kBatteryResistance, kBatteryOCV);
|
||||
static LowBatteryShutdownMetrics shutdownMetrics(kVoltageAvg);
|
||||
static DeviceHealth deviceHealth;
|
||||
|
||||
#define UFS_DIR "/dev/sys/block/bootdevice"
|
||||
constexpr char kUfsHealthEol[]{UFS_DIR "/health_descriptor/eol_info"};
|
||||
constexpr char kUfsHealthLifetimeA[]{UFS_DIR "/health_descriptor/life_time_estimation_a"};
|
||||
constexpr char kUfsHealthLifetimeB[]{UFS_DIR "/health_descriptor/life_time_estimation_b"};
|
||||
constexpr char kUfsVersion[]{UFS_DIR "/device_descriptor/specification_version"};
|
||||
constexpr char kDiskStatsFile[]{"/sys/block/sda/stat"};
|
||||
constexpr char kUFSName[]{"UFS0"};
|
||||
|
||||
static std::string ufs_version;
|
||||
static uint16_t eol;
|
||||
static uint16_t lifetimeA;
|
||||
static uint16_t lifetimeB;
|
||||
static std::chrono::system_clock::time_point ufs_last_query_time;
|
||||
constexpr auto kUfsQueryIntervalHours = std::chrono::hours{24};
|
||||
|
||||
#define WLC_DIR "/sys/class/power_supply/wireless"
|
||||
static bool needs_wlc_updates = false;
|
||||
constexpr char kWlcCapacity[]{WLC_DIR "/capacity"};
|
||||
|
||||
std::ifstream assert_open(const std::string &path) {
|
||||
std::ifstream stream(path);
|
||||
if (!stream.is_open()) {
|
||||
LOG(WARNING) << "Cannot read " << path;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void read_value_from_file(const std::string &path, T *field) {
|
||||
auto stream = assert_open(path);
|
||||
stream.unsetf(std::ios_base::basefield);
|
||||
stream >> *field;
|
||||
}
|
||||
|
||||
void read_ufs_version(StorageInfo *info) {
|
||||
if (ufs_version.empty()) {
|
||||
uint64_t value;
|
||||
read_value_from_file(kUfsVersion, &value);
|
||||
std::stringstream ss;
|
||||
ss << "ufs " << std::hex << value;
|
||||
ufs_version = ss.str();
|
||||
LOG(INFO) << "ufs: " << ufs_version << " detected";
|
||||
}
|
||||
info->version = ufs_version;
|
||||
}
|
||||
|
||||
void fill_ufs_storage_attribute(StorageAttribute *attr) {
|
||||
attr->isInternal = true;
|
||||
attr->isBootDevice = true;
|
||||
attr->name = kUFSName;
|
||||
}
|
||||
|
||||
static bool FileExists(const std::string &filename) {
|
||||
struct stat buffer;
|
||||
|
||||
return stat(filename.c_str(), &buffer) == 0;
|
||||
}
|
||||
|
||||
void private_healthd_board_init(struct healthd_config *hc) {
|
||||
std::string tcpmPsyName;
|
||||
ChargerDetect::populateTcpmPsyName(&tcpmPsyName);
|
||||
hc->ignorePowerSupplyNames.push_back(android::String8(tcpmPsyName.c_str()));
|
||||
needs_wlc_updates = FileExists(kWlcCapacity);
|
||||
}
|
||||
|
||||
int private_healthd_board_battery_update(struct android::BatteryProperties *props) {
|
||||
deviceHealth.update(props);
|
||||
battThermalControl.updateThermalState(props);
|
||||
battMetricsLogger.logBatteryProperties(props);
|
||||
shutdownMetrics.logShutdownVoltage(props);
|
||||
// Allow BatteryDefender to override online properties
|
||||
ChargerDetect::onlineUpdate(props);
|
||||
battDefender.update(props);
|
||||
|
||||
if (needs_wlc_updates &&
|
||||
!android::base::WriteStringToFile(std::to_string(props->batteryLevel), kWlcCapacity))
|
||||
LOG(INFO) << "Unable to write battery level to wireless capacity";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void private_get_storage_info(std::vector<StorageInfo> &vec_storage_info) {
|
||||
vec_storage_info.resize(1);
|
||||
StorageInfo *storage_info = &vec_storage_info[0];
|
||||
fill_ufs_storage_attribute(&storage_info->attr);
|
||||
|
||||
read_ufs_version(storage_info);
|
||||
|
||||
auto time_now = std::chrono::system_clock::now();
|
||||
auto time_delta = time_now - ufs_last_query_time;
|
||||
auto hoursElapsed = std::chrono::duration_cast<std::chrono::hours>(time_delta);
|
||||
if (hoursElapsed >= kUfsQueryIntervalHours) {
|
||||
ufs_last_query_time = time_now;
|
||||
read_value_from_file(kUfsHealthEol, &eol);
|
||||
read_value_from_file(kUfsHealthLifetimeA, &lifetimeA);
|
||||
read_value_from_file(kUfsHealthLifetimeB, &lifetimeB);
|
||||
LOG(INFO) << "ufs: eol=" << eol << " lifetimeA=" << lifetimeA << " lifetimeB=" << lifetimeB;
|
||||
}
|
||||
storage_info->eol = eol;
|
||||
storage_info->lifetimeA = lifetimeA;
|
||||
storage_info->lifetimeB = lifetimeB;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void private_get_disk_stats(std::vector<DiskStats> &vec_stats) {
|
||||
vec_stats.resize(1);
|
||||
DiskStats *stats = &vec_stats[0];
|
||||
fill_ufs_storage_attribute(&stats->attr);
|
||||
|
||||
auto stream = assert_open(kDiskStatsFile);
|
||||
// Regular diskstats entries
|
||||
stream >> stats->reads >> stats->readMerges >> stats->readSectors >>
|
||||
stats->readTicks >> stats->writes >> stats->writeMerges >>
|
||||
stats->writeSectors >> stats->writeTicks >> stats->ioInFlight >>
|
||||
stats->ioTicks >> stats->ioInQueue;
|
||||
return;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace health {
|
||||
namespace V2_1 {
|
||||
namespace implementation {
|
||||
class HealthImpl : public Health {
|
||||
public:
|
||||
HealthImpl(std::unique_ptr<healthd_config>&& config)
|
||||
: Health(std::move(config)) {}
|
||||
|
||||
Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
|
||||
Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
|
||||
|
||||
protected:
|
||||
void UpdateHealthInfo(HealthInfo* health_info) override;
|
||||
|
||||
};
|
||||
|
||||
void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) {
|
||||
struct BatteryProperties props;
|
||||
convertFromHealthInfo(health_info->legacy.legacy, &props);
|
||||
private_healthd_board_battery_update(&props);
|
||||
convertToHealthInfo(&props, health_info->legacy.legacy);
|
||||
}
|
||||
|
||||
Return<void> HealthImpl::getStorageInfo(getStorageInfo_cb _hidl_cb)
|
||||
{
|
||||
std::vector<struct StorageInfo> info;
|
||||
private_get_storage_info(info);
|
||||
hidl_vec<struct StorageInfo> info_vec(info);
|
||||
if (!info.size()) {
|
||||
_hidl_cb(Result::NOT_SUPPORTED, info_vec);
|
||||
} else {
|
||||
_hidl_cb(Result::SUCCESS, info_vec);
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> HealthImpl::getDiskStats(getDiskStats_cb _hidl_cb)
|
||||
{
|
||||
std::vector<struct DiskStats> stats;
|
||||
private_get_disk_stats(stats);
|
||||
hidl_vec<struct DiskStats> stats_vec(stats);
|
||||
if (!stats.size()) {
|
||||
_hidl_cb(Result::NOT_SUPPORTED, stats_vec);
|
||||
} else {
|
||||
_hidl_cb(Result::SUCCESS, stats_vec);
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V2_1
|
||||
} // namespace health
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
|
||||
using ::android::hardware::health::V2_1::implementation::HealthImpl;
|
||||
if (instance != "default"sv) {
|
||||
return nullptr;
|
||||
}
|
||||
auto config = std::make_unique<healthd_config>();
|
||||
InitHealthdConfig(config.get());
|
||||
|
||||
private_healthd_board_init(config.get());
|
||||
|
||||
return new HealthImpl(std::move(config));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue