From 660208ad2ee2ea394adab0d1c1cea9b068bb70c6 Mon Sep 17 00:00:00 2001 From: Kyle Horimoto Date: Tue, 30 Aug 2016 17:54:16 -0700 Subject: [PATCH] ContextMap: Remove connection references when an app is removed This fixes an issue which could cause a stale Bluetooth address to be used. The issue would manifest itself when an app is added with a connection ID, then the app is removed and app is re-added, causing the original connection ID (which could be stale) to be used. Bug: 30765855 Change-Id: Idacbbfb07d895bf9276fdd986100e832a54d81b0 --- src/com/android/bluetooth/gatt/ContextMap.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/com/android/bluetooth/gatt/ContextMap.java b/src/com/android/bluetooth/gatt/ContextMap.java index e3044d58..02457279 100644 --- a/src/com/android/bluetooth/gatt/ContextMap.java +++ b/src/com/android/bluetooth/gatt/ContextMap.java @@ -190,6 +190,7 @@ import com.android.bluetooth.btservice.BluetoothProto; while (i.hasNext()) { App entry = i.next(); if (entry.id == id) { + removeConnectionsByAppId(id); entry.unlinkToDeath(); entry.appScanStats.isRegistered = false; i.remove(); @@ -205,7 +206,7 @@ import com.android.bluetooth.btservice.BluetoothProto; void addConnection(int id, int connId, String address) { synchronized (mConnections) { App entry = getById(id); - if (entry != null){ + if (entry != null) { mConnections.add(new Connection(connId, address, id)); } } @@ -228,6 +229,19 @@ import com.android.bluetooth.btservice.BluetoothProto; } /** + * Remove all connections for a given application ID. + */ + void removeConnectionsByAppId(int appId) { + Iterator i = mConnections.iterator(); + while (i.hasNext()) { + Connection connection = i.next(); + if (connection.appId == appId) { + i.remove(); + } + } + } + + /** * Get an application context by ID. */ App getById(int id) { -- 2.11.0