2013-06-12 22:25:59 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 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 "healthd"
|
|
|
|
|
2016-02-17 21:21:34 +01:00
|
|
|
#include <healthd/healthd.h>
|
|
|
|
#include <healthd/BatteryMonitor.h>
|
2013-06-12 22:25:59 +02:00
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-07-23 18:22:50 +02:00
|
|
|
#include <sys/types.h>
|
2013-06-12 22:25:59 +02:00
|
|
|
#include <unistd.h>
|
2019-01-12 02:09:20 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
2016-02-18 23:52:46 +01:00
|
|
|
#include <memory>
|
2019-10-07 20:18:04 +02:00
|
|
|
#include <optional>
|
2015-07-23 18:22:50 +02:00
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
#include <aidl/android/hardware/health/HealthInfo.h>
|
2016-06-05 20:20:13 +02:00
|
|
|
#include <android-base/file.h>
|
2016-10-12 02:09:00 +02:00
|
|
|
#include <android-base/parseint.h>
|
2016-06-05 20:20:13 +02:00
|
|
|
#include <android-base/strings.h>
|
2019-10-07 20:18:04 +02:00
|
|
|
#include <android/hardware/health/2.1/types.h>
|
2022-03-01 21:12:34 +01:00
|
|
|
#include <android/hardware/health/translate-ndk.h>
|
2013-06-12 22:25:59 +02:00
|
|
|
#include <batteryservice/BatteryService.h>
|
|
|
|
#include <cutils/klog.h>
|
2014-05-22 01:28:13 +02:00
|
|
|
#include <cutils/properties.h>
|
2013-08-15 02:39:13 +02:00
|
|
|
#include <utils/Errors.h>
|
2013-06-12 22:25:59 +02:00
|
|
|
#include <utils/String8.h>
|
|
|
|
#include <utils/Vector.h>
|
|
|
|
|
|
|
|
#define POWER_SUPPLY_SUBSYSTEM "power_supply"
|
|
|
|
#define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM
|
2014-07-11 00:06:21 +02:00
|
|
|
#define FAKE_BATTERY_CAPACITY 42
|
|
|
|
#define FAKE_BATTERY_TEMPERATURE 424
|
2016-02-26 01:19:30 +01:00
|
|
|
#define MILLION 1.0e6
|
2015-10-27 18:43:53 +01:00
|
|
|
#define DEFAULT_VBUS_VOLTAGE 5000000
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
using HealthInfo_1_0 = android::hardware::health::V1_0::HealthInfo;
|
|
|
|
using HealthInfo_2_0 = android::hardware::health::V2_0::HealthInfo;
|
|
|
|
using HealthInfo_2_1 = android::hardware::health::V2_1::HealthInfo;
|
2022-03-01 21:12:34 +01:00
|
|
|
using aidl::android::hardware::health::BatteryCapacityLevel;
|
2022-11-24 05:19:41 +01:00
|
|
|
using aidl::android::hardware::health::BatteryChargingPolicy;
|
|
|
|
using aidl::android::hardware::health::BatteryChargingState;
|
2022-03-01 21:12:34 +01:00
|
|
|
using aidl::android::hardware::health::BatteryHealth;
|
2022-11-24 05:19:41 +01:00
|
|
|
using aidl::android::hardware::health::BatteryHealthData;
|
2023-12-09 00:12:24 +01:00
|
|
|
using aidl::android::hardware::health::BatteryPartStatus;
|
2022-03-01 21:12:34 +01:00
|
|
|
using aidl::android::hardware::health::BatteryStatus;
|
|
|
|
using aidl::android::hardware::health::HealthInfo;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Translate from AIDL back to HIDL definition for getHealthInfo_*_* calls.
|
|
|
|
// Skips storageInfo and diskStats.
|
|
|
|
void translateToHidl(const ::aidl::android::hardware::health::HealthInfo& in,
|
|
|
|
::android::hardware::health::V1_0::HealthInfo* out) {
|
|
|
|
out->chargerAcOnline = in.chargerAcOnline;
|
|
|
|
out->chargerUsbOnline = in.chargerUsbOnline;
|
|
|
|
out->chargerWirelessOnline = in.chargerWirelessOnline;
|
|
|
|
out->maxChargingCurrent = in.maxChargingCurrentMicroamps;
|
|
|
|
out->maxChargingVoltage = in.maxChargingVoltageMicrovolts;
|
|
|
|
out->batteryStatus =
|
|
|
|
static_cast<::android::hardware::health::V1_0::BatteryStatus>(in.batteryStatus);
|
|
|
|
out->batteryHealth =
|
|
|
|
static_cast<::android::hardware::health::V1_0::BatteryHealth>(in.batteryHealth);
|
|
|
|
out->batteryPresent = in.batteryPresent;
|
|
|
|
out->batteryLevel = in.batteryLevel;
|
|
|
|
out->batteryVoltage = in.batteryVoltageMillivolts;
|
|
|
|
out->batteryTemperature = in.batteryTemperatureTenthsCelsius;
|
|
|
|
out->batteryCurrent = in.batteryCurrentMicroamps;
|
|
|
|
out->batteryCycleCount = in.batteryCycleCount;
|
|
|
|
out->batteryFullCharge = in.batteryFullChargeUah;
|
|
|
|
out->batteryChargeCounter = in.batteryChargeCounterUah;
|
|
|
|
out->batteryTechnology = in.batteryTechnology;
|
|
|
|
}
|
|
|
|
|
|
|
|
void translateToHidl(const ::aidl::android::hardware::health::HealthInfo& in,
|
|
|
|
::android::hardware::health::V2_0::HealthInfo* out) {
|
|
|
|
translateToHidl(in, &out->legacy);
|
|
|
|
out->batteryCurrentAverage = in.batteryCurrentAverageMicroamps;
|
|
|
|
// Skip storageInfo and diskStats
|
|
|
|
}
|
|
|
|
|
|
|
|
void translateToHidl(const ::aidl::android::hardware::health::HealthInfo& in,
|
|
|
|
::android::hardware::health::V2_1::HealthInfo* out) {
|
|
|
|
translateToHidl(in, &out->legacy);
|
|
|
|
out->batteryCapacityLevel = static_cast<android::hardware::health::V2_1::BatteryCapacityLevel>(
|
|
|
|
in.batteryCapacityLevel);
|
|
|
|
out->batteryChargeTimeToFullNowSeconds = in.batteryChargeTimeToFullNowSeconds;
|
|
|
|
out->batteryFullChargeDesignCapacityUah = in.batteryFullChargeDesignCapacityUah;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2019-10-07 20:18:04 +02:00
|
|
|
|
2013-06-12 22:25:59 +02:00
|
|
|
namespace android {
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
template <typename T>
|
|
|
|
struct SysfsStringEnumMap {
|
2014-05-16 00:00:59 +02:00
|
|
|
const char* s;
|
2019-10-07 20:18:04 +02:00
|
|
|
T val;
|
2013-06-12 22:25:59 +02:00
|
|
|
};
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
template <typename T>
|
|
|
|
static std::optional<T> mapSysfsString(const char* str, SysfsStringEnumMap<T> map[]) {
|
2013-06-12 22:25:59 +02:00
|
|
|
for (int i = 0; map[i].s; i++)
|
|
|
|
if (!strcmp(str, map[i].s))
|
|
|
|
return map[i].val;
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
return std::nullopt;
|
2016-02-17 02:19:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
static void initHealthInfo(HealthInfo* health_info) {
|
2022-02-24 22:22:07 +01:00
|
|
|
*health_info = {
|
|
|
|
.batteryCapacityLevel = BatteryCapacityLevel::UNSUPPORTED,
|
|
|
|
.batteryChargeTimeToFullNowSeconds =
|
|
|
|
(int64_t)HealthInfo::BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED,
|
|
|
|
.batteryStatus = BatteryStatus::UNKNOWN,
|
|
|
|
.batteryHealth = BatteryHealth::UNKNOWN,
|
|
|
|
};
|
2019-11-06 02:04:50 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 23:03:59 +01:00
|
|
|
BatteryMonitor::BatteryMonitor()
|
|
|
|
: mHealthdConfig(nullptr),
|
|
|
|
mBatteryDevicePresent(false),
|
|
|
|
mBatteryFixedCapacity(0),
|
2019-10-07 20:18:04 +02:00
|
|
|
mBatteryFixedTemperature(0),
|
2023-02-04 12:56:06 +01:00
|
|
|
mBatteryHealthStatus(BatteryMonitor::BH_UNKNOWN),
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo(std::make_unique<HealthInfo>()) {
|
2019-11-06 02:04:50 +01:00
|
|
|
initHealthInfo(mHealthInfo.get());
|
|
|
|
}
|
2019-10-07 20:18:04 +02:00
|
|
|
|
|
|
|
BatteryMonitor::~BatteryMonitor() {}
|
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
HealthInfo_1_0 BatteryMonitor::getHealthInfo_1_0() const {
|
|
|
|
HealthInfo_1_0 health_info_1_0;
|
|
|
|
translateToHidl(*mHealthInfo, &health_info_1_0);
|
|
|
|
return health_info_1_0;
|
2019-10-07 20:18:04 +02:00
|
|
|
}
|
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
HealthInfo_2_0 BatteryMonitor::getHealthInfo_2_0() const {
|
|
|
|
HealthInfo_2_0 health_info_2_0;
|
|
|
|
translateToHidl(*mHealthInfo, &health_info_2_0);
|
|
|
|
return health_info_2_0;
|
2016-02-17 02:19:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
HealthInfo_2_1 BatteryMonitor::getHealthInfo_2_1() const {
|
|
|
|
HealthInfo_2_1 health_info_2_1;
|
|
|
|
translateToHidl(*mHealthInfo, &health_info_2_1);
|
|
|
|
return health_info_2_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const HealthInfo& BatteryMonitor::getHealthInfo() const {
|
2019-10-07 20:18:04 +02:00
|
|
|
return *mHealthInfo;
|
2018-01-13 02:44:33 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
BatteryStatus getBatteryStatus(const char* status) {
|
|
|
|
static SysfsStringEnumMap<BatteryStatus> batteryStatusMap[] = {
|
|
|
|
{"Unknown", BatteryStatus::UNKNOWN},
|
|
|
|
{"Charging", BatteryStatus::CHARGING},
|
|
|
|
{"Discharging", BatteryStatus::DISCHARGING},
|
|
|
|
{"Not charging", BatteryStatus::NOT_CHARGING},
|
|
|
|
{"Full", BatteryStatus::FULL},
|
|
|
|
{NULL, BatteryStatus::UNKNOWN},
|
2013-06-12 22:25:59 +02:00
|
|
|
};
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
auto ret = mapSysfsString(status, batteryStatusMap);
|
|
|
|
if (!ret) {
|
2013-06-12 22:25:59 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "Unknown battery status '%s'\n", status);
|
2019-10-07 20:18:04 +02:00
|
|
|
*ret = BatteryStatus::UNKNOWN;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
return *ret;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2019-12-20 00:09:41 +01:00
|
|
|
BatteryCapacityLevel getBatteryCapacityLevel(const char* capacityLevel) {
|
|
|
|
static SysfsStringEnumMap<BatteryCapacityLevel> batteryCapacityLevelMap[] = {
|
|
|
|
{"Unknown", BatteryCapacityLevel::UNKNOWN},
|
|
|
|
{"Critical", BatteryCapacityLevel::CRITICAL},
|
|
|
|
{"Low", BatteryCapacityLevel::LOW},
|
|
|
|
{"Normal", BatteryCapacityLevel::NORMAL},
|
|
|
|
{"High", BatteryCapacityLevel::HIGH},
|
|
|
|
{"Full", BatteryCapacityLevel::FULL},
|
2020-02-13 02:00:24 +01:00
|
|
|
{NULL, BatteryCapacityLevel::UNSUPPORTED},
|
2019-12-20 00:09:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
auto ret = mapSysfsString(capacityLevel, batteryCapacityLevelMap);
|
|
|
|
if (!ret) {
|
2020-02-13 02:00:24 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "Unsupported battery capacity level '%s'\n", capacityLevel);
|
|
|
|
*ret = BatteryCapacityLevel::UNSUPPORTED;
|
2019-12-20 00:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
BatteryHealth getBatteryHealth(const char* status) {
|
|
|
|
static SysfsStringEnumMap<BatteryHealth> batteryHealthMap[] = {
|
|
|
|
{"Unknown", BatteryHealth::UNKNOWN},
|
|
|
|
{"Good", BatteryHealth::GOOD},
|
|
|
|
{"Overheat", BatteryHealth::OVERHEAT},
|
|
|
|
{"Dead", BatteryHealth::DEAD},
|
|
|
|
{"Over voltage", BatteryHealth::OVER_VOLTAGE},
|
|
|
|
{"Unspecified failure", BatteryHealth::UNSPECIFIED_FAILURE},
|
|
|
|
{"Cold", BatteryHealth::COLD},
|
|
|
|
// battery health values from JEITA spec
|
|
|
|
{"Warm", BatteryHealth::GOOD},
|
|
|
|
{"Cool", BatteryHealth::GOOD},
|
|
|
|
{"Hot", BatteryHealth::OVERHEAT},
|
2023-12-12 00:25:13 +01:00
|
|
|
{"Calibration required", BatteryHealth::INCONSISTENT},
|
2019-10-07 20:18:04 +02:00
|
|
|
{NULL, BatteryHealth::UNKNOWN},
|
2013-06-12 22:25:59 +02:00
|
|
|
};
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
auto ret = mapSysfsString(status, batteryHealthMap);
|
|
|
|
if (!ret) {
|
2013-06-12 22:25:59 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "Unknown battery health '%s'\n", status);
|
2019-10-07 20:18:04 +02:00
|
|
|
*ret = BatteryHealth::UNKNOWN;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
return *ret;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2023-02-04 12:56:06 +01:00
|
|
|
BatteryHealth getBatteryHealthStatus(int status) {
|
|
|
|
BatteryHealth value;
|
|
|
|
|
|
|
|
if (status == BatteryMonitor::BH_NOMINAL)
|
|
|
|
value = BatteryHealth::GOOD;
|
|
|
|
else if (status == BatteryMonitor::BH_MARGINAL)
|
|
|
|
value = BatteryHealth::FAIR;
|
|
|
|
else if (status == BatteryMonitor::BH_NEEDS_REPLACEMENT)
|
|
|
|
value = BatteryHealth::DEAD;
|
|
|
|
else if (status == BatteryMonitor::BH_FAILED)
|
|
|
|
value = BatteryHealth::UNSPECIFIED_FAILURE;
|
2023-04-13 13:37:46 +02:00
|
|
|
else if (status == BatteryMonitor::BH_NOT_AVAILABLE)
|
|
|
|
value = BatteryHealth::NOT_AVAILABLE;
|
2023-05-19 08:31:53 +02:00
|
|
|
else if (status == BatteryMonitor::BH_INCONSISTENT)
|
|
|
|
value = BatteryHealth::INCONSISTENT;
|
2023-02-04 12:56:06 +01:00
|
|
|
else
|
|
|
|
value = BatteryHealth::UNKNOWN;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2022-11-24 05:19:41 +01:00
|
|
|
BatteryChargingPolicy getBatteryChargingPolicy(const char* chargingPolicy) {
|
|
|
|
static SysfsStringEnumMap<BatteryChargingPolicy> batteryChargingPolicyMap[] = {
|
|
|
|
{"0", BatteryChargingPolicy::INVALID}, {"1", BatteryChargingPolicy::DEFAULT},
|
|
|
|
{"2", BatteryChargingPolicy::LONG_LIFE}, {"3", BatteryChargingPolicy::ADAPTIVE},
|
|
|
|
{NULL, BatteryChargingPolicy::DEFAULT},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto ret = mapSysfsString(chargingPolicy, batteryChargingPolicyMap);
|
|
|
|
if (!ret) {
|
|
|
|
*ret = BatteryChargingPolicy::DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BatteryChargingState getBatteryChargingState(const char* chargingState) {
|
|
|
|
static SysfsStringEnumMap<BatteryChargingState> batteryChargingStateMap[] = {
|
|
|
|
{"0", BatteryChargingState::INVALID}, {"1", BatteryChargingState::NORMAL},
|
|
|
|
{"2", BatteryChargingState::TOO_COLD}, {"3", BatteryChargingState::TOO_HOT},
|
|
|
|
{"4", BatteryChargingState::LONG_LIFE}, {"5", BatteryChargingState::ADAPTIVE},
|
|
|
|
{NULL, BatteryChargingState::NORMAL},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto ret = mapSysfsString(chargingState, batteryChargingStateMap);
|
|
|
|
if (!ret) {
|
|
|
|
*ret = BatteryChargingState::NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
static int readFromFile(const String8& path, std::string* buf) {
|
2022-02-24 22:40:15 +01:00
|
|
|
buf->clear();
|
2017-03-11 07:31:08 +01:00
|
|
|
if (android::base::ReadFileToString(path.c_str(), buf)) {
|
2016-06-05 20:20:13 +02:00
|
|
|
*buf = android::base::Trim(*buf);
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
2016-06-05 20:20:13 +02:00
|
|
|
return buf->length();
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-24 05:19:41 +01:00
|
|
|
static bool writeToFile(const String8& path, int32_t in_value) {
|
|
|
|
return android::base::WriteStringToFile(std::to_string(in_value), path.c_str());
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
static BatteryMonitor::PowerSupplyType readPowerSupplyType(const String8& path) {
|
2019-10-07 20:18:04 +02:00
|
|
|
static SysfsStringEnumMap<int> supplyTypeMap[] = {
|
2022-03-02 18:36:34 +01:00
|
|
|
{"Unknown", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_UNKNOWN},
|
|
|
|
{"Battery", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_BATTERY},
|
|
|
|
{"UPS", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"Mains", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_USB},
|
|
|
|
{"USB_DCP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB_HVDCP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB_CDP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB_ACA", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB_C", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB_PD", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
|
|
|
|
{"USB_PD_DRP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_USB},
|
|
|
|
{"Wireless", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_WIRELESS},
|
|
|
|
{"Dock", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_DOCK},
|
2019-10-07 20:18:04 +02:00
|
|
|
{NULL, 0},
|
2013-06-12 22:25:59 +02:00
|
|
|
};
|
2019-10-07 20:18:04 +02:00
|
|
|
std::string buf;
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
if (readFromFile(path, &buf) <= 0) {
|
|
|
|
return BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_UNKNOWN;
|
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
auto ret = mapSysfsString(buf.c_str(), supplyTypeMap);
|
2019-11-06 01:23:34 +01:00
|
|
|
if (!ret) {
|
2016-06-05 20:20:13 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "Unknown power supply type '%s'\n", buf.c_str());
|
2022-03-02 18:36:34 +01:00
|
|
|
*ret = BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_UNKNOWN;
|
2016-02-03 13:45:54 +01:00
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2019-10-07 20:18:04 +02:00
|
|
|
return static_cast<BatteryMonitor::PowerSupplyType>(*ret);
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
static bool getBooleanField(const String8& path) {
|
2016-06-05 20:20:13 +02:00
|
|
|
std::string buf;
|
2013-06-12 22:25:59 +02:00
|
|
|
bool value = false;
|
2016-06-05 20:20:13 +02:00
|
|
|
|
|
|
|
if (readFromFile(path, &buf) > 0)
|
|
|
|
if (buf[0] != '0')
|
2013-06-12 22:25:59 +02:00
|
|
|
value = true;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
static int getIntField(const String8& path) {
|
2016-06-05 20:20:13 +02:00
|
|
|
std::string buf;
|
2013-06-12 22:25:59 +02:00
|
|
|
int value = 0;
|
2016-06-05 20:20:13 +02:00
|
|
|
|
|
|
|
if (readFromFile(path, &buf) > 0)
|
2016-10-12 02:09:00 +02:00
|
|
|
android::base::ParseInt(buf, &value);
|
2016-06-05 20:20:13 +02:00
|
|
|
|
2013-06-12 22:25:59 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
static bool isScopedPowerSupply(const char* name) {
|
2019-06-12 06:46:08 +02:00
|
|
|
constexpr char kScopeDevice[] = "Device";
|
|
|
|
|
|
|
|
String8 path;
|
|
|
|
path.appendFormat("%s/%s/scope", POWER_SUPPLY_SYSFS_PATH, name);
|
|
|
|
std::string scope;
|
|
|
|
return (readFromFile(path, &scope) > 0 && scope == kScopeDevice);
|
|
|
|
}
|
|
|
|
|
2019-10-07 19:41:30 +02:00
|
|
|
void BatteryMonitor::updateValues(void) {
|
2019-11-06 02:04:50 +01:00
|
|
|
initHealthInfo(mHealthInfo.get());
|
2019-10-07 20:18:04 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryPresentPath.empty())
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath);
|
2013-06-12 22:25:59 +02:00
|
|
|
else
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryPresent = mBatteryDevicePresent;
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryLevel = mBatteryFixedCapacity
|
|
|
|
? mBatteryFixedCapacity
|
|
|
|
: getIntField(mHealthdConfig->batteryCapacityPath);
|
|
|
|
mHealthInfo->batteryVoltageMillivolts = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
|
2013-07-31 03:57:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentNowPath.empty())
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryCurrentMicroamps = getIntField(mHealthdConfig->batteryCurrentNowPath);
|
2015-08-24 22:01:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryFullChargePath.empty())
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryFullChargeUah = getIntField(mHealthdConfig->batteryFullChargePath);
|
2015-08-24 22:01:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCycleCountPath.empty())
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath);
|
2015-08-24 22:01:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryChargeCounterPath.empty())
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryChargeCounterUah =
|
|
|
|
getIntField(mHealthdConfig->batteryChargeCounterPath);
|
2016-04-07 21:34:40 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentAvgPath.empty())
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryCurrentAverageMicroamps =
|
2019-10-07 22:58:29 +02:00
|
|
|
getIntField(mHealthdConfig->batteryCurrentAvgPath);
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryChargeTimeToFullNowPath.empty())
|
2019-12-20 00:09:41 +01:00
|
|
|
mHealthInfo->batteryChargeTimeToFullNowSeconds =
|
|
|
|
getIntField(mHealthdConfig->batteryChargeTimeToFullNowPath);
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryFullChargeDesignCapacityUahPath.empty())
|
2020-02-11 03:23:57 +01:00
|
|
|
mHealthInfo->batteryFullChargeDesignCapacityUah =
|
|
|
|
getIntField(mHealthdConfig->batteryFullChargeDesignCapacityUahPath);
|
2019-10-07 22:58:29 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryHealthStatusPath.empty())
|
2023-02-04 12:56:06 +01:00
|
|
|
mBatteryHealthStatus = getIntField(mHealthdConfig->batteryHealthStatusPath);
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryStateOfHealthPath.empty())
|
2023-02-17 02:39:21 +01:00
|
|
|
mHealthInfo->batteryHealthData->batteryStateOfHealth =
|
|
|
|
getIntField(mHealthdConfig->batteryStateOfHealthPath);
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryManufacturingDatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
mHealthInfo->batteryHealthData->batteryManufacturingDateSeconds =
|
|
|
|
getIntField(mHealthdConfig->batteryManufacturingDatePath);
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryFirstUsageDatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
mHealthInfo->batteryHealthData->batteryFirstUsageSeconds =
|
|
|
|
getIntField(mHealthdConfig->batteryFirstUsageDatePath);
|
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryTemperatureTenthsCelsius =
|
|
|
|
mBatteryFixedTemperature ? mBatteryFixedTemperature
|
|
|
|
: getIntField(mHealthdConfig->batteryTemperaturePath);
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2016-06-05 20:20:13 +02:00
|
|
|
std::string buf;
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2019-12-20 00:09:41 +01:00
|
|
|
if (readFromFile(mHealthdConfig->batteryCapacityLevelPath, &buf) > 0)
|
|
|
|
mHealthInfo->batteryCapacityLevel = getBatteryCapacityLevel(buf.c_str());
|
|
|
|
|
2016-06-05 20:20:13 +02:00
|
|
|
if (readFromFile(mHealthdConfig->batteryStatusPath, &buf) > 0)
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->batteryStatus = getBatteryStatus(buf.c_str());
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2023-02-04 12:56:06 +01:00
|
|
|
// Backward compatible with android.hardware.health V1
|
|
|
|
if (mBatteryHealthStatus < BatteryMonitor::BH_MARGINAL) {
|
|
|
|
if (readFromFile(mHealthdConfig->batteryHealthPath, &buf) > 0)
|
|
|
|
mHealthInfo->batteryHealth = getBatteryHealth(buf.c_str());
|
|
|
|
} else {
|
|
|
|
mHealthInfo->batteryHealth = getBatteryHealthStatus(mBatteryHealthStatus);
|
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2016-06-05 20:20:13 +02:00
|
|
|
if (readFromFile(mHealthdConfig->batteryTechnologyPath, &buf) > 0)
|
2023-09-12 17:26:15 +02:00
|
|
|
mHealthInfo->batteryTechnology = buf;
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2022-11-24 05:19:41 +01:00
|
|
|
if (readFromFile(mHealthdConfig->chargingPolicyPath, &buf) > 0)
|
|
|
|
mHealthInfo->chargingPolicy = getBatteryChargingPolicy(buf.c_str());
|
|
|
|
|
|
|
|
if (readFromFile(mHealthdConfig->chargingStatePath, &buf) > 0)
|
|
|
|
mHealthInfo->chargingState = getBatteryChargingState(buf.c_str());
|
|
|
|
|
2015-10-27 18:43:53 +01:00
|
|
|
double MaxPower = 0;
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2018-07-26 10:47:47 +02:00
|
|
|
for (size_t i = 0; i < mChargerNames.size(); i++) {
|
2013-06-12 22:25:59 +02:00
|
|
|
String8 path;
|
2023-08-11 01:29:50 +02:00
|
|
|
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
|
2016-06-05 20:20:13 +02:00
|
|
|
if (getIntField(path)) {
|
|
|
|
path.clear();
|
2023-08-11 01:29:50 +02:00
|
|
|
path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
|
2016-06-05 20:20:13 +02:00
|
|
|
switch(readPowerSupplyType(path)) {
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_AC:
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->chargerAcOnline = true;
|
2016-06-05 20:20:13 +02:00
|
|
|
break;
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_USB:
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->chargerUsbOnline = true;
|
2016-06-05 20:20:13 +02:00
|
|
|
break;
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->chargerWirelessOnline = true;
|
2016-06-05 20:20:13 +02:00
|
|
|
break;
|
2021-12-15 13:40:21 +01:00
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_DOCK:
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->chargerDockOnline = true;
|
2021-12-15 13:40:21 +01:00
|
|
|
break;
|
2016-06-05 20:20:13 +02:00
|
|
|
default:
|
2021-12-15 13:40:21 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH,
|
2023-08-11 01:29:50 +02:00
|
|
|
mChargerNames[i].c_str());
|
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->chargerDockOnline = true;
|
|
|
|
else
|
2021-12-15 13:40:21 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
|
2023-08-11 01:29:50 +02:00
|
|
|
mChargerNames[i].c_str());
|
2016-06-05 20:20:13 +02:00
|
|
|
}
|
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
|
2023-08-11 01:29:50 +02:00
|
|
|
mChargerNames[i].c_str());
|
|
|
|
int ChargingCurrent = (access(path.c_str(), R_OK) == 0) ? getIntField(path) : 0;
|
2015-10-27 18:43:53 +01:00
|
|
|
|
2016-06-20 21:58:37 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH,
|
2023-08-11 01:29:50 +02:00
|
|
|
mChargerNames[i].c_str());
|
2016-06-20 21:58:37 +02:00
|
|
|
|
|
|
|
int ChargingVoltage =
|
2023-08-11 01:29:50 +02:00
|
|
|
(access(path.c_str(), R_OK) == 0) ? getIntField(path) : DEFAULT_VBUS_VOLTAGE;
|
2016-06-20 21:58:37 +02:00
|
|
|
|
|
|
|
double power = ((double)ChargingCurrent / MILLION) *
|
|
|
|
((double)ChargingVoltage / MILLION);
|
|
|
|
if (MaxPower < power) {
|
2022-03-01 21:12:34 +01:00
|
|
|
mHealthInfo->maxChargingCurrentMicroamps = ChargingCurrent;
|
|
|
|
mHealthInfo->maxChargingVoltageMicrovolts = ChargingVoltage;
|
2016-06-20 21:58:37 +02:00
|
|
|
MaxPower = power;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-07 19:41:30 +02:00
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
static void doLogValues(const HealthInfo& props, const struct healthd_config& healthd_config) {
|
2019-10-07 19:41:30 +02:00
|
|
|
char dmesgline[256];
|
|
|
|
size_t len;
|
|
|
|
if (props.batteryPresent) {
|
|
|
|
snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
|
2022-03-01 21:12:34 +01:00
|
|
|
props.batteryLevel, props.batteryVoltageMillivolts,
|
|
|
|
props.batteryTemperatureTenthsCelsius < 0 ? "-" : "",
|
|
|
|
abs(props.batteryTemperatureTenthsCelsius / 10),
|
|
|
|
abs(props.batteryTemperatureTenthsCelsius % 10), props.batteryHealth,
|
|
|
|
props.batteryStatus);
|
2015-08-24 22:01:16 +02:00
|
|
|
|
2019-10-07 19:41:30 +02:00
|
|
|
len = strlen(dmesgline);
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!healthd_config.batteryCurrentNowPath.empty()) {
|
2019-10-07 19:41:30 +02:00
|
|
|
len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " c=%d",
|
2022-03-01 21:12:34 +01:00
|
|
|
props.batteryCurrentMicroamps);
|
2013-08-08 00:25:14 +02:00
|
|
|
}
|
2013-07-31 03:57:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!healthd_config.batteryFullChargePath.empty()) {
|
2019-10-07 19:41:30 +02:00
|
|
|
len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " fc=%d",
|
2022-03-01 21:12:34 +01:00
|
|
|
props.batteryFullChargeUah);
|
2019-10-07 19:41:30 +02:00
|
|
|
}
|
2015-07-23 18:22:50 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!healthd_config.batteryCycleCountPath.empty()) {
|
2019-10-07 19:41:30 +02:00
|
|
|
len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " cc=%d",
|
|
|
|
props.batteryCycleCount);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
len = snprintf(dmesgline, sizeof(dmesgline), "battery none");
|
2013-08-08 00:25:14 +02:00
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2022-03-01 21:12:34 +01:00
|
|
|
snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s%s",
|
2019-10-07 19:41:30 +02:00
|
|
|
props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "",
|
2022-03-01 21:12:34 +01:00
|
|
|
props.chargerWirelessOnline ? "w" : "", props.chargerDockOnline ? "d" : "");
|
2019-10-07 19:41:30 +02:00
|
|
|
|
|
|
|
KLOG_WARNING(LOG_TAG, "%s\n", dmesgline);
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:36:34 +01:00
|
|
|
void BatteryMonitor::logValues(const HealthInfo_2_1& health_info,
|
|
|
|
const struct healthd_config& healthd_config) {
|
|
|
|
HealthInfo aidl_health_info;
|
|
|
|
(void)android::h2a::translate(health_info, &aidl_health_info);
|
|
|
|
doLogValues(aidl_health_info, healthd_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BatteryMonitor::logValues(void) {
|
|
|
|
doLogValues(*mHealthInfo, *mHealthdConfig);
|
|
|
|
}
|
|
|
|
|
2019-10-07 19:41:30 +02:00
|
|
|
bool BatteryMonitor::isChargerOnline() {
|
2022-03-01 21:12:34 +01:00
|
|
|
const HealthInfo& props = *mHealthInfo;
|
2021-12-15 13:40:21 +01:00
|
|
|
return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline |
|
2022-03-01 21:12:34 +01:00
|
|
|
props.chargerDockOnline;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 03:03:23 +01:00
|
|
|
int BatteryMonitor::getChargeStatus() {
|
2019-10-07 20:18:04 +02:00
|
|
|
BatteryStatus result = BatteryStatus::UNKNOWN;
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryStatusPath.empty()) {
|
2016-06-05 20:20:13 +02:00
|
|
|
std::string buf;
|
|
|
|
if (readFromFile(mHealthdConfig->batteryStatusPath, &buf) > 0)
|
|
|
|
result = getBatteryStatus(buf.c_str());
|
2016-02-20 03:03:23 +01:00
|
|
|
}
|
2019-10-07 20:18:04 +02:00
|
|
|
return static_cast<int>(result);
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-24 05:19:41 +01:00
|
|
|
status_t BatteryMonitor::setChargingPolicy(int value) {
|
|
|
|
status_t ret = NAME_NOT_FOUND;
|
|
|
|
bool result;
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->chargingPolicyPath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
result = writeToFile(mHealthdConfig->chargingPolicyPath, value);
|
|
|
|
if (!result) {
|
|
|
|
KLOG_WARNING(LOG_TAG, "setChargingPolicy fail\n");
|
|
|
|
ret = BAD_VALUE;
|
|
|
|
} else {
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BatteryMonitor::getChargingPolicy() {
|
|
|
|
BatteryChargingPolicy result = BatteryChargingPolicy::DEFAULT;
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->chargingPolicyPath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
std::string buf;
|
|
|
|
if (readFromFile(mHealthdConfig->chargingPolicyPath, &buf) > 0)
|
|
|
|
result = getBatteryChargingPolicy(buf.c_str());
|
|
|
|
}
|
|
|
|
return static_cast<int>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int BatteryMonitor::getBatteryHealthData(int id) {
|
|
|
|
if (id == BATTERY_PROP_MANUFACTURING_DATE) {
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryManufacturingDatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
return getIntField(mHealthdConfig->batteryManufacturingDatePath);
|
|
|
|
}
|
|
|
|
if (id == BATTERY_PROP_FIRST_USAGE_DATE) {
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryFirstUsageDatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
return getIntField(mHealthdConfig->batteryFirstUsageDatePath);
|
|
|
|
}
|
2023-02-17 02:39:21 +01:00
|
|
|
if (id == BATTERY_PROP_STATE_OF_HEALTH) {
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryStateOfHealthPath.empty())
|
2023-02-17 02:39:21 +01:00
|
|
|
return getIntField(mHealthdConfig->batteryStateOfHealthPath);
|
|
|
|
}
|
2023-12-09 00:12:24 +01:00
|
|
|
if (id == BATTERY_PROP_PART_STATUS) {
|
|
|
|
return static_cast<int>(BatteryPartStatus::UNSUPPORTED);
|
|
|
|
}
|
2022-11-24 05:19:41 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-15 02:39:13 +02:00
|
|
|
status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) {
|
|
|
|
status_t ret = BAD_VALUE;
|
2017-02-03 02:31:13 +01:00
|
|
|
std::string buf;
|
2013-08-15 02:39:13 +02:00
|
|
|
|
2014-05-09 02:15:45 +02:00
|
|
|
val->valueInt64 = LONG_MIN;
|
|
|
|
|
2013-08-15 02:39:13 +02:00
|
|
|
switch(id) {
|
|
|
|
case BATTERY_PROP_CHARGE_COUNTER:
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryChargeCounterPath.empty()) {
|
2014-05-09 02:15:45 +02:00
|
|
|
val->valueInt64 =
|
2013-08-15 02:39:13 +02:00
|
|
|
getIntField(mHealthdConfig->batteryChargeCounterPath);
|
2018-10-08 20:10:11 +02:00
|
|
|
ret = OK;
|
2013-08-15 02:39:13 +02:00
|
|
|
} else {
|
|
|
|
ret = NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BATTERY_PROP_CURRENT_NOW:
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentNowPath.empty()) {
|
2014-05-09 02:15:45 +02:00
|
|
|
val->valueInt64 =
|
2013-08-15 02:39:13 +02:00
|
|
|
getIntField(mHealthdConfig->batteryCurrentNowPath);
|
2018-10-08 20:10:11 +02:00
|
|
|
ret = OK;
|
2013-08-15 02:39:13 +02:00
|
|
|
} else {
|
|
|
|
ret = NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-08-28 03:11:49 +02:00
|
|
|
case BATTERY_PROP_CURRENT_AVG:
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentAvgPath.empty()) {
|
2014-05-09 02:15:45 +02:00
|
|
|
val->valueInt64 =
|
2013-08-28 03:11:49 +02:00
|
|
|
getIntField(mHealthdConfig->batteryCurrentAvgPath);
|
2018-10-08 20:10:11 +02:00
|
|
|
ret = OK;
|
2013-08-28 03:11:49 +02:00
|
|
|
} else {
|
|
|
|
ret = NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-03-19 23:04:40 +01:00
|
|
|
case BATTERY_PROP_CAPACITY:
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCapacityPath.empty()) {
|
2014-05-09 02:15:45 +02:00
|
|
|
val->valueInt64 =
|
2014-03-19 23:04:40 +01:00
|
|
|
getIntField(mHealthdConfig->batteryCapacityPath);
|
2018-10-08 20:10:11 +02:00
|
|
|
ret = OK;
|
2014-03-19 23:04:40 +01:00
|
|
|
} else {
|
|
|
|
ret = NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-09 02:15:45 +02:00
|
|
|
case BATTERY_PROP_ENERGY_COUNTER:
|
2014-05-20 22:54:40 +02:00
|
|
|
if (mHealthdConfig->energyCounter) {
|
|
|
|
ret = mHealthdConfig->energyCounter(&val->valueInt64);
|
|
|
|
} else {
|
|
|
|
ret = NAME_NOT_FOUND;
|
|
|
|
}
|
2014-05-09 02:15:45 +02:00
|
|
|
break;
|
|
|
|
|
2017-02-03 02:31:13 +01:00
|
|
|
case BATTERY_PROP_BATTERY_STATUS:
|
2018-01-19 23:03:59 +01:00
|
|
|
val->valueInt64 = getChargeStatus();
|
2018-10-08 20:10:11 +02:00
|
|
|
ret = OK;
|
2017-02-03 02:31:13 +01:00
|
|
|
break;
|
|
|
|
|
2022-11-24 05:19:41 +01:00
|
|
|
case BATTERY_PROP_CHARGING_POLICY:
|
|
|
|
val->valueInt64 = getChargingPolicy();
|
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BATTERY_PROP_MANUFACTURING_DATE:
|
|
|
|
val->valueInt64 = getBatteryHealthData(BATTERY_PROP_MANUFACTURING_DATE);
|
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BATTERY_PROP_FIRST_USAGE_DATE:
|
|
|
|
val->valueInt64 = getBatteryHealthData(BATTERY_PROP_FIRST_USAGE_DATE);
|
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
|
2023-02-17 02:39:21 +01:00
|
|
|
case BATTERY_PROP_STATE_OF_HEALTH:
|
|
|
|
val->valueInt64 = getBatteryHealthData(BATTERY_PROP_STATE_OF_HEALTH);
|
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
|
2023-12-09 00:12:24 +01:00
|
|
|
case BATTERY_PROP_PART_STATUS:
|
|
|
|
val->valueInt64 = getBatteryHealthData(BATTERY_PROP_PART_STATUS);
|
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
|
2013-08-15 02:39:13 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-09 00:12:24 +01:00
|
|
|
status_t BatteryMonitor::getSerialNumber(std::optional<std::string>* out) {
|
|
|
|
*out = std::nullopt;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-09-19 05:09:33 +02:00
|
|
|
void BatteryMonitor::dumpState(int fd) {
|
|
|
|
int v;
|
|
|
|
char vs[128];
|
2022-03-01 21:12:34 +01:00
|
|
|
const HealthInfo& props = *mHealthInfo;
|
2013-09-19 05:09:33 +02:00
|
|
|
|
2021-12-15 13:40:21 +01:00
|
|
|
snprintf(vs, sizeof(vs),
|
|
|
|
"ac: %d usb: %d wireless: %d dock: %d current_max: %d voltage_max: %d\n",
|
|
|
|
props.chargerAcOnline, props.chargerUsbOnline, props.chargerWirelessOnline,
|
2022-03-01 21:12:34 +01:00
|
|
|
props.chargerDockOnline, props.maxChargingCurrentMicroamps,
|
|
|
|
props.maxChargingVoltageMicrovolts);
|
2013-09-19 05:09:33 +02:00
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
|
|
|
|
props.batteryStatus, props.batteryHealth, props.batteryPresent);
|
|
|
|
write(fd, vs, strlen(vs));
|
2022-03-01 21:12:34 +01:00
|
|
|
snprintf(vs, sizeof(vs), "level: %d voltage: %d temp: %d\n", props.batteryLevel,
|
|
|
|
props.batteryVoltageMillivolts, props.batteryTemperatureTenthsCelsius);
|
2013-09-19 05:09:33 +02:00
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentNowPath.empty()) {
|
2013-09-19 05:09:33 +02:00
|
|
|
v = getIntField(mHealthdConfig->batteryCurrentNowPath);
|
|
|
|
snprintf(vs, sizeof(vs), "current now: %d\n", v);
|
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentAvgPath.empty()) {
|
2013-09-19 05:09:33 +02:00
|
|
|
v = getIntField(mHealthdConfig->batteryCurrentAvgPath);
|
|
|
|
snprintf(vs, sizeof(vs), "current avg: %d\n", v);
|
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryChargeCounterPath.empty()) {
|
2013-09-19 05:09:33 +02:00
|
|
|
v = getIntField(mHealthdConfig->batteryChargeCounterPath);
|
|
|
|
snprintf(vs, sizeof(vs), "charge counter: %d\n", v);
|
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
}
|
2015-08-24 22:01:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCurrentNowPath.empty()) {
|
2022-03-01 21:12:34 +01:00
|
|
|
snprintf(vs, sizeof(vs), "current now: %d\n", props.batteryCurrentMicroamps);
|
2015-08-24 22:01:16 +02:00
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryCycleCountPath.empty()) {
|
2015-08-24 22:01:16 +02:00
|
|
|
snprintf(vs, sizeof(vs), "cycle count: %d\n", props.batteryCycleCount);
|
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (!mHealthdConfig->batteryFullChargePath.empty()) {
|
2022-03-01 21:12:34 +01:00
|
|
|
snprintf(vs, sizeof(vs), "Full charge: %d\n", props.batteryFullChargeUah);
|
2015-08-24 22:01:16 +02:00
|
|
|
write(fd, vs, strlen(vs));
|
|
|
|
}
|
2013-09-19 05:09:33 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 21:40:00 +02:00
|
|
|
void BatteryMonitor::init(struct healthd_config *hc) {
|
2013-06-12 22:25:59 +02:00
|
|
|
String8 path;
|
2014-05-22 01:28:13 +02:00
|
|
|
char pval[PROPERTY_VALUE_MAX];
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2013-08-13 02:03:35 +02:00
|
|
|
mHealthdConfig = hc;
|
2016-02-18 23:52:46 +01:00
|
|
|
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(POWER_SUPPLY_SYSFS_PATH), closedir);
|
2013-06-12 22:25:59 +02:00
|
|
|
if (dir == NULL) {
|
|
|
|
KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH);
|
|
|
|
} else {
|
|
|
|
struct dirent* entry;
|
|
|
|
|
2016-02-18 23:52:46 +01:00
|
|
|
while ((entry = readdir(dir.get()))) {
|
2013-06-12 22:25:59 +02:00
|
|
|
const char* name = entry->d_name;
|
|
|
|
|
|
|
|
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
|
|
|
continue;
|
|
|
|
|
2022-02-24 22:51:34 +01:00
|
|
|
std::vector<String8>::iterator itIgnoreName =
|
|
|
|
find(hc->ignorePowerSupplyNames.begin(), hc->ignorePowerSupplyNames.end(),
|
|
|
|
String8(name));
|
2019-01-12 02:09:20 +01:00
|
|
|
if (itIgnoreName != hc->ignorePowerSupplyNames.end())
|
|
|
|
continue;
|
|
|
|
|
2013-06-12 22:25:59 +02:00
|
|
|
// Look for "type" file in each subdirectory
|
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name);
|
|
|
|
switch(readPowerSupplyType(path)) {
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_AC:
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_USB:
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
|
2021-12-15 13:40:21 +01:00
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_DOCK:
|
2013-06-12 22:25:59 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-08-11 01:29:50 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mChargerNames.add(String8(name));
|
2013-06-12 22:25:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
|
2019-06-12 06:46:08 +02:00
|
|
|
// Some devices expose the battery status of sub-component like
|
|
|
|
// stylus. Such a device-scoped battery info needs to be skipped
|
|
|
|
// in BatteryMonitor, which is intended to report the status of
|
|
|
|
// the battery supplying the power to the whole system.
|
|
|
|
if (isScopedPowerSupply(name)) continue;
|
2013-10-22 05:26:25 +02:00
|
|
|
mBatteryDevicePresent = true;
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryStatusPath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH,
|
|
|
|
name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryStatusPath = path;
|
2013-08-13 02:03:35 +02:00
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryHealthPath.empty()) {
|
2013-06-12 22:25:59 +02:00
|
|
|
path.clear();
|
2013-08-13 02:03:35 +02:00
|
|
|
path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH,
|
|
|
|
name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryHealthPath = path;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryPresentPath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH,
|
|
|
|
name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryPresentPath = path;
|
2013-08-13 02:03:35 +02:00
|
|
|
}
|
2013-07-31 03:57:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCapacityPath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH,
|
|
|
|
name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCapacityPath = path;
|
2013-08-13 02:03:35 +02:00
|
|
|
}
|
2013-07-31 03:57:16 +02:00
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryVoltagePath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/voltage_now",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
2013-08-13 02:03:35 +02:00
|
|
|
mHealthdConfig->batteryVoltagePath = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryFullChargePath.empty()) {
|
2015-08-24 22:01:16 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/charge_full",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2015-08-24 22:01:16 +02:00
|
|
|
mHealthdConfig->batteryFullChargePath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCurrentNowPath.empty()) {
|
2013-06-12 22:25:59 +02:00
|
|
|
path.clear();
|
2013-08-13 02:03:35 +02:00
|
|
|
path.appendFormat("%s/%s/current_now",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2013-08-13 02:03:35 +02:00
|
|
|
mHealthdConfig->batteryCurrentNowPath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCycleCountPath.empty()) {
|
2015-08-24 22:01:16 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/cycle_count",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2015-08-24 22:01:16 +02:00
|
|
|
mHealthdConfig->batteryCycleCountPath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCapacityLevelPath.empty()) {
|
2019-12-20 00:09:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/capacity_level", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
|
|
|
mHealthdConfig->batteryCapacityLevelPath = path;
|
|
|
|
}
|
2019-12-20 00:09:41 +01:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryChargeTimeToFullNowPath.empty()) {
|
2019-12-20 00:09:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/time_to_full_now", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2019-12-20 00:09:41 +01:00
|
|
|
mHealthdConfig->batteryChargeTimeToFullNowPath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryFullChargeDesignCapacityUahPath.empty()) {
|
2020-02-11 03:23:57 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/charge_full_design", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2020-02-11 03:23:57 +01:00
|
|
|
mHealthdConfig->batteryFullChargeDesignCapacityUahPath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCurrentAvgPath.empty()) {
|
2013-08-28 03:11:49 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/current_avg",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2013-08-28 03:11:49 +02:00
|
|
|
mHealthdConfig->batteryCurrentAvgPath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryChargeCounterPath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/charge_counter",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2013-08-13 02:03:35 +02:00
|
|
|
mHealthdConfig->batteryChargeCounterPath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryTemperaturePath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH,
|
|
|
|
name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
2013-08-13 02:03:35 +02:00
|
|
|
mHealthdConfig->batteryTemperaturePath = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryTechnologyPath.empty()) {
|
2013-08-13 02:03:35 +02:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/technology",
|
|
|
|
POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2013-08-13 02:03:35 +02:00
|
|
|
mHealthdConfig->batteryTechnologyPath = path;
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryStateOfHealthPath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/state_of_health", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
2022-11-24 05:19:41 +01:00
|
|
|
mHealthdConfig->batteryStateOfHealthPath = path;
|
|
|
|
} else {
|
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/health_index", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2022-11-24 05:19:41 +01:00
|
|
|
mHealthdConfig->batteryStateOfHealthPath = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryHealthStatusPath.empty()) {
|
2023-02-04 12:56:06 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/health_status", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
|
|
|
mHealthdConfig->batteryHealthStatusPath = path;
|
|
|
|
}
|
2023-02-04 12:56:06 +01:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryManufacturingDatePath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/manufacturing_date", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0)
|
2022-11-24 05:19:41 +01:00
|
|
|
mHealthdConfig->batteryManufacturingDatePath = path;
|
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryFirstUsageDatePath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/first_usage_date", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
|
|
|
mHealthdConfig->batteryFirstUsageDatePath = path;
|
|
|
|
}
|
2022-11-24 05:19:41 +01:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->chargingStatePath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/charging_state", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mHealthdConfig->chargingStatePath = path;
|
2022-11-24 05:19:41 +01:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->chargingPolicyPath.empty()) {
|
2022-11-24 05:19:41 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/charging_policy", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-09-12 17:26:15 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mHealthdConfig->chargingPolicyPath = path;
|
2022-11-24 05:19:41 +01:00
|
|
|
}
|
|
|
|
|
2013-06-12 22:25:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN:
|
|
|
|
break;
|
|
|
|
}
|
2021-12-15 13:40:21 +01:00
|
|
|
|
|
|
|
// Look for "is_dock" file
|
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-08-11 01:29:50 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) {
|
2021-12-15 13:40:21 +01:00
|
|
|
path.clear();
|
|
|
|
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
|
2023-08-11 01:29:50 +02:00
|
|
|
if (access(path.c_str(), R_OK) == 0) mChargerNames.add(String8(name));
|
2021-12-15 13:40:21 +01:00
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 04:01:00 +02:00
|
|
|
// Typically the case for devices which do not have a battery and
|
|
|
|
// and are always plugged into AC mains.
|
2013-10-22 05:26:25 +02:00
|
|
|
if (!mBatteryDevicePresent) {
|
2014-09-23 23:54:24 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "No battery devices found\n");
|
2013-10-22 05:26:25 +02:00
|
|
|
hc->periodic_chores_interval_fast = -1;
|
|
|
|
hc->periodic_chores_interval_slow = -1;
|
|
|
|
} else {
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryStatusPath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryHealthPath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryHealthPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryPresentPath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryPresentPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCapacityPath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryCapacityPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryVoltagePath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryVoltagePath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryTemperaturePath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryTechnologyPath.empty())
|
2013-10-22 05:26:25 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCurrentNowPath.empty())
|
2015-08-24 22:01:16 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryCurrentNowPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryFullChargePath.empty())
|
2015-08-24 22:01:16 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryFullChargePath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCycleCountPath.empty())
|
2015-08-24 22:01:16 +02:00
|
|
|
KLOG_WARNING(LOG_TAG, "BatteryCycleCountPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryCapacityLevelPath.empty())
|
2019-12-20 00:09:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryCapacityLevelPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryChargeTimeToFullNowPath.empty())
|
2019-12-20 00:09:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryChargeTimeToFullNowPath. not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryFullChargeDesignCapacityUahPath.empty())
|
2020-02-11 03:23:57 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryFullChargeDesignCapacityUahPath. not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryStateOfHealthPath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryStateOfHealthPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryHealthStatusPath.empty())
|
2023-02-04 12:56:06 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryHealthStatusPath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryManufacturingDatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryManufacturingDatePath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->batteryFirstUsageDatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "batteryFirstUsageDatePath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->chargingStatePath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "chargingStatePath not found\n");
|
2023-08-14 20:18:26 +02:00
|
|
|
if (mHealthdConfig->chargingPolicyPath.empty())
|
2022-11-24 05:19:41 +01:00
|
|
|
KLOG_WARNING(LOG_TAG, "chargingPolicyPath not found\n");
|
2013-10-22 05:26:25 +02:00
|
|
|
}
|
2014-05-22 01:28:13 +02:00
|
|
|
|
2014-07-11 00:06:21 +02:00
|
|
|
if (property_get("ro.boot.fake_battery", pval, NULL) > 0
|
|
|
|
&& strtol(pval, NULL, 10) != 0) {
|
|
|
|
mBatteryFixedCapacity = FAKE_BATTERY_CAPACITY;
|
|
|
|
mBatteryFixedTemperature = FAKE_BATTERY_TEMPERATURE;
|
|
|
|
}
|
2013-06-12 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace android
|