Commit graph

117 commits

Author SHA1 Message Date
AleX Pelosi
f08aeded81 Revert "healthd: BatteryMonitor: doLogValues: reduce log level to debug"
This reverts commit aeccbb8f3a.

Reason for revert: needed for debug and investigations of battery and charging issues. The tooling depends on these lines (and have been for years). You should have these lines only on SOC changes and in the presence of a serious problem. Please do not remove logging without consulting with the BMS SW team first.

Change-Id: Ife0079a7e0c1499b22e843429832b019139c0d89
2024-02-15 19:28:02 +00:00
Neill Kapron
aeccbb8f3a healthd: BatteryMonitor: doLogValues: reduce log level to debug
This is log spam and fills the kernel log. Reduce log level from warning
to debug.

Test: manual
Bug: 36785118
Change-Id: I70fc3a0d796cb1a984705236fe7527e266a69a03
Signed-off-by: Neill Kapron <nkapron@google.com>
2024-02-07 23:37:50 +00:00
David Anderson
629a26b6c5 healthd: Add handling for "Calibration required" battery health.
This string was added to sysfs fairly recently. It indicates that
re-calibration is needed, which we've already added an indicator for via
the INCONSISTENT health status.

Bug: 300585313
Test: m
Change-Id: I9594523e509ad94480ad13f489eee6d1c0a75e7e
2023-12-11 15:25:13 -08:00
David Anderson
d5ed26a45a healthd: Add support for the new Health HAL v3 properties.
Add BATTERY_PROP_PART_STATUS support via getProperty.

Add serial number support via a new helper function, since it doesn't
fit neatly into the BatteryProperty structure.

There are no sysfs nodes for this yet, so currently it is stubbed.

Bug: 309792384
Test: fastboot getvar battery-part-status
      fastboot getvar battery-serial-number
Change-Id: I3777e092d4ef26c02a7dd5420c9eaf1ec5aeae92
2023-12-11 11:59:23 -08:00
Tomasz Wasilczyk
2b1a0599c4 Don't depend on String8 cast to C string
Bug: 295394788
Test: m checkbuild
Change-Id: I5b86ae56250d409a23ab3f2bc72b725bcf6ab23e
2023-09-20 15:11:54 +00:00
Tomasz Wasilczyk
f597129282 Migrate from android::String isEmpty to empty
This empty method is different from the old one - it aligns with
std::string definition.

Bug: 295394788
Test: make checkbuild
Change-Id: Id6baed8cde01a75a8839ad6b4475a31ba1f49c8a
2023-08-18 22:07:28 +00:00
Tomasz Wasilczyk
18b746188c Migrate String8/16 from .string() to c_str()
This will align usage with std::string.

Bug: 295394788
Test: make checkbuild
Change-Id: Ic5c215b011197950dcbcb0339f44cc68fefc65a1
2023-08-11 19:53:20 +00:00
Jack Wu
8231c3fe2d BatteryMonitor: support battery health INCONSISTENT from health status
Report Battery health INCONSISTENT when there is a battery recalibration
pending.

Bug: 283182048
Test: m
Change-Id: I8b944ddac7cc919fc95b1b71b015101642a62f96
Signed-off-by: Jack Wu <wjack@google.com>
2023-05-24 03:25:59 +00:00
Jack Wu
cf996f3d8d BatteryMonitor: support battery health NOT_AVAILABLE from health status
Battery health is supported but there is not enough information to
determine an accurate value  This is a temporary state.

Bug: 276400004
Test: m
Change-Id: I0d422db20c51ef7e9dc4fa904729beda625c9fea
Signed-off-by: Jack Wu <wjack@google.com>
2023-04-24 11:37:40 +00:00
AleX Pelosi
ff7089295a BatteryMonitor: batteryStateOfHealth should be a property
Bug: 251427118
Test: m
Change-Id: I21bcd160f51cf8818d0c3c8c54c615314808e586
Signed-off-by: AleX Pelosi <apelosi@google.com>
2023-02-23 01:22:34 +00:00
Jack Wu
b57f68aedd BatteryMonitor: report battery health from health status
Bug: 251425963
Test: m
Change-Id: I0a34262c8146032120273ab9be4ef4d3b285d115
Signed-off-by: Jack Wu <wjack@google.com>
2023-02-10 07:40:20 +00:00
Jack Wu
e561d03cdf BatteryMonitor: get battery health data from sys file nodes
Requirements for battery health aidl hal v2, include sysfs nodes:
  - Battery state of health
  - Charging state
  - Charging policy
  - Date of manufacturing of the battery
  - Date of first use of the battery

