Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4598102pxf; Tue, 30 Mar 2021 11:43:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgcvgI3PZnEGkGCQt16lccVGKyP2ebpQAGcortHYxvI9da+xNSDvDS9eZXo5ZICMVcbevP X-Received: by 2002:a17:906:4f10:: with SMTP id t16mr34647969eju.531.1617129816612; Tue, 30 Mar 2021 11:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617129816; cv=none; d=google.com; s=arc-20160816; b=sqye6hCEcyw/Iw6lvbbYXXmInb7qen3MVopt0Vy1coY43KEAEe0UA4rOq86Xjjihd1 cIew0GKuwBid1/vgsW+A6XdINFASz6LqeoWjFVouwlLu4jWdWPf5eRVCzoXw7V/aMkkN T/otGtXsV7jy5Ps6p/qpA3J2RFxDn/eHhphnDkeFWPbGHMS2cIq4MyzynhRUTwer+dul Ty0M4kBKZ2IGr4UytC8fX890dFwsHhw4Zmwttm8TPk+rs2shbmbq1CnQwUq6YQejXiqd EAxcVa53vBSqZQA859swlgW0BQDpU55Z+jPActTsEbA4xPj53sUrNFY/uQLqKj52lzWw sttw== 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=h3alyGEBvGi920HN5uHjFjp9GGLAfe3KXLwuYe7WnNM=; b=E3PrMxQvMI+tSBzt7Cp3/wMnicushP8rrK15QdhRCv7RUfQLQoGF5wPj+YhNRbvf2y 4KcNNFOUecZSmZ6bPQ+9kp6Xr+miFPn+AWWtKrlMukBd/nG6OSFZo4jTXyECtD5ryN3F UjI7RPKzT3xildFC3wx0byv5KA6MTTtByDaHljpl2c7BYW0ID1SSFuOyHs69WxLmKOYb zISKHxiENOyE7WgmxmO//gfy9FGweiJT0Roz9DnDncxAqM48jZargS/jGDAjDMxGzdwp q2PJVpOhLBLbd3lbLJaxC1g26eG5rKbIQ3uSMZHaE0oQuuy+xjp/q9fKs/JhqlxTCkE1 C70Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d0+dA4MX; 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 v12si15233479ejb.425.2021.03.30.11.43.13; Tue, 30 Mar 2021 11:43:36 -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=d0+dA4MX; 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 S232866AbhC3Sjc (ORCPT + 99 others); Tue, 30 Mar 2021 14:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232854AbhC3SjR (ORCPT ); Tue, 30 Mar 2021 14:39:17 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CD7DC061574 for ; Tue, 30 Mar 2021 11:39:16 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id h10so19352278edt.13 for ; Tue, 30 Mar 2021 11:39:16 -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=h3alyGEBvGi920HN5uHjFjp9GGLAfe3KXLwuYe7WnNM=; b=d0+dA4MX2Rds/Zqi7gPN3ro5LW9pCYivsZ62E3SX27pH05iWB2Q9gGngISStpIZcHw FPoeeGJLb+ngf5M/B9zO5AcrA/tImdWNw5nuTuGT7EBciamKbs6FL2VBrGvUXtoClDhC WYHELueJdwtwaRxUKDiD9x9sAqZg2Is6ytXOc= 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=h3alyGEBvGi920HN5uHjFjp9GGLAfe3KXLwuYe7WnNM=; b=N7tEqull61SW9AQEYYzmdxDjmKBbmqGV1rwb0RsdNxBBM+e/241YBmrRG7LOp0u5yk tLJxGyWKvuaJYtRwCBYRnBYYS6rnGjU8NQ2DL109ItoV4T2cl8Oowj+ZN8Lgr2nwYYtU kyetBREdTfckjFddrh95S9SOcgje4LEFRXFkyIGD9my/wHrtBI2Arpnm0IVIjvL2d47S uQDw+/2RgugENU3mbyZEAgs6m67Etg6leM+pTIPpoUJ9l1LNr5fkcWHyBoIv7SqbFy/+ az4PI67aPa1bJGa1Tgan+y7vVztJAkpcfeploPIpfwmyjUznJKDTqYxgah+UlQ9XdAyz bpLw== X-Gm-Message-State: AOAM533d31y1z1Qmz+eUFcVtxNdTee4pL39mAaY1BXtVisae9Cii840H 5P5FEPbG/DRcefMZiS1erlXzs1UpaoJBtQ== X-Received: by 2002:a05:6402:1a4f:: with SMTP id bf15mr35392096edb.304.1617129555214; Tue, 30 Mar 2021 11:39:15 -0700 (PDT) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com. [209.85.128.46]) by smtp.gmail.com with ESMTPSA id gn19sm10269945ejc.4.2021.03.30.11.39.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Mar 2021 11:39:14 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so8941216wmj.1 for ; Tue, 30 Mar 2021 11:39:14 -0700 (PDT) X-Received: by 2002:a1c:318b:: with SMTP id x133mr5429596wmx.154.1617129554001; Tue, 30 Mar 2021 11:39:14 -0700 (PDT) MIME-Version: 1.0 References: <20210330170924.16983-1-sonnysasaka@chromium.org> In-Reply-To: From: Sonny Sasaka Date: Tue, 30 Mar 2021 11:39:02 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH BlueZ] profiles/battery: Always update initial battery value To: Luiz Augusto von Dentz Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, That's a good idea. Please take a look at the latest patch titled "Reset battery value cache on disconnect". On Tue, Mar 30, 2021 at 11:25 AM Luiz Augusto von Dentz wrote: > > Hi Sonny, > > On Tue, Mar 30, 2021 at 10:12 AM 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 */); > > I guess it would have been better to reset the initial_value on disconnect. > > > g_free (batt->initial_value); > > batt->initial_value = NULL; > > > > -- > > 2.29.2 > > > > > -- > Luiz Augusto von Dentz