Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4589044pxf; Tue, 30 Mar 2021 11:27:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgByYEVZ57A1/DYITfehkv30y1t2nztkcV9HnR2cIe0VkTHdZDIcevE/bzbOBbGg18zkjD X-Received: by 2002:a05:6402:4395:: with SMTP id o21mr34525927edc.22.1617128844179; Tue, 30 Mar 2021 11:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617128844; cv=none; d=google.com; s=arc-20160816; b=jltS6U3YT/KcVNvObpaXBwJkT5um4eKahk0+LVZnLMUe1xoDimg9fQBFKmH6Tw3PUz Y4LlZw2x4RLkKDUK9Va65EdmVmq42sPYmEUi6dbgOFtLepr9CD77hAwsXYAc3WonF5uB C7g/asGLe4psx252+1kOn+0yQ5TF4j33bOQG8v33WGLzGSTAdADXTiPx4LLX4rCq100Z TlYrcG1Fn/b6LJBxsLsVmbZVArTPV8vTRPYYLVDfXiLFiktcks1cNz+cdDwwBhdDx9Vw TA5+EDtjdXdpLm+lf/LeuVrr8gp1rZPEs/EBPSbcFn9okEPw8GagxCWCfu9u8glsbkxg vIHg== 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=KL9iPK60wP/pqQowpgVvgJX56lp5odnBnpAbntpETLE=; b=nKPXtIZPaxoTV9PAxF6iAjxRp7f5Lbv48bO09BreaFtMOmnlmp/YJ2fN3dyQp3Sc76 1M4QfVwat01mrxJWwfRQdDj3H982VWknukCOUuJd3LI3/hRFHAspWU/U/fUifDP4J5CZ dM5vRJg7262j9XH0i4LplCFiFlLgkU7Hsbhw9xOvCm9l45CvvvLjf1I7UZbUDOj0IieQ gZVl2BC/NrsrxixHij0puv/lanauk4y48Ml8ZzwgsPXKcMbJFRnk1CrAQh9VYZZ4fMCH igucZnA5dgDKGjZz0L/FWVwC7A2bmXsefnXDWFdOQp8FiwKX2mZA63PMQWVcrkE7zgZg zaMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=umQupaVN; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a29si16332353edb.437.2021.03.30.11.27.01; Tue, 30 Mar 2021 11:27:24 -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=@gmail.com header.s=20161025 header.b=umQupaVN; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232329AbhC3SZj (ORCPT + 99 others); Tue, 30 Mar 2021 14:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232649AbhC3SZd (ORCPT ); Tue, 30 Mar 2021 14:25:33 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670A6C061574 for ; Tue, 30 Mar 2021 11:25:32 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id g8-20020a9d6c480000b02901b65ca2432cso16488739otq.3 for ; Tue, 30 Mar 2021 11:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KL9iPK60wP/pqQowpgVvgJX56lp5odnBnpAbntpETLE=; b=umQupaVNiimV+S9Y9b5FvwDCd07ri7QjqU4bdEp9yTJOK3IP+5GA2x5dlbphLSRdE4 LvoCiZ9TYfhOsLbLuj8GijOu6mQsYCYZmkZsnNB7KD+D26g0sBYrtapycp3lZ5Y/B8D4 hkTcHcFl4p4m8LHtVyqjwEujTr1Wlp/DG/rs2Xy+XMLn50Sq8q5PLeR3g1ZQbMlmJU0E G6rX/kOb4Xgyi+OCq3j/VaHutptARttGFUIzUbdZGq6VYrZ2KnfD1WrCohp8qluOjZtA 5jE5yfXUgkhhmYwoJnhjGtFk/SSEYFe/Yg6XuFLmPa5QmDfV5UbPDbfNnLBdwrwiHV3D fnxg== 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=KL9iPK60wP/pqQowpgVvgJX56lp5odnBnpAbntpETLE=; b=erp1I8dFffWtigHC6dWHDz/A6GDHuo9uQjZYFhmbBFd9EQjGMTnCmgpmEBHFG4Suy1 75tq8WbV3WS6vK7ak1/j/nZ30xfg1hhQzczRYS4nvOkR43TImQbF7w5zPahA7At9Yo7i UB2xlHnANcHVfdO6MeWjBW090TVwivg2eEvAZff9FIyHuNhn6IR7UAc+2n+T6gaopQ6x CJ+Hj/NwtXk3z/QIksJ3XHqLWGzG2CGnfe38foqUzeALH0EJv6TI8e4+uMjGwjTB50r9 bu4Ok7ziwYELU7ObR3v86lMWArgKLbMv0b7Yk05UEWnYAGzjow4oQEJYjsHBW+yXiE7j WPSA== X-Gm-Message-State: AOAM532IfLAf9uNnVA4cg1m7uDrRVNBQZoXxhoiNG87EjnSB4fyq+HzH EomU2Rm95jAPLATUyq/29txNWj8NAlXrYfNIZVIdWcd/ipI= X-Received: by 2002:a9d:21a5:: with SMTP id s34mr29374273otb.240.1617128731704; Tue, 30 Mar 2021 11:25:31 -0700 (PDT) MIME-Version: 1.0 References: <20210330170924.16983-1-sonnysasaka@chromium.org> In-Reply-To: <20210330170924.16983-1-sonnysasaka@chromium.org> From: Luiz Augusto von Dentz Date: Tue, 30 Mar 2021 11:25:20 -0700 Message-ID: Subject: Re: [PATCH BlueZ] profiles/battery: Always update initial battery value To: Sonny Sasaka 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 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