and functions
  - setChargingPolicy
  - getChargingPolicy
  - getBatteryHealthData

Bug: 251425963
Test: m
Change-Id: I210dc403ba95b1b75759227f84bc32f32be1bbaf
Signed-off-by: Jack Wu <wjack@google.com>
2023-01-21 15:20:19 +08:00
Bart Van Assche
095c944b48 healthd: Convert multiple private methods into static nonmember functions
The private methods in class BatteryMonitor do not use the 'this'
pointer. Hence convert these into static nonmember functions.

Test: Compile-tested only.
Change-Id: I4b9b76c9697f1db894ba9fb939ce096ee6b7ff3b
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-03-03 18:46:12 +00:00
Bart Van Assche
5a7e5083e6 healthd: Fix readFromFile()
Not all readFromFile() callers pass an empty string. Make sure that
readFromFile() returns 0 (failure) if the *buf argument is not empty and
if reading fails.

Fixes: 3217c5c7d9 ("batterymonitor: simplify readFromFile and use std::string buffers")
Test: Compile-tested only.
Change-Id: I6f329491f8aa4a6d378eb7c3cbc17038eb6aa64d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-03-03 18:46:12 +00:00
Bart Van Assche
024e18f060 healthd: Make initHealthInfo() easier to read
Use aggregate initialization instead of memberwise initialization. This
patch does not change any functionality.

Test: Compile-tested only.
Change-Id: I9c7831936e449aec8a48336b1ee76d26638e4f72
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-03-03 18:46:12 +00:00
Bart Van Assche
25b2a8de53 healthd: Improve readability of BatteryMonitor::init()
Declare and assign in a single statement instead of in two separate
statements. This patch does not change any functionality.

Test: Compile-tested only.
Change-Id: I0798cc940f5f2ca329548568ab68e96891521dd8
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-03-03 18:46:12 +00:00
Yifan Hong
b99d15c529 healthd: batterymonitor uses AIDL HealthInfo.
This change cleans up technical debt. As a side
effect, this change also exposes chargerDockOnline
properly to health HAL implementations.

Test: TH
Bug: 222120465
Change-Id: I306bd0538d94b310a69befb93b5862dd7208447f
2022-03-02 16:20:35 +08:00
Jack Wu
06b9041736 BatteryMonitor: support Dock charging
Bug: 194012532
Test: Show dock type correctly
Signed-off-by: Jack Wu <wjack@google.com>
Change-Id: I1698328b7b20c23d9b2571b7dbf1b907834582c8
2022-01-13 20:30:32 +08:00
Yifan Hong
605e7d20ee BatteryMonitor: Add helper of logValues()
... that logs values for an arbitrary health info and
health config.

This allows health 2.1 HAL implementation to log the
updated health info struct, which is not stored in
BatteryMonitor.

Test: healthd kernel log has correct values
Bug: 179326883
Change-Id: I394ef3f317229f94f4db82de5635d9380c183394
2021-02-08 15:22:28 -08:00
Stephane Lee
bab6877710 Assume UNSUPPORTED if the battery capacity level sysfs node does
not exist.

Bug: 163382088
Test: Ensure that, if the ./capacity_level does not exist,
  that the device will shut down at 0 % SOC in an Health 2.1
  implementation
