Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4546325pxf; Tue, 30 Mar 2021 10:18:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmmyAfy6xmoOSFyKAHavH1uGEDwPQZeyVY5bHfAWg7oT2XdVo770qmTpwZgOFBnGRLbE7f X-Received: by 2002:aa7:dcc7:: with SMTP id w7mr2155599edu.255.1617124727333; Tue, 30 Mar 2021 10:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617124727; cv=none; d=google.com; s=arc-20160816; b=mWGNy8Cv+PwefxKj42qdxtxqupnxr4X2I9yhX1It+4kCUc8E18TzHXI2eMZBTUR4iS 2up+RbRGCN1wjamqFX2FLKaitS/Eq8VQmyq7Z/AJpokMaZRWxReH4Z/Hs2iuwYZDW1VN Ik4g9FIikX4+VefcURMDIn5CAW49dqjgL34mMxn02dwuQItMQ1WDHMv5rPGhPsvLOGQa rMcz65pCn+Rw93Ew2Cbz7QXCrkVOvz0GCXkhgJkfuXUXZtZMiSUaFI++pZy8bAdfK836 7cXbgJ22HPhtUH9bre3nSdq6kGoTin3szok2CsXZw3KrZD+WoFhu4TVwof3jSpy/5HTj 9F5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:to:from:subject:message-id; bh=RKy8I9iAGs8XjIXE3vucJEzJoXC9laJwS+1S126hQUk=; b=EztsRKnAXE2gsLDhBifaCL+3/QAbKN8NUwZYuLNwDdRFYovYl6S3KlE/KRC6C8vZt/ neZwgDtLNGb/7nX8PBIF+QXH939s1JKf783qEyVTu2hYMWYbrVPzDviUG6ufez5QrwS3 9OUN3m8gK4snBBRM24DjKJUC9dV/8eMze1I2WllpUK3Why/5J/TcSOxLMMLus8hQTksI Omckh5yvlL8nc1RawQjlI8ydqrieKMbdEgLDiYW5HJwekGAOJK8TGTl6/dEJl5sQ2JZT chQ0zPLHBv+8wjoiJpf7rfPKFN+LIfLr1k1WruhaJ9X/2OkwKRbZGLUcQ/ymGu8V8z0m pjYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y10si15536443ejw.185.2021.03.30.10.18.24; Tue, 30 Mar 2021 10:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231874AbhC3RQ7 (ORCPT + 99 others); Tue, 30 Mar 2021 13:16:59 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:51485 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbhC3RQu (ORCPT ); Tue, 30 Mar 2021 13:16:50 -0400 X-Originating-IP: 78.199.60.242 Received: from [192.168.1.150] (unknown [78.199.60.242]) (Authenticated sender: hadess@hadess.net) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 076D1240006; Tue, 30 Mar 2021 17:16:48 +0000 (UTC) Message-ID: <48cba7cf96bb9c6f5d6c95d8ab0b62ecf1b8d107.camel@hadess.net> Subject: Re: [PATCH BlueZ] profiles/battery: Always update initial battery value From: Bastien Nocera To: Sonny Sasaka , linux-bluetooth@vger.kernel.org Date: Tue, 30 Mar 2021 19:16:48 +0200 In-Reply-To: <20210330170924.16983-1-sonnysasaka@chromium.org> References: <20210330170924.16983-1-sonnysasaka@chromium.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.0 (3.40.0-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Tue, 2021-03-30 at 10:09 -0700, Sonny Sasaka wrote: > 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. > > --- >  profiles/battery/battery.c | 9 +++++---- >  1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c > index 81f849d57..0f8d6ef18 100644 > --- a/profiles/battery/battery.c > +++ b/profiles/battery/battery.c > @@ -88,12 +88,13 @@ static void batt_reset(struct batt *batt) >  } >   >  static void parse_battery_level(struct batt *batt, > -                               const uint8_t *value) > +                               const uint8_t *value, > +                               bool force_update) >  { >         uint8_t percentage; >   >         percentage = value[0]; > -       if (batt->percentage != percentage) { > +       if (force_update || batt->percentage != percentage) { >                 batt->percentage = percentage; >                 DBG("Battery Level updated: %d%%", percentage); >                 if (!batt->battery) { > @@ -110,7 +111,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, false /* force_update > */); >         } else { >                 g_assert_not_reached(); >         } > @@ -134,7 +135,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, true /* > force_update */); If you need to do this, that means that you should probably declare an enum instead. This is old, but still relevant: https://blog.ometer.com/2011/01/20/boolean-parameters-are-wrong/ >         g_free (batt->initial_value); >         batt->initial_value = NULL; >