Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4588501pxf; Tue, 30 Mar 2021 11:26:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWRpPjqu2PTwU7CVNcANjeMLtc8KE3uvcMi+tGtSEgV9RNh54BEugsXop47b3xfcgBS5vE X-Received: by 2002:aa7:dc49:: with SMTP id g9mr34303453edu.60.1617128782161; Tue, 30 Mar 2021 11:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617128782; cv=none; d=google.com; s=arc-20160816; b=a9uDpBKUvdEV+41teqXkb/ixgSDbBEbSI+zcedBJhPXton+50+cX+ra+d7dGIOR5uH z0naNXiSu9FEM577EUbvupkaZQPwRcVMguRrnvcqVTsgILESJvV/5e5FmKJCnCLhkXh/ Uguuso2ABFb49R0QMgRCVKgaWOIrLpXk/8SglRk3wEUROSWooRqc7qeozINnQJfa4HYA eE35USLezm7xUYvu5bVcRdJ0Li8eevdG5mdrOW89ASsvV3NNNO4ffZV3H5uD1FNpPD/E rvAqGPWdRrTurDHcUEuQnixDeQW2rw8cbvz5cot2vRjeXdhNQF++5VAy6JFu7eOhhBVw d0IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/UfCZumSjjZ+gCLKiVpTNp4n1wCiRZNAE9JXSMeCYMA=; b=0diUKV/PUhxP1PDW368WTZEwUEQZCWwG+zXIEiFBoAf2Q6Q5SdaQd9QSgZsxD28iP6 7ttC15RlZujkXDD+dsJTFMsPt6HlTmdfXrQbcyZKJ5U5Z6SuGJcHuBDgGOH3RO7xxTAp lZcVQlWDEFuieHNj4pdUupedF4ru2Qs/QaNUnIS4tSCkV3ixDw3R6zwh6I4a5tqo5B4F OqAMGPEkwE2QpKHcMrInJuRPXk837ZDgo5MH9DFeVMcLXuBc4D6ZES7Q6gw3PgSpCxca BFIB+TWDUmM0mVs+dmfuvatrXDt6iSJAd7VHPYFLwJHMREEZZasCii+nGEFwnfdCi327 9ybQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="I77lQP/1"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc2si2287483ejc.653.2021.03.30.11.25.59; Tue, 30 Mar 2021 11:26:22 -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; dkim=pass header.i=@chromium.org header.s=google header.b="I77lQP/1"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232827AbhC3SYf (ORCPT + 99 others); Tue, 30 Mar 2021 14:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbhC3SYI (ORCPT ); Tue, 30 Mar 2021 14:24:08 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74148C061574 for ; Tue, 30 Mar 2021 11:24:08 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id x21so19317092eds.4 for ; Tue, 30 Mar 2021 11:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/UfCZumSjjZ+gCLKiVpTNp4n1wCiRZNAE9JXSMeCYMA=; b=I77lQP/14JsBMZfPU/eO4Pi8WbA4bZJCjeibvwRlA5A5FTslb21WP2Nu8waaLxeZhw /gDQWNXhgNgM9YntfUG7RLZEp4EQu8XZ7iNZ12yVxeFQGrgMguJGfaiT9cRiqF466w27 UUqF84ccoB3VZQXhC2QcMh0m/y5D/VO9+7Fac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/UfCZumSjjZ+gCLKiVpTNp4n1wCiRZNAE9JXSMeCYMA=; b=OUrlC+A3YOe0Y1lGkZnOBuQQhGaQY2qsX5VvaSQYioJo9ZYHt7RJlmuXtF3EV+dTe7 jdaLA0e9qM0lmYX1m7uS+miMwWrSrtXDez0xNpaLQdcXbfTqqXEGLwsMmp7NQ2kHiJrk v3Gy7iSyzKUoSQtQ+IBzRNtXPvFUOHqrMZzEEDQCQxGtGv/xT0oJ5MXURZzKF5ylg2/K E9DDRxiU23Ru0UY77qTTy//dEpUfLqewnQqNx315Sg2ey1QZiMqCG7/fQy8b8yEz1YEu QwdMEUfLtaIaBwhoMgZYMIxjLJUPdOhfgJtMsMLA/Vwi857jAtjXrcYm0ds/K9AaeYDE wvvw== X-Gm-Message-State: AOAM531smLmSDByxL0QjUkVEnbKoy7k3ADG3uE9cjvDkmNMOAUGMKv9/ mcaAXuhjQQkk4UvDcbf5XWyNBL7vugPVYg== X-Received: by 2002:a05:6402:26c9:: with SMTP id x9mr34490340edd.322.1617128647113; Tue, 30 Mar 2021 11:24:07 -0700 (PDT) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com. [209.85.221.53]) by smtp.gmail.com with ESMTPSA id h8sm11506999ede.25.2021.03.30.11.24.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Mar 2021 11:24:06 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id v11so17131112wro.7 for ; Tue, 30 Mar 2021 11:24:06 -0700 (PDT) X-Received: by 2002:adf:c186:: with SMTP id x6mr35791013wre.253.1617128645577; Tue, 30 Mar 2021 11:24:05 -0700 (PDT) MIME-Version: 1.0 References: <20210330170924.16983-1-sonnysasaka@chromium.org> <48cba7cf96bb9c6f5d6c95d8ab0b62ecf1b8d107.camel@hadess.net> In-Reply-To: <48cba7cf96bb9c6f5d6c95d8ab0b62ecf1b8d107.camel@hadess.net> From: Sonny Sasaka Date: Tue, 30 Mar 2021 11:23:54 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH BlueZ] profiles/battery: Always update initial battery value To: Bastien Nocera Cc: BlueZ Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Bastien, That's a good idea. I updated it in v2. On Tue, Mar 30, 2021 at 10:16 AM Bastien Nocera wrote: > > 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; > > > >