google_battery: add a testing fixture for battery present
Allow testing UI behavior when the battery is flagged as not present.
Bug: 165331959
Test: rebuild, trigger, check logs, UI
Signed-off-by: AleX Pelosi <[email protected]>
Change-Id: I37144e88dd4f1473e4243cde903d75c8245f252e
Signed-off-by: Ken Tsou <[email protected]>
(cherry picked from commit fded82ca5d0b94f182e87463ce4c5fb20f1e6569)
diff --git a/google_battery.c b/google_battery.c
index 57fb89f..9da427f 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -219,6 +219,7 @@
bool init_complete;
bool resume_complete;
bool batt_present;
+ u32 fake_battery_present;
struct mutex batt_lock;
struct mutex chg_lock;
@@ -3889,6 +3890,8 @@
debugfs_create_file("pairing_state", 0200, de, batt_drv, &debug_pairing_fops);
debugfs_create_file("blf_state", 0400, de, batt_drv, &debug_blf_state_fops);
debugfs_create_file("temp", 0400, de, batt_drv, &debug_fake_temp_fops);
+ debugfs_create_u32("battery_present", 0600, de,
+ &batt_drv->fake_battery_present);
/* health charging */
debugfs_create_file("chg_health_thr_soc", 0600, de, batt_drv,
@@ -4544,6 +4547,20 @@
val->intval = -val->intval;
break;
+ /* Can force the state here */
+ case POWER_SUPPLY_PROP_PRESENT:
+ if (batt_drv->fake_battery_present != -1) {
+ val->intval = batt_drv->fake_battery_present;
+ } else if (batt_drv->fg_psy) {
+ rc = power_supply_get_property(batt_drv->fg_psy,
+ psp, val);
+ if (rc < 0)
+ val->intval = 0;
+ } else {
+ err = -EINVAL;
+ }
+ break;
+
default:
if (!batt_drv->fg_psy)
return -EINVAL;
@@ -4661,6 +4678,7 @@
batt_drv->ssoc_state.buck_enabled = -1;
batt_drv->hold_taper_ws = false;
batt_drv->fake_temp = 0;
+ batt_drv->fake_battery_present = -1;
batt_reset_chg_drv_state(batt_drv);
mutex_init(&batt_drv->chg_lock);