2021-03-30 18:26:17

by Sonny Sasaka

[permalink] [raw]
Subject: [PATCH BlueZ v2] profiles/battery: Always update initial battery value

Due to cache in gatt db, bluetoothd fails to update publish the battery
value after reconnection when the battery value does not change compared
to before reconnection. For initial battery value, we should update the
value to D-Bus regardless of the cache value.

Reviewed-by: Alain Michaud <[email protected]>

---
profiles/battery/battery.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 81f849d57..d273908f9 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -46,6 +46,8 @@

#define BATT_UUID16 0x180f

+enum battery_update { UPDATE_ON_CHANGE, ALWAYS_UPDATE };
+
/* Generic Attribute/Access Service */
struct batt {
struct btd_battery *battery;
@@ -88,12 +90,13 @@ static void batt_reset(struct batt *batt)
}

static void parse_battery_level(struct batt *batt,
- const uint8_t *value)
+ const uint8_t *value,
+ enum battery_update update)
{
uint8_t percentage;

percentage = value[0];
- if (batt->percentage != percentage) {
+ if (update == ALWAYS_UPDATE || batt->percentage != percentage) {
batt->percentage = percentage;
DBG("Battery Level updated: %d%%", percentage);
if (!batt->battery) {
@@ -110,7 +113,7 @@ static void batt_io_value_cb(uint16_t value_handle, const uint8_t *value,
struct batt *batt = user_data;

if (value_handle == batt->batt_level_io_handle) {
- parse_battery_level(batt, value);
+ parse_battery_level(batt, value, UPDATE_ON_CHANGE);
} else {
g_assert_not_reached();
}
@@ -134,7 +137,7 @@ static void batt_io_ccc_written_cb(uint16_t att_ecode, void *user_data)
return;
}

- parse_battery_level(batt, batt->initial_value);
+ parse_battery_level(batt, batt->initial_value, ALWAYS_UPDATE);
g_free (batt->initial_value);
batt->initial_value = NULL;

--
2.29.2


2021-03-30 18:59:24

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ,v2] profiles/battery: Always update initial battery value

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=458273

---Test result---

##############################
Test: CheckPatch - PASS

##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild: Setup ELL - PASS

##############################
Test: CheckBuild: Setup - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS

##############################
Test: CheckBuild w/external ell - PASS



---
Regards,
Linux Bluetooth