Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb97d9df authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Ajay Panicker
Browse files

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
(cherry picked from commit 15ce1f78)
parent d6678ae1
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -189,6 +189,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();
@@ -226,6 +227,19 @@ import com.android.bluetooth.btservice.BluetoothProto;
        }
    }

    /**
     * Remove all connections for a given application ID.
     */
    void removeConnectionsByAppId(int appId) {
        Iterator<Connection> i = mConnections.iterator();
        while (i.hasNext()) {
            Connection connection = i.next();
            if (connection.appId == appId) {
                i.remove();
            }
        }
    }

    /**
     * Get an application context by ID.
     */