Change-Id: I00822b4bfba5d823c1a30163ea6824e59d3aae32
2020-08-13 14:31:02 -07:00
Yifan Hong
e5bd5f914f BatteryMonitor: report current_now in uA
/sys/class/power_supply/*/current_now should return uA and the HAL
expects uA too.

Test: VtsHalHealthV2_0TargetTest
Bug: 136717180
Change-Id: I675be1ae645413b9494af4a5d49955aad5bd4f2e
2020-04-08 16:24:17 -07:00
Kazuhiro Inaba
8e4d982d52 healthd: Don't take device-scoped battery as the main system battery.
Some devices expose the battery state of stylus etc in sysfs,
in addition to the whole system's main battery. Android only
recognizes the first battery enumerated here. We need to
filter out such HID-specific battery to let Android correctly
monitor the main battery status.

Bug: 136111013
Test: CtsBatterySavingTestCases on arcada
Change-Id: I4cbf6e3bf883fb3d107bedd2849d8ad525538629
2020-03-16 12:50:42 +09:00
Stephane Lee
06846044fe Add UNSUPPORTED to health HAL 2.1 values
Bug: 149429835
Test: lshal debug android.hardware.health@2.1::IHealth/default
Change-Id: Ibbcd89f38ed9ec2966b31854ab1cbe218c8e19cb
2020-02-15 16:51:02 -08:00
Stephane Lee
1c108edc74 Consume design capacity in health HAL 2.1
Bug: 149121450
Test: lshal debug <health hal 2.1>
Change-Id: I005fa47bda7e58f6636fdc87293227622d74187a
2020-02-13 15:14:40 -08:00
Stephane Lee
86f9f6aed5 Populate fields for health HAL 2.1
+ batteryCapacityLevel
+ batteryChargeTimeToFullNow

Bug: 137790244
Test: lshal debug (health service)
Change-Id: Ieb0b42e6cdded5974f01198ee151453367f82579
2020-01-22 10:50:05 -08:00
Treehugger Robot
ec56c59dbb Merge "healthd: Fix incorrect return check" 2019-11-07 21:18:59 +00:00
John Stultz
47a6bf014d healthd: Fix incorrect return check
In commit 1d4368b494 ("[REFACTOR] healthd: BatteryMonitor
use health 2.1 types"), the mapSysfsString() function was
changed to return NULL instead of -1 on error.

Everywher else that function is used commit 1d4368b494
tweaked the return value check from (ret < 0) to (!ret),
but one spot was missed.

This patch corrects the one missed check so that we compare
against null rather then negative value, since the return
value can no longer be negative.

This issue was found by inspection, and I've not seen an actual
problem with it, but thought it should be corrected.

Change-Id: I0a6564274d01276352a5dc0660b8ffbe748b5fde
Signed-off-by: John Stultz <john.stultz@linaro.org>
2019-11-06 01:40:18 +00:00
Yifan Hong
6cabe9bbc7 BatteryMonitor: init health info properly.
HIDL enum values are zero initialized, not the first value
of the enum. They need to be initialized properly.

Test: pass
Change-Id: I2adb8b851e6ac607ac4f547a6a6600604d07816f
2019-11-06 01:37:01 +00:00
Yifan Hong
35cb0838f6 healthd: partially fill in health 2.1 HAL fields
- batteryCurrentAverage
- batteryCapacityLevel
- batteryChargeTimeToFullNowSeconds
- batteryFullCapacityUah

Some of the fields are left 0 / UNKNOWN and will be
implemented in b/142260281.

Bug: 142260281

Test: lshal debug health 2.1 HAL shows these values
Change-Id: I8e462d612b39c16cfb3ae1b63b3e293153585c28
2019-10-23 14:55:35 -07:00
Yifan Hong
1d4368b494 [REFACTOR] healthd: BatteryMonitor use health 2.1 types
... instead of BatteryProperties. HealthInfo contains
much more information and is easy for health HAL impl
to use it.

Also add getHealthInfo* functions for health HAL
implentations to use.

Test: health VTS 2.0 test
Bug: 142260281
Change-Id: I188276788fd8f11e69f8e046b91a873afaa23457
2019-10-23 14:55:35 -07:00
Yifan Hong
1353e70278 [REFACTOR] healthd: BatteryMonitor::update split into 3 funcs
split bool update() into three functions:

void update()
void logValues()
bool isChargerOnline

... so that it doesn't depend on healthd_board_battery_update and
healthd_mode_ops, which are deprecated.

Test: health 2.0 VTS test
Bug: 142260281
Change-Id: I65908a04bae00654213efb4b5569ced0a7e76076
2019-10-14 14:07:13 -07:00
Thierry Strudel
f73de6f037 healthd.h: add ignorePowerSupplyNames to healthd_config
In case some power supply paths should not be considered, add a black list
to the healthd_config to instruct BatteryMonitor of the power supply paths
to ignore on init.

Bug: 117903348
Change-Id: I6f9ddeff9351ad01772b43728ddc2627da81df2a
Signed-off-by: Thierry Strudel <tstrudel@google.com>
2019-01-11 18:08:23 -08:00
ShevT
9d98a6ac93 healthd: BatteryMonitor: Fix compiler warning
system/core/healthd/BatteryMonitor.cpp:248:19: note: initialize the variable 'i' to silence this warning
    unsigned int i;
                  ^
                   = 0
1 warning generated.

Change-Id: Ib2fa0061d657fd93871ca8a9056d173d5b7ab58d
2018-11-02 17:59:09 +00:00
Elliott Hughes
643268f325 Move system/core/ off NO_ERROR.
It causes trouble for Windows, and OK already exists.

Bug: N/A
Test: builds
Change-Id: Ida22fd658b0ebb259c710ba39049b07c9e495d9c
2018-10-08 11:15:52 -07:00
Yi Kong
979ace46ed Merge "healthd: Fix negativity check after cast to unsigned enum" am: 3dad67af05 am: 4734981245
am: eb066ae098

Change-Id: I2327adfd50fceb232ef2a52e535914743c25cf3a
2018-03-03 00:46:57 +00:00
Yi Kong
808e57e3f3 healthd: Fix negativity check after cast to unsigned enum
mapSysfsString return code is checked for negativity after being casted
to unsigned enum type, which will always be false. This is obviously
unintended behaviour.

Fixes tautological-unsigned-enum-zero-compare warning.

Bug: 72331526
Test: m
Change-Id: Icec76d7a1121cb56fd9d05feb70cede69954c322
2018-03-02 18:42:03 +00:00
Todd Poynor
4d7ee2ebbb healthd: don't report fake data for battery-less devices
If the kernel does not implement a power_supply class device of type
battery, do not report fake data, instead report the following by
default:

* batteryPresent = false (instead of true),
* charging status = unknown (instead of charging),
* capacity = 0 (instead of 100%),
* health = unknown (instead of good),
* AC charger online not modified (instead of forcing true)

If no charger and no battery devices are supplied by the kernel, the
AC charger online property will no longer be forced to true.  Devices
that are always plugged into AC power should either implement a
power_supply class charger device or implement a Health HAL that sets
properties appropriately.

Bug: 34507420
Test: manual: gce_x6_phone (no battery or charger),
      boots and stays booted, inspect properties
Merged-In: I14cb3b685e8130428e417e7d08c4246f7415210a

Change-Id: I64bd4431af10f3d232f36fcf8d356b6d88b08013
2018-02-05 19:48:30 +00:00
Yifan Hong
43f731ae45 healthd: Remove access to /sys/class/power_supply/battery/batt_vol and batt_temp
These are custom paths from early Android devices that the framework used to
read, and that code was copied into healthd. Removed because this is not
defined in upstream kernel.

Change-Id: I375a8a62610c1235d82c1f27568437b16e0f96a8
Fixes: 72824944
Test: health 2.0 VTS test
2018-02-01 13:51:04 -08:00
Todd Poynor
e030a10d0f Revert "Revert "healthd: don't report fake data for battery-less devices""
This reverts commit 1bc572dfe8.

The presubmit test that (incorrectly) fails on the original commit
has been marked @FlakyTest and a bug is failed on Assistant.

Bug: 34507420
Test: manual: gce_x6_phone (no battery or charger),
      boots and stays booted, inspect properties,
      presubmit tests on gce_x86
Change-Id: I5509bf5de9fceffdd5fd8abc3f1f4f6101119248
2018-01-23 19:07:23 +00:00
Hridya Valsaraju
7fa7225cc4 Create a friend method for reporting battery health
Bug: 71860528
Test: Test: vts-tradefed run vts -m VtsHalHealthV2_0
Change-Id: I6c56c601ee59fe33ee4a19dd4aeafbe3a1bd4c72
2018-01-16 11:15:51 -08:00
Todd Poynor
1bc572dfe8 Revert "healthd: don't report fake data for battery-less devices"
This reverts commit de610c9a0e.

Reason for revert: May trigger flakiness in CTS ActivityManagerAssistantStackTests.

Change-Id: I02f831048f7802d91331e67bd9006860e4572b92
2017-12-15 06:51:04 +00:00
Todd Poynor
de610c9a0e healthd: don't report fake data for battery-less devices
If the kernel does not implement a power_supply class device of type
battery, do not report fake data, instead report the following by
default:

* batteryPresent = false (instead of true),
* charging status = unknown (instead of charging),
* capacity = 0 (instead of 100%),
* health = unknown (instead of good),
* AC charger online not modified (instead of forcing true)

If no charger and no battery devices are supplied by the kernel, the
AC charger online property will no longer be forced to true.  Devices
that are always plugged into AC power should either implement a
power_supply class charger device or implement a Health HAL that sets
properties appropriately.

Bug: 34507420
Test: manual: gce_x6_phone (no battery or charger),
      boots and stays booted, inspect properties
Change-Id: I14cb3b685e8130428e417e7d08c4246f7415210a
2017-12-14 21:13:06 +00:00
Yueyao Zhu
8e5671f55c Merge "healthd: add battery health status values from JEITA spec" am: 5dd87c4ef6
am: 7a79592e4e

Change-Id: Ife13b29af4f44d3d6f5cc7b00435f4c6a57e0d2b
2017-06-21 19:29:25 +00:00
Yueyao Zhu
9bbfbf7ffe healthd: add battery health status values from JEITA spec
Some vendors implement JEITA battery health spec.

Bug: 35780570
Test: build and boot
Change-Id: I532cd0fbdbcae0a32879de7d7930f3ccb8605ffd
2017-06-20 18:08:51 -07:00
Steven Moreland
aa47993b23 Merge "libutils: String\d+ make std_string private" am: 76850afa52 am: 2ebb1e5404
am: 4ba3f784ef

Change-Id: I14f003992db222ef285551c6d9a8ffe71620f70d
2017-03-11 09:07:23 +00:00
Steven Moreland
2aac335128 libutils: String\d+ make std_string private
This method is still used by prebuilts, but making it private to start
the process of removing it from everywhere.

Test: pass
Bug: 35363681
Change-Id: I4d53f68d10c9abcca32023c4d930e99912afa697
2017-03-10 22:51:55 -08:00
TreeHugger Robot
068e00b3c9 Merge "Revert "Add BMS as a Battery type"" 2017-03-06 23:34:59 +00:00
Yueyao Zhu
8d17bc6a7a Revert "Add BMS as a Battery type"
This reverts commit f13c6ff50a.

Bug: 34166515
Change-Id: I102d3ee071f214deba1a72738af62b6f6b7c52f4
2017-03-06 21:42:35 +00:00
Jin Qian
72adf11daf healthd: return battery status property
Bug: 34198239
Change-Id: Ib0f312c15eb75ba7482f4f0b3f30ba2feae2c209
2017-02-07 21:41:05 +00:00
Adam Lesinski
f13c6ff50a Add BMS as a Battery type
In order to automatically use the /sys/class/power_supply/bms/charge_full
path for reading learned capacity of the battery, the BMS power supply
(Battery Management System) needs to be considered a battery.
Test: Manual

Change-Id: I66e5751547c3dbdc8de0bb3893367cc6f2c9d733
2016-12-09 19:23:46 -08:00