Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4588463pxf; Tue, 30 Mar 2021 11:26:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuVIXbVZI+/sfT02q+W5HKRu2glWGGaFsAat0CGwkWZ8+R6kNG+XmaftSqR91YQDA5/fpP X-Received: by 2002:a17:907:110c:: with SMTP id qu12mr35213138ejb.442.1617128777621; Tue, 30 Mar 2021 11:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617128777; cv=none; d=google.com; s=arc-20160816; b=lpTRYH5La6bul278Pq26pqEAzhS4bGBeBLQ7612rTJo94a2lSlQXNzt/TVAtBnQRYu 4jqIyXsJc3wSqZXjhr0cUXMGfFG0Y8M9G22mwg8JnGYbVRz9k6c7GC2Ye0A7dztNhHEH ITuKHenIlnU+dvsusGn0ZD0GcUBfe0PbzySH0FT1LJ7kS/8P2PMJfoSQsg/Vne5QK6t5 UEBqrwpRzvTGWrw5XqqlnwOdZE2ebYtBSrvvmX/2+sqyOsnIiyrRRZonA7HxkUX9MQ7x EvBtCp5UI9eKYr/kJODeIQX9WppLpR0aPdVWDUxVju0lPxfliF9HUQNosnsFL0HZUfMn +EDA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rlwLfk5Pcjc8ov49J3YIWAGsLTxvnqJQPkiZoKs4R1M=; b=izd1kb3uzc/hD+Qy6CczIEvsNb/jYT/9nKjpdSWroeevbzK+xssGu2yOeaTp5dmNV5 zfvUgABhAsAnpx0L0dzWjvtUUjRWcyOBStkiEoLlCXQSDE0bHH9Jpm/AnXF/w1lBSs/w 6WFBks92LR2jbPi3QDBc2xqxzADDm+s/BZMU6z+6H+JIZE1KQj69aSL2RlnTbJjbjXG2 govDvtyp9PpTnGKj1HHUWHUcJD0y95cmkq0s8rjP0D63lhb4NV1uxKFCx7irRGK3YwcL z8NK/tnVPckg45Jq+bhN+z7vobwLclBzuLWADiNYrrrKqnUKw82XAQfOurkmqBNwczBk HHHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gsimQjj3; 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 b3si15646568ejg.74.2021.03.30.11.25.46; Tue, 30 Mar 2021 11:26:17 -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=gsimQjj3; 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 S232504AbhC3SX7 (ORCPT + 99 others); Tue, 30 Mar 2021 14:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232726AbhC3SX3 (ORCPT ); Tue, 30 Mar 2021 14:23:29 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E405C061574 for ; Tue, 30 Mar 2021 11:23:28 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id w8so8180357pjf.4 for ; Tue, 30 Mar 2021 11:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rlwLfk5Pcjc8ov49J3YIWAGsLTxvnqJQPkiZoKs4R1M=; b=gsimQjj3KBQqrDjKDcQi3q8HYqgW1Ba+3Dnvxo6QW0nMr/QvTYdQTI2ciAae0w59CU TS6SAXr3F7Nt63/MmU9hvmoSo+oyzA/8yTPBuQX0FC+HBXpvPN9cBI3a/lhAVjYd1nhi 5Xs2nP9seHQAbG1qkqwwOx5kzTf64V7dHRGlU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rlwLfk5Pcjc8ov49J3YIWAGsLTxvnqJQPkiZoKs4R1M=; b=W9WBzcCqPUNvthgb8eNCZfnnPgXR4LkhmDDyPY05VXqdGdJHrxPIXxuikUrAfXiTa2 DALPcmcGUquiIKgAq57VOZwWoID1g9OnrMWBr/Ld/0J2waez4qJ3oXwD+DQbx+zzcxko yLuwjCzm89Ax/2qn8NaaPnQrHlLk9n6yLU9JO/a6jGEpdFT4ey2n13OEz4Ow75wrxg06 mDWes5uY8gRKO0luzOoCasA5ZmTZpnfrVjXnB/E2NUSGpaZRougSkBmoanNMRo+j2iYo U0hSlTLDM3NuyLFAZ3/3UzlBFgsfR/bcXTSwogi0yhnIhUUt5vCMFgsTNPX6YsUsNo18 2Hkg== X-Gm-Message-State: AOAM531vbgGgjF+utD19MHp/2Y3hEALap+SVnv9W44wG7Bvt63eKygao 5rp8ASkkEz762/BC08jbjubA3912Bdiuyw== X-Received: by 2002:a17:903:188:b029:e6:52f4:1b2d with SMTP id z8-20020a1709030188b02900e652f41b2dmr35534995plg.58.1617128607816; Tue, 30 Mar 2021 11:23:27 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:7587:91c9:c28b:2af5]) by smtp.gmail.com with ESMTPSA id 6sm21154125pfv.179.2021.03.30.11.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Mar 2021 11:23:27 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Alain Michaud Subject: [PATCH BlueZ v2] profiles/battery: Always update initial battery value Date: Tue, 30 Mar 2021 11:23:19 -0700 Message-Id: <20210330182319.17537-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 --- 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