diff mbox series

[BlueZ] a2dp: Remove Endpoints cache entries on device removal

Message ID 20250217114802.52247-1-frederic.danis@collabora.com (mailing list archive)
State Accepted
Commit ea3f4047e452b081e34d017cce316aba9d623301
Headers show
Series [BlueZ] a2dp: Remove Endpoints cache entries on device removal | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/BuildEll success Build ELL PASS
tedd_an/BluezMake success Bluez Make PASS
tedd_an/MakeCheck success Bluez Make Check PASS
tedd_an/MakeDistcheck success Make Distcheck PASS
tedd_an/CheckValgrind success Check Valgrind PASS
tedd_an/CheckSmatch success CheckSparse PASS
tedd_an/bluezmakeextell success Make External ELL PASS
tedd_an/ScanBuild success Scan Build PASS

Commit Message

Frédéric Danis Feb. 17, 2025, 11:48 a.m. UTC
When a device is removed, currently the endpoints and last used info
are kept in cache:
  [General]
  Name=Frederic's Phone

  [Endpoints]
  01=00:00:01:29f50235
  02=00:02:01:80010484e200
  LastUsed=01:02

This may prevent future connection, after a new pairing, to use the
best codec available.
---
 profiles/audio/a2dp.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

Comments

bluez.test.bot@gmail.com Feb. 17, 2025, 1:29 p.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=934674

---Test result---

Test Summary:
CheckPatch                    PENDING   0.46 seconds
GitLint                       PENDING   0.31 seconds
BuildEll                      PASS      20.67 seconds
BluezMake                     PASS      1595.63 seconds
MakeCheck                     PASS      39.34 seconds
MakeDistcheck                 PASS      161.52 seconds
CheckValgrind                 PASS      215.86 seconds
CheckSmatch                   PASS      286.32 seconds
bluezmakeextell               PASS      102.52 seconds
IncrementalBuild              PENDING   0.38 seconds
ScanBuild                     PASS      897.58 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth
patchwork-bot+bluetooth@kernel.org Feb. 19, 2025, 8:30 p.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 17 Feb 2025 12:48:02 +0100 you wrote:
> When a device is removed, currently the endpoints and last used info
> are kept in cache:
>   [General]
>   Name=Frederic's Phone
> 
>   [Endpoints]
>   01=00:00:01:29f50235
>   02=00:02:01:80010484e200
>   LastUsed=01:02
> 
> [...]

Here is the summary with links:
  - [BlueZ] a2dp: Remove Endpoints cache entries on device removal
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ea3f4047e452

You are awesome, thank you!
diff mbox series

Patch

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 0eac151db..81dbbfae3 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -880,6 +880,44 @@  static void store_remote_seps(struct a2dp_channel *chan)
 	g_key_file_free(key_file);
 }
 
+static void remove_endpoints_cache(struct btd_service *service)
+{
+	struct btd_device *device = btd_service_get_device(service);
+	char filename[PATH_MAX];
+	char dst_addr[18];
+	GKeyFile *key_file;
+	GError *gerr = NULL;
+	char *data;
+	gsize length = 0;
+
+	ba2str(device_get_address(device), dst_addr);
+
+	create_filename(filename, PATH_MAX, "/%s/cache/%s",
+		btd_adapter_get_storage_dir(device_get_adapter(device)),
+		dst_addr);
+
+	key_file = g_key_file_new();
+	if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+		g_error_free(gerr);
+		g_key_file_free(key_file);
+		return;
+	}
+	g_key_file_remove_group(key_file, "Endpoints", NULL);
+
+	data = g_key_file_to_data(key_file, &length, NULL);
+	if (length > 0) {
+		create_file(filename, 0600);
+		if (!g_file_set_contents(filename, data, length, &gerr)) {
+			error("Unable set contents for %s: (%s)", filename,
+								gerr->message);
+			g_error_free(gerr);
+		}
+	}
+
+	g_free(data);
+	g_key_file_free(key_file);
+}
+
 static void invalidate_remote_cache(struct a2dp_setup *setup,
 						struct avdtp_error *err)
 {
@@ -3352,6 +3390,7 @@  static int a2dp_source_probe(struct btd_service *service)
 static void a2dp_source_remove(struct btd_service *service)
 {
 	source_unregister(service);
+	remove_endpoints_cache(service);
 }
 
 static int a2dp_sink_probe(struct btd_service *service)
@@ -3366,6 +3405,7 @@  static int a2dp_sink_probe(struct btd_service *service)
 static void a2dp_sink_remove(struct btd_service *service)
 {
 	sink_unregister(service);
+	remove_endpoints_cache(service);
 }
 
 static int a2dp_source_connect(struct btd_service *service)