google_charger: fix incorrect csi_type for dock_defend

When dd_state is active and disable_pwrsrc is 1, buck_enabled will
become 0 and set csi_type to CSI_TYPE_None.

Consider csi_type connected and report CSI_TYPE_LongLife when
dd_state is active.

Bug: 278192441
Change-Id: I3528244cd91e0e14ce5cc436b72a4cd973efb632
Signed-off-by: Jack Wu <[email protected]>
(cherry picked from commit 6c8b90f4a5df1dedfe3d83b4f97062a996fd53f1)
diff --git a/google_battery.c b/google_battery.c
index d6ce2b9..f835438 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -2668,6 +2668,17 @@
 	return 0;
 }
 
+static bool batt_csi_status_is_dock(const struct batt_drv *batt_drv)
+{
+	int dock_status;
+
+	if (!batt_drv->csi_status_votable)
+		return false;
+
+	dock_status = gvotable_get_int_vote(batt_drv->csi_status_votable, "CSI_STATUS_DEFEND_DOCK");
+	return dock_status == CSI_STATUS_Defender_Dock;
+}
+
 /* all reset on disconnect */
 static void batt_update_csi_type(struct batt_drv *batt_drv)
 {
@@ -2676,6 +2687,7 @@
 	const bool is_ac = batt_drv->msc_state == MSC_HEALTH ||
 			batt_drv->msc_state == MSC_HEALTH_PAUSE ||
 			batt_drv->msc_state == MSC_HEALTH_ALWAYS_ON;
+	const bool is_dock = batt_csi_status_is_dock(batt_drv);
 
 	if (!batt_drv->csi_type_votable) {
 		batt_drv->csi_type_votable =
@@ -2686,7 +2698,7 @@
 
 	/* normal or full if connected, nothing otherwise */
 	gvotable_cast_long_vote(batt_drv->csi_type_votable, "CSI_TYPE_CONNECTED",
-				is_disconnected ? CSI_TYPE_None : CSI_TYPE_Normal,
+				(is_disconnected && !is_dock) ? CSI_TYPE_None : CSI_TYPE_Normal,
 				true);
 
 	/* SW JEITA */
diff --git a/google_charger.c b/google_charger.c
index 70f43b8..b49ef0d 100644
--- a/google_charger.c
+++ b/google_charger.c
@@ -2268,7 +2268,7 @@
 	/* Charging Status Defender_Dock */
 	gvotable_cast_long_vote(chg_drv->csi_status_votable, "CSI_STATUS_DEFEND_DOCK",
 				CSI_STATUS_Defender_Dock,
-				!is_disconnected && is_dock);
+				is_dock);
 
 	/* Battery defenders (but also retail mode) */
 	gvotable_cast_long_vote(chg_drv->csi_status_votable, "CSI_STATUS_DEFEND_TEMP",
@@ -2281,9 +2281,12 @@
 	/* Longlife is set on TEMP, DWELL and TRICKLE */
 	gvotable_cast_long_vote(chg_drv->csi_type_votable, "CSI_TYPE_DEFEND",
 				CSI_TYPE_LongLife,
-				is_temp || is_dwell ||
-				(!is_disconnected && is_dock));
+				is_temp || is_dwell || is_dock);
 
+	/* Set to normal if the device docked */
+	if (is_dock)
+		gvotable_cast_long_vote(chg_drv->csi_type_votable, "CSI_TYPE_CONNECTED",
+					CSI_TYPE_Normal, true);
 
 	/* Charging Status Normal */
 }