Merge "Bumble: Make asynchronous gRPC calls be cancelable" into main
diff --git a/Android.bp b/Android.bp
index 63b4b52..72221e2 100644
--- a/Android.bp
+++ b/Android.bp
@@ -95,6 +95,11 @@
     "-*",
     "misc-*",
 
+    // Checks for unused and missing includes.
+    // Should be enabled as an alternative to IWYU, but currently generates
+    // too many warnings.
+    "-misc-include-cleaner",
+
     // This check implements detection of local variables which could be declared
     // as const but are not.
     "-misc-const-correctness",
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index ab0ab90..49d13ca 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -22,7 +22,6 @@
 checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
                   --config_xml checkstyle.xml
                   -fw android/app/src/com/android/bluetooth/
-                      android/app/lib/mapapi/com/android/bluetooth/mapapi/
                       android/app/tests/src/com/android/bluetooth/
                       framework/
                       service/
diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
index de37a5b..20db690 100644
--- a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -17,7 +17,6 @@
 package com.android.bluetooth.a2dp;
 
 import static android.Manifest.permission.BLUETOOTH_CONNECT;
-import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
 import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
 import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
 import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
@@ -30,7 +29,6 @@
 import static java.util.Objects.requireNonNullElseGet;
 
 import android.annotation.NonNull;
-import android.annotation.RequiresPermission;
 import android.bluetooth.BluetoothA2dp;
 import android.bluetooth.BluetoothA2dp.OptionalCodecsPreferenceStatus;
 import android.bluetooth.BluetoothA2dp.OptionalCodecsSupportStatus;
@@ -850,10 +848,7 @@
      *     BluetoothA2dp#DYNAMIC_BUFFER_SUPPORT_A2DP_OFFLOAD}, {@link
      *     BluetoothA2dp#DYNAMIC_BUFFER_SUPPORT_A2DP_SOFTWARE_ENCODING}.
      */
-    @RequiresPermission(BLUETOOTH_PRIVILEGED)
     public int getDynamicBufferSupport() {
-        enforceCallingOrSelfPermission(
-                BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission");
         return mAdapterService.getDynamicBufferSupport();
     }
 
@@ -862,10 +857,7 @@
      *
      * @return BufferConstraints
      */
-    @RequiresPermission(BLUETOOTH_PRIVILEGED)
     public BufferConstraints getBufferConstraints() {
-        enforceCallingOrSelfPermission(
-                BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission");
         return mAdapterService.getBufferConstraints();
     }
 
@@ -876,10 +868,7 @@
      * @param value buffer millis
      * @return true if the settings is successful, false otherwise
      */
-    @RequiresPermission(BLUETOOTH_PRIVILEGED)
     public boolean setBufferLengthMillis(int codec, int value) {
-        enforceCallingOrSelfPermission(
-                BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission");
         return mAdapterService.setBufferLengthMillis(codec, value);
     }
 
diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpServiceBinder.java b/android/app/src/com/android/bluetooth/a2dp/A2dpServiceBinder.java
index da8aaae..24a7c1c 100644
--- a/android/app/src/com/android/bluetooth/a2dp/A2dpServiceBinder.java
+++ b/android/app/src/com/android/bluetooth/a2dp/A2dpServiceBinder.java
@@ -311,6 +311,7 @@
             return BluetoothA2dp.DYNAMIC_BUFFER_SUPPORT_NONE;
         }
 
+        service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
         return service.getDynamicBufferSupport();
     }
 
@@ -321,6 +322,7 @@
             return null;
         }
 
+        service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
         return service.getBufferConstraints();
     }
 
@@ -331,6 +333,7 @@
             return false;
         }
 
+        service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
         return service.setBufferLengthMillis(codec, value);
     }
 }
diff --git a/android/app/src/com/android/bluetooth/bass_client/BaseData.java b/android/app/src/com/android/bluetooth/bass_client/BaseData.java
index 200bfe7..224b75d 100644
--- a/android/app/src/com/android/bluetooth/bass_client/BaseData.java
+++ b/android/app/src/com/android/bluetooth/bass_client/BaseData.java
@@ -159,7 +159,7 @@
                 offset = pair2.second;
             }
         }
-        consolidateBaseOfLevelTwo(levelTwo, levelThree);
+        consolidateBaseOfLevels(levelTwo, levelThree);
         return new BaseData(levelOne, levelTwo, levelThree, numOfBISIndices);
     }
 
@@ -256,26 +256,16 @@
         return new Pair<BaseInformation, Integer>(node, offset);
     }
 
-    static void consolidateBaseOfLevelTwo(
+    private static void consolidateBaseOfLevels(
             List<BaseInformation> levelTwo, List<BaseInformation> levelThree) {
-        int startIdx = 0;
-        int children = 0;
-        for (int i = 0; i < levelTwo.size(); i++) {
-            startIdx = startIdx + children;
-            children = children + levelTwo.get(i).mNumSubGroups;
-            consolidateBaseOfLevelThree(
-                    levelTwo, levelThree, i, startIdx, levelTwo.get(i).mNumSubGroups);
-        }
-    }
-
-    static void consolidateBaseOfLevelThree(
-            List<BaseInformation> levelTwo,
-            List<BaseInformation> levelThree,
-            int parentSubgroup,
-            int startIdx,
-            int numNodes) {
-        for (int i = startIdx; i < startIdx + numNodes || i < levelThree.size(); i++) {
-            levelThree.get(i).mSubGroupId = levelTwo.get(parentSubgroup).mSubGroupId;
+        int currentIdx = 0;
+        for (BaseInformation baseTwo : levelTwo) {
+            int endIdx = Math.min(currentIdx + baseTwo.mNumSubGroups, levelThree.size());
+            // Assign subgroupId to levelThree base
+            for (int i = currentIdx; i < endIdx; i++) {
+                levelThree.get(i).mSubGroupId = baseTwo.mSubGroupId;
+            }
+            currentIdx = endIdx;
         }
     }
 
diff --git a/android/app/src/com/android/bluetooth/hfpclient/HfpClientCall.java b/android/app/src/com/android/bluetooth/hfpclient/HfpClientCall.java
index 47dfe2b..6344e74 100644
--- a/android/app/src/com/android/bluetooth/hfpclient/HfpClientCall.java
+++ b/android/app/src/com/android/bluetooth/hfpclient/HfpClientCall.java
@@ -18,6 +18,7 @@
 
 import static android.bluetooth.BluetoothUtils.writeStringToParcel;
 
+import android.annotation.NonNull;
 import android.bluetooth.BluetoothDevice;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -273,7 +274,7 @@
     }
 
     /** {@link Parcelable.Creator} interface implementation. */
-    public static final @android.annotation.NonNull Parcelable.Creator<HfpClientCall> CREATOR =
+    public static final @NonNull Parcelable.Creator<HfpClientCall> CREATOR =
             new Parcelable.Creator<HfpClientCall>() {
                 @Override
                 public HfpClientCall createFromParcel(Parcel in) {
diff --git a/android/app/src/com/android/bluetooth/vc/VolumeControlService.java b/android/app/src/com/android/bluetooth/vc/VolumeControlService.java
index a3789a5..48112e0 100644
--- a/android/app/src/com/android/bluetooth/vc/VolumeControlService.java
+++ b/android/app/src/com/android/bluetooth/vc/VolumeControlService.java
@@ -29,8 +29,6 @@
 import static android.bluetooth.IBluetoothLeAudio.LE_AUDIO_GROUP_ID_INVALID;
 import static android.bluetooth.IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME;
 
-import static com.android.bluetooth.flags.Flags.vcpDeviceVolumeApiImprovements;
-
 import static java.util.Objects.requireNonNull;
 import static java.util.Objects.requireNonNullElseGet;
 
@@ -550,12 +548,9 @@
             mDeviceVolumeCache.put(device, volume);
             mNativeInterface.setVolume(device, volume);
 
-            if (vcpDeviceVolumeApiImprovements()) {
-                // We only receive the volume change and mute state needs to be acquired manually
-                Boolean isStreamMute =
-                        mAudioManager.isStreamMute(getBluetoothContextualVolumeStream());
-                adjustDeviceMute(device, volume, isStreamMute);
-            }
+            // We only receive the volume change and mute state needs to be acquired manually
+            Boolean isStreamMute = mAudioManager.isStreamMute(getBluetoothContextualVolumeStream());
+            adjustDeviceMute(device, volume, isStreamMute);
         }
     }
 
@@ -597,10 +592,8 @@
 
         synchronized (mDeviceVolumeCache) {
             mGroupVolumeCache.put(groupId, volume);
-            if (vcpDeviceVolumeApiImprovements()) {
-                for (BluetoothDevice dev : getGroupDevices(groupId)) {
-                    mDeviceVolumeCache.put(dev, volume);
-                }
+            for (BluetoothDevice dev : getGroupDevices(groupId)) {
+                mDeviceVolumeCache.put(dev, volume);
             }
         }
         mNativeInterface.setGroupVolume(groupId, volume);
@@ -634,7 +627,7 @@
                 Log.i(TAG, "Unmute the group " + groupId);
                 unmuteGroup(groupId);
             }
-        } else if (vcpDeviceVolumeApiImprovements()) {
+        } else {
             for (BluetoothDevice device : getGroupDevices(groupId)) {
                 adjustDeviceMute(device, volume, isStreamMute);
             }
@@ -648,24 +641,20 @@
      * @return the cached volume
      */
     public int getGroupVolume(int groupId) {
-        if (vcpDeviceVolumeApiImprovements()) {
-            synchronized (mDeviceVolumeCache) {
-                Integer volume = mGroupVolumeCache.get(groupId);
+        synchronized (mDeviceVolumeCache) {
+            Integer volume = mGroupVolumeCache.get(groupId);
+            if (volume != null) {
+                return volume;
+            }
+            Log.d(TAG, "No group volume available");
+            for (BluetoothDevice device : getGroupDevices(groupId)) {
+                volume = mDeviceVolumeCache.get(device);
                 if (volume != null) {
+                    Log.w(TAG, "Volume taken from device: " + device);
                     return volume;
                 }
-                Log.d(TAG, "No group volume available");
-                for (BluetoothDevice device : getGroupDevices(groupId)) {
-                    volume = mDeviceVolumeCache.get(device);
-                    if (volume != null) {
-                        Log.w(TAG, "Volume taken from device: " + device);
-                        return volume;
-                    }
-                }
-                return VOLUME_CONTROL_UNKNOWN_VOLUME;
             }
-        } else {
-            return mGroupVolumeCache.getOrDefault(groupId, VOLUME_CONTROL_UNKNOWN_VOLUME);
+            return VOLUME_CONTROL_UNKNOWN_VOLUME;
         }
     }
 
@@ -676,17 +665,13 @@
      * @return the cached volume
      */
     public int getDeviceVolume(BluetoothDevice device) {
-        if (vcpDeviceVolumeApiImprovements()) {
-            synchronized (mDeviceVolumeCache) {
-                Integer volume = mDeviceVolumeCache.get(device);
-                if (volume != null) {
-                    return volume;
-                }
-                return mGroupVolumeCache.getOrDefault(
-                        getGroupId(device), VOLUME_CONTROL_UNKNOWN_VOLUME);
+        synchronized (mDeviceVolumeCache) {
+            Integer volume = mDeviceVolumeCache.get(device);
+            if (volume != null) {
+                return volume;
             }
-        } else {
-            return mDeviceVolumeCache.getOrDefault(device, VOLUME_CONTROL_UNKNOWN_VOLUME);
+            return mGroupVolumeCache.getOrDefault(
+                    getGroupId(device), VOLUME_CONTROL_UNKNOWN_VOLUME);
         }
     }
 
@@ -736,22 +721,18 @@
      * @return mute status
      */
     public Boolean getGroupMute(int groupId) {
-        if (vcpDeviceVolumeApiImprovements()) {
-            synchronized (mDeviceMuteCache) {
-                Boolean isMute = mGroupMuteCache.get(groupId);
+        synchronized (mDeviceMuteCache) {
+            Boolean isMute = mGroupMuteCache.get(groupId);
+            if (isMute != null) {
+                return isMute;
+            }
+            for (BluetoothDevice device : getGroupDevices(groupId)) {
+                isMute = mDeviceMuteCache.get(device);
                 if (isMute != null) {
                     return isMute;
                 }
-                for (BluetoothDevice device : getGroupDevices(groupId)) {
-                    isMute = mDeviceMuteCache.get(device);
-                    if (isMute != null) {
-                        return isMute;
-                    }
-                }
-                return false;
             }
-        } else {
-            return mGroupMuteCache.getOrDefault(groupId, false);
+            return false;
         }
     }
 
@@ -864,32 +845,16 @@
         }
 
         // If group volume has already changed, the new group member should set it
-        if (vcpDeviceVolumeApiImprovements()) {
-            int volume = getDeviceVolume(device);
-            if (volume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
-                Log.i(TAG, "Setting device/group volume:" + volume + " to the device:" + device);
-                setDeviceVolume(device, volume, false);
-                Boolean isDeviceMuted = getMute(device);
-                Log.i(TAG, "Setting mute:" + isDeviceMuted + " to " + device);
-                if (isDeviceMuted) {
-                    mute(device);
-                } else {
-                    unmute(device);
-                }
-            }
-        } else {
-            Integer groupVolume = getGroupVolume(groupId);
-            if (groupVolume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
-                Log.i(TAG, "Setting value:" + groupVolume + " to " + device);
-                mNativeInterface.setVolume(device, groupVolume);
-            }
-
-            Boolean isGroupMuted = getGroupMute(groupId);
-            Log.i(TAG, "Setting mute:" + isGroupMuted + " to " + device);
-            if (isGroupMuted) {
-                mNativeInterface.mute(device);
+        int volume = getDeviceVolume(device);
+        if (volume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
+            Log.i(TAG, "Setting device/group volume:" + volume + " to the device:" + device);
+            setDeviceVolume(device, volume, false);
+            Boolean isDeviceMuted = getMute(device);
+            Log.i(TAG, "Setting mute:" + isDeviceMuted + " to " + device);
+            if (isDeviceMuted) {
+                mute(device);
             } else {
-                mNativeInterface.unmute(device);
+                unmute(device);
             }
         }
     }
@@ -914,11 +879,9 @@
         synchronized (mDeviceVolumeCache) {
             mGroupVolumeCache.put(groupId, volume);
             mGroupMuteCache.put(groupId, mute);
-            if (vcpDeviceVolumeApiImprovements()) {
-                for (BluetoothDevice dev : getGroupDevices(groupId)) {
-                    mDeviceVolumeCache.put(dev, volume);
-                    mDeviceMuteCache.put(dev, mute);
-                }
+            for (BluetoothDevice dev : getGroupDevices(groupId)) {
+                mDeviceVolumeCache.put(dev, volume);
+                mDeviceMuteCache.put(dev, mute);
             }
         }
 
@@ -1004,56 +967,38 @@
             if (((flags & VOLUME_FLAGS_PERSISTED_USER_SET_VOLUME_MASK) == 0x01)
                     && (getConnectedDevices(groupId).size() == 1)) {
                 Log.i(TAG, "Setting device: " + device + " volume: " + volume + " to the system");
-                if (vcpDeviceVolumeApiImprovements()) {
-                    // Ignore volume from AF because persisted volume was used
-                    setIgnoreSetVolumeFromAfFlag(true);
-                }
+                // Ignore volume from AF because persisted volume was used
+                setIgnoreSetVolumeFromAfFlag(true);
                 updateGroupCacheAndAudioSystem(groupId, volume, mute, false);
                 return;
             }
 
             // Reset flag is used
-            if (vcpDeviceVolumeApiImprovements()) {
-                int deviceVolume = getDeviceVolume(device);
-                if (deviceVolume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
-                    Log.i(
-                            TAG,
-                            "Setting device/group volume: "
-                                    + deviceVolume
-                                    + " to the device: "
-                                    + device);
-                    setDeviceVolume(device, deviceVolume, false);
-                    Boolean isDeviceMuted = getMute(device);
-                    Log.i(TAG, "Setting mute:" + isDeviceMuted + " to " + device);
-                    if (isDeviceMuted) {
-                        mute(device);
-                    } else {
-                        unmute(device);
-                    }
-                    if (getConnectedDevices(groupId).size() == 1) {
-                        // Ignore volume from AF because cached volume was used
-                        setIgnoreSetVolumeFromAfFlag(true);
-                    }
+            int deviceVolume = getDeviceVolume(device);
+            if (deviceVolume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
+                Log.i(
+                        TAG,
+                        "Setting device/group volume: "
+                                + deviceVolume
+                                + " to the device: "
+                                + device);
+                setDeviceVolume(device, deviceVolume, false);
+                Boolean isDeviceMuted = getMute(device);
+                Log.i(TAG, "Setting mute:" + isDeviceMuted + " to " + device);
+                if (isDeviceMuted) {
+                    mute(device);
                 } else {
-                    Log.i(TAG, "Waiting for volume from AF to set to the device: " + device);
-                    if (getConnectedDevices(groupId).size() == 1) {
-                        // Clear ignore flag as volume from AF is needed
-                        setIgnoreSetVolumeFromAfFlag(false);
-                    }
+                    unmute(device);
+                }
+                if (getConnectedDevices(groupId).size() == 1) {
+                    // Ignore volume from AF because cached volume was used
+                    setIgnoreSetVolumeFromAfFlag(true);
                 }
             } else {
-                int groupVolume = getGroupVolume(groupId);
-                if (groupVolume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
-                    Log.i(
-                            TAG,
-                            "Setting group volume: " + groupVolume + " to the device: " + device);
-                    setGroupVolume(groupId, groupVolume);
-                } else {
-                    int systemVolume = getBleVolumeFromCurrentStream();
-                    Log.i(
-                            TAG,
-                            "Setting system volume: " + systemVolume + " to the group: " + groupId);
-                    setGroupVolume(groupId, systemVolume);
+                Log.i(TAG, "Waiting for volume from AF to set to the device: " + device);
+                if (getConnectedDevices(groupId).size() == 1) {
+                    // Clear ignore flag as volume from AF is needed
+                    setIgnoreSetVolumeFromAfFlag(false);
                 }
             }
 
@@ -1079,53 +1024,6 @@
             }
         }
 
-        if (!vcpDeviceVolumeApiImprovements() && !isAutonomous) {
-            /* If the change is triggered by Android device, the stream is already changed.
-             * However it might be called with isAutonomous, one the first read of after
-             * reconnection. Make sure device has group volume. Also it might happen that
-             * remote side send us wrong value - lets check it.
-             */
-
-            int groupVolume = getGroupVolume(groupId);
-            Boolean groupMute = getGroupMute(groupId);
-
-            if ((groupVolume == volume) && (groupMute == mute)) {
-                Log.i(TAG, " Volume:" + volume + ", mute:" + mute + " confirmed by remote side.");
-                return;
-            }
-
-            if (device != null) {
-                // Correct the volume level only if device was already reported as connected.
-                boolean can_change_volume = false;
-                synchronized (mStateMachines) {
-                    VolumeControlStateMachine sm = mStateMachines.get(device);
-                    if (sm != null) {
-                        can_change_volume = sm.isConnected();
-                    }
-                }
-
-                if (can_change_volume && (groupVolume != volume)) {
-                    Log.i(TAG, "Setting value:" + groupVolume + " to " + device);
-                    mNativeInterface.setVolume(device, groupVolume);
-                }
-                if (can_change_volume && (groupMute != mute)) {
-                    Log.i(TAG, "Setting mute:" + groupMute + " to " + device);
-                    if (groupMute) {
-                        mNativeInterface.mute(device);
-                    } else {
-                        mNativeInterface.unmute(device);
-                    }
-                }
-            } else {
-                Log.e(
-                        TAG,
-                        "Volume changed did not succeed. Volume: "
-                                + volume
-                                + " expected volume: "
-                                + groupVolume);
-            }
-        }
-
         if (isAutonomous && device == null) {
             /* Received group notification for autonomous change. Update cache and audio system. */
             updateGroupCacheAndAudioSystem(groupId, volume, mute, true);
@@ -1565,15 +1463,8 @@
             int broadcastVolume = VOLUME_CONTROL_UNKNOWN_VOLUME;
             if (volume.isPresent()) {
                 broadcastVolume = volume.get();
-                if (!vcpDeviceVolumeApiImprovements()) {
-                    mDeviceVolumeCache.put(dev, broadcastVolume);
-                }
             } else {
                 broadcastVolume = getDeviceVolume(dev);
-                if (!vcpDeviceVolumeApiImprovements()
-                        && broadcastVolume == VOLUME_CONTROL_UNKNOWN_VOLUME) {
-                    broadcastVolume = getGroupVolume(getGroupId(dev));
-                }
             }
             int n = callbacks.beginBroadcast();
             for (int i = 0; i < n; i++) {
@@ -1667,22 +1558,6 @@
                 Log.d(TAG, device + " is unbond. Remove state machine");
                 removeStateMachine(device);
             }
-        } else if (!vcpDeviceVolumeApiImprovements() && toState == STATE_CONNECTED) {
-            // Restore the group volume if it was changed while the device was not yet connected.
-            Integer groupId = getGroupId(device);
-            if (groupId != GROUP_ID_INVALID) {
-                Integer groupVolume = getGroupVolume(groupId);
-                if (groupVolume != VOLUME_CONTROL_UNKNOWN_VOLUME) {
-                    mNativeInterface.setVolume(device, groupVolume);
-                }
-
-                Boolean groupMute = getGroupMute(groupId);
-                if (groupMute) {
-                    mNativeInterface.mute(device);
-                } else {
-                    mNativeInterface.unmute(device);
-                }
-            }
         }
         mAdapterService.handleProfileConnectionStateChange(
                 BluetoothProfile.VOLUME_CONTROL, device, fromState, toState);
@@ -1724,17 +1599,15 @@
                             + getGroupMute(entry.getKey()));
         }
 
-        if (vcpDeviceVolumeApiImprovements()) {
-            for (Map.Entry<BluetoothDevice, Integer> entry : mDeviceVolumeCache.entrySet()) {
-                ProfileService.println(
-                        sb,
-                        "    Device: "
-                                + entry.getKey()
-                                + " volume: "
-                                + entry.getValue()
-                                + ", mute: "
-                                + getMute(entry.getKey()));
-            }
+        for (Map.Entry<BluetoothDevice, Integer> entry : mDeviceVolumeCache.entrySet()) {
+            ProfileService.println(
+                    sb,
+                    "    Device: "
+                            + entry.getKey()
+                            + " volume: "
+                            + entry.getValue()
+                            + ", mute: "
+                            + getMute(entry.getKey()));
         }
     }
 }
diff --git a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BaseDataTest.java b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BaseDataTest.java
index 2b644a3..edc427f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BaseDataTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BaseDataTest.java
@@ -466,4 +466,249 @@
         assertThat(level.mIndex).isEqualTo(4);
         assertThat(level.mCodecConfigLength).isEqualTo(3);
     }
+
+    @Test
+    public void parseBaseData_multiple_subgroup() {
+        assertThrows(IllegalArgumentException.class, () -> BaseData.parseBaseData(null));
+
+        byte[] serviceData =
+                new byte[] {
+                    // LEVEL 1
+                    (byte) 0x40,
+                    (byte) 0x9C,
+                    (byte) 0x00, // mPresentationDelay
+                    (byte) 0x03, // mNumSubGroups
+                    // LEVEL 2
+                    (byte) 0x01, // mNumBis
+                    (byte) 0x06,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00, // LC3
+                    (byte) 0x0A, // mCodecConfigLength
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x04,
+                    (byte) 0x28,
+                    (byte) 0x00,
+                    (byte) 0x04, // mMetaDataLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x00, // mMetaData
+                    // LEVEL 3
+                    (byte) 0x01, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+
+                    // LEVEL 2
+                    (byte) 0x01, // mNumBis
+                    (byte) 0x06,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00, // LC3
+                    (byte) 0x0A, // mCodecConfigLength
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x04,
+                    (byte) 0x28,
+                    (byte) 0x00,
+                    (byte) 0x04, // mMetaDataLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x00, // mMetaData
+                    // LEVEL 3
+                    (byte) 0x02, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+
+                    // LEVEL 2
+                    (byte) 0x02, // mNumBis
+                    (byte) 0x06,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00, // LC3
+                    (byte) 0x0A, // mCodecConfigLength
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x04,
+                    (byte) 0x28,
+                    (byte) 0x00,
+                    (byte) 0x04, // mMetaDataLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x00, // mMetaData
+                    // LEVEL 3
+                    (byte) 0x03, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+                    (byte) 0x03, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+                };
+
+        BaseData data = BaseData.parseBaseData(serviceData);
+        BaseData.BaseInformation level = data.levelOne();
+        assertThat(level.mPresentationDelay)
+                .isEqualTo(new byte[] {(byte) 0x40, (byte) 0x9C, (byte) 0x00});
+        assertThat(level.mNumSubGroups).isEqualTo(3);
+
+        assertThat(data.levelTwo()).hasSize(3);
+        level = data.levelTwo().get(0);
+        assertThat(level.mNumSubGroups).isEqualTo(1);
+        assertThat(level.mCodecId).isEqualTo(new byte[] {0x06, 0x00, 0x00, 0x00, 0x00});
+        assertThat(level.mCodecConfigLength).isEqualTo(10);
+        assertThat(level.mMetaDataLength).isEqualTo(4);
+        level = data.levelTwo().get(1);
+        assertThat(level.mNumSubGroups).isEqualTo(1);
+        assertThat(level.mCodecConfigLength).isEqualTo(10);
+        assertThat(level.mMetaDataLength).isEqualTo(4);
+        level = data.levelTwo().get(2);
+        assertThat(level.mNumSubGroups).isEqualTo(2);
+        assertThat(level.mCodecConfigLength).isEqualTo(10);
+        assertThat(level.mMetaDataLength).isEqualTo(4);
+
+        assertThat(data.levelThree()).hasSize(4);
+        level = data.levelThree().get(0);
+        assertThat(level.mIndex).isEqualTo(1);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+        level = data.levelThree().get(1);
+        assertThat(level.mIndex).isEqualTo(2);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+        level = data.levelThree().get(2);
+        assertThat(level.mIndex).isEqualTo(3);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+    }
+
+    @Test
+    public void parseBaseData_multiple_bis() {
+        assertThrows(IllegalArgumentException.class, () -> BaseData.parseBaseData(null));
+
+        byte[] serviceData =
+                new byte[] {
+                    // LEVEL 1
+                    (byte) 0x40,
+                    (byte) 0x9C,
+                    (byte) 0x00, // mPresentationDelay
+                    (byte) 0x02, // mNumSubGroups
+                    // LEVEL 2
+                    (byte) 0x02, // mNumBis
+                    (byte) 0x06,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00, // LC3
+                    (byte) 0x0A, // mCodecConfigLength
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x04,
+                    (byte) 0x28,
+                    (byte) 0x00,
+                    (byte) 0x04, // mMetaDataLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x00, // mMetaData
+                    // LEVEL 3
+                    (byte) 0x01, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+                    (byte) 0x02, // mIndex
+                    (byte) 0x03, // mCodecConfigLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01, // opaque vendor data
+
+                    // LEVEL 2
+                    (byte) 0x04, // mNumBis
+                    (byte) 0x06,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00,
+                    (byte) 0x00, // LC3
+                    (byte) 0x0A, // mCodecConfigLength
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x02,
+                    (byte) 0x01,
+                    (byte) 0x03,
+                    (byte) 0x04,
+                    (byte) 0x28,
+                    (byte) 0x00,
+                    (byte) 0x03, // mMetaDataLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01, // mMetaData
+                    // LEVEL 3
+                    (byte) 0x03, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+                    (byte) 0x04, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+                    (byte) 0x05, // mIndex
+                    (byte) 0x03, // mCodecConfigLength
+                    (byte) 0x03,
+                    (byte) 0x02,
+                    (byte) 0x01, // opaque vendor data
+                    (byte) 0x06, // mIndex
+                    (byte) 0x00, // mCodecConfigLength
+                };
+
+        BaseData data = BaseData.parseBaseData(serviceData);
+        BaseData.BaseInformation level = data.levelOne();
+        assertThat(level.mPresentationDelay)
+                .isEqualTo(new byte[] {(byte) 0x40, (byte) 0x9C, (byte) 0x00});
+        assertThat(level.mNumSubGroups).isEqualTo(2);
+
+        assertThat(data.levelTwo()).hasSize(2);
+        level = data.levelTwo().get(0);
+        assertThat(level.mNumSubGroups).isEqualTo(2);
+        assertThat(level.mCodecId).isEqualTo(new byte[] {0x06, 0x00, 0x00, 0x00, 0x00});
+        assertThat(level.mCodecConfigLength).isEqualTo(10);
+        assertThat(level.mMetaDataLength).isEqualTo(4);
+        level = data.levelTwo().get(1);
+        assertThat(level.mNumSubGroups).isEqualTo(4);
+        assertThat(level.mCodecConfigLength).isEqualTo(10);
+        assertThat(level.mMetaDataLength).isEqualTo(3);
+
+        assertThat(data.levelThree()).hasSize(6);
+        level = data.levelThree().get(0);
+        assertThat(level.mIndex).isEqualTo(1);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+        level = data.levelThree().get(1);
+        assertThat(level.mIndex).isEqualTo(2);
+        assertThat(level.mCodecConfigLength).isEqualTo(3);
+        level = data.levelThree().get(2);
+        assertThat(level.mIndex).isEqualTo(3);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+        level = data.levelThree().get(3);
+        assertThat(level.mIndex).isEqualTo(4);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+        level = data.levelThree().get(4);
+        assertThat(level.mIndex).isEqualTo(5);
+        assertThat(level.mCodecConfigLength).isEqualTo(3);
+        level = data.levelThree().get(5);
+        assertThat(level.mIndex).isEqualTo(6);
+        assertThat(level.mCodecConfigLength).isEqualTo(0);
+    }
 }
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapContractTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContractTest.java
similarity index 100%
rename from android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapContractTest.java
rename to android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContractTest.java
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapapi/OWNERS b/android/app/tests/unit/src/com/android/bluetooth/mapapi/OWNERS
deleted file mode 100644
index 8f87191..0000000
--- a/android/app/tests/unit/src/com/android/bluetooth/mapapi/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_content
\ No newline at end of file
diff --git a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java
index 07b5653..c0feb6f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java
@@ -61,7 +61,6 @@
 import android.media.AudioManager;
 import android.os.Binder;
 import android.os.ParcelUuid;
-import android.platform.test.annotations.DisableFlags;
 import android.platform.test.annotations.EnableFlags;
 import android.platform.test.flag.junit.SetFlagsRule;
 
@@ -469,25 +468,6 @@
     }
 
     @Test
-    @DisableFlags(Flags.FLAG_VCP_DEVICE_VOLUME_API_IMPROVEMENTS)
-    public void volumeCacheDeprecated() {
-        int groupId = 1;
-        int volume = 6;
-
-        assertThat(mService.getGroupVolume(groupId)).isEqualTo(-1);
-        mService.setGroupVolume(groupId, volume);
-
-        assertThat(mService.getGroupVolume(groupId)).isEqualTo(volume);
-
-        volume = 10;
-        // Send autonomous volume change.
-        generateVolumeStateChanged(null, groupId, volume, 0, false, true);
-
-        assertThat(mService.getGroupVolume(groupId)).isEqualTo(volume);
-    }
-
-    @Test
-    @EnableFlags(Flags.FLAG_VCP_DEVICE_VOLUME_API_IMPROVEMENTS)
     public void volumeCache() {
         int groupId = 1;
         int groupVolume = 6;
@@ -568,31 +548,6 @@
     }
 
     @Test
-    @DisableFlags(Flags.FLAG_VCP_DEVICE_VOLUME_API_IMPROVEMENTS)
-    public void muteCacheDeprecated() {
-        int groupId = 1;
-        int volume = 6;
-
-        assertThat(mService.getGroupMute(groupId)).isFalse();
-
-        // Send autonomous volume change
-        generateVolumeStateChanged(null, groupId, volume, 0, false, true);
-
-        // Mute
-        mService.muteGroup(groupId);
-        assertThat(mService.getGroupMute(groupId)).isTrue();
-
-        // Make sure the volume is kept even when muted
-        assertThat(mService.getGroupVolume(groupId)).isEqualTo(volume);
-
-        // Send autonomous unmute
-        generateVolumeStateChanged(null, groupId, volume, 0, false, true);
-
-        assertThat(mService.getGroupMute(groupId)).isFalse();
-    }
-
-    @Test
-    @EnableFlags(Flags.FLAG_VCP_DEVICE_VOLUME_API_IMPROVEMENTS)
     public void muteCache() {
         int groupId = 1;
         int groupVolume = 6;
@@ -727,12 +682,10 @@
         inOrderAudio.verify(mAudioManager, never()).setStreamVolume(anyInt(), anyInt(), anyInt());
 
         InOrder inOrderNative = inOrder(mNativeInterface);
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            // AF always call setVolume via LeAudioService at first connected remote from group
-            mService.setGroupVolume(groupId, 123);
-            // It should be ignored and not set to native
-            inOrderNative.verify(mNativeInterface, never()).setGroupVolume(anyInt(), anyInt());
-        }
+        // AF always call setVolume via LeAudioService at first connected remote from group
+        mService.setGroupVolume(groupId, 123);
+        // It should be ignored and not set to native
+        inOrderNative.verify(mNativeInterface, never()).setGroupVolume(anyInt(), anyInt());
 
         // Make device Active now. This will trigger setting volume to AF
         when(mLeAudioService.getActiveGroupId()).thenReturn(groupId);
@@ -756,15 +709,10 @@
                 initialAutonomousFlag);
 
         inOrderAudio.verify(mAudioManager, never()).setStreamVolume(anyInt(), anyInt(), anyInt());
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(volumeDevice));
-        } else {
-            inOrderNative.verify(mNativeInterface).setGroupVolume(eq(groupId), eq(volumeDevice));
-        }
+        inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(volumeDevice));
     }
 
     @Test
-    @EnableFlags(Flags.FLAG_VCP_DEVICE_VOLUME_API_IMPROVEMENTS)
     public void testClearingSetVolumeFromAF() {
         int groupId = 1;
         int groupId2 = 2;
@@ -860,10 +808,8 @@
         InOrder inOrderAudio = inOrder(mAudioManager);
         inOrderAudio.verify(mAudioManager, never()).setStreamVolume(anyInt(), anyInt(), anyInt());
         InOrder inOrderNative = inOrder(mNativeInterface);
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            // AF always call setVolume via LeAudioService at first connected remote from group
-            mService.setGroupVolume(groupId, expectedAfVol);
-        }
+        // AF always call setVolume via LeAudioService at first connected remote from group
+        mService.setGroupVolume(groupId, expectedAfVol);
         inOrderNative.verify(mNativeInterface).setGroupVolume(eq(groupId), eq(expectedAfVol));
 
         // Make device Active now. This will trigger setting volume to AF
@@ -886,11 +832,7 @@
                 initialAutonomousFlag);
 
         inOrderAudio.verify(mAudioManager, never()).setStreamVolume(anyInt(), anyInt(), anyInt());
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(expectedAfVol));
-        } else {
-            inOrderNative.verify(mNativeInterface).setGroupVolume(eq(groupId), eq(expectedAfVol));
-        }
+        inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(expectedAfVol));
     }
 
     /** Test if phone will set volume which is read from the buds */
@@ -934,12 +876,7 @@
         assertThat(mService.getDevices()).contains(mDeviceTwo);
         generateVolumeStateChanged(mDeviceTwo, LE_AUDIO_GROUP_ID_INVALID, volume_2, 0, false, true);
 
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(groupVolume));
-        } else {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(groupVolume));
-            inOrderNative.verify(mNativeInterface).setGroupVolume(eq(groupId), eq(groupVolume));
-        }
+        inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(groupVolume));
     }
 
     /**
@@ -1013,14 +950,8 @@
         generateVolumeStateChanged(mDeviceTwo, LE_AUDIO_GROUP_ID_INVALID, volume_2, 0, false, true);
 
         // Check if new device was muted
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(volume));
-            inOrderNative.verify(mNativeInterface).mute(eq(mDeviceTwo));
-        } else {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(volume));
-            inOrderNative.verify(mNativeInterface).mute(eq(mDeviceTwo));
-            inOrderNative.verify(mNativeInterface).setGroupVolume(eq(groupId), eq(volume));
-        }
+        inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(volume));
+        inOrderNative.verify(mNativeInterface).mute(eq(mDeviceTwo));
     }
 
     /**
@@ -1265,12 +1196,7 @@
         generateVolumeStateChanged(
                 mDeviceTwo, LE_AUDIO_GROUP_ID_INVALID, groupVolume, 0, false, true);
 
-        if (Flags.vcpDeviceVolumeApiImprovements()) {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(groupVolume));
-        } else {
-            inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(groupVolume));
-            inOrderNative.verify(mNativeInterface).setGroupVolume(eq(groupId), eq(groupVolume));
-        }
+        inOrderNative.verify(mNativeInterface).setVolume(eq(mDeviceTwo), eq(groupVolume));
 
         // Generate events for both devices
         generateDeviceOffsetChangedMessageFromNative(mDevice, 1, 100);
diff --git a/android/pandora/mmi2grpc/mmi2grpc/_helpers.py b/android/pandora/mmi2grpc/mmi2grpc/_helpers.py
index c973092..9809283 100644
--- a/android/pandora/mmi2grpc/mmi2grpc/_helpers.py
+++ b/android/pandora/mmi2grpc/mmi2grpc/_helpers.py
@@ -24,6 +24,10 @@
 DOCSTRING_WIDTH = 80 - 8  # 80 cols - 8 indentation spaces
 
 
+def normalize(desc):
+    return re.sub('\s+', ' ', desc).strip()
+
+
 def assert_description(f):
     """Decorator which verifies the description of a PTS MMI implementation.
 
@@ -40,11 +44,8 @@
 
     @functools.wraps(f)
     def wrapper(*args, **kwargs):
-        description = textwrap.fill(kwargs['description'],
-                                    DOCSTRING_WIDTH,
-                                    replace_whitespace=False)
-        description = ('\n'.join(map(lambda line: line.rstrip(), description.split('\n')))).strip()
-        docstring = textwrap.dedent(f.__doc__ or '').strip()
+        docstring = normalize(textwrap.dedent(f.__doc__))
+        description = normalize(kwargs['description'])
 
         if docstring != description:
             print(f'Expected description of {f.__name__}:')
@@ -76,9 +77,6 @@
             description.
     """
 
-    def normalize(desc):
-        return re.sub('\s+', ' ', desc).strip()
-
     docstring = normalize(textwrap.dedent(f.__doc__))
     regex = re.compile(docstring)
 
diff --git a/android/pandora/test/a2dp_test.py b/android/pandora/test/a2dp_test.py
index 5148216..434be4f 100644
--- a/android/pandora/test/a2dp_test.py
+++ b/android/pandora/test/a2dp_test.py
@@ -616,7 +616,7 @@
         logger.info(f"response: {response}")
 
         # Wait for AVDTP Open from DUT
-        await asyncio.wait_for(avdtp_future, timeout=10.0)
+        await asyncio.wait_for(avdtp_future, timeout=20.0)
 
     @avatar.asynchronous
     async def test_avdt_signaling_channel_connection_collision_case1(self) -> None:
diff --git a/flags/connectivity.aconfig b/flags/connectivity.aconfig
index 738c294..4896af3 100644
--- a/flags/connectivity.aconfig
+++ b/flags/connectivity.aconfig
@@ -8,3 +8,12 @@
     bug: "389274300"
 }
 
+flag {
+    name: "idempotent_direct_connect_add"
+    namespace: "bluetooth"
+    description: "Make direct_connect_add idempotent"
+    bug: "409239278"
+    metadata {
+        purpose: PURPOSE_BUGFIX
+    }
+}
\ No newline at end of file
diff --git a/flags/gap.aconfig b/flags/gap.aconfig
index 777774a..6f1b503 100644
--- a/flags/gap.aconfig
+++ b/flags/gap.aconfig
@@ -2,13 +2,6 @@
 container: "com.android.bt"
 
 flag {
-    name: "encrypted_advertising_data"
-    namespace: "bluetooth"
-    description: "Enable support for the decryption of Encrypted Advertising Data"
-    bug: "308855997"
-}
-
-flag {
     name: "only_start_scan_during_ble_on"
     namespace: "bluetooth"
     description: "Instead of starting scan and gatt in ble_on, only start scan"
diff --git a/flags/hfp.aconfig b/flags/hfp.aconfig
index 3e4659c..3c93699 100644
--- a/flags/hfp.aconfig
+++ b/flags/hfp.aconfig
@@ -132,3 +132,13 @@
         purpose: PURPOSE_BUGFIX
     }
 }
+
+flag {
+    name: "qc_send_error_at_bcc_ibr_disabled"
+    namespace: "bluetooth"
+    description: "QC patch to send an error when HF sends AT+BCC when IBR is disabled"
+    bug: "409845355"
+    metadata {
+        purpose: PURPOSE_BUGFIX
+    }
+}
diff --git a/flags/pairing.aconfig b/flags/pairing.aconfig
index 73f040e..316dfbb 100644
--- a/flags/pairing.aconfig
+++ b/flags/pairing.aconfig
@@ -12,16 +12,6 @@
 }
 
 flag {
-    name: "remove_dup_pairing_response_in_oob_pairing"
-    namespace: "bluetooth"
-    description: "Avoid sending duplicate pairing response when device is in peripheral role & OOB pairing mode chosen"
-    bug: "351948689"
-    metadata {
-        purpose: PURPOSE_BUGFIX
-    }
-}
-
-flag {
     name: "donot_queue_dup_rnr"
     namespace: "bluetooth"
     description: "Avoid queueing second RNR as part of ssp process"
@@ -52,16 +42,6 @@
 }
 
 flag {
-    name: "save_peer_csrk_after_ltk_gen"
-    namespace: "bluetooth"
-    description: "save peer csrk after ltk generated so that right security level is marked as part of peer csrk"
-    bug: "365567905"
-    metadata {
-        purpose: PURPOSE_BUGFIX
-    }
-}
-
-flag {
     name: "wait_for_lea_disc_on_le_acl_stat"
     namespace: "bluetooth"
     description: "Check for LE ACL status before waiting on LEA discovery"
diff --git a/flags/rfcomm.aconfig b/flags/rfcomm.aconfig
index 6a4020e..a46f9f6 100644
--- a/flags/rfcomm.aconfig
+++ b/flags/rfcomm.aconfig
@@ -2,16 +2,6 @@
 container: "com.android.bt"
 
 flag {
-    name: "rfcomm_always_disc_initiator_in_disc_wait_ua"
-    namespace: "bluetooth"
-    description: "Always be the DISC initiator in the DISC_WAIT_UA state to avoid unnecessary hang"
-    bug: "350839022"
-    metadata {
-        purpose: PURPOSE_BUGFIX
-    }
-}
-
-flag {
     name: "allow_free_last_scn"
     namespace: "bluetooth"
     description: "Allow SCN 30 to be freed"
diff --git a/flags/vcp.aconfig b/flags/vcp.aconfig
index 12e55de..b862b9e 100644
--- a/flags/vcp.aconfig
+++ b/flags/vcp.aconfig
@@ -9,16 +9,6 @@
 }
 
 flag {
-    name: "vcp_device_volume_api_improvements"
-    namespace: "bluetooth"
-    description: "Refactor Device Volume API for generic usage"
-    bug: "381507732"
-    metadata {
-        purpose: PURPOSE_BUGFIX
-    }
-}
-
-flag {
     name: "vcp_allow_set_same_volume_if_pending"
     namespace: "bluetooth"
     description: "Allow to set the same volume during already pending operation"
diff --git a/framework/java/android/bluetooth/BluetoothClass.java b/framework/java/android/bluetooth/BluetoothClass.java
index db421b3..186ed4a 100644
--- a/framework/java/android/bluetooth/BluetoothClass.java
+++ b/framework/java/android/bluetooth/BluetoothClass.java
@@ -16,6 +16,7 @@
 
 package android.bluetooth;
 
+import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
 import android.compat.annotation.UnsupportedAppUsage;
@@ -86,7 +87,7 @@
         return 0;
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<BluetoothClass> CREATOR =
+    public static final @NonNull Parcelable.Creator<BluetoothClass> CREATOR =
             new Parcelable.Creator<BluetoothClass>() {
                 public BluetoothClass createFromParcel(Parcel in) {
                     return new BluetoothClass(in.readInt());
diff --git a/framework/java/android/bluetooth/BluetoothLeAudioCodecConfig.java b/framework/java/android/bluetooth/BluetoothLeAudioCodecConfig.java
index 2245383..585cfe0 100644
--- a/framework/java/android/bluetooth/BluetoothLeAudioCodecConfig.java
+++ b/framework/java/android/bluetooth/BluetoothLeAudioCodecConfig.java
@@ -261,35 +261,34 @@
     }
 
     /** {@link Parcelable.Creator} interface implementation. */
-    public static final @android.annotation.NonNull Parcelable.Creator<BluetoothLeAudioCodecConfig>
-            CREATOR =
-                    new Parcelable.Creator<BluetoothLeAudioCodecConfig>() {
-                        public BluetoothLeAudioCodecConfig createFromParcel(Parcel in) {
-                            int codecType = in.readInt();
-                            int codecPriority = in.readInt();
-                            int sampleRate = in.readInt();
-                            int bitsPerSample = in.readInt();
-                            int channelCount = in.readInt();
-                            int frameDuration = in.readInt();
-                            int octetsPerFrame = in.readInt();
-                            int minOctetsPerFrame = in.readInt();
-                            int maxOctetsPerFrame = in.readInt();
-                            return new BluetoothLeAudioCodecConfig(
-                                    codecType,
-                                    codecPriority,
-                                    sampleRate,
-                                    bitsPerSample,
-                                    channelCount,
-                                    frameDuration,
-                                    octetsPerFrame,
-                                    minOctetsPerFrame,
-                                    maxOctetsPerFrame);
-                        }
+    public static final @NonNull Parcelable.Creator<BluetoothLeAudioCodecConfig> CREATOR =
+            new Parcelable.Creator<BluetoothLeAudioCodecConfig>() {
+                public BluetoothLeAudioCodecConfig createFromParcel(Parcel in) {
+                    int codecType = in.readInt();
+                    int codecPriority = in.readInt();
+                    int sampleRate = in.readInt();
+                    int bitsPerSample = in.readInt();
+                    int channelCount = in.readInt();
+                    int frameDuration = in.readInt();
+                    int octetsPerFrame = in.readInt();
+                    int minOctetsPerFrame = in.readInt();
+                    int maxOctetsPerFrame = in.readInt();
+                    return new BluetoothLeAudioCodecConfig(
+                            codecType,
+                            codecPriority,
+                            sampleRate,
+                            bitsPerSample,
+                            channelCount,
+                            frameDuration,
+                            octetsPerFrame,
+                            minOctetsPerFrame,
+                            maxOctetsPerFrame);
+                }
 
-                        public BluetoothLeAudioCodecConfig[] newArray(int size) {
-                            return new BluetoothLeAudioCodecConfig[size];
-                        }
-                    };
+                public BluetoothLeAudioCodecConfig[] newArray(int size) {
+                    return new BluetoothLeAudioCodecConfig[size];
+                }
+            };
 
     @Override
     public void writeToParcel(@NonNull Parcel out, int flags) {
diff --git a/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java b/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java
index 7089529..b6a31bb 100644
--- a/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java
+++ b/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java
@@ -239,17 +239,16 @@
     }
 
     /** {@link Parcelable.Creator} interface implementation. */
-    public static final @android.annotation.NonNull Parcelable.Creator<BluetoothLeAudioCodecStatus>
-            CREATOR =
-                    new Parcelable.Creator<BluetoothLeAudioCodecStatus>() {
-                        public BluetoothLeAudioCodecStatus createFromParcel(Parcel in) {
-                            return new BluetoothLeAudioCodecStatus(in);
-                        }
+    public static final @NonNull Parcelable.Creator<BluetoothLeAudioCodecStatus> CREATOR =
+            new Parcelable.Creator<BluetoothLeAudioCodecStatus>() {
+                public BluetoothLeAudioCodecStatus createFromParcel(Parcel in) {
+                    return new BluetoothLeAudioCodecStatus(in);
+                }
 
-                        public BluetoothLeAudioCodecStatus[] newArray(int size) {
-                            return new BluetoothLeAudioCodecStatus[size];
-                        }
-                    };
+                public BluetoothLeAudioCodecStatus[] newArray(int size) {
+                    return new BluetoothLeAudioCodecStatus[size];
+                }
+            };
 
     /**
      * Flattens the object to a parcel.
diff --git a/framework/java/android/bluetooth/BluetoothSinkAudioPolicy.java b/framework/java/android/bluetooth/BluetoothSinkAudioPolicy.java
index 5ebffbd..c00f5a2 100644
--- a/framework/java/android/bluetooth/BluetoothSinkAudioPolicy.java
+++ b/framework/java/android/bluetooth/BluetoothSinkAudioPolicy.java
@@ -178,20 +178,18 @@
     }
 
     /** {@link Parcelable.Creator} interface implementation. */
-    public static final @android.annotation.NonNull Parcelable.Creator<BluetoothSinkAudioPolicy>
-            CREATOR =
-                    new Parcelable.Creator<BluetoothSinkAudioPolicy>() {
-                        @Override
-                        public BluetoothSinkAudioPolicy createFromParcel(@NonNull Parcel in) {
-                            return new BluetoothSinkAudioPolicy(
-                                    in.readInt(), in.readInt(), in.readInt());
-                        }
+    public static final @NonNull Parcelable.Creator<BluetoothSinkAudioPolicy> CREATOR =
+            new Parcelable.Creator<BluetoothSinkAudioPolicy>() {
+                @Override
+                public BluetoothSinkAudioPolicy createFromParcel(@NonNull Parcel in) {
+                    return new BluetoothSinkAudioPolicy(in.readInt(), in.readInt(), in.readInt());
+                }
 
-                        @Override
-                        public BluetoothSinkAudioPolicy[] newArray(int size) {
-                            return new BluetoothSinkAudioPolicy[size];
-                        }
-                    };
+                @Override
+                public BluetoothSinkAudioPolicy[] newArray(int size) {
+                    return new BluetoothSinkAudioPolicy[size];
+                }
+            };
 
     @Override
     public void writeToParcel(@NonNull Parcel out, int flags) {
diff --git a/framework/java/android/bluetooth/le/AdvertiseData.java b/framework/java/android/bluetooth/le/AdvertiseData.java
index 6c313d8..c50a509 100644
--- a/framework/java/android/bluetooth/le/AdvertiseData.java
+++ b/framework/java/android/bluetooth/le/AdvertiseData.java
@@ -200,7 +200,7 @@
         dest.writeByte((byte) (getIncludeDeviceName() ? 1 : 0));
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<AdvertiseData> CREATOR =
+    public static final @NonNull Parcelable.Creator<AdvertiseData> CREATOR =
             new Creator<AdvertiseData>() {
                 @Override
                 public AdvertiseData[] newArray(int size) {
diff --git a/framework/java/android/bluetooth/le/AdvertiseSettings.java b/framework/java/android/bluetooth/le/AdvertiseSettings.java
index d0ec495..f820cf6 100644
--- a/framework/java/android/bluetooth/le/AdvertiseSettings.java
+++ b/framework/java/android/bluetooth/le/AdvertiseSettings.java
@@ -167,7 +167,7 @@
         dest.writeInt(mAdvertiseDiscoverable ? 1 : 0);
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<AdvertiseSettings> CREATOR =
+    public static final @NonNull Parcelable.Creator<AdvertiseSettings> CREATOR =
             new Creator<AdvertiseSettings>() {
                 @Override
                 public AdvertiseSettings[] newArray(int size) {
diff --git a/framework/java/android/bluetooth/le/AdvertisingSetParameters.java b/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
index b8fa11c..6d740f3 100644
--- a/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
+++ b/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
@@ -356,19 +356,18 @@
         dest.writeInt(mPeerAddressType);
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<AdvertisingSetParameters>
-            CREATOR =
-                    new Creator<AdvertisingSetParameters>() {
-                        @Override
-                        public AdvertisingSetParameters[] newArray(int size) {
-                            return new AdvertisingSetParameters[size];
-                        }
+    public static final @NonNull Parcelable.Creator<AdvertisingSetParameters> CREATOR =
+            new Creator<AdvertisingSetParameters>() {
+                @Override
+                public AdvertisingSetParameters[] newArray(int size) {
+                    return new AdvertisingSetParameters[size];
+                }
 
-                        @Override
-                        public AdvertisingSetParameters createFromParcel(Parcel in) {
-                            return new AdvertisingSetParameters(in);
-                        }
-                    };
+                @Override
+                public AdvertisingSetParameters createFromParcel(Parcel in) {
+                    return new AdvertisingSetParameters(in);
+                }
+            };
 
     /** Builder class for {@link AdvertisingSetParameters}. */
     public static final class Builder {
diff --git a/framework/java/android/bluetooth/le/PeriodicAdvertisingReport.java b/framework/java/android/bluetooth/le/PeriodicAdvertisingReport.java
index 095b046..487d2a9 100644
--- a/framework/java/android/bluetooth/le/PeriodicAdvertisingReport.java
+++ b/framework/java/android/bluetooth/le/PeriodicAdvertisingReport.java
@@ -16,6 +16,7 @@
 
 package android.bluetooth.le;
 
+import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -168,17 +169,16 @@
                 + '}';
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<PeriodicAdvertisingReport>
-            CREATOR =
-                    new Creator<PeriodicAdvertisingReport>() {
-                        @Override
-                        public PeriodicAdvertisingReport createFromParcel(Parcel source) {
-                            return new PeriodicAdvertisingReport(source);
-                        }
+    public static final @NonNull Parcelable.Creator<PeriodicAdvertisingReport> CREATOR =
+            new Creator<PeriodicAdvertisingReport>() {
+                @Override
+                public PeriodicAdvertisingReport createFromParcel(Parcel source) {
+                    return new PeriodicAdvertisingReport(source);
+                }
 
-                        @Override
-                        public PeriodicAdvertisingReport[] newArray(int size) {
-                            return new PeriodicAdvertisingReport[size];
-                        }
-                    };
+                @Override
+                public PeriodicAdvertisingReport[] newArray(int size) {
+                    return new PeriodicAdvertisingReport[size];
+                }
+            };
 }
diff --git a/framework/java/android/bluetooth/le/ResultStorageDescriptor.java b/framework/java/android/bluetooth/le/ResultStorageDescriptor.java
index 4b5bd76..b2a3e6c 100644
--- a/framework/java/android/bluetooth/le/ResultStorageDescriptor.java
+++ b/framework/java/android/bluetooth/le/ResultStorageDescriptor.java
@@ -16,6 +16,7 @@
 
 package android.bluetooth.le;
 
+import android.annotation.NonNull;
 import android.annotation.SystemApi;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -80,17 +81,16 @@
         mLength = in.readInt();
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<ResultStorageDescriptor>
-            CREATOR =
-                    new Creator<ResultStorageDescriptor>() {
-                        @Override
-                        public ResultStorageDescriptor createFromParcel(Parcel source) {
-                            return new ResultStorageDescriptor(source);
-                        }
+    public static final @NonNull Parcelable.Creator<ResultStorageDescriptor> CREATOR =
+            new Creator<ResultStorageDescriptor>() {
+                @Override
+                public ResultStorageDescriptor createFromParcel(Parcel source) {
+                    return new ResultStorageDescriptor(source);
+                }
 
-                        @Override
-                        public ResultStorageDescriptor[] newArray(int size) {
-                            return new ResultStorageDescriptor[size];
-                        }
-                    };
+                @Override
+                public ResultStorageDescriptor[] newArray(int size) {
+                    return new ResultStorageDescriptor[size];
+                }
+            };
 }
diff --git a/framework/java/android/bluetooth/le/ScanFilter.java b/framework/java/android/bluetooth/le/ScanFilter.java
index d78fa19..7ddd7b1 100644
--- a/framework/java/android/bluetooth/le/ScanFilter.java
+++ b/framework/java/android/bluetooth/le/ScanFilter.java
@@ -216,7 +216,7 @@
     }
 
     /** A {@link android.os.Parcelable.Creator} to create {@link ScanFilter} from parcel. */
-    public static final @android.annotation.NonNull Creator<ScanFilter> CREATOR =
+    public static final @NonNull Creator<ScanFilter> CREATOR =
             new Creator<ScanFilter>() {
 
                 @Override
diff --git a/framework/java/android/bluetooth/le/ScanResult.java b/framework/java/android/bluetooth/le/ScanResult.java
index 690dc79..2b15cb9 100644
--- a/framework/java/android/bluetooth/le/ScanResult.java
+++ b/framework/java/android/bluetooth/le/ScanResult.java
@@ -348,7 +348,7 @@
                 + '}';
     }
 
-    public static final @android.annotation.NonNull Parcelable.Creator<ScanResult> CREATOR =
+    public static final @NonNull Parcelable.Creator<ScanResult> CREATOR =
             new Creator<ScanResult>() {
                 @Override
                 public ScanResult createFromParcel(Parcel source) {
diff --git a/system/audio_hal_interface/aidl/a2dp/a2dp_provider_info.cc b/system/audio_hal_interface/aidl/a2dp/a2dp_provider_info.cc
index 445cb52..bc8bd06 100644
--- a/system/audio_hal_interface/aidl/a2dp/a2dp_provider_info.cc
+++ b/system/audio_hal_interface/aidl/a2dp/a2dp_provider_info.cc
@@ -39,7 +39,6 @@
 using ::aidl::android::hardware::bluetooth::audio::ChannelMode;
 using ::aidl::android::hardware::bluetooth::audio::CodecId;
 using ::aidl::android::hardware::bluetooth::audio::CodecInfo;
-using ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProviderFactory;
 using ::aidl::android::hardware::bluetooth::audio::SessionType;
 
 /***
diff --git a/system/audio_hal_interface/aidl/hearing_aid_software_encoding_aidl.cc b/system/audio_hal_interface/aidl/hearing_aid_software_encoding_aidl.cc
index ec9f3a5..c7ac3a7 100644
--- a/system/audio_hal_interface/aidl/hearing_aid_software_encoding_aidl.cc
+++ b/system/audio_hal_interface/aidl/hearing_aid_software_encoding_aidl.cc
@@ -35,7 +35,6 @@
 namespace {
 
 using ::aidl::android::hardware::bluetooth::audio::ChannelMode;
-using ::aidl::android::hardware::bluetooth::audio::CodecType;
 using ::bluetooth::audio::aidl::AudioConfiguration;
 using ::bluetooth::audio::aidl::BluetoothAudioCtrlAck;
 using ::bluetooth::audio::aidl::LatencyMode;
diff --git a/system/audio_hal_interface/aidl/hfp_client_interface_aidl.cc b/system/audio_hal_interface/aidl/hfp_client_interface_aidl.cc
index f1b1a7a..62996d5 100644
--- a/system/audio_hal_interface/aidl/hfp_client_interface_aidl.cc
+++ b/system/audio_hal_interface/aidl/hfp_client_interface_aidl.cc
@@ -40,7 +40,7 @@
 
 using namespace metrics;
 
-std::map<bt_status_t, BluetoothAudioCtrlAck> status_to_ack_map = {
+static std::map<bt_status_t, BluetoothAudioCtrlAck> status_to_ack_map = {
         {BT_STATUS_SUCCESS, BluetoothAudioCtrlAck::SUCCESS_FINISHED},
         {BT_STATUS_DONE, BluetoothAudioCtrlAck::SUCCESS_FINISHED},
         {BT_STATUS_FAIL, BluetoothAudioCtrlAck::FAILURE},
diff --git a/system/audio_hal_interface/aidl/le_audio_software_aidl.cc b/system/audio_hal_interface/aidl/le_audio_software_aidl.cc
index e0b9647..b389791 100644
--- a/system/audio_hal_interface/aidl/le_audio_software_aidl.cc
+++ b/system/audio_hal_interface/aidl/le_audio_software_aidl.cc
@@ -47,11 +47,9 @@
 using ::aidl::android::hardware::bluetooth::audio::PcmConfiguration;
 using ::bluetooth::audio::aidl::AudioConfiguration;
 using ::bluetooth::audio::aidl::BluetoothAudioCtrlAck;
-using ::bluetooth::audio::le_audio::LeAudioClientInterface;
 using ::bluetooth::audio::le_audio::StartRequestState;
 using ::bluetooth::audio::le_audio::StreamCallbacks;
 using ::bluetooth::le_audio::types::AseConfiguration;
-using ::bluetooth::le_audio::types::LeAudioCoreCodecConfig;
 
 static ChannelMode le_audio_channel_mode2audio_hal(uint8_t channels_count) {
   switch (channels_count) {
@@ -296,7 +294,7 @@
   start_request_state_ = state;
 }
 
-inline void flush_unicast_sink() {
+static void flush_unicast_sink() {
   if (LeAudioSinkTransport::interface_unicast_ == nullptr) {
     return;
   }
@@ -304,7 +302,7 @@
   LeAudioSinkTransport::interface_unicast_->FlushAudioData();
 }
 
-inline void flush_broadcast_sink() {
+static void flush_broadcast_sink() {
   if (LeAudioSinkTransport::interface_broadcast_ == nullptr) {
     return;
   }
@@ -312,13 +310,9 @@
   LeAudioSinkTransport::interface_broadcast_->FlushAudioData();
 }
 
-inline bool is_broadcaster_session(SessionType session_type) {
-  if (session_type == SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
-      session_type == SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH) {
-    return true;
-  }
-
-  return false;
+static bool is_broadcaster_session(SessionType session_type) {
+  return session_type == SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
+         session_type == SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH;
 }
 
 LeAudioSinkTransport::LeAudioSinkTransport(SessionType session_type, StreamCallbacks stream_cb)
@@ -485,7 +479,7 @@
   transport_->SetStartRequestState(state);
 }
 
-std::unordered_map<int32_t, uint8_t> sampling_freq_map{
+static std::unordered_map<int32_t, uint8_t> sampling_freq_map{
         {8000, ::bluetooth::le_audio::codec_spec_conf::kLeAudioSamplingFreq8000Hz},
         {16000, ::bluetooth::le_audio::codec_spec_conf::kLeAudioSamplingFreq16000Hz},
         {24000, ::bluetooth::le_audio::codec_spec_conf::kLeAudioSamplingFreq24000Hz},
@@ -497,11 +491,11 @@
         {176400, ::bluetooth::le_audio::codec_spec_conf::kLeAudioSamplingFreq176400Hz},
         {192000, ::bluetooth::le_audio::codec_spec_conf::kLeAudioSamplingFreq192000Hz}};
 
-std::unordered_map<int32_t, uint8_t> frame_duration_map{
+static std::unordered_map<int32_t, uint8_t> frame_duration_map{
         {7500, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameDur7500us},
         {10000, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameDur10000us}};
 
-std::unordered_map<int32_t, uint16_t> octets_per_frame_map{
+static std::unordered_map<int32_t, uint16_t> octets_per_frame_map{
         {30, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameLen30},
         {40, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameLen40},
         {60, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameLen60},
@@ -509,7 +503,7 @@
         {100, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameLen100},
         {120, ::bluetooth::le_audio::codec_spec_conf::kLeAudioCodecFrameLen120}};
 
-std::unordered_map<AudioLocation, uint32_t> audio_location_map{
+static std::unordered_map<AudioLocation, uint32_t> audio_location_map{
         {AudioLocation::UNKNOWN,
          ::bluetooth::le_audio::codec_spec_conf::kLeAudioLocationFrontCenter},
         {AudioLocation::FRONT_LEFT,
diff --git a/system/audio_hal_interface/hidl/hearing_aid_software_encoding_hidl.cc b/system/audio_hal_interface/hidl/hearing_aid_software_encoding_hidl.cc
index a129917..5d82ccd 100644
--- a/system/audio_hal_interface/hidl/hearing_aid_software_encoding_hidl.cc
+++ b/system/audio_hal_interface/hidl/hearing_aid_software_encoding_hidl.cc
@@ -34,7 +34,6 @@
 
 namespace {
 
-using ::android::hardware::bluetooth::audio::V2_0::CodecType;
 using ::bluetooth::audio::hidl::AudioConfiguration;
 using ::bluetooth::audio::hidl::BitsPerSample;
 using ::bluetooth::audio::hidl::BluetoothAudioCtrlAck;
diff --git a/system/audio_hal_interface/hidl/le_audio_software_hidl.cc b/system/audio_hal_interface/hidl/le_audio_software_hidl.cc
index 740c05a..4175f77 100644
--- a/system/audio_hal_interface/hidl/le_audio_software_hidl.cc
+++ b/system/audio_hal_interface/hidl/le_audio_software_hidl.cc
@@ -28,12 +28,10 @@
 
 using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
 using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
-using ::android::hardware::bluetooth::audio::V2_0::CodecType;
 using ::bluetooth::audio::hidl::SampleRate_2_1;
 using ::bluetooth::audio::hidl::SessionType;
 using ::bluetooth::audio::hidl::SessionType_2_1;
 
-using ::bluetooth::audio::le_audio::LeAudioClientInterface;
 using ::bluetooth::audio::le_audio::StartRequestState;
 using ::bluetooth::le_audio::DsaMode;
 
diff --git a/system/audio_hal_interface/le_audio_software.cc b/system/audio_hal_interface/le_audio_software.cc
index 2352981..dd8ee9f 100644
--- a/system/audio_hal_interface/le_audio_software.cc
+++ b/system/audio_hal_interface/le_audio_software.cc
@@ -49,13 +49,10 @@
 
 namespace {
 
-using ::android::hardware::bluetooth::audio::V2_1::PcmParameters;
 using AudioConfiguration_2_1 = ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration;
 using AudioConfigurationAIDL = ::aidl::android::hardware::bluetooth::audio::AudioConfiguration;
-using ::aidl::android::hardware::bluetooth::audio::AudioContext;
 using ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider;
 using ::aidl::android::hardware::bluetooth::audio::LatencyMode;
-using ::aidl::android::hardware::bluetooth::audio::LeAudioCodecConfiguration;
 using ::aidl::android::hardware::bluetooth::audio::SessionType;
 
 using ::bluetooth::le_audio::CodecManager;
diff --git a/system/bta/ag/bta_ag_cmd.cc b/system/bta/ag/bta_ag_cmd.cc
index ad9f88e..c8509ff 100644
--- a/system/bta/ag/bta_ag_cmd.cc
+++ b/system/bta/ag/bta_ag_cmd.cc
@@ -1355,6 +1355,13 @@
         bta_ag_send_error(p_scb, BTA_AG_ERR_OP_NOT_SUPPORTED);
         break;
       }
+      if (com::android::bluetooth::flags::qc_prioritize_lc3_codec() &&
+          hfp_hal_interface::get_swb_supported() && (p_scb->peer_codecs & BTM_SCO_CODEC_LC3) &&
+          !(p_scb->disabled_codecs & BTM_SCO_CODEC_LC3)) {
+        log::warn("Phone and BT device support LC3, return error for QAC");
+        bta_ag_send_error(p_scb, BTA_AG_ERR_OP_NOT_SUPPORTED);
+        break;
+      }
       p_scb->peer_codecs |= bta_ag_parse_qac(p_arg);
       // AT+%QAC needs to be responded with +%QAC
       bta_ag_swb_handle_vs_at_events(p_scb, cmd, int_arg, &val);
diff --git a/system/bta/ag/bta_ag_sdp.cc b/system/bta/ag/bta_ag_sdp.cc
index 3bb707b..ecc6c6f 100644
--- a/system/bta/ag/bta_ag_sdp.cc
+++ b/system/bta/ag/bta_ag_sdp.cc
@@ -76,18 +76,18 @@
 #endif
 
 /* declare sdp callback functions */
-void bta_ag_sdp_cback_1(const RawAddress& bd_addr, tSDP_RESULT);
-void bta_ag_sdp_cback_2(const RawAddress& bd_addr, tSDP_RESULT);
-void bta_ag_sdp_cback_3(const RawAddress& bd_addr, tSDP_RESULT);
-void bta_ag_sdp_cback_4(const RawAddress& bd_addr, tSDP_RESULT);
-void bta_ag_sdp_cback_5(const RawAddress& bd_addr, tSDP_RESULT);
-void bta_ag_sdp_cback_6(const RawAddress& bd_addr, tSDP_RESULT);
+static void bta_ag_sdp_cback_1(const RawAddress& bd_addr, tSDP_RESULT);
+static void bta_ag_sdp_cback_2(const RawAddress& bd_addr, tSDP_RESULT);
+static void bta_ag_sdp_cback_3(const RawAddress& bd_addr, tSDP_RESULT);
+static void bta_ag_sdp_cback_4(const RawAddress& bd_addr, tSDP_RESULT);
+static void bta_ag_sdp_cback_5(const RawAddress& bd_addr, tSDP_RESULT);
+static void bta_ag_sdp_cback_6(const RawAddress& bd_addr, tSDP_RESULT);
 
 /* SDP callback function table */
 typedef tSDP_DISC_CMPL_CB* tBTA_AG_SDP_CBACK;
-const tBTA_AG_SDP_CBACK bta_ag_sdp_cback_tbl[] = {bta_ag_sdp_cback_1, bta_ag_sdp_cback_2,
-                                                  bta_ag_sdp_cback_3, bta_ag_sdp_cback_4,
-                                                  bta_ag_sdp_cback_5, bta_ag_sdp_cback_6};
+static const tBTA_AG_SDP_CBACK bta_ag_sdp_cback_tbl[] = {bta_ag_sdp_cback_1, bta_ag_sdp_cback_2,
+                                                         bta_ag_sdp_cback_3, bta_ag_sdp_cback_4,
+                                                         bta_ag_sdp_cback_5, bta_ag_sdp_cback_6};
 
 /*******************************************************************************
  *
@@ -130,22 +130,22 @@
  * Returns          void
  *
  ******************************************************************************/
-void bta_ag_sdp_cback_1(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
+static void bta_ag_sdp_cback_1(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
   bta_ag_sdp_cback(status, 1);
 }
-void bta_ag_sdp_cback_2(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
+static void bta_ag_sdp_cback_2(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
   bta_ag_sdp_cback(status, 2);
 }
-void bta_ag_sdp_cback_3(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
+static void bta_ag_sdp_cback_3(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
   bta_ag_sdp_cback(status, 3);
 }
-void bta_ag_sdp_cback_4(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
+static void bta_ag_sdp_cback_4(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
   bta_ag_sdp_cback(status, 4);
 }
-void bta_ag_sdp_cback_5(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
+static void bta_ag_sdp_cback_5(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
   bta_ag_sdp_cback(status, 5);
 }
-void bta_ag_sdp_cback_6(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
+static void bta_ag_sdp_cback_6(const RawAddress& /* bd_addr */, tSDP_STATUS status) {
   bta_ag_sdp_cback(status, 6);
 }
 
diff --git a/system/bta/av/bta_av_aact.cc b/system/bta/av/bta_av_aact.cc
index 7266522..e7bcb2b 100644
--- a/system/bta/av/bta_av_aact.cc
+++ b/system/bta/av/bta_av_aact.cc
@@ -118,7 +118,7 @@
 /* Time to wait for open from SNK when signaling is initiated from SNK. */
 /* If not, we abort and try to initiate the connection as SRC. */
 #ifndef BTA_AV_ACCEPT_OPEN_TIMEOUT_MS
-#define BTA_AV_ACCEPT_OPEN_TIMEOUT_MS (2 * 1000) /* 2 seconds */
+#define BTA_AV_ACCEPT_OPEN_TIMEOUT_MS (10 * 1000) /* 10 seconds */
 #endif
 
 static void bta_av_accept_open_timer_cback(void* data);
diff --git a/system/bta/dm/bta_dm_api.cc b/system/bta/dm/bta_dm_api.cc
index 89ce30b..ca61f9d 100644
--- a/system/bta/dm/bta_dm_api.cc
+++ b/system/bta/dm/bta_dm_api.cc
@@ -43,8 +43,6 @@
 using namespace bluetooth::legacy::stack::sdp;
 using namespace bluetooth;
 
-using bluetooth::Uuid;
-
 /*****************************************************************************
  *  Constants
  ****************************************************************************/
diff --git a/system/bta/dm/bta_dm_cfg.cc b/system/bta/dm/bta_dm_cfg.cc
index 1b811dd..1b6c6ee 100644
--- a/system/bta/dm/bta_dm_cfg.cc
+++ b/system/bta/dm/bta_dm_cfg.cc
@@ -479,7 +479,7 @@
 /* the smaller of the SSR max latency wins.
  * the entries in this table must be from highest latency (biggest interval) to
  * lowest latency */
-tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] = {
+static tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] = {
         /*max_lat, min_rmt_to, min_loc_to*/
         {0, 0, 0, "no_ssr"}, /* BTA_DM_PM_SSR0 - do not use SSR */
         /* BTA_DM_PM_SSR1 - HH, can NOT share entry with any other profile, setting
diff --git a/system/bta/dm/bta_dm_device_search.cc b/system/bta/dm/bta_dm_device_search.cc
index a8a3e57..5b2b671 100644
--- a/system/bta/dm/bta_dm_device_search.cc
+++ b/system/bta/dm/bta_dm_device_search.cc
@@ -762,7 +762,7 @@
   }
 };
 
-bluetooth::common::TimestampedCircularBuffer<tSEARCH_STATE_HISTORY> search_state_history_(
+static bluetooth::common::TimestampedCircularBuffer<tSEARCH_STATE_HISTORY> search_state_history_(
         kSearchStateHistorySize);
 
 /*******************************************************************************
diff --git a/system/bta/dm/bta_dm_disc.cc b/system/bta/dm/bta_dm_disc.cc
index 79d3421..1b3b571 100644
--- a/system/bta/dm/bta_dm_disc.cc
+++ b/system/bta/dm/bta_dm_disc.cc
@@ -739,8 +739,8 @@
   }
 };
 
-bluetooth::common::TimestampedCircularBuffer<tDISCOVERY_STATE_HISTORY> discovery_state_history_(
-        50 /*history size*/);
+static bluetooth::common::TimestampedCircularBuffer<tDISCOVERY_STATE_HISTORY>
+        discovery_state_history_(50 /*history size*/);
 
 static void bta_dm_disc_sm_execute(tBTA_DM_DISC_EVT event, std::unique_ptr<tBTA_DM_MSG> msg) {
   log::info("state:{}, event:{}[0x{:x}]", bta_dm_state_text(bta_dm_discovery_get_state()),
diff --git a/system/bta/dm/bta_dm_gatt_client.cc b/system/bta/dm/bta_dm_gatt_client.cc
index 9e511db..842d89a 100644
--- a/system/bta/dm/bta_dm_gatt_client.cc
+++ b/system/bta/dm/bta_dm_gatt_client.cc
@@ -44,7 +44,7 @@
 }
 }  // namespace
 
-gatt_interface_t default_gatt_interface = {
+static gatt_interface_t default_gatt_interface = {
         .BTA_GATTC_CancelOpen =
                 [](tGATT_IF client_if, const RawAddress& remote_bda, bool is_direct) {
                   gatt_history_.Push(std::format("{:<32s} bd_addr:{} client_if:{} is_direct:{:c}",
@@ -100,7 +100,7 @@
                 },
 };
 
-gatt_interface_t* gatt_interface = &default_gatt_interface;
+static gatt_interface_t* gatt_interface = &default_gatt_interface;
 
 gatt_interface_t& get_gatt_interface() { return *gatt_interface; }
 
diff --git a/system/bta/gatt/bta_gattc_cache.cc b/system/bta/gatt/bta_gattc_cache.cc
index 491a29a..37fa54e 100644
--- a/system/bta/gatt/bta_gattc_cache.cc
+++ b/system/bta/gatt/bta_gattc_cache.cc
@@ -53,7 +53,6 @@
 
 using bluetooth::Uuid;
 using gatt::Characteristic;
-using gatt::Database;
 using gatt::DatabaseBuilder;
 using gatt::Descriptor;
 using gatt::IncludedService;
diff --git a/system/bta/gatt/bta_gatts_act.cc b/system/bta/gatt/bta_gatts_act.cc
index 049899f..f63ecc7 100644
--- a/system/bta/gatt/bta_gatts_act.cc
+++ b/system/bta/gatt/bta_gatts_act.cc
@@ -71,7 +71,7 @@
         .p_subrate_chg_cb = bta_gatts_subrate_chg_cback,
 };
 
-tGATT_APPL_INFO bta_gatts_nv_cback = {bta_gatts_nv_save_cback, bta_gatts_nv_srv_chg_cback};
+static tGATT_APPL_INFO bta_gatts_nv_cback = {bta_gatts_nv_save_cback, bta_gatts_nv_srv_chg_cback};
 
 /*******************************************************************************
  *
diff --git a/system/bta/gatt/bta_gatts_queue.cc b/system/bta/gatt/bta_gatts_queue.cc
index ef6a73e..8797923 100644
--- a/system/bta/gatt/bta_gatts_queue.cc
+++ b/system/bta/gatt/bta_gatts_queue.cc
@@ -25,7 +25,6 @@
 #include "bta_gatt_server_queue.h"
 
 using gatts_operation = BtaGattServerQueue::gatts_operation;
-using bluetooth::Uuid;
 using namespace bluetooth;
 
 constexpr uint8_t GATT_NOTIFY = 1;
diff --git a/system/bta/groups/groups.cc b/system/bta/groups/groups.cc
index 3d79cdf..5bb3045 100644
--- a/system/bta/groups/groups.cc
+++ b/system/bta/groups/groups.cc
@@ -45,8 +45,8 @@
 namespace groups {
 
 class DeviceGroupsImpl;
-DeviceGroupsImpl* instance;
-std::mutex instance_mutex;
+static DeviceGroupsImpl* instance;
+static std::mutex instance_mutex;
 static constexpr int kMaxGroupId = 0xEF;
 
 class DeviceGroup {
diff --git a/system/bta/has/has_client.cc b/system/bta/has/has_client.cc
index 8fe0cf6..5f7e976 100644
--- a/system/bta/has/has_client.cc
+++ b/system/bta/has/has_client.cc
@@ -43,6 +43,7 @@
 #include "bta_gatt_queue.h"
 #include "bta_has_api.h"
 #include "bta_le_audio_uuids.h"
+#include "btif/include/btif_profile_storage.h"
 #include "btm_ble_api_types.h"
 #include "btm_sec.h"
 #include "btm_sec_api_types.h"
@@ -57,6 +58,7 @@
 #include "has_types.h"
 #include "osi/include/alarm.h"
 #include "osi/include/properties.h"
+#include "stack/gatt/gatt_int.h"
 #include "stack/include/bt_types.h"
 #include "types/bluetooth/uuid.h"
 #include "types/bt_transport.h"
@@ -85,21 +87,6 @@
 using bluetooth::le_audio::has::PresetCtpOpcode;
 using namespace bluetooth;
 
-void btif_storage_add_leaudio_has_device(const RawAddress& address,
-                                         std::vector<uint8_t> presets_bin, uint8_t features,
-                                         uint8_t active_preset);
-bool btif_storage_get_leaudio_has_presets(const RawAddress& address,
-                                          std::vector<uint8_t>& presets_bin,
-                                          uint8_t& active_preset);
-void btif_storage_set_leaudio_has_presets(const RawAddress& address,
-                                          std::vector<uint8_t> presets_bin);
-bool btif_storage_get_leaudio_has_features(const RawAddress& address, uint8_t& features);
-void btif_storage_set_leaudio_has_features(const RawAddress& address, uint8_t features);
-void btif_storage_set_leaudio_has_active_preset(const RawAddress& address, uint8_t active_preset);
-void btif_storage_remove_leaudio_has(const RawAddress& address);
-
-bool gatt_profile_get_eatt_support(const RawAddress& remote_bda);
-
 namespace {
 class HasClientImpl;
 HasClientImpl* instance;
diff --git a/system/bta/hd/bta_hd_act.cc b/system/bta/hd/bta_hd_act.cc
index bcdc1bc..124cfa4 100644
--- a/system/bta/hd/bta_hd_act.cc
+++ b/system/bta/hd/bta_hd_act.cc
@@ -184,8 +184,7 @@
     log::error("Descriptor is too long or malformed");
     ret.reg_status.status = BTA_HD_ERROR;
     (*bta_hd_cb.p_cback)(BTA_HD_REGISTER_APP_EVT, &ret);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_REGISTER_DESCRIPTOR_MALFORMED, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_REGISTER_DESCRIPTOR_MALFORMED);
     return;
   }
 
diff --git a/system/bta/hearing_aid/hearing_aid.cc b/system/bta/hearing_aid/hearing_aid.cc
index f4c849a..8084dbc 100644
--- a/system/bta/hearing_aid/hearing_aid.cc
+++ b/system/bta/hearing_aid/hearing_aid.cc
@@ -48,6 +48,7 @@
 #include "bta/include/bta_gatt_api.h"
 #include "bta/include/bta_gatt_queue.h"
 #include "bta/include/bta_hearing_aid_api.h"
+#include "btif/include/btif_profile_storage.h"
 #include "btm_api_types.h"
 #include "btm_ble_api_types.h"
 #include "btm_iso_api.h"
@@ -94,11 +95,6 @@
 constexpr uint16_t CONNECTION_INTERVAL_10MS_PARAM = 0x0008;
 constexpr uint16_t CONNECTION_INTERVAL_20MS_PARAM = 0x0010;
 
-void btif_storage_add_hearing_aid(const HearingDevice& dev_info);
-bool btif_storage_get_hearing_aid_prop(const RawAddress& address, uint8_t* capabilities,
-                                       uint64_t* hi_sync_id, uint16_t* render_delay,
-                                       uint16_t* preparation_delay, uint16_t* codecs);
-
 constexpr uint8_t CODEC_G722_16KHZ = 0x01;
 constexpr uint8_t CODEC_G722_24KHZ = 0x02;
 
@@ -154,7 +150,7 @@
   return msg;
 }
 
-inline uint8_t* get_l2cap_sdu_start_ptr(BT_HDR* msg) {
+static uint8_t* get_l2cap_sdu_start_ptr(BT_HDR* msg) {
   return (uint8_t*)(msg) + BT_HDR_SIZE + L2CAP_MIN_OFFSET;
 }
 
diff --git a/system/bta/hf_client/bta_hf_client_main.cc b/system/bta/hf_client/bta_hf_client_main.cc
index 526bf65..fd0679c 100644
--- a/system/bta/hf_client/bta_hf_client_main.cc
+++ b/system/bta/hf_client/bta_hf_client_main.cc
@@ -45,7 +45,7 @@
 
 static const char* bta_hf_client_evt_str(uint16_t event);
 static const char* bta_hf_client_state_str(uint8_t state);
-void bta_hf_client_cb_init(tBTA_HF_CLIENT_CB* client_cb, uint16_t handle);
+static void bta_hf_client_cb_init(tBTA_HF_CLIENT_CB* client_cb, uint16_t handle);
 
 /* state machine states */
 enum {
@@ -273,7 +273,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void bta_hf_client_cb_init(tBTA_HF_CLIENT_CB* client_cb, uint16_t handle) {
+static void bta_hf_client_cb_init(tBTA_HF_CLIENT_CB* client_cb, uint16_t handle) {
   log::verbose("");
 
   // Free any memory we need to explicity release
diff --git a/system/bta/hh/bta_hh_cfg.cc b/system/bta/hh/bta_hh_cfg.cc
index 98cda37..2850a4b 100644
--- a/system/bta/hh/bta_hh_cfg.cc
+++ b/system/bta/hh/bta_hh_cfg.cc
@@ -23,6 +23,7 @@
  *
  ******************************************************************************/
 
+#include "bta/hh/bta_hh_int.h"
 #include "bta/include/bta_hh_api.h"
 #include "internal_include/bt_target.h"
 
@@ -35,7 +36,7 @@
 #endif
 
 /* The type of devices supported by BTA HH and corresponding application ID */
-tBTA_HH_SPT_TOD p_devt_list[BTA_HH_MAX_DEVT_SPT] = {
+static tBTA_HH_SPT_TOD p_devt_list[BTA_HH_MAX_DEVT_SPT] = {
         {BTA_HH_DEVT_MIC, BTA_HH_APP_ID_MI},
         {BTA_HH_DEVT_KBD, BTA_HH_APP_ID_KB},
         {BTA_HH_DEVT_KBD | BTA_HH_DEVT_MIC, BTA_HH_APP_ID_KB},
@@ -46,7 +47,7 @@
         {BTA_HH_DEVT_GPD, BTA_HH_APP_ID_GPAD},
         {BTA_HH_DEVT_UNKNOWN, BTA_HH_APP_ID_3DSG}};
 
-const tBTA_HH_CFG bta_hh_cfg = {
+static const tBTA_HH_CFG bta_hh_cfg = {
         BTA_HH_MAX_DEVT_SPT, /* number of supported type of devices */
         p_devt_list,         /* ToD & AppID list */
         BTA_HH_DISC_BUF_SIZE /* HH SDP discovery database size */
diff --git a/system/bta/hh/bta_hh_int.h b/system/bta/hh/bta_hh_int.h
index 4ebcfad..2ff7727 100644
--- a/system/bta/hh/bta_hh_int.h
+++ b/system/bta/hh/bta_hh_int.h
@@ -245,7 +245,7 @@
 extern tBTA_HH_CB bta_hh_cb;
 
 /* from bta_hh_cfg.c */
-extern tBTA_HH_CFG* p_bta_hh_cfg;
+extern const tBTA_HH_CFG* p_bta_hh_cfg;
 
 /*****************************************************************************
  *  Function prototypes
diff --git a/system/bta/jv/bta_jv_act.cc b/system/bta/jv/bta_jv_act.cc
index d9eb9d0..3d69149 100644
--- a/system/bta/jv/bta_jv_act.cc
+++ b/system/bta/jv/bta_jv_act.cc
@@ -78,7 +78,7 @@
 static tSDP_DISCOVERY_DB bta_jv_sdp_db_data[BTA_JV_SDP_DB_SIZE / sizeof(tSDP_DISCOVERY_DB)];
 
 /* JV configuration structure */
-struct tBTA_JV_CFG {
+static struct tBTA_JV_CFG {
   uint16_t sdp_raw_size;       /* The size of p_sdp_raw_data */
   uint16_t sdp_db_size;        /* The size of p_sdp_db */
   uint8_t* p_sdp_raw_data;     /* The data buffer to keep raw data */
@@ -91,7 +91,7 @@
         bta_jv_sdp_db_data                 /* The data buffer to keep SDP database */
 };
 
-tBTA_JV_CFG* p_bta_jv_cfg = &bta_jv_cfg;
+static tBTA_JV_CFG* p_bta_jv_cfg = &bta_jv_cfg;
 
 /*******************************************************************************
  *
@@ -802,7 +802,7 @@
     log::warn("Received unexpected service discovery callback bd_addr:{} result:{}", bd_addr,
               sdp_result_text(result), bta_jv_cb.sdp_cb.sdp_active);
   }
-  if (bta_jv_cb.sdp_cb.bd_addr != bta_jv_cb.sdp_cb.bd_addr) {
+  if (bta_jv_cb.sdp_cb.bd_addr != bd_addr) {
     log::warn(
             "Received incorrect service discovery callback expected_bd_addr:{} "
             "actual_bd_addr:{} result:{}",
@@ -1970,8 +1970,15 @@
 
   bta_jv_pm_conn_busy(p_pcb->p_pm_cb);
 
-  if (!evt_data.cong && PORT_WriteDataCO(p_pcb->port_handle, &evt_data.len) == PORT_SUCCESS) {
-    evt_data.status = tBTA_JV_STATUS::SUCCESS;
+  if (!evt_data.cong) {
+    int write_status = PORT_WriteDataCO(p_pcb->port_handle, &evt_data.len);
+    if (write_status == PORT_SUCCESS) {
+      evt_data.status = tBTA_JV_STATUS::SUCCESS;
+    } else {
+      log::warn("write failed with result:{}", static_cast<tPORT_RESULT>(write_status));
+    }
+  } else {
+    log::debug("write failed due to congestion");
   }
 
   // Update congestion flag
diff --git a/system/bta/le_audio/client.cc b/system/bta/le_audio/client.cc
index 8ce7dd2..eeb61c9 100644
--- a/system/bta/le_audio/client.cc
+++ b/system/bta/le_audio/client.cc
@@ -147,7 +147,6 @@
 using bluetooth::le_audio::types::BidirectionalPair;
 using bluetooth::le_audio::types::DataPathState;
 using bluetooth::le_audio::types::hdl_pair;
-using bluetooth::le_audio::types::hdl_pair_wrapper;
 using bluetooth::le_audio::types::kLeAudioContextAllRemoteSource;
 using bluetooth::le_audio::types::kLeAudioContextAllTypesArray;
 using bluetooth::le_audio::types::LeAudioContextType;
diff --git a/system/bta/le_audio/le_audio_health_status.cc b/system/bta/le_audio/le_audio_health_status.cc
index 7114731..30d1fcf 100644
--- a/system/bta/le_audio/le_audio_health_status.cc
+++ b/system/bta/le_audio/le_audio_health_status.cc
@@ -41,7 +41,7 @@
 
 namespace bluetooth::le_audio {
 class LeAudioHealthStatusImpl;
-LeAudioHealthStatusImpl* instance;
+static LeAudioHealthStatusImpl* instance;
 
 class LeAudioHealthStatusImpl : public LeAudioHealthStatus {
 public:
@@ -298,20 +298,19 @@
 
   void log_counter_metrics_for_device(LeAudioHealthDeviceStatType type, bool in_allowlist) {
     log::debug("in_allowlist: {}, type: {}", in_allowlist, ToString(type));
-    android::bluetooth::CodePathCounterKeyEnum key;
+    bluetooth::metrics::CounterKey key;
     if (in_allowlist) {
       switch (type) {
         case LeAudioHealthDeviceStatType::VALID_DB:
         case LeAudioHealthDeviceStatType::VALID_CSIS:
-          key = android::bluetooth::CodePathCounterKeyEnum::
-                  LE_AUDIO_ALLOWLIST_DEVICE_HEALTH_STATUS_GOOD;
+          key = bluetooth::metrics::CounterKey::LE_AUDIO_ALLOWLIST_DEVICE_HEALTH_STATUS_GOOD;
           break;
         case LeAudioHealthDeviceStatType::INVALID_DB:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_ALLOWLIST_DEVICE_HEALTH_STATUS_BAD_INVALID_DB;
           break;
         case LeAudioHealthDeviceStatType::INVALID_CSIS:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_ALLOWLIST_DEVICE_HEALTH_STATUS_BAD_INVALID_CSIS;
           break;
         default:
@@ -322,15 +321,14 @@
       switch (type) {
         case LeAudioHealthDeviceStatType::VALID_DB:
         case LeAudioHealthDeviceStatType::VALID_CSIS:
-          key = android::bluetooth::CodePathCounterKeyEnum::
-                  LE_AUDIO_NONALLOWLIST_DEVICE_HEALTH_STATUS_GOOD;
+          key = bluetooth::metrics::CounterKey::LE_AUDIO_NONALLOWLIST_DEVICE_HEALTH_STATUS_GOOD;
           break;
         case LeAudioHealthDeviceStatType::INVALID_DB:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_NONALLOWLIST_DEVICE_HEALTH_STATUS_BAD_INVALID_DB;
           break;
         case LeAudioHealthDeviceStatType::INVALID_CSIS:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_NONALLOWLIST_DEVICE_HEALTH_STATUS_BAD_INVALID_CSIS;
           break;
         default:
@@ -338,24 +336,23 @@
           return;
       }
     }
-    bluetooth::metrics::CountCounterMetrics(key, 1);
+    bluetooth::metrics::Counter(key);
   }
 
   void log_counter_metrics_for_group(LeAudioHealthGroupStatType type, bool in_allowlist) {
     log::debug("in_allowlist: {}, type: {}", in_allowlist, ToString(type));
-    android::bluetooth::CodePathCounterKeyEnum key;
+    bluetooth::metrics::CounterKey key;
     if (in_allowlist) {
       switch (type) {
         case LeAudioHealthGroupStatType::STREAM_CREATE_SUCCESS:
-          key = android::bluetooth::CodePathCounterKeyEnum::
-                  LE_AUDIO_ALLOWLIST_GROUP_HEALTH_STATUS_GOOD;
+          key = bluetooth::metrics::CounterKey::LE_AUDIO_ALLOWLIST_GROUP_HEALTH_STATUS_GOOD;
           break;
         case LeAudioHealthGroupStatType::STREAM_CREATE_CIS_FAILED:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_ALLOWLIST_GROUP_HEALTH_STATUS_BAD_ONCE_CIS_FAILED;
           break;
         case LeAudioHealthGroupStatType::STREAM_CREATE_SIGNALING_FAILED:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_ALLOWLIST_GROUP_HEALTH_STATUS_BAD_ONCE_SIGNALING_FAILED;
           break;
         default:
@@ -365,15 +362,14 @@
     } else {
       switch (type) {
         case LeAudioHealthGroupStatType::STREAM_CREATE_SUCCESS:
-          key = android::bluetooth::CodePathCounterKeyEnum::
-                  LE_AUDIO_NONALLOWLIST_GROUP_HEALTH_STATUS_GOOD;
+          key = bluetooth::metrics::CounterKey::LE_AUDIO_NONALLOWLIST_GROUP_HEALTH_STATUS_GOOD;
           break;
         case LeAudioHealthGroupStatType::STREAM_CREATE_CIS_FAILED:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_NONALLOWLIST_GROUP_HEALTH_STATUS_BAD_ONCE_CIS_FAILED;
           break;
         case LeAudioHealthGroupStatType::STREAM_CREATE_SIGNALING_FAILED:
-          key = android::bluetooth::CodePathCounterKeyEnum::
+          key = bluetooth::metrics::CounterKey::
                   LE_AUDIO_NONALLOWLIST_GROUP_HEALTH_STATUS_BAD_ONCE_SIGNALING_FAILED;
           break;
         default:
@@ -381,7 +377,7 @@
           return;
       }
     }
-    bluetooth::metrics::CountCounterMetrics(key, 1);
+    bluetooth::metrics::Counter(key);
   }
 };
 }  // namespace bluetooth::le_audio
diff --git a/system/bta/le_audio/le_audio_log_history.cc b/system/bta/le_audio/le_audio_log_history.cc
index 95998ca..5acac11 100644
--- a/system/bta/le_audio/le_audio_log_history.cc
+++ b/system/bta/le_audio/le_audio_log_history.cc
@@ -54,7 +54,7 @@
 };
 
 class LeAudioLogHistoryImpl;
-LeAudioLogHistoryImpl* instance;
+static LeAudioLogHistoryImpl* instance;
 
 constexpr size_t kMaxLogHistoryTagLength = 14;
 constexpr size_t kMaxLogHistoryMsgLength = 44;
diff --git a/system/bta/le_audio/le_audio_set_configuration_provider_json.cc b/system/bta/le_audio/le_audio_set_configuration_provider_json.cc
index 1121cf9..79e2687 100644
--- a/system/bta/le_audio/le_audio_set_configuration_provider_json.cc
+++ b/system/bta/le_audio/le_audio_set_configuration_provider_json.cc
@@ -579,7 +579,7 @@
 };
 
 static std::unique_ptr<AudioSetConfigurationProvider> config_provider;
-std::mutex instance_mutex;
+static std::mutex instance_mutex;
 
 AudioSetConfigurationProvider::AudioSetConfigurationProvider()
     : pimpl_(std::make_unique<AudioSetConfigurationProvider::impl>(*this)) {}
diff --git a/system/bta/le_audio/metrics_collector.cc b/system/bta/le_audio/metrics_collector.cc
index 3a3d19f..bc4366b 100644
--- a/system/bta/le_audio/metrics_collector.cc
+++ b/system/bta/le_audio/metrics_collector.cc
@@ -39,7 +39,7 @@
 
 MetricsCollector* MetricsCollector::instance = nullptr;
 
-inline int64_t get_timedelta_nanos(const metrics::ClockTimePoint& t1,
+static int64_t get_timedelta_nanos(const metrics::ClockTimePoint& t1,
                                    const metrics::ClockTimePoint& t2) {
   if (t1 == kInvalidTimePoint || t2 == kInvalidTimePoint) {
     return -1;
@@ -64,7 +64,7 @@
         {LeAudioContextType::RFU, LeAudioMetricsContextType::RFU},
 };
 
-inline int32_t to_atom_context_type(const LeAudioContextType stack_type) {
+static int32_t to_atom_context_type(const LeAudioContextType stack_type) {
   auto it = kContextTypeTable.find(stack_type);
   if (it != kContextTypeTable.end()) {
     return static_cast<int32_t>(it->second);
diff --git a/system/bta/pan/bta_pan_api.cc b/system/bta/pan/bta_pan_api.cc
index 4fb2c04..0caa57f 100644
--- a/system/bta/pan/bta_pan_api.cc
+++ b/system/bta/pan/bta_pan_api.cc
@@ -40,10 +40,6 @@
 
 static const tBTA_SYS_REG bta_pan_reg = {bta_pan_hdl_event, BTA_PanDisable};
 
-std::string user_service_name; /* Service name for PANU role */
-std::string gn_service_name;   /* Service name for GN role */
-std::string nap_service_name;  /* Service name for NAP role */
-
 #ifndef PAN_SECURITY
 #define PAN_SECURITY \
   (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_OUT_ENCRYPT)
diff --git a/system/bta/sdp/bta_sdp_act.cc b/system/bta/sdp/bta_sdp_act.cc
index e6bd825..96c8846 100644
--- a/system/bta/sdp/bta_sdp_act.cc
+++ b/system/bta/sdp/bta_sdp_act.cc
@@ -599,8 +599,7 @@
   tBTA_SDP bta_sdp;
   bta_sdp.sdp_search_comp = evt_data;
   bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, &bta_sdp, (void*)&uuid);
-  bluetooth::metrics::CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum::SDP_SUCCESS,
-                                          1);
+  bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::SDP_SUCCESS);
 }
 
 /*******************************************************************************
@@ -676,8 +675,7 @@
       tBTA_SDP bta_sdp;
       bta_sdp.sdp_search_comp = result;
       bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, &bta_sdp, NULL);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::SDP_FAILURE, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::SDP_FAILURE);
     }
   }
   /*
diff --git a/system/bta/sdp/bta_sdp_cfg.cc b/system/bta/sdp/bta_sdp_cfg.cc
index 7ded154..b6f526c 100644
--- a/system/bta/sdp/bta_sdp_cfg.cc
+++ b/system/bta/sdp/bta_sdp_cfg.cc
@@ -21,6 +21,7 @@
  ******************************************************************************/
 
 #include "bta/include/bta_sdp_api.h"
+#include "bta/sdp/bta_sdp_int.h"
 #include "internal_include/bt_target.h"
 #include "stack/include/sdp_api.h"
 
@@ -31,7 +32,7 @@
 static tSDP_DISCOVERY_DB bta_sdp_db_data[BTA_SDP_DB_SIZE / sizeof(tSDP_DISCOVERY_DB)];
 
 /* SDP configuration structure */
-const tBTA_SDP_CFG bta_sdp_cfg = {
+static const tBTA_SDP_CFG bta_sdp_cfg = {
         (BTA_SDP_DB_SIZE / sizeof(tSDP_DISCOVERY_DB)) * sizeof(tSDP_DISCOVERY_DB),
         bta_sdp_db_data /* The data buffer to keep SDP database */
 };
diff --git a/system/bta/sdp/bta_sdp_int.h b/system/bta/sdp/bta_sdp_int.h
index 703bdbf..852f226 100644
--- a/system/bta/sdp/bta_sdp_int.h
+++ b/system/bta/sdp/bta_sdp_int.h
@@ -47,7 +47,7 @@
 extern tBTA_SDP_CB bta_sdp_cb;
 
 /* config struct */
-extern tBTA_SDP_CFG* p_bta_sdp_cfg;
+extern const tBTA_SDP_CFG* p_bta_sdp_cfg;
 
 void bta_sdp_enable(tBTA_SDP_DM_CBACK* p_cback);
 void bta_sdp_search(const RawAddress bd_addr, const bluetooth::Uuid uuid);
diff --git a/system/bta/sys/utl.cc b/system/bta/sys/utl.cc
index 2d62508..ba60d91 100644
--- a/system/bta/sys/utl.cc
+++ b/system/bta/sys/utl.cc
@@ -46,7 +46,7 @@
 int16_t utl_str2int(const char* p_s) {
   int32_t val = 0;
 
-  for (; *p_s == ' ' && *p_s != 0; p_s++)
+  for (; *p_s == ' '; p_s++)
     ;
 
   if (*p_s == 0) {
diff --git a/system/btcore/src/module.cc b/system/btcore/src/module.cc
index 62ab21a..55b33f2 100644
--- a/system/btcore/src/module.cc
+++ b/system/btcore/src/module.cc
@@ -29,7 +29,6 @@
 
 #include "common/message_loop_thread.h"
 
-using bluetooth::common::MessageLoopThread;
 using namespace bluetooth;
 
 typedef enum {
diff --git a/system/btif/avrcp/avrcp_service.cc b/system/btif/avrcp/avrcp_service.cc
index 955d5cc..5b84bc9 100644
--- a/system/btif/avrcp/avrcp_service.cc
+++ b/system/btif/avrcp/avrcp_service.cc
@@ -68,7 +68,7 @@
 AvrcpService* AvrcpService::instance_ = nullptr;
 AvrcpService::ServiceInterfaceImpl* AvrcpService::service_interface_ = nullptr;
 
-class A2dpInterfaceImpl : public A2dpInterface {
+static class A2dpInterfaceImpl : public A2dpInterface {
   RawAddress active_peer() override { return btif_av_source_active_peer(); }
 
   bool is_peer_in_silence_mode(const RawAddress& peer_address) override {
@@ -94,7 +94,7 @@
   }
 } a2dp_interface_;
 
-class AvrcpInterfaceImpl : public AvrcpInterface {
+static class AvrcpInterfaceImpl : public AvrcpInterface {
 public:
   uint16_t GetAvrcpControlVersion() { return AVRC_GetControlProfileVersion(); }
 
@@ -139,7 +139,7 @@
   }
 } avrcp_interface_;
 
-class SdpInterfaceImpl : public SdpInterface {
+static class SdpInterfaceImpl : public SdpInterface {
 public:
   bool InitDiscoveryDb(tSDP_DISCOVERY_DB* a, uint32_t b, uint16_t c, const bluetooth::Uuid* d,
                        uint16_t e, uint16_t* f) override {
diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc
index 3850345..a2c6300 100644
--- a/system/btif/src/bluetooth.cc
+++ b/system/btif/src/bluetooth.cc
@@ -133,11 +133,6 @@
 #include "types/bt_transport.h"
 #include "types/raw_address.h"
 
-using bluetooth::csis::CsisClientInterface;
-using bluetooth::has::HasClientInterface;
-using bluetooth::le_audio::LeAudioBroadcasterInterface;
-using bluetooth::le_audio::LeAudioClientInterface;
-using bluetooth::vc::VolumeControlInterface;
 using namespace bluetooth;
 
 namespace {
diff --git a/system/btif/src/btif_av.cc b/system/btif/src/btif_av.cc
index c7c1504..09a83d9 100644
--- a/system/btif/src/btif_av.cc
+++ b/system/btif/src/btif_av.cc
@@ -1984,8 +1984,7 @@
       // incoming/outgoing connect/disconnect requests.
       log::warn("Peer {} : event={}: transitioning to Idle due to ACL Disconnect",
                 peer_.PeerAddress(), BtifAvEvent::EventName(event));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_ACL_DISCONNECTED, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_ACL_DISCONNECTED);
       btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
                                    bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL,
                                    peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
@@ -1997,8 +1996,7 @@
     case BTA_AV_REJECT_EVT:
       log::warn("Peer {} : event={} flags={}", peer_.PeerAddress(), BtifAvEvent::EventName(event),
                 peer_.FlagsToString());
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_REJECT_EVT, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_REJECT_EVT);
       btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
                                    bt_status_t::BT_STATUS_AUTH_REJECTED, BTA_AV_FAIL,
                                    peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
@@ -2079,8 +2077,7 @@
         btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTED,
                                      bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
                                      peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_SUCCESS, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_SUCCESS);
       } else {
         if (btif_rc_is_connected_peer(peer_.PeerAddress())) {
           // Disconnect the AVRCP connection, in case the A2DP connectiton
@@ -2098,8 +2095,7 @@
         btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
                                      bt_status_t::BT_STATUS_FAIL, status,
                                      peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_FAILURE, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_FAILURE);
       }
 
       // Change state to Open/Idle based on the status
@@ -2138,8 +2134,7 @@
               "Peer {} : event={} : device is already connecting, ignore Connect "
               "request",
               peer_.PeerAddress(), BtifAvEvent::EventName(event));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_ALREADY_CONNECTING);
       btif_queue_advance();
     } break;
 
@@ -2150,16 +2145,14 @@
               "Peer {} : event={} : device is already connecting, ignore incoming "
               "request",
               peer_.PeerAddress(), BtifAvEvent::EventName(event));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_ALREADY_CONNECTING);
     } break;
 
     case BTIF_AV_OFFLOAD_START_REQ_EVT:
       log::error("Peer {} : event={}: stream is not Opened", peer_.PeerAddress(),
                  BtifAvEvent::EventName(event));
       btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_OFFLOAD_START_REQ_FAILURE, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_OFFLOAD_START_REQ_FAILURE);
       break;
 
     case BTA_AV_CLOSE_EVT:
@@ -2168,8 +2161,7 @@
                                    bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL,
                                    peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
       peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_CLOSE, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_CLOSE);
       DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(peer_.PeerAddress(), IOT_CONF_KEY_A2DP_CONN_FAIL_COUNT);
       if (peer_.SelfInitiatedConnection()) {
         btif_queue_advance();
@@ -2183,8 +2175,7 @@
                                    peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
       peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
       DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(peer_.PeerAddress(), IOT_CONF_KEY_A2DP_CONN_FAIL_COUNT);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_DISCONNECTED, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_DISCONNECTED);
       if (peer_.SelfInitiatedConnection()) {
         btif_queue_advance();
       }
@@ -2202,8 +2193,7 @@
       CHECK_RC_EVENT(event, reinterpret_cast<tBTA_AV*>(p_data));
 
     default:
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_UNKNOWN_EVENT, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::A2DP_CONNECTION_UNKNOWN_EVENT);
       log::warn("Peer {} : Unhandled event={}", peer_.PeerAddress(), BtifAvEvent::EventName(event));
       return false;
   }
diff --git a/system/btif/src/btif_avrcp_audio_track.cc b/system/btif/src/btif_avrcp_audio_track.cc
index 9ba26d9..066d5ba 100644
--- a/system/btif/src/btif_avrcp_audio_track.cc
+++ b/system/btif/src/btif_avrcp_audio_track.cc
@@ -47,7 +47,7 @@
 // Minimum track gain that can be set.
 constexpr float kMinTrackGain = 0.0f;
 
-struct AudioEngine {
+static struct AudioEngine {
   int trackFreq = 0;
   int channelCount = 0;
   std::thread* thread = nullptr;
diff --git a/system/btif/src/btif_bqr.cc b/system/btif/src/btif_bqr.cc
index 23460fc..6bdd4fb 100644
--- a/system/btif/src/btif_bqr.cc
+++ b/system/btif/src/btif_bqr.cc
@@ -66,7 +66,7 @@
 static uint16_t BtSchedulingTraceCounter = 0;
 
 class BluetoothQualityReportInterfaceImpl;
-std::unique_ptr<BluetoothQualityReportInterface> bluetoothQualityReportInstance;
+static std::unique_ptr<BluetoothQualityReportInterface> bluetoothQualityReportInstance;
 
 namespace {
 static std::recursive_mutex life_cycle_guard_;
@@ -411,8 +411,8 @@
   }
 }
 
-void register_vse();
-void unregister_vse();
+static void register_vse();
+static void unregister_vse();
 
 static void ConfigureBqr(const BqrConfiguration& bqr_config);
 
@@ -1085,12 +1085,12 @@
   }
 }
 
-void register_vse() {
+static void register_vse() {
   bluetooth::shim::GetHciLayer()->RegisterVendorSpecificEventHandler(
           hci::VseSubeventCode::BQR_EVENT, to_bind_->Bind(vendor_specific_event_callback));
 }
 
-void unregister_vse() {
+static void unregister_vse() {
   bluetooth::shim::GetHciLayer()->UnregisterVendorSpecificEventHandler(
           hci::VseSubeventCode::BQR_EVENT);
 }
diff --git a/system/btif/src/btif_config.cc b/system/btif/src/btif_config.cc
index 2b03700..b00dbdc 100644
--- a/system/btif/src/btif_config.cc
+++ b/system/btif/src/btif_config.cc
@@ -48,7 +48,6 @@
 #define TIME_STRING_LENGTH sizeof("YYYY-MM-DD HH:MM:SS")
 #define DISABLED "disabled"
 
-using bluetooth::bluetooth_keystore::BluetoothKeystoreInterface;
 using bluetooth::common::AddressObfuscator;
 using namespace bluetooth;
 
diff --git a/system/btif/src/btif_core.cc b/system/btif/src/btif_core.cc
index 520574f..342c38c 100644
--- a/system/btif/src/btif_core.cc
+++ b/system/btif/src/btif_core.cc
@@ -66,9 +66,7 @@
 #include "types/ble_address_with_type.h"
 #include "types/bluetooth/uuid.h"
 
-using base::PlatformThread;
 using bluetooth::Uuid;
-using bluetooth::common::MessageLoopThread;
 using namespace bluetooth;
 
 /*******************************************************************************
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index 81627d5..a005154 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -63,6 +63,7 @@
 #include "btif_sdp.h"
 #include "btif_storage.h"
 #include "btif_util.h"
+#include "btif_iot_config.h"
 #include "common/lru_cache.h"
 #include "common/strings.h"
 #include "device/include/interop.h"
@@ -288,11 +289,6 @@
                               bool during_device_search);
 
 /******************************************************************************
- *  Externs
- *****************************************************************************/
-void btif_iot_update_remote_info(tBTA_DM_AUTH_CMPL* p_auth_cmpl, bool is_ble, bool is_ssp);
-
-/******************************************************************************
  *  Functions
  *****************************************************************************/
 
diff --git a/system/btif/src/btif_gatt_client.cc b/system/btif/src/btif_gatt_client.cc
index cdd099d..f5580aa 100644
--- a/system/btif/src/btif_gatt_client.cc
+++ b/system/btif/src/btif_gatt_client.cc
@@ -63,7 +63,6 @@
 #include "types/raw_address.h"
 
 using base::Bind;
-using base::Owned;
 using bluetooth::Uuid;
 
 using namespace bluetooth;
diff --git a/system/btif/src/btif_gatt_util.cc b/system/btif/src/btif_gatt_util.cc
index 324ada3..ddc3b7d 100644
--- a/system/btif/src/btif_gatt_util.cc
+++ b/system/btif/src/btif_gatt_util.cc
@@ -39,7 +39,6 @@
 #include "types/bt_transport.h"
 #include "types/raw_address.h"
 
-using bluetooth::Uuid;
 using namespace bluetooth;
 
 /*******************************************************************************
diff --git a/system/btif/src/btif_hci_vs.cc b/system/btif/src/btif_hci_vs.cc
index 90af5cb..ff22e7f 100644
--- a/system/btif/src/btif_hci_vs.cc
+++ b/system/btif/src/btif_hci_vs.cc
@@ -33,7 +33,7 @@
 using hci::OpCode;
 using hci::VendorSpecificEventView;
 
-std::unique_ptr<BluetoothHciVendorSpecificInterface> hciVendorSpecificInterface;
+static std::unique_ptr<BluetoothHciVendorSpecificInterface> hciVendorSpecificInterface;
 
 static void CommandStatusOrCompleteCallback(BluetoothHciVendorSpecificCallbacks* callbacks,
                                             Cookie cookie,
diff --git a/system/btif/src/btif_hf.cc b/system/btif/src/btif_hf.cc
index 3194e66..73d60f3 100644
--- a/system/btif/src/btif_hf.cc
+++ b/system/btif/src/btif_hf.cc
@@ -389,8 +389,7 @@
                     p_data->open.status, btif_hf_cb[idx].connected_bda, p_data->open.bd_addr);
             bt_hf_callbacks->ConnectionStateCallback(BTHF_CONNECTION_STATE_DISCONNECTED,
                                                      &(p_data->open.bd_addr));
-            bluetooth::metrics::CountCounterMetrics(
-                    android::bluetooth::CodePathCounterKeyEnum::HFP_COLLISON_AT_AG_OPEN, 1);
+            bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HFP_COLLISON_AT_AG_OPEN);
           }
           break;
         }
@@ -411,8 +410,7 @@
                   btif_hf_cb[idx].connected_bda, p_data->open.bd_addr);
           bt_hf_callbacks->ConnectionStateCallback(BTHF_CONNECTION_STATE_DISCONNECTED,
                                                    &(btif_hf_cb[idx].connected_bda));
-          bluetooth::metrics::CountCounterMetrics(
-                  android::bluetooth::CodePathCounterKeyEnum::HFP_COLLISON_AT_CONNECTING, 1);
+          bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HFP_COLLISON_AT_CONNECTING);
           reset_control_block(&btif_hf_cb[idx]);
           btif_queue_advance();
         }
@@ -471,8 +469,7 @@
           bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, &connected_bda);
         }
 
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::HFP_SELF_INITIATED_AG_FAILED, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HFP_SELF_INITIATED_AG_FAILED);
         btif_queue_advance();
         if (btm_sec_is_a_bonded_dev(connected_bda)) {
           DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(connected_bda, IOT_CONF_KEY_HFP_SLC_CONN_FAIL_COUNT);
@@ -495,8 +492,7 @@
       bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, &connected_bda);
       if (failed_to_setup_slc) {
         log::error("failed to setup SLC for {}", connected_bda);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::HFP_SLC_SETUP_FAILED, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HFP_SLC_SETUP_FAILED);
         btif_queue_advance();
         bluetooth::metrics::LogMetricHfpSlcFail(p_data->open.bd_addr);
         DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(btif_hf_cb[idx].connected_bda,
diff --git a/system/btif/src/btif_hf_client.cc b/system/btif/src/btif_hf_client.cc
index 842b586..4eff314 100644
--- a/system/btif/src/btif_hf_client.cc
+++ b/system/btif/src/btif_hf_client.cc
@@ -104,8 +104,6 @@
  ******************************************************************************/
 static bthf_client_callbacks_t* bt_hf_client_callbacks = NULL;
 
-char btif_hf_client_version[PROPERTY_VALUE_MAX];
-
 static const char* dump_hf_client_conn_state(uint16_t event) {
   switch (event) {
     CASE_RETURN_STR(BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED)
@@ -313,7 +311,6 @@
 }
 
 static bt_status_t connect(const RawAddress* bd_addr) {
-  log::verbose("HFP Client version is  {}", btif_hf_client_version);
   CHECK_BTHF_CLIENT_INIT();
   return btif_queue_connect(UUID_SERVCLASS_HF_HANDSFREE, bd_addr, connect_int);
 }
diff --git a/system/btif/src/btif_hh.cc b/system/btif/src/btif_hh.cc
index 1cc443b..06cf12a 100644
--- a/system/btif/src/btif_hh.cc
+++ b/system/btif/src/btif_hh.cc
@@ -468,8 +468,8 @@
                handle);
   }
   log::warn("Reject unexpected incoming HID Connection, device: {}", conn.link_spec);
-  bluetooth::metrics::CountCounterMetrics(
-          android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, 1);
+  bluetooth::metrics::Counter(
+          bluetooth::metrics::CounterKey::HIDH_COUNT_INCOMING_CONNECTION_REJECTED);
 
   btif_hh_device_t* p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec);
   if (p_dev != nullptr) {
@@ -538,8 +538,8 @@
   }
 
   log::error("Out of space to add device");
-  bluetooth::metrics::CountCounterMetrics(
-          android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_MAX_ADDED_DEVICE_LIMIT_REACHED, 1);
+  bluetooth::metrics::Counter(
+          bluetooth::metrics::CounterKey::HIDH_COUNT_MAX_ADDED_DEVICE_LIMIT_REACHED);
   return false;
 }
 
@@ -688,8 +688,8 @@
 
     log::warn("Reject Incoming HID Connection, device: {}, state: {}", conn.link_spec,
               bthh_connection_state_text(dev_status));
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_COUNT_INCOMING_CONNECTION_REJECTED);
 
     if (p_dev != nullptr) {
       p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
@@ -757,8 +757,8 @@
     }
 
     log::warn("Reject Incoming HID Connection, device: {}", conn.link_spec);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_COUNT_INCOMING_CONNECTION_REJECTED);
     BTA_HhClose(conn.handle);
     return;
   }
@@ -1009,10 +1009,8 @@
   BTHH_STATE_UPDATE(p_dev->link_spec, p_dev->dev_status);
 
   if (!p_dev->local_vup) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::
-                    HIDH_COUNT_VIRTUAL_UNPLUG_REQUESTED_BY_REMOTE_DEVICE,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_COUNT_VIRTUAL_UNPLUG_REQUESTED_BY_REMOTE_DEVICE);
   }
 
   // Remove the HID device
@@ -1315,10 +1313,8 @@
   if (!p_dev && btif_hh_cb.device_num >= BTIF_HH_MAX_HID) {
     // No space for more HID device now.
     log::warn("Error, exceeded the maximum supported HID device number {}", BTIF_HH_MAX_HID);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::
-                    HIDH_COUNT_CONNECT_REQ_WHEN_MAX_DEVICE_LIMIT_REACHED,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_COUNT_CONNECT_REQ_WHEN_MAX_DEVICE_LIMIT_REACHED);
     return BT_STATUS_NOMEM;
   }
 
@@ -2163,8 +2159,7 @@
     return BT_STATUS_DEVICE_NOT_FOUND;
   } else if (((int)reportType) <= BTA_HH_RPTT_RESRV || ((int)reportType) > BTA_HH_RPTT_FEATURE) {
     log::error("report type={} not supported", reportType);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_WRONG_REPORT_TYPE, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_COUNT_WRONG_REPORT_TYPE);
     return BT_STATUS_UNSUPPORTED;
   } else {
     BTA_HhGetReport(p_dev->dev_handle, reportType, reportId, bufferSize);
@@ -2235,8 +2230,7 @@
     return BT_STATUS_DEVICE_NOT_FOUND;
   } else if (((int)reportType) <= BTA_HH_RPTT_RESRV || ((int)reportType) > BTA_HH_RPTT_FEATURE) {
     log::error("report type={} not supported", reportType);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_WRONG_REPORT_TYPE, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_COUNT_WRONG_REPORT_TYPE);
     return BT_STATUS_UNSUPPORTED;
   } else {
     int hex_bytes_filled;
diff --git a/system/btif/src/btif_keystore.cc b/system/btif/src/btif_keystore.cc
index ef5f7d9..9a8ffa9 100644
--- a/system/btif/src/btif_keystore.cc
+++ b/system/btif/src/btif_keystore.cc
@@ -29,15 +29,14 @@
 #include "main/shim/config.h"
 #include "os/parameter_provider.h"
 
-using base::Bind;
-using base::Unretained;
 using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks;
 using bluetooth::bluetooth_keystore::BluetoothKeystoreInterface;
 
 namespace bluetooth {
 namespace bluetooth_keystore {
+
 class BluetoothKeystoreInterfaceImpl;
-std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance;
+static std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance;
 const int CONFIG_COMPARE_ALL_PASS = 0b11;
 
 class BluetoothKeystoreInterfaceImpl
diff --git a/system/btif/src/btif_sock_l2cap.cc b/system/btif/src/btif_sock_l2cap.cc
index b5861fe..e12716b 100644
--- a/system/btif/src/btif_sock_l2cap.cc
+++ b/system/btif/src/btif_sock_l2cap.cc
@@ -1088,7 +1088,7 @@
   return false;
 }
 
-inline BT_HDR* malloc_l2cap_buf(uint16_t len) {
+static BT_HDR* malloc_l2cap_buf(uint16_t len) {
   // We need FCS only for L2CAP_FCR_ERTM_MODE, but it's just 2 bytes so it's ok
   BT_HDR* msg = (BT_HDR*)osi_malloc(BT_HDR_SIZE + L2CAP_MIN_OFFSET + len + L2CAP_FCS_LENGTH);
   msg->offset = L2CAP_MIN_OFFSET;
@@ -1096,7 +1096,7 @@
   return msg;
 }
 
-inline uint8_t* get_l2cap_sdu_start_ptr(BT_HDR* msg) {
+static uint8_t* get_l2cap_sdu_start_ptr(BT_HDR* msg) {
   return (uint8_t*)(msg) + BT_HDR_SIZE + msg->offset;
 }
 
diff --git a/system/btif/src/btif_sock_rfc.cc b/system/btif/src/btif_sock_rfc.cc
index 1ec9b58..f063621 100644
--- a/system/btif/src/btif_sock_rfc.cc
+++ b/system/btif/src/btif_sock_rfc.cc
@@ -920,7 +920,7 @@
 
 static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) {
   if (p->status != tBTA_JV_STATUS::SUCCESS) {
-    log::error("error writing to RFCOMM socket, req_id:{}.", p->req_id);
+    log::error("error writing to RFCOMM socket, slot_id:{}.", p->req_id);
     return;
   }
 
diff --git a/system/btif/src/stack_manager.cc b/system/btif/src/stack_manager.cc
index 9c74339..d0c87cb 100644
--- a/system/btif/src/stack_manager.cc
+++ b/system/btif/src/stack_manager.cc
@@ -224,7 +224,7 @@
         {NULL, NULL},
 };
 
-inline const module_t* get_local_module(const char* name) {
+static const module_t* get_local_module(const char* name) {
   size_t len = strlen(name);
 
   for (const struct module_lookup* l = module_table; l->module; l++) {
diff --git a/system/common/message_loop_thread.cc b/system/common/message_loop_thread.cc
index a6dd211..5af121d 100644
--- a/system/common/message_loop_thread.cc
+++ b/system/common/message_loop_thread.cc
@@ -127,12 +127,20 @@
 
 std::string MessageLoopThread::ToString() const {
   std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
+#if defined(TARGET_FLOSS) && BASE_VER >= 1419016
+  return std::format("{}({})", thread_name_, thread_id_.raw());
+#else
   return std::format("{}({})", thread_name_, thread_id_);
+#endif // defined(TARGET_FLOSS) && BASE_VER >= 1419016
 }
 
 bool MessageLoopThread::IsRunning() const {
   std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
+#if defined(TARGET_FLOSS) && BASE_VER >= 1419016
+  return thread_id_.raw() != -1;
+#else
   return thread_id_ != -1;
+#endif // defined(TARGET_FLOSS) && BASE_VER >= 1419016
 }
 
 // Non API method, should not be protected by API mutex
@@ -187,7 +195,11 @@
 
   {
     std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
+  #if defined(TARGET_FLOSS) && BASE_VER >= 1419016
+    thread_id_ = base::PlatformThreadId(-1);
+  #else
     thread_id_ = -1;
+  #endif // defined(TARGET_FLOSS) && BASE_VER >= 1419016
     linux_tid_ = -1;
     delete message_loop_;
     message_loop_ = nullptr;
diff --git a/system/device/src/interop.cc b/system/device/src/interop.cc
index 4431366..1a67978 100644
--- a/system/device/src/interop.cc
+++ b/system/device/src/interop.cc
@@ -84,9 +84,9 @@
 
 static list_t* interop_list = NULL;
 
-bool interop_is_initialized = false;
+static bool interop_is_initialized = false;
 // protects operations on |interop_list|
-pthread_mutex_t interop_list_lock;
+static pthread_mutex_t interop_list_lock;
 
 // protects operations on |config|
 static pthread_mutex_t file_lock;
diff --git a/system/gd/hal/hci_hal_android.cc b/system/gd/hal/hci_hal_android.cc
index f548080..89e9e5d 100644
--- a/system/gd/hal/hci_hal_android.cc
+++ b/system/gd/hal/hci_hal_android.cc
@@ -32,7 +32,7 @@
 namespace bluetooth::hal {
 
 template <class VecType>
-std::string GetTimerText(const char* func_name, VecType vec) {
+static std::string GetTimerText(const char* func_name, VecType vec) {
   return common::StringFormat(
           "%s: len %zu, 1st 5 bytes '%s'", func_name, vec.size(),
           common::ToHexString(vec.begin(), std::min(vec.end(), vec.begin() + 5)).c_str());
diff --git a/system/gd/hal/ranging_hal_android.cc b/system/gd/hal/ranging_hal_android.cc
index 086e651..e99ceb3 100644
--- a/system/gd/hal/ranging_hal_android.cc
+++ b/system/gd/hal/ranging_hal_android.cc
@@ -41,7 +41,6 @@
 using aidl::android::hardware::bluetooth::ranging::CsSyncPhyType;
 using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSounding;
 using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSoundingSession;
-using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSoundingSessionCallback;
 using aidl::android::hardware::bluetooth::ranging::ModeType;
 using aidl::android::hardware::bluetooth::ranging::ProcedureEnableConfig;
 using aidl::android::hardware::bluetooth::ranging::Role;
@@ -59,7 +58,6 @@
 using aidl::android::hardware::bluetooth::ranging::ModeType;
 using aidl::android::hardware::bluetooth::ranging::ModeZeroData;
 using aidl::android::hardware::bluetooth::ranging::Nadm;
-using aidl::android::hardware::bluetooth::ranging::PctIQSample;
 using aidl::android::hardware::bluetooth::ranging::ProcedureAbortReason;
 using aidl::android::hardware::bluetooth::ranging::RttToaTodData;
 using aidl::android::hardware::bluetooth::ranging::StepData;
diff --git a/system/gd/hal/snoop_logger_socket.cc b/system/gd/hal/snoop_logger_socket.cc
index 0405950..4ccaa72 100644
--- a/system/gd/hal/snoop_logger_socket.cc
+++ b/system/gd/hal/snoop_logger_socket.cc
@@ -67,7 +67,7 @@
   }
 
   ssize_t ret;
-  RUN_NO_INTR(ret = syscall_if_->Send(client_socket, data, length, MSG_DONTWAIT));
+  RUN_NO_INTR(ret = syscall_if_->Send(client_socket, data, length, MSG_DONTWAIT | MSG_NOSIGNAL));
 
   if (ret == -1 && syscall_if_->GetErrno() == ECONNRESET) {
     SafeCloseSocket(client_socket);
diff --git a/system/gd/hal/snoop_logger_socket_thread.cc b/system/gd/hal/snoop_logger_socket_thread.cc
index f622fb2..b8c1cdf 100644
--- a/system/gd/hal/snoop_logger_socket_thread.cc
+++ b/system/gd/hal/snoop_logger_socket_thread.cc
@@ -47,6 +47,10 @@
 std::future<bool> SnoopLoggerSocketThread::Start() {
   log::debug("");
   std::promise<bool> thread_started;
+  if (listen_thread_) {
+    thread_started.set_value(true);
+    return thread_started.get_future();
+  }
   auto future = thread_started.get_future();
   stop_thread_ = false;
   listen_thread_ = std::make_unique<std::thread>(&SnoopLoggerSocketThread::Run, this,
@@ -63,6 +67,7 @@
   if (listen_thread_ && listen_thread_->joinable()) {
     listen_thread_->join();
     listen_thread_.reset();
+    socket_->Cleanup();
   }
 }
 
@@ -87,7 +92,12 @@
   while (!stop_thread_ && socket_->ProcessIncomingRequest()) {
   }
 
-  socket_->Cleanup();
+  // We don't call `socket_->Cleanup()` here because it's possible for that to lead to SIGPIPE: in
+  // `Stop` it sets `stop_thread_` to true, and then calls `socket_->NotifySocketListener()`. Within
+  // that small window, we might have checked `stop_thread_` above, and if we were to call
+  // `socket_->Cleanup` here, that would then mean that `socket_->NotifySocketListener()` could
+  // result in SIGPIPE, which, by default will terminate the process.
+
   listen_thread_running_ = false;
 }
 
diff --git a/system/gd/hal/snoop_logger_socket_thread.h b/system/gd/hal/snoop_logger_socket_thread.h
index f508ff9..ca783ac 100644
--- a/system/gd/hal/snoop_logger_socket_thread.h
+++ b/system/gd/hal/snoop_logger_socket_thread.h
@@ -51,10 +51,8 @@
 
   // Socket thread for listening to incoming connections.
   std::unique_ptr<std::thread> listen_thread_;
-  bool listen_thread_running_ = false;
+  std::atomic<bool> listen_thread_running_ = false;
 
-  std::condition_variable listen_thread_running_cv_;
-  std::mutex listen_thread_running_mutex_;
   std::atomic<bool> stop_thread_;
 };
 
diff --git a/system/gd/hal/snoop_logger_socket_thread_test.cc b/system/gd/hal/snoop_logger_socket_thread_test.cc
index 7f0dc48..5cfa457 100644
--- a/system/gd/hal/snoop_logger_socket_thread_test.cc
+++ b/system/gd/hal/snoop_logger_socket_thread_test.cc
@@ -150,7 +150,6 @@
   sls.Stop();
 
   ASSERT_FALSE(sls.ThreadIsRunning());
-  close(socket_fd);
 }
 
 TEST_F(SnoopLoggerSocketThreadModuleTest, socket_send_no_start_test) {
diff --git a/system/gd/hal/snoop_logger_tracing.cc b/system/gd/hal/snoop_logger_tracing.cc
index 38ce3de..43729a4 100644
--- a/system/gd/hal/snoop_logger_tracing.cc
+++ b/system/gd/hal/snoop_logger_tracing.cc
@@ -81,7 +81,7 @@
 }
 
 template <typename T, typename... Rest>
-void HashCombine(std::size_t& seed, const T& val, const Rest&... rest) {
+static void HashCombine(std::size_t& seed, const T& val, const Rest&... rest) {
   seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
   (HashCombine(seed, rest), ...);
 }
diff --git a/system/gd/hci/acl_manager.cc b/system/gd/hci/acl_manager.cc
index 4c19132..f474a27 100644
--- a/system/gd/hci/acl_manager.cc
+++ b/system/gd/hci/acl_manager.cc
@@ -47,21 +47,17 @@
 constexpr uint16_t kQualcommDebugHandle = 0xedc;
 constexpr uint16_t kSamsungDebugHandle = 0xeef;
 
-using acl_manager::AclConnection;
 using common::Bind;
 using common::BindOnce;
 
 using acl_manager::classic_impl;
-using acl_manager::ClassicAclConnection;
 using acl_manager::ConnectionCallbacks;
 
 using acl_manager::le_impl;
-using acl_manager::LeAclConnection;
 using acl_manager::LeConnectionCallbacks;
 
-using acl_manager::RoundRobinScheduler;
-
 using acl_manager::AclScheduler;
+using acl_manager::RoundRobinScheduler;
 
 struct AclManager::impl {
   explicit impl(const AclManager& acl_manager) : acl_manager_(acl_manager) {}
diff --git a/system/gd/hci/acl_manager/le_acl_connection.cc b/system/gd/hci/acl_manager/le_acl_connection.cc
index 903e125..8308564 100644
--- a/system/gd/hci/acl_manager/le_acl_connection.cc
+++ b/system/gd/hci/acl_manager/le_acl_connection.cc
@@ -23,8 +23,6 @@
 #include "hci/acl_manager/le_connection_management_callbacks.h"
 #include "hci/event_checkers.h"
 
-using bluetooth::hci::Address;
-
 namespace bluetooth {
 namespace hci {
 namespace acl_manager {
diff --git a/system/gd/hci/distance_measurement_manager.cc b/system/gd/hci/distance_measurement_manager.cc
index 14cfba1..387d50c 100644
--- a/system/gd/hci/distance_measurement_manager.cc
+++ b/system/gd/hci/distance_measurement_manager.cc
@@ -117,7 +117,6 @@
       for (uint8_t i = 0; i < num_antenna_paths; i++) {
         ranging_header_.antenna_paths_mask_ |= (1 << i);
       }
-      ranging_header_.pct_format_ = PctFormat::IQ;
       procedure_data_v2_.local_selected_tx_power_ = selected_tx_power;
     }
     // Procedure counter
diff --git a/system/gd/hci/hci_layer_fake.cc b/system/gd/hci/hci_layer_fake.cc
index ffad279..2f8419e 100644
--- a/system/gd/hci/hci_layer_fake.cc
+++ b/system/gd/hci/hci_layer_fake.cc
@@ -21,6 +21,7 @@
 #include <gtest/gtest.h>
 
 #include <chrono>
+#include <future>
 
 #include "packet/raw_builder.h"
 
@@ -73,33 +74,31 @@
 void HciLayerFake::EnqueueCommand(
         std::unique_ptr<CommandBuilder> command,
         common::ContextualOnceCallback<void(CommandStatusView)> on_status) {
-  std::lock_guard<std::mutex> lock(mutex_);
+  {
+    std::lock_guard<std::mutex> lock(mutex_);
 
-  DebugPrintCommandOpcode(std::string("Sending with command status, "), command);
+    DebugPrintCommandOpcode(std::string("Sending with command status, "), command);
 
-  command_queue_.push(std::move(command));
-  command_status_callbacks.push_back(std::move(on_status));
-
-  if (command_queue_.size() == 1) {
-    // since GetCommand may replace this promise, we have to do this inside the lock
-    command_promise_.set_value();
+    command_queue_.push(std::move(command));
+    command_status_callbacks_.push_back(std::move(on_status));
   }
+
+  condition_.notify_all();
 }
 
 void HciLayerFake::EnqueueCommand(
         std::unique_ptr<CommandBuilder> command,
         common::ContextualOnceCallback<void(CommandCompleteView)> on_complete) {
-  std::lock_guard<std::mutex> lock(mutex_);
+  {
+    std::lock_guard<std::mutex> lock(mutex_);
 
-  DebugPrintCommandOpcode(std::string("Sending with command complete, "), command);
+    DebugPrintCommandOpcode(std::string("Sending with command complete, "), command);
 
-  command_queue_.push(std::move(command));
-  command_complete_callbacks.push_back(std::move(on_complete));
-
-  if (command_queue_.size() == 1) {
-    // since GetCommand may replace this promise, we have to do this inside the lock
-    command_promise_.set_value();
+    command_queue_.push(std::move(command));
+    command_complete_callbacks_.push_back(std::move(on_complete));
   }
+
+  condition_.notify_all();
 }
 
 void HciLayerFake::EnqueueCommand(
@@ -110,23 +109,18 @@
 }
 
 CommandView HciLayerFake::GetCommand() {
-  EXPECT_EQ(command_future_.wait_for(std::chrono::milliseconds(1000)), std::future_status::ready);
-
   std::lock_guard<std::mutex> lock(mutex_);
 
-  if (command_queue_.empty()) {
-    log::error("Command queue is empty");
+  if (!condition_.wait_for(
+              mutex_, std::chrono::milliseconds(1000),
+              [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) { return !command_queue_.empty(); })) {
+    ADD_FAILURE() << "Command queue is empty";
     return empty_command_view_;
   }
 
   auto last = std::move(command_queue_.front());
   command_queue_.pop();
 
-  if (command_queue_.empty()) {
-    command_promise_ = {};
-    command_future_ = command_promise_.get_future();
-  }
-
   CommandView command_packet_view = CommandView::Create(GetPacketView(std::move(last)));
   log::assert_that(command_packet_view.IsValid(), "Got invalid command");
   return command_packet_view;
@@ -140,34 +134,43 @@
   return next_command;
 }
 
-void HciLayerFake::AssertNoQueuedCommand() { EXPECT_TRUE(command_queue_.empty()); }
+void HciLayerFake::AssertNoQueuedCommand() {
+  std::lock_guard lock(mutex_);
+  EXPECT_TRUE(command_queue_.empty());
+}
 
 void HciLayerFake::RegisterEventHandler(EventCode event_code,
                                         common::ContextualCallback<void(EventView)> event_handler) {
+  std::lock_guard lock(mutex_);
   registered_events_[event_code] = event_handler;
 }
 
 void HciLayerFake::UnregisterEventHandler(EventCode event_code) {
+  std::lock_guard lock(mutex_);
   registered_events_.erase(event_code);
 }
 
 void HciLayerFake::RegisterLeEventHandler(
         SubeventCode subevent_code,
         common::ContextualCallback<void(LeMetaEventView)> event_handler) {
+  std::lock_guard lock(mutex_);
   registered_le_events_[subevent_code] = event_handler;
 }
 
 void HciLayerFake::UnregisterLeEventHandler(SubeventCode subevent_code) {
+  std::lock_guard lock(mutex_);
   registered_le_events_.erase(subevent_code);
 }
 
 void HciLayerFake::RegisterVendorSpecificEventHandler(
         VseSubeventCode subevent_code,
         common::ContextualCallback<void(VendorSpecificEventView)> event_handler) {
+  std::lock_guard lock(mutex_);
   registered_vs_events_[subevent_code] = event_handler;
 }
 
 void HciLayerFake::UnregisterVendorSpecificEventHandler(VseSubeventCode subevent_code) {
+  std::lock_guard lock(mutex_);
   registered_vs_events_.erase(subevent_code);
 }
 
@@ -181,6 +184,7 @@
   } else if (event_code == EventCode::COMMAND_STATUS) {
     CommandStatusCallback(event);
   } else {
+    std::lock_guard lock(mutex_);
     ASSERT_NE(registered_events_.find(event_code), registered_events_.end())
             << EventCodeText(event_code);
     registered_events_[event_code](event);
@@ -188,6 +192,7 @@
 }
 
 void HciLayerFake::IncomingLeMetaEvent(std::unique_ptr<LeMetaEventBuilder> event_builder) {
+  std::lock_guard lock(mutex_);
   auto packet = GetPacketView(std::move(event_builder));
   EventView event = EventView::Create(packet);
   LeMetaEventView meta_event_view = LeMetaEventView::Create(event);
@@ -200,18 +205,29 @@
 void HciLayerFake::CommandCompleteCallback(EventView event) {
   CommandCompleteView complete_view = CommandCompleteView::Create(event);
   ASSERT_TRUE(complete_view.IsValid());
-  std::move(command_complete_callbacks.front())(complete_view);
-  command_complete_callbacks.pop_front();
+  common::ContextualOnceCallback<void(CommandCompleteView)> callback;
+  {
+    std::lock_guard lock(mutex_);
+    callback = std::move(command_complete_callbacks_.front());
+    command_complete_callbacks_.pop_front();
+  }
+  callback(complete_view);
 }
 
 void HciLayerFake::CommandStatusCallback(EventView event) {
   CommandStatusView status_view = CommandStatusView::Create(event);
   ASSERT_TRUE(status_view.IsValid());
-  std::move(command_status_callbacks.front())(status_view);
-  command_status_callbacks.pop_front();
+  common::ContextualOnceCallback<void(CommandStatusView)> callback;
+  {
+    std::lock_guard lock(mutex_);
+    callback = std::move(command_status_callbacks_.front());
+    command_status_callbacks_.pop_front();
+  }
+  callback(status_view);
 }
 
 void HciLayerFake::InitEmptyCommand() {
+  std::lock_guard lock(mutex_);
   auto payload = std::make_unique<bluetooth::packet::RawBuilder>();
   auto command_builder = CommandBuilder::Create(OpCode::NONE, std::move(payload));
   empty_command_view_ = CommandView::Create(GetPacketView(std::move(command_builder)));
@@ -219,6 +235,7 @@
 }
 
 void HciLayerFake::IncomingAclData(uint16_t handle, std::unique_ptr<AclBuilder> acl_builder) {
+  std::lock_guard lock(mutex_);
   os::Handler* hci_handler = GetHandler();
   auto* queue_end = acl_queue_.GetDownEnd();
   std::promise<void> promise;
@@ -243,11 +260,13 @@
 }
 
 void HciLayerFake::AssertNoOutgoingAclData() {
+  std::lock_guard lock(mutex_);
   auto queue_end = acl_queue_.GetDownEnd();
   EXPECT_EQ(queue_end->TryDequeue(), nullptr);
 }
 
 PacketView<kLittleEndian> HciLayerFake::OutgoingAclData() {
+  std::lock_guard lock(mutex_);
   auto queue_end = acl_queue_.GetDownEnd();
   std::unique_ptr<AclBuilder> received;
   do {
@@ -257,7 +276,10 @@
   return GetPacketView(std::move(received));
 }
 
-BidiQueueEnd<AclBuilder, AclView>* HciLayerFake::GetAclQueueEnd() { return acl_queue_.GetUpEnd(); }
+BidiQueueEnd<AclBuilder, AclView>* HciLayerFake::GetAclQueueEnd() {
+  std::lock_guard lock(mutex_);
+  return acl_queue_.GetUpEnd();
+}
 
 void HciLayerFake::Disconnect(uint16_t handle, ErrorCode reason) {
   GetHandler()->Post(
@@ -270,7 +292,6 @@
 
 void HciLayerFake::ListDependencies(ModuleList* /* list */) const {}
 void HciLayerFake::Start() {
-  std::lock_guard<std::mutex> lock(mutex_);
   InitEmptyCommand();
   os::Handler* handler = GetHandler();
   StartWithNoHalDependencies(handler);
diff --git a/system/gd/hci/hci_layer_fake.h b/system/gd/hci/hci_layer_fake.h
index d5d024a..1116b24 100644
--- a/system/gd/hci/hci_layer_fake.h
+++ b/system/gd/hci/hci_layer_fake.h
@@ -14,7 +14,9 @@
  * limitations under the License.
  */
 
-#include <future>
+#include <android-base/thread_annotations.h>
+
+#include <condition_variable>
 #include <list>
 #include <map>
 #include <memory>
@@ -44,11 +46,11 @@
                       common::ContextualOnceCallback<void(CommandStatusOrCompleteView)>
                               on_status_or_complete) override;
 
-  CommandView GetCommand();
+  CommandView GetCommand() LOCKS_EXCLUDED(mutex_);
 
-  CommandView GetCommand(OpCode op_code);
+  CommandView GetCommand(OpCode op_code) LOCKS_EXCLUDED(mutex_);
 
-  void AssertNoQueuedCommand();
+  void AssertNoQueuedCommand() LOCKS_EXCLUDED(mutex_);
 
   void RegisterEventHandler(EventCode event_code,
                             common::ContextualCallback<void(EventView)> event_handler) override;
@@ -67,21 +69,23 @@
 
   void UnregisterVendorSpecificEventHandler(VseSubeventCode subevent_code) override;
 
-  void IncomingEvent(std::unique_ptr<EventBuilder> event_builder);
+  void IncomingEvent(std::unique_ptr<EventBuilder> event_builder) LOCKS_EXCLUDED(mutex_);
 
-  void IncomingLeMetaEvent(std::unique_ptr<LeMetaEventBuilder> event_builder);
+  void IncomingLeMetaEvent(std::unique_ptr<LeMetaEventBuilder> event_builder)
+          LOCKS_EXCLUDED(mutex_);
 
-  void CommandCompleteCallback(EventView event);
+  void CommandCompleteCallback(EventView event) LOCKS_EXCLUDED(mutex_);
 
-  void CommandStatusCallback(EventView event);
+  void CommandStatusCallback(EventView event) LOCKS_EXCLUDED(mutex_);
 
-  void IncomingAclData(uint16_t handle);
+  void IncomingAclData(uint16_t handle) LOCKS_EXCLUDED(mutex_);
 
-  void IncomingAclData(uint16_t handle, std::unique_ptr<AclBuilder> acl_builder);
+  void IncomingAclData(uint16_t handle, std::unique_ptr<AclBuilder> acl_builder)
+          LOCKS_EXCLUDED(mutex_);
 
-  void AssertNoOutgoingAclData();
+  void AssertNoOutgoingAclData() LOCKS_EXCLUDED(mutex_);
 
-  packet::PacketView<packet::kLittleEndian> OutgoingAclData();
+  packet::PacketView<packet::kLittleEndian> OutgoingAclData() LOCKS_EXCLUDED(mutex_);
 
   common::BidiQueueEnd<AclBuilder, AclView>* GetAclQueueEnd() override;
 
@@ -93,37 +97,30 @@
   void Stop() override;
 
 private:
-  void InitEmptyCommand();
+  void InitEmptyCommand() LOCKS_EXCLUDED(mutex_);
   void do_disconnect(uint16_t handle, ErrorCode reason);
 
-  // Handler-only state. Mutexes are not needed when accessing these fields.
-  std::list<common::ContextualOnceCallback<void(CommandCompleteView)>> command_complete_callbacks;
-  std::list<common::ContextualOnceCallback<void(CommandStatusView)>> command_status_callbacks;
-  std::map<EventCode, common::ContextualCallback<void(EventView)>> registered_events_;
-  std::map<SubeventCode, common::ContextualCallback<void(LeMetaEventView)>> registered_le_events_;
+  std::list<common::ContextualOnceCallback<void(CommandCompleteView)>> command_complete_callbacks_
+          GUARDED_BY(mutex_);
+  std::list<common::ContextualOnceCallback<void(CommandStatusView)>> command_status_callbacks_
+          GUARDED_BY(mutex_);
+  std::map<EventCode, common::ContextualCallback<void(EventView)>> registered_events_
+          GUARDED_BY(mutex_);
+  std::map<SubeventCode, common::ContextualCallback<void(LeMetaEventView)>> registered_le_events_
+          GUARDED_BY(mutex_);
   std::map<VseSubeventCode, common::ContextualCallback<void(VendorSpecificEventView)>>
-          registered_vs_events_;
+          registered_vs_events_ GUARDED_BY(mutex_);
 
-  // thread-safe
-  common::BidiQueue<AclView, AclBuilder> acl_queue_{3 /* TODO: Set queue depth */};
+  common::BidiQueue<AclView, AclBuilder> acl_queue_ GUARDED_BY(mutex_){
+          3 /* TODO: Set queue depth */};
 
-  // Most operations must acquire this mutex before manipulating shared state. The ONLY exception
-  // is blocking on a promise, IF your thread is the only one mutating it. Note that SETTING a
-  // promise REQUIRES a lock, since another thread may replace the promise while you are doing so.
-  mutable std::mutex mutex_{};
+  mutable std::mutex mutex_;
+  std::condition_variable_any condition_;  // Used to notify when new commands are enqueued.
 
   // Shared state between the test and stack threads
-  std::queue<std::unique_ptr<CommandBuilder>> command_queue_;
+  std::queue<std::unique_ptr<CommandBuilder>> command_queue_ GUARDED_BY(mutex_);
 
-  // We start with Consumed=Set, Command=Unset.
-  // When a command is enqueued, we set Command=set
-  // When a command is popped, we block until Command=Set, then (if the queue is now empty) we
-  // reset Command=Unset and set Consumed=Set. This way we emulate a blocking queue.
-  std::promise<void> command_promise_{};  // Set when at least one command is in the queue
-  std::future<void> command_future_ =
-          command_promise_.get_future();  // GetCommand() blocks until this is fulfilled
-
-  CommandView empty_command_view_ = CommandView::Create(
+  CommandView empty_command_view_ GUARDED_BY(mutex_) = CommandView::Create(
           PacketView<packet::kLittleEndian>(std::make_shared<std::vector<uint8_t>>()));
 };
 
diff --git a/system/gd/packet/parser/parent_def.cc b/system/gd/packet/parser/parent_def.cc
index 416ee76..8f1174b 100644
--- a/system/gd/packet/parser/parent_def.cc
+++ b/system/gd/packet/parser/parent_def.cc
@@ -286,6 +286,64 @@
   }
 }
 
+Size ParentDef::HeaderAndFooterSizeIfStatic() const {
+  auto header_fields = fields_.GetFieldsBeforePayloadOrBody();
+  auto footer_fields = fields_.GetFieldsAfterPayloadOrBody();
+
+  Size padded_size;
+  const PacketField* padded_field = nullptr;
+  const PacketField* last_field = nullptr;
+  for (const auto& field : fields_) {
+    if (field->GetFieldType() == PaddingField::kFieldType) {
+      if (!padded_size.empty()) {
+        ERROR() << "Only one padding field is allowed.  Second field: " << field->GetName();
+      }
+      padded_field = last_field;
+      padded_size = field->GetSize();
+    }
+    last_field = field;
+  }
+  const Size INVALID{};
+  Size result{0};
+  for (const auto& field : header_fields) {
+    if (field == padded_field) {
+      result += padded_size;
+    } else {
+      result += field->GetBuilderSize();
+    }
+  }
+
+  if (result.has_dynamic()) {
+    return INVALID;
+  }
+
+  for (const auto& field : footer_fields) {
+    if (field == padded_field) {
+      result += padded_size;
+    } else {
+      result += field->GetBuilderSize();
+    }
+  }
+
+  if (result.has_dynamic()) {
+    return INVALID;
+  }
+
+  if (parent_ != nullptr) {
+    if (parent_->GetDefinitionType() == Type::PACKET) {
+      result += parent_->HeaderAndFooterSizeIfStatic();
+    } else {
+      return INVALID;
+    }
+  }
+
+  if (result.has_dynamic()) {
+    return INVALID;
+  }
+
+  return result;
+}
+
 void ParentDef::GenSize(std::ostream& s) const {
   auto header_fields = fields_.GetFieldsBeforePayloadOrBody();
   auto footer_fields = fields_.GetFieldsAfterPayloadOrBody();
@@ -305,58 +363,71 @@
   }
 
   s << "protected:";
-  s << "size_t BitsOfHeader() const {";
-  s << "return 0";
+  auto size_if_static = HeaderAndFooterSizeIfStatic();
 
-  if (parent_ != nullptr) {
-    if (parent_->GetDefinitionType() == Type::PACKET) {
-      s << " + " << parent_->name_ << "Builder::BitsOfHeader() ";
-    } else {
-      s << " + " << parent_->name_ << "::BitsOfHeader() ";
+  if (size_if_static.empty()) {
+    s << "size_t BitsOfHeaderAndFooter() const {";
+    s << "return 0";
+    if (parent_ != nullptr) {
+      if (parent_->GetDefinitionType() == Type::PACKET) {
+        auto parent_size_if_static = parent_->HeaderAndFooterSizeIfStatic();
+        if (parent_size_if_static.empty()) {
+          s << " + " << parent_->name_ << "Builder::BitsOfHeaderAndFooter() ";
+        } else {
+          s << " + " << parent_size_if_static.bits();
+        }
+      } else {
+        auto parent_size_if_static = parent_->HeaderAndFooterSizeIfStatic();
+        if (parent_size_if_static.empty()) {
+          s << " + " << parent_->name_ << "::BitsOfHeaderAndFooter() ";
+        } else {
+          s << " + " << parent_size_if_static.bits();
+        }
+      }
     }
-  }
 
-  for (const auto& field : header_fields) {
-    if (field == padded_field) {
-      s << " + " << padded_size;
-    } else {
-      s << " + " << field->GetBuilderSize();
+    for (const auto& field : header_fields) {
+      if (field == padded_field) {
+        s << " + " << padded_size;
+      } else {
+        s << " + " << field->GetBuilderSize();
+      }
     }
-  }
-  s << ";";
 
-  s << "}\n\n";
-
-  s << "size_t BitsOfFooter() const {";
-  s << "return 0";
-  for (const auto& field : footer_fields) {
-    if (field == padded_field) {
-      s << " + " << padded_size;
-    } else {
-      s << " + " << field->GetBuilderSize();
+    for (const auto& field : footer_fields) {
+      if (field == padded_field) {
+        s << " + " << padded_size;
+      } else {
+        s << " + " << field->GetBuilderSize();
+      }
     }
+    s << ";";
+    s << "}\n\n";
   }
 
-  if (parent_ != nullptr) {
-    if (parent_->GetDefinitionType() == Type::PACKET) {
-      s << " + " << parent_->name_ << "Builder::BitsOfFooter() ";
-    } else {
-      s << " + " << parent_->name_ << "::BitsOfFooter() ";
-    }
-  }
-  s << ";";
-  s << "}\n\n";
-
   if (fields_.HasPayload()) {
     s << "size_t GetPayloadSize() const {";
     s << "if (payload_ != nullptr) {return payload_->size();}";
-    s << "else { return size() - (BitsOfHeader() + BitsOfFooter()) / 8;}";
+
+    s << "else { return size() - ";
+
+    if (size_if_static.empty()) {
+      s << "(BitsOfHeaderAndFooter()) / 8;}";
+    } else {
+      s << size_if_static.bits() / 8 << ";}";
+    }
+
     s << ";}\n\n";
   }
 
   s << "public:";
   s << "virtual size_t size() const override {";
-  s << "return (BitsOfHeader() / 8)";
+
+  if (size_if_static.empty()) {
+    s << "return (BitsOfHeaderAndFooter() / 8)";
+  } else {
+    s << "return " << size_if_static.bits() / 8;
+  }
   if (fields_.HasPayload()) {
     s << "+ payload_->size()";
   }
@@ -370,8 +441,7 @@
       }
     }
   }
-  s << " + (BitsOfFooter() / 8);";
-  s << "}\n";
+  s << ";}";
 }
 
 void ParentDef::GenSerialize(std::ostream& s) const {
diff --git a/system/gd/packet/parser/parent_def.h b/system/gd/packet/parser/parent_def.h
index acaf202..0597fdf 100644
--- a/system/gd/packet/parser/parent_def.h
+++ b/system/gd/packet/parser/parent_def.h
@@ -61,6 +61,8 @@
 
   void GenMembers(std::ostream& s) const;
 
+  Size HeaderAndFooterSizeIfStatic() const;
+
   void GenSize(std::ostream& s) const;
 
   void GenSerialize(std::ostream& s) const;
diff --git a/system/gd/storage/config_cache.cc b/system/gd/storage/config_cache.cc
index c506c3d..f980ae5 100644
--- a/system/gd/storage/config_cache.cc
+++ b/system/gd/storage/config_cache.cc
@@ -58,8 +58,7 @@
         "LinkKey", "SdpDiMaufacturer", "SdpDiModel", "SdpDiHardwareVersion", "SdpDiVendorSource"};
 
 const std::string ConfigCache::kDefaultSectionName = "Global";
-
-std::string kEncryptedStr = "encrypted";
+static const std::string kEncryptedStr = "encrypted";
 
 ConfigCache::ConfigCache(size_t temp_device_capacity,
                          std::unordered_set<std::string_view> persistent_property_names)
diff --git a/system/main/shim/acl_interface.cc b/system/main/shim/acl_interface.cc
index 3f3a2d4..08668c5 100644
--- a/system/main/shim/acl_interface.cc
+++ b/system/main/shim/acl_interface.cc
@@ -16,17 +16,13 @@
 
 #include "main/shim/acl_interface.h"
 
+#include "stack/gatt/gatt_int.h"
 #include "stack/include/acl_hci_link_interface.h"
 #include "stack/include/ble_acl_interface.h"
 #include "stack/include/sec_hci_link_interface.h"
+#include "stack/l2cap/l2c_int.h"
 
 struct tBTM_ESCO_DATA;
-void gatt_notify_phy_updated(tHCI_STATUS status, uint16_t handle, uint8_t tx_phy, uint8_t rx_phy);
-void gatt_notify_subrate_change(uint16_t handle, uint16_t subrate_factor, uint16_t latency,
-                                uint16_t cont_num, uint16_t timeout, uint8_t status);
-void l2cble_process_subrate_change_evt(uint16_t handle, uint8_t status, uint16_t subrate_factor,
-                                       uint16_t peripheral_latency, uint16_t cont_num,
-                                       uint16_t timeout);
 
 static void on_le_subrate_change(uint16_t handle, uint16_t subrate_factor, uint16_t latency,
                                  uint16_t cont_num, uint16_t timeout, uint8_t status) {
diff --git a/system/main/shim/config.cc b/system/main/shim/config.cc
index a2568e4..7b6af0a 100644
--- a/system/main/shim/config.cc
+++ b/system/main/shim/config.cc
@@ -25,9 +25,6 @@
 #include "main/shim/entry.h"
 #include "storage/storage_module.h"
 
-using ::bluetooth::shim::GetStorage;
-using ::bluetooth::storage::ConfigCacheHelper;
-
 namespace bluetooth {
 namespace shim {
 
diff --git a/system/main/shim/distance_measurement_manager.cc b/system/main/shim/distance_measurement_manager.cc
index 72764a1..9e001dc 100644
--- a/system/main/shim/distance_measurement_manager.cc
+++ b/system/main/shim/distance_measurement_manager.cc
@@ -280,8 +280,6 @@
   static constexpr uint16_t kIllegalConnectionHandle = 0xffff;
 };
 
-DistanceMeasurementInterfaceImpl* distance_measurement_instance = nullptr;
-
 void bluetooth::shim::init_distance_measurement_manager() {
   static_cast<DistanceMeasurementInterfaceImpl*>(
           bluetooth::shim::get_distance_measurement_instance())
@@ -289,6 +287,7 @@
 }
 
 DistanceMeasurementInterface* bluetooth::shim::get_distance_measurement_instance() {
+  static DistanceMeasurementInterfaceImpl* distance_measurement_instance = nullptr;
   if (distance_measurement_instance == nullptr) {
     distance_measurement_instance = new DistanceMeasurementInterfaceImpl();
   }
diff --git a/system/main/shim/hci_layer.cc b/system/main/shim/hci_layer.cc
index 86557e8..6b28107 100644
--- a/system/main/shim/hci_layer.cc
+++ b/system/main/shim/hci_layer.cc
@@ -112,7 +112,7 @@
 }  // namespace
 
 namespace cpp {
-bluetooth::common::BidiQueueEnd<bluetooth::hci::IsoBuilder, bluetooth::hci::IsoView>*
+static bluetooth::common::BidiQueueEnd<bluetooth::hci::IsoBuilder, bluetooth::hci::IsoView>*
         hci_iso_queue_end = nullptr;
 static bluetooth::os::EnqueueBuffer<bluetooth::hci::IsoBuilder>* pending_iso_data = nullptr;
 
@@ -322,10 +322,6 @@
 
 }  // namespace cpp
 
-using bluetooth::common::Bind;
-using bluetooth::common::BindOnce;
-using bluetooth::common::Unretained;
-
 static void set_data_cb(base::Callback<void(BT_HDR*)> send_data_cb) {
   send_data_upwards = std::move(send_data_cb);
 }
diff --git a/system/main/shim/le_advertising_manager.cc b/system/main/shim/le_advertising_manager.cc
index 7d7cc14..0b7050a 100644
--- a/system/main/shim/le_advertising_manager.cc
+++ b/system/main/shim/le_advertising_manager.cc
@@ -426,9 +426,8 @@
   std::map<uint8_t, std::set<int>> native_reg_id_map;
 };
 
-BleAdvertiserInterfaceImpl* bt_le_advertiser_instance = nullptr;
-
 ::BleAdvertiserInterface* bluetooth::shim::get_ble_advertiser_instance() {
+  static BleAdvertiserInterfaceImpl* bt_le_advertiser_instance = nullptr;
   if (bt_le_advertiser_instance == nullptr) {
     bt_le_advertiser_instance = new BleAdvertiserInterfaceImpl();
   }
diff --git a/system/main/shim/le_scanning_manager.cc b/system/main/shim/le_scanning_manager.cc
index 0206870..41e7877 100644
--- a/system/main/shim/le_scanning_manager.cc
+++ b/system/main/shim/le_scanning_manager.cc
@@ -36,10 +36,12 @@
 #include "main/shim/le_scanning_manager.h"
 #include "main/shim/shim.h"
 #include "main_thread.h"
+#include "stack/acl/acl.h"
 #include "stack/btm/btm_int_types.h"
 #include "stack/include/advertise_data_parser.h"
 #include "stack/include/ble_hci_link_interface.h"
 #include "stack/include/bt_dev_class.h"
+#include "stack/include/btm_ble_addr.h"
 #include "stack/include/btm_log_history.h"
 #include "stack/include/btm_sec_api.h"
 #include "stack/include/btm_status.h"
@@ -375,14 +377,6 @@
   bluetooth::shim::GetScanning()->BatchScanReadReport(scanner_id, batch_scan_mode);
 }
 
-bool btm_random_pseudo_to_identity_addr(RawAddress* random_pseudo,
-                                        tBLE_ADDR_TYPE* p_identity_addr_type);
-
-bool btm_identity_addr_to_random_pseudo(RawAddress* bd_addr, tBLE_ADDR_TYPE* p_addr_type,
-                                        bool refresh);
-
-extern tACL_CONN* btm_acl_for_bda(const RawAddress& bd_addr, tBT_TRANSPORT transport);
-
 void BleScannerInterfaceImpl::StartSync(uint8_t sid, RawAddress address, uint16_t skip,
                                         uint16_t timeout, int reg_id) {
   log::info("in shim layer");
@@ -781,9 +775,8 @@
   remote_bdaddr_cache_ordered_ = {};
 }
 
-BleScannerInterfaceImpl* bt_le_scanner_instance = nullptr;
-
 BleScannerInterface* bluetooth::shim::get_ble_scanner_instance() {
+  static BleScannerInterfaceImpl* bt_le_scanner_instance = nullptr;
   if (bt_le_scanner_instance == nullptr) {
     bt_le_scanner_instance = new BleScannerInterfaceImpl();
   }
diff --git a/system/metrics/Android.bp b/system/metrics/Android.bp
index 90dd3c3..d63a774 100644
--- a/system/metrics/Android.bp
+++ b/system/metrics/Android.bp
@@ -47,6 +47,7 @@
     min_sdk_version: "36",
     defaults: [
         "bluetooth_cflags",
+        "bluetooth_tidy",
     ],
     export_include_dirs: [
         "include",
diff --git a/system/metrics/include/bluetooth/metrics/os_metrics.h b/system/metrics/include/bluetooth/metrics/os_metrics.h
index 0ca1604..f6c1562 100644
--- a/system/metrics/include/bluetooth/metrics/os_metrics.h
+++ b/system/metrics/include/bluetooth/metrics/os_metrics.h
@@ -31,10 +31,13 @@
 
 namespace bluetooth::metrics {
 
-/**
- * Unknown connection handle for metrics purpose
- */
-static const uint32_t kUnknownConnectionHandle = 0xFFFF;
+using CounterKey = android::bluetooth::CodePathCounterKeyEnum;
+
+/** Unknown connection handle for metrics purpose. */
+constexpr uint32_t kUnknownConnectionHandle = 0xFFFF;
+
+/** Simple counter metric. */
+void Counter(CounterKey key, int64_t count = 1);
 
 /**
  * Log link layer connection event
@@ -301,8 +304,6 @@
 void LogMetricBluetoothRemoteSupportedFeatures(const hci::Address& address, uint32_t page,
                                                uint64_t features, uint32_t connection_handle);
 
-void CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t count);
-
 using android::bluetooth::le::LeAclConnectionState;
 using android::bluetooth::le::LeConnectionOriginType;
 using android::bluetooth::le::LeConnectionState;
diff --git a/system/metrics/mock/metrics_mock.cc b/system/metrics/mock/metrics_mock.cc
index 4f1d23fa..1bc569a 100644
--- a/system/metrics/mock/metrics_mock.cc
+++ b/system/metrics/mock/metrics_mock.cc
@@ -78,6 +78,12 @@
   }
 }
 
+void Counter(CounterKey key, int64_t count) {
+  if (metricsInstance) {
+    metricsInstance->Counter(key, count);
+  }
+}
+
 void LogMetricLinkLayerConnectionEvent(const hci::Address& address, uint32_t connection_handle,
                                        android::bluetooth::DirectionEnum direction,
                                        uint16_t link_type, uint32_t hci_cmd, uint16_t hci_event,
@@ -265,12 +271,6 @@
   }
 }
 
-void CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t count) {
-  if (metricsInstance) {
-    metricsInstance->CountCounterMetrics(key, count);
-  }
-}
-
 void LogMetricBluetoothLEConnection(LEConnectionSessionOptions session_options) {
   if (metricsInstance) {
     metricsInstance->LogMetricBluetoothLEConnection(session_options);
diff --git a/system/metrics/mock/metrics_mock.h b/system/metrics/mock/metrics_mock.h
index 361d582..87baf85 100644
--- a/system/metrics/mock/metrics_mock.h
+++ b/system/metrics/mock/metrics_mock.h
@@ -37,6 +37,7 @@
   MOCK_METHOD(bool, IsValidIdFromMetricIdAllocator, (int));
 
   // Methods from os_metrics.h
+  MOCK_METHOD(void, Counter, (bluetooth::metrics::CounterKey, int64_t));
   MOCK_METHOD(void, LogMetricLinkLayerConnectionEvent,
               (const hci::Address&, uint32_t, android::bluetooth::DirectionEnum, uint16_t, uint32_t,
                uint16_t, uint16_t, uint16_t, uint16_t));
@@ -76,7 +77,6 @@
               (uint32_t, const hci::Address&, uint32_t));
   MOCK_METHOD(void, LogMetricBluetoothRemoteSupportedFeatures,
               (const hci::Address&, uint32_t, uint64_t, uint32_t));
-  MOCK_METHOD(void, CountCounterMetrics, (android::bluetooth::CodePathCounterKeyEnum, int64_t));
   MOCK_METHOD(void, LogMetricBluetoothLEConnection, (LEConnectionSessionOptions));
   MOCK_METHOD(void, LogMetricBluetoothEvent,
               (const hci::Address&, android::bluetooth::EventType, android::bluetooth::State));
diff --git a/system/metrics/src/android/metrics.cc b/system/metrics/src/android/metrics.cc
index 88b9ea1..dd38155 100644
--- a/system/metrics/src/android/metrics.cc
+++ b/system/metrics/src/android/metrics.cc
@@ -69,8 +69,8 @@
 struct formatter<android::bluetooth::SocketErrorEnum>
     : enum_formatter<android::bluetooth::SocketErrorEnum> {};
 template <>
-struct formatter<android::bluetooth::CodePathCounterKeyEnum>
-    : enum_formatter<android::bluetooth::CodePathCounterKeyEnum> {};
+struct formatter<bluetooth::metrics::CounterKey> : enum_formatter<bluetooth::metrics::CounterKey> {
+};
 }  // namespace std
 
 namespace bluetooth::metrics {
@@ -84,6 +84,13 @@
  */
 static const BytesField byteField(nullptr, 0);
 
+void Counter(CounterKey key, int64_t count) {
+  int ret = stats_write(BLUETOOTH_CODE_PATH_COUNTER, key, count);
+  if (ret < 0) {
+    log::warn("Failed counter metrics for {}, count {}, error {}", key, count, ret);
+  }
+}
+
 void LogMetricLinkLayerConnectionEvent(const Address& address, uint32_t connection_handle,
                                        android::bluetooth::DirectionEnum direction,
                                        uint16_t link_type, uint32_t hci_cmd, uint16_t hci_event,
@@ -445,13 +452,6 @@
   }
 }
 
-void CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t count) {
-  int ret = stats_write(BLUETOOTH_CODE_PATH_COUNTER, key, count);
-  if (ret < 0) {
-    log::warn("Failed counter metrics for {}, count {}, error {}", key, count, ret);
-  }
-}
-
 void LogMetricBluetoothLEConnection(LEConnectionSessionOptions session_options) {
   int metric_id = 0;
   if (!session_options.remote_address.IsEmpty()) {
diff --git a/system/metrics/src/chromeos/metrics.cc b/system/metrics/src/chromeos/metrics.cc
index e8cf379..f2c59d7 100644
--- a/system/metrics/src/chromeos/metrics.cc
+++ b/system/metrics/src/chromeos/metrics.cc
@@ -38,6 +38,8 @@
 
 using hci::Address;
 
+void Counter(CounterKey key, int64_t count) {}
+
 void LogMetricClassicPairingEvent(const Address& address, uint16_t handle, uint32_t hci_cmd,
                                   uint16_t hci_event, uint16_t cmd_status, uint16_t reason_code,
                                   int64_t event_value) {}
@@ -190,8 +192,6 @@
 void LogMetricBluetoothRemoteSupportedFeatures(const Address& address, uint32_t page,
                                                uint64_t features, uint32_t connection_handle) {}
 
-void CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t count) {}
-
 void LogMetricBluetoothLEConnection(LEConnectionSessionOptions /* session_options */) {}
 
 void LogMetricBluetoothEvent(const Address& address, android::bluetooth::EventType event_type,
diff --git a/system/metrics/src/host/metrics.cc b/system/metrics/src/host/metrics.cc
index e3a4ea6..a7ddcf5 100644
--- a/system/metrics/src/host/metrics.cc
+++ b/system/metrics/src/host/metrics.cc
@@ -22,6 +22,8 @@
 
 using bluetooth::hci::Address;
 
+void Counter(CounterKey /* key */, int64_t /* count */) {}
+
 void LogMetricClassicPairingEvent(const Address& /* address */, uint16_t /* handle */,
                                   uint32_t /* hci_cmd */, uint16_t /* hci_event */,
                                   uint16_t /* cmd_status */, uint16_t /* reason_code */,
@@ -114,9 +116,6 @@
                                                uint64_t /* features */,
                                                uint32_t /* connection_handle */) {}
 
-void CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum /* key */,
-                         int64_t /* count */) {}
-
 void LogMetricBluetoothLEConnection(LEConnectionSessionOptions /* session_options */) {}
 
 void LogMetricBluetoothEvent(const Address& /* address */,
diff --git a/system/packet/Android.bp b/system/packet/Android.bp
index 12176cd..aa2a740 100644
--- a/system/packet/Android.bp
+++ b/system/packet/Android.bp
@@ -9,7 +9,10 @@
 
 cc_library_static {
     name: "lib-bt-packets",
-    defaults: ["bluetooth_cflags"],
+    defaults: [
+        "bluetooth_cflags",
+        "bluetooth_tidy",
+    ],
     host_supported: true,
     export_include_dirs: [
         "./",
diff --git a/system/packet/avrcp/Android.bp b/system/packet/avrcp/Android.bp
index 107cf4f..f303a65 100644
--- a/system/packet/avrcp/Android.bp
+++ b/system/packet/avrcp/Android.bp
@@ -9,7 +9,10 @@
 
 cc_library_static {
     name: "lib-bt-packets-avrcp",
-    defaults: ["bluetooth_cflags"],
+    defaults: [
+        "bluetooth_cflags",
+        "bluetooth_tidy",
+    ],
     header_libs: ["avrcp_headers"],
     export_header_lib_headers: ["avrcp_headers"],
     export_include_dirs: ["."],
diff --git a/system/packet/base/Android.bp b/system/packet/base/Android.bp
index 9b483a9..4027242 100644
--- a/system/packet/base/Android.bp
+++ b/system/packet/base/Android.bp
@@ -9,7 +9,10 @@
 
 cc_library_static {
     name: "lib-bt-packets-base",
-    defaults: ["bluetooth_cflags"],
+    defaults: [
+        "bluetooth_cflags",
+        "bluetooth_tidy",
+    ],
     export_include_dirs: ["./"],
     host_supported: true,
     include_dirs: ["packages/modules/Bluetooth/system/include"],
diff --git a/system/pdl/ras/ras_packets.pdl b/system/pdl/ras/ras_packets.pdl
index c9d7217..d1d713c 100644
--- a/system/pdl/ras/ras_packets.pdl
+++ b/system/pdl/ras/ras_packets.pdl
@@ -2,11 +2,6 @@
 
 // Ranging Service
 
-enum PctFormat : 2 {
-  IQ = 0,
-  PHASE = 1,
-}
-
 enum RangingDoneStatus : 4 {
   ALL_RESULTS_COMPLETE = 0x0,
   PARTIAL_RESULTS = 0x1,
@@ -61,8 +56,7 @@
   configuration_id : 4,
   selected_tx_power : 8,
   antenna_paths_mask : 4,
-  _reserved_ : 2,
-  pct_format : PctFormat,
+  _reserved_ : 4,
 }
 
 struct SegmentationHeader {
diff --git a/system/profile/avrcp/connection_handler.cc b/system/profile/avrcp/connection_handler.cc
index 5e034e2..427cad3 100644
--- a/system/profile/avrcp/connection_handler.cc
+++ b/system/profile/avrcp/connection_handler.cc
@@ -52,7 +52,7 @@
 // ConnectionHandler::CleanUp take the lock and calls
 // ConnectionHandler::AcceptorControlCB with AVRC_CLOSE_IND_EVT
 // which also takes the lock, so use a recursive_mutex.
-std::recursive_mutex device_map_lock;
+static std::recursive_mutex device_map_lock;
 
 ConnectionHandler* ConnectionHandler::Get() {
   log::assert_that(instance_ != nullptr, "assert failed: instance_ != nullptr");
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index 02c6371f..d11febc 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -293,6 +293,7 @@
     host_supported: true,
     defaults: [
         "bluetooth_cflags",
+        "bluetooth_tidy",
     ],
     cflags: [
         "-Wno-missing-prototypes",
diff --git a/system/stack/a2dp/a2dp_sbc_up_sample.cc b/system/stack/a2dp/a2dp_sbc_up_sample.cc
index f1019d4..71d6f6b 100644
--- a/system/stack/a2dp/a2dp_sbc_up_sample.cc
+++ b/system/stack/a2dp/a2dp_sbc_up_sample.cc
@@ -42,7 +42,7 @@
   uint8_t div;
 } tA2DP_SBC_UPS_CB;
 
-tA2DP_SBC_UPS_CB a2dp_sbc_ups_cb;
+static tA2DP_SBC_UPS_CB a2dp_sbc_ups_cb;
 
 /*******************************************************************************
  *
diff --git a/system/stack/ais/ais_ble.cc b/system/stack/ais/ais_ble.cc
index d843eba..041fef9 100644
--- a/system/stack/ais/ais_ble.cc
+++ b/system/stack/ais/ais_ble.cc
@@ -44,7 +44,7 @@
 
 static uint32_t api_level;
 
-void ais_request_cback(tCONN_ID, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*);
+static void ais_request_cback(tCONN_ID, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*);
 
 static tGATT_CBACK ais_cback = {
         .p_conn_cb = nullptr,
@@ -60,7 +60,7 @@
 };
 
 /** AIS ATT server attribute access request callback */
-void ais_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type,
+static void ais_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type,
                        tGATTS_DATA* p_data) {
   tGATT_STATUS status = GATT_INVALID_PDU;
   tGATTS_RSP rsp_msg = {};
diff --git a/system/stack/avdt/avdt_l2c.cc b/system/stack/avdt/avdt_l2c.cc
index c813878..6876614 100644
--- a/system/stack/avdt/avdt_l2c.cc
+++ b/system/stack/avdt/avdt_l2c.cc
@@ -44,13 +44,13 @@
 using namespace bluetooth;
 
 /* callback function declarations */
-void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, uint16_t psm, uint8_t id);
-void avdt_l2c_connect_cfm_cback(uint16_t lcid, tL2CAP_CONN result);
-void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t result, tL2CAP_CFG_INFO* p_cfg);
-void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg);
-void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed);
-void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested);
-void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf);
+static void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, uint16_t psm, uint8_t id);
+static void avdt_l2c_connect_cfm_cback(uint16_t lcid, tL2CAP_CONN result);
+static void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t result, tL2CAP_CFG_INFO* p_cfg);
+static void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg);
+static void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed);
+static void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested);
+static void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf);
 static void avdt_on_l2cap_error(uint16_t lcid, uint16_t result);
 
 /* L2CAP callback function structure */
@@ -79,7 +79,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, uint16_t /* psm */,
+static void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, uint16_t /* psm */,
                                 uint8_t /* id */) {
   AvdtpCcb* p_ccb;
   AvdtpTransportChannel* p_tbl = NULL;
@@ -198,7 +198,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_connect_cfm_cback(uint16_t lcid, tL2CAP_CONN result) {
+static void avdt_l2c_connect_cfm_cback(uint16_t lcid, tL2CAP_CONN result) {
   AvdtpTransportChannel* p_tbl;
   AvdtpCcb* p_ccb;
 
@@ -252,7 +252,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator, tL2CAP_CFG_INFO* p_cfg) {
+static void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator, tL2CAP_CFG_INFO* p_cfg) {
   AvdtpTransportChannel* p_tbl;
 
   /* look up info for this channel */
@@ -286,7 +286,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) {
+static void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) {
   AvdtpTransportChannel* p_tbl;
 
   /* look up info for this channel */
@@ -315,7 +315,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) {
+static void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) {
   AvdtpTransportChannel* p_tbl;
 
   log::verbose("lcid: 0x{:04x}, ack_needed: {}", lcid, ack_needed);
@@ -338,7 +338,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) {
+static void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) {
   AvdtpTransportChannel* p_tbl;
 
   log::verbose("lcid: 0x{:04x}, is_congested: {}", lcid, is_congested);
@@ -361,7 +361,7 @@
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) {
+static void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) {
   AvdtpTransportChannel* p_tbl;
 
   /* look up info for this channel */
diff --git a/system/stack/btm/btm_ble_adv_filter.cc b/system/stack/btm/btm_ble_adv_filter.cc
index 7f06413..e41acf6 100644
--- a/system/stack/btm/btm_ble_adv_filter.cc
+++ b/system/stack/btm/btm_ble_adv_filter.cc
@@ -34,8 +34,6 @@
 extern tBTM_CB btm_cb;
 
 using namespace bluetooth;
-using base::Bind;
-using bluetooth::Uuid;
 
 #define BTM_BLE_ADV_FILT_META_HDR_LENGTH 3
 #define BTM_BLE_ADV_FILT_FEAT_SELN_LEN 13
@@ -53,8 +51,8 @@
 
 #define BTM_BLE_PF_BIT_TO_MASK(x) (uint16_t)(1 << (x))
 
-tBTM_BLE_ADV_FILTER_CB btm_ble_adv_filt_cb;
-tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
+static tBTM_BLE_ADV_FILTER_CB btm_ble_adv_filt_cb;
+static tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
 
 static uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, uint8_t cond_type,
                                             tBLE_BD_ADDR* p_bd_addr, uint8_t num_available);
diff --git a/system/stack/btm/btm_ble_cont_energy.cc b/system/stack/btm/btm_ble_cont_energy.cc
index 1782dfe..e96973d 100644
--- a/system/stack/btm/btm_ble_cont_energy.cc
+++ b/system/stack/btm/btm_ble_cont_energy.cc
@@ -30,7 +30,7 @@
 
 extern tBTM_CB btm_cb;
 
-tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb;
+static tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb;
 
 /*******************************************************************************
  *
diff --git a/system/stack/btm/btm_ble_gap.cc b/system/stack/btm/btm_ble_gap.cc
index b399c1e..10ef8b2 100644
--- a/system/stack/btm/btm_ble_gap.cc
+++ b/system/stack/btm/btm_ble_gap.cc
@@ -219,7 +219,7 @@
   PERIODIC_SYNC_LOST,
 } tBTM_BLE_PERIODIC_SYNC_STATE;
 
-struct alarm_t* sync_timeout_alarm;
+static struct alarm_t* sync_timeout_alarm;
 typedef struct {
   uint8_t sid;
   RawAddress remote_bda;
@@ -263,8 +263,7 @@
   tBTM_BLE_PERIODIC_SYNC p_sync[MAX_SYNC_TRANSACTION];
   tBTM_BLE_PERIODIC_SYNC_TRANSFER sync_transfer[MAX_SYNC_TRANSACTION];
 } tBTM_BLE_PA_SYNC_TX_CB;
-tBTM_BLE_PA_SYNC_TX_CB btm_ble_pa_sync_cb;
-StartSyncCb sync_rcvd_cb;
+static tBTM_BLE_PA_SYNC_TX_CB btm_ble_pa_sync_cb;
 static bool syncRcvdCbRegistered = false;
 static int btm_ble_get_psync_index(uint8_t adv_sid, RawAddress addr);
 static void btm_ble_start_sync_timeout(void* data);
@@ -458,7 +457,7 @@
         }};
 
 /* check LE combo state supported */
-inline bool BTM_LE_STATES_SUPPORTED(const uint64_t x, uint8_t bit_num) {
+static bool BTM_LE_STATES_SUPPORTED(const uint64_t x, uint8_t bit_num) {
   uint64_t mask = 1 << bit_num;
   return (x)&mask;
 }
diff --git a/system/stack/btm/btm_ble_scanner.cc b/system/stack/btm/btm_ble_scanner.cc
index be44ee2..e96dbc0 100644
--- a/system/stack/btm/btm_ble_scanner.cc
+++ b/system/stack/btm/btm_ble_scanner.cc
@@ -22,14 +22,13 @@
 
 using namespace bluetooth;
 
-std::mutex lock1;
-
 namespace {
 
 class BleScanningManagerImpl;
 
-BleScanningManager* instance;
-base::WeakPtr<BleScanningManagerImpl> instance_weakptr;
+static std::mutex lock1;
+static BleScanningManager* instance;
+static base::WeakPtr<BleScanningManagerImpl> instance_weakptr;
 
 static void status_callback(uint8_t status) {
   log::verbose("Received status_cb with status:{}", status);
diff --git a/system/stack/btm/btm_sco.cc b/system/stack/btm/btm_sco.cc
index 34a7dc0..b80ad94 100644
--- a/system/stack/btm/btm_sco.cc
+++ b/system/stack/btm/btm_sco.cc
@@ -101,7 +101,7 @@
 static bool btm_sco_removed(uint16_t hci_handle, tHCI_REASON reason);
 
 namespace cpp {
-bluetooth::common::BidiQueueEnd<bluetooth::hci::ScoBuilder, bluetooth::hci::ScoView>*
+static bluetooth::common::BidiQueueEnd<bluetooth::hci::ScoBuilder, bluetooth::hci::ScoView>*
         hci_sco_queue_end = nullptr;
 static bluetooth::os::EnqueueBuffer<bluetooth::hci::ScoBuilder>* pending_sco_data = nullptr;
 
diff --git a/system/stack/btm/security_event_parser.cc b/system/stack/btm/security_event_parser.cc
index 36ba5c1..3c8c608 100644
--- a/system/stack/btm/security_event_parser.cc
+++ b/system/stack/btm/security_event_parser.cc
@@ -32,8 +32,6 @@
 
 using namespace bluetooth;
 using namespace bluetooth::hci;
-using android::bluetooth::hci::CMD_UNKNOWN;
-using android::bluetooth::hci::STATUS_UNKNOWN;
 
 namespace bluetooth::stack::btm {
 namespace {
diff --git a/system/stack/gatt/gatt_cl.cc b/system/stack/gatt/gatt_cl.cc
index e9f4f76..8fa1186 100644
--- a/system/stack/gatt/gatt_cl.cc
+++ b/system/stack/gatt/gatt_cl.cc
@@ -59,9 +59,9 @@
 /*******************************************************************************
  *                      G L O B A L      G A T T       D A T A                 *
  ******************************************************************************/
-void gatt_send_prepare_write(tGATT_TCB& tcb, tGATT_CLCB* p_clcb);
+static void gatt_send_prepare_write(tGATT_TCB& tcb, tGATT_CLCB* p_clcb);
 
-uint8_t disc_type_to_att_opcode[GATT_DISC_MAX] = {
+static uint8_t disc_type_to_att_opcode[GATT_DISC_MAX] = {
         0,
         GATT_REQ_READ_BY_GRP_TYPE, /*  GATT_DISC_SRVC_ALL = 1, */
         GATT_REQ_FIND_TYPE_VALUE,  /*  GATT_DISC_SRVC_BY_UUID,  */
@@ -70,7 +70,7 @@
         GATT_REQ_FIND_INFO         /*  GATT_DISC_CHAR_DSCPT,    */
 };
 
-uint16_t disc_type_to_uuid[GATT_DISC_MAX] = {
+static uint16_t disc_type_to_uuid[GATT_DISC_MAX] = {
         0,                         /* reserved */
         GATT_UUID_PRI_SERVICE,     /* <service> DISC_SRVC_ALL */
         GATT_UUID_PRI_SERVICE,     /* <service> for DISC_SERVC_BY_UUID */
@@ -337,7 +337,7 @@
 }
 
 /** Send prepare write */
-void gatt_send_prepare_write(tGATT_TCB& tcb, tGATT_CLCB* p_clcb) {
+static void gatt_send_prepare_write(tGATT_TCB& tcb, tGATT_CLCB* p_clcb) {
   tGATT_VALUE* p_attr = (tGATT_VALUE*)p_clcb->p_attr_buf;
   uint8_t type = p_clcb->op_subtype;
 
diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc
index efa2745..b786c2a 100644
--- a/system/stack/gatt/gatt_main.cc
+++ b/system/stack/gatt/gatt_main.cc
@@ -77,7 +77,7 @@
 static void gatt_send_conn_cback(tGATT_TCB* p_tcb);
 static void gatt_l2cif_congest_cback(uint16_t cid, bool congested);
 static void gatt_on_l2cap_error(uint16_t lcid, uint16_t result);
-bool check_cached_model_name(const RawAddress& bd_addr);
+static bool check_cached_model_name(const RawAddress& bd_addr);
 static void read_dis_cback(const RawAddress& bd_addr, tDIS_VALUE* p_dis_value);
 
 static const tL2CAP_APPL_INFO dyn_info = {gatt_l2cif_connect_ind_cback,
@@ -571,7 +571,7 @@
   }
 }
 
-bool check_cached_model_name(const RawAddress& bd_addr) {
+static bool check_cached_model_name(const RawAddress& bd_addr) {
   bt_property_t prop;
   bt_bdname_t model_name;
   BTIF_STORAGE_FILL_PROPERTY(&prop, BT_PROPERTY_REMOTE_MODEL_NUM, sizeof(model_name), &model_name);
diff --git a/system/stack/hid/hidd_api.cc b/system/stack/hid/hidd_api.cc
index 5532eca..2933c99 100644
--- a/system/stack/hid/hidd_api.cc
+++ b/system/stack/hid/hidd_api.cc
@@ -83,14 +83,12 @@
   log::verbose("");
 
   if (hd_cb.reg_flag) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_REGISTERED, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_ALREADY_REGISTERED);
     return HID_ERR_ALREADY_REGISTERED;
   }
 
   if (host_cback == NULL) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_HOST_CALLBACK_NULL, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_HOST_CALLBACK_NULL);
     return HID_ERR_INVALID_PARAM;
   }
 
@@ -124,8 +122,8 @@
   log::verbose("");
 
   if (!hd_cb.reg_flag) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_DEREGISTER, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_AT_DEREGISTER);
     return HID_ERR_NOT_REGISTERED;
   }
 
@@ -265,10 +263,8 @@
 
       if (desc_len > HIDD_APP_DESCRIPTOR_LEN) {
         log::error("descriptor length = {}, larger than max {}", desc_len, HIDD_APP_DESCRIPTOR_LEN);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::
-                        HIDD_ERR_NOT_REGISTERED_DUE_TO_DESCRIPTOR_LENGTH,
-                1);
+        bluetooth::metrics::Counter(
+                bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_DUE_TO_DESCRIPTOR_LENGTH);
         return HID_ERR_NOT_REGISTERED;
       };
 
@@ -276,10 +272,8 @@
 
       if (p_buf == NULL) {
         log::error("Buffer allocation failure for size = {}", buf_len);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::
-                        HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION,
-                1);
+        bluetooth::metrics::Counter(
+                bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION);
         return HID_ERR_NOT_REGISTERED;
       }
 
@@ -350,8 +344,7 @@
 
   if (!result) {
     log::error("failed to complete SDP record");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_SDP, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_AT_SDP);
     return HID_ERR_NOT_REGISTERED;
   }
 
@@ -380,8 +373,7 @@
     return hidd_conn_send_data(HID_CHANNEL_INTR, HID_TRANS_DATA, HID_PAR_REP_TYPE_INPUT, id, len,
                                p_data);
   }
-  bluetooth::metrics::CountCounterMetrics(
-          android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_INVALID_PARAM_SEND_REPORT, 1);
+  bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_INVALID_PARAM_SEND_REPORT);
   return HID_ERR_INVALID_PARAM;
 }
 
@@ -448,20 +440,18 @@
  ******************************************************************************/
 tHID_STATUS HID_DevConnect(void) {
   if (!hd_cb.reg_flag) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_CONNECT, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_AT_CONNECT);
     return HID_ERR_NOT_REGISTERED;
   }
 
   if (!hd_cb.device.in_use) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DEVICE_NOT_IN_USE_AT_CONNECT, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_DEVICE_NOT_IN_USE_AT_CONNECT);
     return HID_ERR_INVALID_PARAM;
   }
 
   if (hd_cb.device.state != HIDD_DEV_NO_CONN) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_CONN, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_ALREADY_CONN);
     return HID_ERR_ALREADY_CONN;
   }
 
@@ -479,15 +469,14 @@
  ******************************************************************************/
 tHID_STATUS HID_DevDisconnect(void) {
   if (!hd_cb.reg_flag) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_DISCONNECT, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_AT_DISCONNECT);
     return HID_ERR_NOT_REGISTERED;
   }
 
   if (!hd_cb.device.in_use) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DEVICE_NOT_IN_USE_AT_DISCONNECT,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_DEVICE_NOT_IN_USE_AT_DISCONNECT);
     return HID_ERR_INVALID_PARAM;
   }
 
@@ -497,12 +486,11 @@
       tHID_STATUS ret = hidd_conn_disconnect();
       hd_cb.device.conn.conn_state = HID_CONN_STATE_UNUSED;
       hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_ERR_DISCONNECTING, NULL);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DISCONNECTING, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_DISCONNECTING);
       return ret;
     }
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_CONNECTION_AT_DISCONNECT, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_NO_CONNECTION_AT_DISCONNECT);
     return HID_ERR_NO_CONNECTION;
   }
 
@@ -571,8 +559,8 @@
   if (hd_cb.device.in_use) {
     *addr = hd_cb.device.addr;
   } else {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_GET_DEVICE, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_AT_GET_DEVICE);
     return HID_ERR_NOT_REGISTERED;
   }
 
diff --git a/system/stack/hid/hidd_conn.cc b/system/stack/hid/hidd_conn.cc
index 664c6af..000e043 100644
--- a/system/stack/hid/hidd_conn.cc
+++ b/system/stack/hid/hidd_conn.cc
@@ -300,8 +300,8 @@
 
         log::warn("could not start L2CAP connection for INTR");
         hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_ERR_L2CAP_FAILED, NULL);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_NOT_STARTED_INCOMING, 1);
+        bluetooth::metrics::Counter(
+                bluetooth::metrics::CounterKey::HIDD_ERR_L2CAP_NOT_STARTED_INCOMING);
         return;
       } else {
         p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
@@ -577,8 +577,7 @@
               HID_PSM_CONTROL, dev_reg_info, false /* enable_snoop */, nullptr, HID_DEV_MTU_SIZE, 0,
               BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     log::error("HID Control (device) registration failed");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_CONTROL, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_L2CAP_FAILED_CONTROL);
     return HID_ERR_L2CAP_FAILED;
   }
 
@@ -587,8 +586,7 @@
               0, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     stack::l2cap::get_interface().L2CA_Deregister(HID_PSM_CONTROL);
     log::error("HID Interrupt (device) registration failed");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_INTERRUPT, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_L2CAP_FAILED_INTERRUPT);
     return HID_ERR_L2CAP_FAILED;
   }
 
@@ -627,15 +625,14 @@
 
   if (!p_dev->in_use) {
     log::warn("no virtual cable established");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_INITIATE, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_NOT_REGISTERED_AT_INITIATE);
     return HID_ERR_NOT_REGISTERED;
   }
 
   if (p_dev->conn.conn_state != HID_CONN_STATE_UNUSED) {
     log::warn("connection already in progress");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONN_IN_PROCESS, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_CONN_IN_PROCESS);
     return HID_ERR_CONN_IN_PROCESS;
   }
 
@@ -650,8 +647,7 @@
                HID_PSM_CONTROL, p_dev->addr, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) == 0) {
     log::warn("could not start L2CAP connection");
     hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_ERR_L2CAP_FAILED, NULL);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_INITIATE, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_L2CAP_FAILED_INITIATE);
   } else {
     p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_CTRL;
   }
@@ -724,8 +720,7 @@
   tHID_CONN* p_hcon = &hd_cb.device.conn;
 
   if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONGESTED_AT_FLAG_CHECK, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_CONGESTED_AT_FLAG_CHECK);
     return HID_ERR_CONGESTED;
   }
 
@@ -745,15 +740,13 @@
       }
       break;
     default:
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_INVALID_PARAM, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_INVALID_PARAM);
       return HID_ERR_INVALID_PARAM;
   }
 
   p_buf = (BT_HDR*)osi_malloc(buf_size);
   if (p_buf == NULL) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_RESOURCES, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_NO_RESOURCES);
     return HID_ERR_NO_RESOURCES;
   }
 
@@ -795,16 +788,15 @@
 
       return HID_SUCCESS;
     }
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_CONNECTION_AT_SEND_DATA, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDD_ERR_NO_CONNECTION_AT_SEND_DATA);
     return HID_ERR_NO_CONNECTION;
   }
 
   log::verbose("report sent");
 
   if (stack::l2cap::get_interface().L2CA_DataWrite(cid, p_buf) == tL2CAP_DW_RESULT::FAILED) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONGESTED_AT_DATA_WRITE, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDD_ERR_CONGESTED_AT_DATA_WRITE);
     return HID_ERR_CONGESTED;
   }
 
diff --git a/system/stack/hid/hidh_api.cc b/system/stack/hid/hidh_api.cc
index db8ca1f..a0bb1ec 100644
--- a/system/stack/hid/hidh_api.cc
+++ b/system/stack/hid/hidh_api.cc
@@ -69,8 +69,7 @@
 tHID_STATUS HID_HostGetSDPRecord(const RawAddress& addr, tSDP_DISCOVERY_DB* p_db, uint32_t db_len,
                                  tHID_HOST_SDP_CALLBACK* sdp_cback) {
   if (hh_cb.sdp_busy) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_SDP_BUSY, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_SDP_BUSY);
     return HID_ERR_SDP_BUSY;
   }
 
@@ -88,8 +87,7 @@
     return HID_SUCCESS;
   } else {
     log::warn("Unable to start SDP service search request peer:{}", addr);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_RESOURCES_SDP, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_NO_RESOURCES_SDP);
     return HID_ERR_NO_RESOURCES;
   }
 }
@@ -291,14 +289,13 @@
   tHID_STATUS st;
 
   if (hh_cb.reg_flag) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_ALREADY_REGISTERED, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_ALREADY_REGISTERED);
     return HID_ERR_ALREADY_REGISTERED;
   }
 
   if (dev_cback == NULL) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_REGISTER, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_INVALID_PARAM_AT_HOST_REGISTER);
     return HID_ERR_INVALID_PARAM;
   }
 
@@ -395,8 +392,7 @@
   }
 
   if (i == HID_HOST_MAX_DEVICES) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_RESOURCES_ADD_DEVICE, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_NO_RESOURCES_ADD_DEVICE);
     return HID_ERR_NO_RESOURCES;
   }
 
@@ -430,9 +426,8 @@
   }
 
   if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_REMOVE_DEV,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_INVALID_PARAM_AT_HOST_REMOVE_DEV);
     return HID_ERR_INVALID_PARAM;
   }
 
@@ -462,15 +457,14 @@
 
   if (dev_handle >= HID_HOST_MAX_DEVICES || !hh_cb.devices[dev_handle].in_use) {
     log::error("Handle {} cannot be used", dev_handle);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_OPEN_DEV, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_INVALID_PARAM_AT_HOST_OPEN_DEV);
     return HID_ERR_INVALID_PARAM;
   }
 
   if (hh_cb.devices[dev_handle].state != HID_DEV_NO_CONN) {
     log::warn("{} already connected, handle: {}", hh_cb.devices[dev_handle].addr, dev_handle);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_ALREADY_CONN, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_ALREADY_CONN);
     return HID_ERR_ALREADY_CONN;
   }
 
@@ -501,15 +495,13 @@
 
   if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
     log::error("HID_ERR_INVALID_PARAM");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_WRITE_DEV,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_INVALID_PARAM_AT_HOST_WRITE_DEV);
     status = HID_ERR_INVALID_PARAM;
   } else if (hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED) {
     log::error("HID_ERR_NO_CONNECTION dev_handle {}", dev_handle);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_CONNECTION_AT_HOST_WRITE_DEV,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_NO_CONNECTION_AT_HOST_WRITE_DEV);
     status = HID_ERR_NO_CONNECTION;
   }
 
@@ -537,16 +529,14 @@
   }
 
   if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_CLOSE_DEV,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_INVALID_PARAM_AT_HOST_CLOSE_DEV);
     return HID_ERR_INVALID_PARAM;
   }
 
   if (hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED) {
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_CONNECTION_AT_HOST_CLOSE_DEV,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_NO_CONNECTION_AT_HOST_CLOSE_DEV);
     return HID_ERR_NO_CONNECTION;
   }
 
diff --git a/system/stack/hid/hidh_conn.cc b/system/stack/hid/hidh_conn.cc
index fe12644..91bf6f4 100644
--- a/system/stack/hid/hidh_conn.cc
+++ b/system/stack/hid/hidh_conn.cc
@@ -120,9 +120,8 @@
               HID_PSM_CONTROL, hst_reg_info, false /* enable_snoop */, nullptr, HID_HOST_MTU, 0,
               BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     log::error("HID-Host Control Registration failed");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_L2CAP_FAILED_AT_REGISTER_CONTROL,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_L2CAP_FAILED_AT_REGISTER_CONTROL);
     return HID_ERR_L2CAP_FAILED;
   }
   if (!stack::l2cap::get_interface().L2CA_RegisterWithSecurity(
@@ -130,9 +129,8 @@
               BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     stack::l2cap::get_interface().L2CA_Deregister(HID_PSM_CONTROL);
     log::error("HID-Host Interrupt Registration failed");
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_L2CAP_FAILED_AT_REGISTER_INTERRUPT,
-            1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_L2CAP_FAILED_AT_REGISTER_INTERRUPT);
     return HID_ERR_L2CAP_FAILED;
   }
 
@@ -553,8 +551,7 @@
           (disc_res == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) ||
           (disc_res == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) ||
           (disc_res == HCI_ERR_REPEATED_ATTEMPTS)) {
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_AUTH_FAILED, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_AUTH_FAILED);
         hid_close_evt_reason = HID_ERR_AUTH_FAILED;
       }
 
@@ -776,15 +773,14 @@
   if (!get_btm_client_interface().peer.BTM_IsAclConnectionUp(hh_cb.devices[dhandle].addr,
                                                              BT_TRANSPORT_BR_EDR)) {
     osi_free(buf);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_CONNECTION_AT_SEND_DATA, 1);
+    bluetooth::metrics::Counter(
+            bluetooth::metrics::CounterKey::HIDH_ERR_NO_CONNECTION_AT_SEND_DATA);
     return HID_ERR_NO_CONNECTION;
   }
 
   if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) {
     osi_free(buf);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONGESTED_AT_FLAG_CHECK, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_CONGESTED_AT_FLAG_CHECK);
     return HID_ERR_CONGESTED;
   }
 
@@ -804,8 +800,8 @@
       buf_size = HID_INTERRUPT_BUF_SIZE;
       break;
     default:
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_SEND_DATA, 1);
+      bluetooth::metrics::Counter(
+              bluetooth::metrics::CounterKey::HIDH_ERR_INVALID_PARAM_AT_SEND_DATA);
       return HID_ERR_INVALID_PARAM;
   }
 
@@ -865,8 +861,7 @@
     /* Send the buffer through L2CAP */
     if ((p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) ||
         (stack::l2cap::get_interface().L2CA_DataWrite(cid, p_buf) == tL2CAP_DW_RESULT::FAILED)) {
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONGESTED_AT_SEND_DATA, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_CONGESTED_AT_SEND_DATA);
       return HID_ERR_CONGESTED;
     }
 
@@ -896,8 +891,7 @@
   if (p_dev->conn.conn_state != HID_CONN_STATE_UNUSED) {
     log::warn("HID-Host Connection already in progress {} state:{}", p_dev->addr,
               p_dev->conn.state_text(p_dev->conn.conn_state));
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONN_IN_PROCESS, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_CONN_IN_PROCESS);
     return HID_ERR_CONN_IN_PROCESS;
   }
 
@@ -916,8 +910,7 @@
     log::warn("Control channel L2CAP connection failed {}", p_dev->addr);
     hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, HID_ERR_L2CAP_FAILED,
                    NULL);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_L2CAP_FAILED_AT_INITIATE, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::HIDH_ERR_L2CAP_FAILED_AT_INITIATE);
   } else {
     /* Transition to the next appropriate state, waiting for connection confirm
      * on control channel. */
diff --git a/system/stack/l2cap/l2c_api.cc b/system/stack/l2cap/l2c_api.cc
index c5e4a36..5c9ac8c 100644
--- a/system/stack/l2cap/l2c_api.cc
+++ b/system/stack/l2cap/l2c_api.cc
@@ -53,9 +53,9 @@
 using namespace bluetooth;
 
 extern fixed_queue_t* btu_general_alarm_queue;
-tL2C_AVDT_CHANNEL_INFO av_media_channels[MAX_ACTIVE_AVDT_CONN];
+static tL2C_AVDT_CHANNEL_INFO av_media_channels[MAX_ACTIVE_AVDT_CONN];
 
-constexpr uint16_t L2CAP_LE_CREDIT_THRESHOLD = 64;
+static constexpr uint16_t L2CAP_LE_CREDIT_THRESHOLD = 64;
 
 uint16_t L2CA_RegisterWithSecurity(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                                    bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
diff --git a/system/stack/l2cap/l2c_csm.cc b/system/stack/l2cap/l2c_csm.cc
index f1d6da3..fa483e2 100644
--- a/system/stack/l2cap/l2c_csm.cc
+++ b/system/stack/l2cap/l2c_csm.cc
@@ -348,8 +348,7 @@
         l2cu_release_ccb(p_ccb);
         (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                 local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_ACL_CONNECTION_FAILED));
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONNECT_CONFIRM_NEG, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_CONNECT_CONFIRM_NEG);
       }
       break;
 
@@ -383,9 +382,8 @@
           l2cu_release_ccb(p_ccb);
           (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                   local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_OTHER_ERROR));
-          bluetooth::metrics::CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum::
-                                                          L2CAP_NO_COMPATIBLE_CHANNEL_AT_CSM_CLOSED,
-                                                  1);
+          bluetooth::metrics::Counter(
+                  bluetooth::metrics::CounterKey::L2CAP_NO_COMPATIBLE_CHANNEL_AT_CSM_CLOSED);
         } else {
           l2cu_send_peer_connect_req(p_ccb);
           alarm_set_on_mloop(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS,
@@ -399,8 +397,7 @@
       (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
               local_cid,
               static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_CLIENT_SECURITY_CLEARANCE_FAILED));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::L2CAP_SECURITY_NEG_AT_CSM_CLOSED, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_SECURITY_NEG_AT_CSM_CLOSED);
       break;
 
     case L2CEVT_L2CAP_CREDIT_BASED_CONNECT_REQ: /* Peer connect request */
@@ -457,8 +454,7 @@
       l2cu_release_ccb(p_ccb);
       (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
               local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_OTHER_ERROR));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::L2CAP_TIMEOUT_AT_CSM_CLOSED, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_TIMEOUT_AT_CSM_CLOSED);
       break;
 
     case L2CEVT_L2CAP_DATA:      /* Peer data packet rcvd    */
@@ -528,9 +524,8 @@
             l2cu_release_ccb(p_ccb);
             (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                     local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_OTHER_ERROR));
-            bluetooth::metrics::CountCounterMetrics(android::bluetooth::CodePathCounterKeyEnum::
-                                                            L2CAP_NO_COMPATIBLE_CHANNEL_AT_W4_SEC,
-                                                    1);
+            bluetooth::metrics::Counter(
+                    bluetooth::metrics::CounterKey::L2CAP_NO_COMPATIBLE_CHANNEL_AT_W4_SEC);
           } else {
             alarm_set_on_mloop(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS,
                                l2c_ccb_timer_timeout, p_ccb);
@@ -552,8 +547,7 @@
       (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
               local_cid,
               static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_CLIENT_SECURITY_CLEARANCE_FAILED));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::L2CAP_SECURITY_NEG_AT_W4_SEC, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_SECURITY_NEG_AT_W4_SEC);
       break;
 
     case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
@@ -809,8 +803,8 @@
     case L2CEVT_L2CAP_CREDIT_BASED_CONNECT_RSP_NEG:
       log::debug("Calling pL2CA_Error_Cb(),cid {}, result 0x{:04x}", local_cid, p_ci->l2cap_result);
       (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, static_cast<uint16_t>(p_ci->l2cap_result));
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::L2CAP_CREDIT_BASED_CONNECT_RSP_NEG, 1);
+      bluetooth::metrics::Counter(
+              bluetooth::metrics::CounterKey::L2CAP_CREDIT_BASED_CONNECT_RSP_NEG);
 
       l2cu_release_ccb(p_ccb);
       break;
@@ -825,8 +819,7 @@
         (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                 local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_OTHER_ERROR));
       }
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONNECT_RSP_NEG, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_CONNECT_RSP_NEG);
       break;
 
     case L2CEVT_TIMEOUT:
@@ -839,8 +832,7 @@
           log::warn("lcid= 0x{:x}", cid);
           (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                   p_ccb->local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_TIMEOUT));
-          bluetooth::metrics::CountCounterMetrics(
-                  android::bluetooth::CodePathCounterKeyEnum::L2CAP_TIMEOUT_AT_CONNECT_RSP, 1);
+          bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_TIMEOUT_AT_CONNECT_RSP);
           l2cu_release_ccb(temp_p_ccb);
         }
         p_lcb->pending_ecoc_conn_cnt = 0;
@@ -851,9 +843,8 @@
         l2cu_release_ccb(p_ccb);
         (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                 local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_OTHER_ERROR));
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONN_OTHER_ERROR_AT_CONNECT_RSP,
-                1);
+        bluetooth::metrics::Counter(
+                bluetooth::metrics::CounterKey::L2CAP_CONN_OTHER_ERROR_AT_CONNECT_RSP);
       }
       break;
 
@@ -884,9 +875,8 @@
         l2cu_release_ccb(p_ccb);
         (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                 local_cid, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_OTHER_ERROR));
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::L2CAP_INFO_NO_COMPATIBLE_CHANNEL_AT_RSP,
-                1);
+        bluetooth::metrics::Counter(
+                bluetooth::metrics::CounterKey::L2CAP_INFO_NO_COMPATIBLE_CHANNEL_AT_RSP);
       } else {
         /* We have feature info, so now send peer connect request */
         alarm_set_on_mloop(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS,
@@ -1108,8 +1098,7 @@
               (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                       p_ccb->local_cid,
                       static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON));
-              bluetooth::metrics::CountCounterMetrics(
-                      android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONFIG_REQ_FAILURE, 1);
+              bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_CONFIG_REQ_FAILURE);
             }
           }
         }
@@ -1213,8 +1202,7 @@
           (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
                   p_ccb->local_cid,
                   static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON));
-          bluetooth::metrics::CountCounterMetrics(
-                  android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONFIG_RSP_NEG, 1);
+          bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::L2CAP_CONFIG_RSP_NEG);
         }
       }
       break;
diff --git a/system/stack/l2cap/l2c_main.cc b/system/stack/l2cap/l2c_main.cc
index 3f82b0c..fa9c6e5 100644
--- a/system/stack/l2cap/l2c_main.cc
+++ b/system/stack/l2cap/l2c_main.cc
@@ -44,7 +44,6 @@
 #include "stack/l2cap/l2c_int.h"
 
 using namespace bluetooth;
-bool is_l2c_cleanup_inprogress;
 
 /******************************************************************************/
 /*            L O C A L    F U N C T I O N     P R O T O T Y P E S            */
@@ -55,6 +54,7 @@
 /*               G L O B A L      L 2 C A P       D A T A                     */
 /******************************************************************************/
 tL2C_CB l2cb;
+static bool is_l2c_cleanup_inprogress;
 
 /*******************************************************************************
  *
diff --git a/system/stack/pan/pan_api.cc b/system/stack/pan/pan_api.cc
index 8650b5d..d1680fa 100644
--- a/system/stack/pan/pan_api.cc
+++ b/system/stack/pan/pan_api.cc
@@ -55,9 +55,9 @@
 constexpr char kBtmLogTag[] = "PAN";
 }
 
-extern std::string user_service_name; /* Service name for PANU role */
-extern std::string gn_service_name;   /* Service name for GN role */
-extern std::string nap_service_name;  /* Service name for NAP role */
+static std::string user_service_name; /* Service name for PANU role */
+static std::string gn_service_name;   /* Service name for GN role */
+static std::string nap_service_name;  /* Service name for NAP role */
 
 /*******************************************************************************
  *
diff --git a/system/stack/rfcomm/port_rfc.cc b/system/stack/rfcomm/port_rfc.cc
index 757b71f..dec4acf 100644
--- a/system/stack/rfcomm/port_rfc.cc
+++ b/system/stack/rfcomm/port_rfc.cc
@@ -51,9 +51,8 @@
 /*
  * Local function definitions
  */
-uint32_t port_rfc_send_tx_data(tPORT* p_port);
-void port_rfc_closed(tPORT* p_port, uint8_t res);
-void port_get_credits(tPORT* p_port, uint8_t k);
+static uint32_t port_rfc_send_tx_data(tPORT* p_port);
+static void port_get_credits(tPORT* p_port, uint8_t k);
 
 /*******************************************************************************
  *
@@ -186,8 +185,7 @@
      * clear tPort */
     if (p_port->p_mgmt_callback) {
       p_port->p_mgmt_callback(PORT_CLOSED, p_port->handle);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_CLOSE, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_PORT_START_CLOSE);
     }
 
     port_release_port(p_port);
@@ -231,8 +229,7 @@
 
         if (p_port->p_mgmt_callback) {
           p_port->p_mgmt_callback(PORT_START_FAILED, p_port->handle);
-          bluetooth::metrics::CountCounterMetrics(
-                  android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_CNF_FAILED, 1);
+          bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_PORT_START_CNF_FAILED);
         }
         port_release_port(p_port);
       }
@@ -458,14 +455,12 @@
     if (p_port->rfc_cfg_info.data_path != BTSOCK_DATA_PATH_HARDWARE_OFFLOAD &&
         p_port->p_mgmt_callback) {
       p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_CONNECTION_SUCCESS_IND);
     }
   } else {
     if (p_port->p_mgmt_callback) {
       p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_CONNECTION_SUCCESS_IND);
     }
   }
 
@@ -494,8 +489,7 @@
   if (result != RFCOMM_SUCCESS) {
     log::warn("Unable to establish configuration dlci:{} result:{}", dlci, result);
     port_rfc_closed(p_port, PORT_START_FAILED);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_FAILED, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_PORT_START_FAILED);
     return;
   }
 
@@ -515,14 +509,12 @@
     if (p_port->rfc_cfg_info.data_path != BTSOCK_DATA_PATH_HARDWARE_OFFLOAD &&
         p_port->p_mgmt_callback) {
       p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_CONNECTION_SUCCESS_CNF);
     }
   } else {
     if (p_port->p_mgmt_callback) {
       p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_CONNECTION_SUCCESS_CNF);
     }
   }
 
@@ -592,8 +584,7 @@
     RFCOMM_DlcReleaseReq(p_mcb, p_port->dlci);
 
     port_rfc_closed(p_port, PORT_PORT_NEG_FAILED);
-    bluetooth::metrics::CountCounterMetrics(
-            android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_NEG_FAILED, 1);
+    bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_PORT_NEG_FAILED);
     return;
   }
 
@@ -664,8 +655,7 @@
     if (p_port->rfc_cfg_info.data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) {
       if (p_port->port_ctrl == PORT_CTRL_SETUP_COMPLETED && p_port->p_mgmt_callback) {
         p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_CONNECTION_SUCCESS_IND);
       }
     }
   }
@@ -711,8 +701,7 @@
     if (p_port->rfc_cfg_info.data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) {
       if (p_port->port_ctrl == PORT_CTRL_SETUP_COMPLETED && p_port->p_mgmt_callback) {
         p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
-        bluetooth::metrics::CountCounterMetrics(
-                android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF, 1);
+        bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_CONNECTION_SUCCESS_CNF);
       }
     }
   }
@@ -770,8 +759,7 @@
     return;
   }
   port_rfc_closed(p_port, PORT_CLOSED);
-  bluetooth::metrics::CountCounterMetrics(
-          android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_CLOSED, 1);
+  bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_PORT_CLOSED);
 }
 
 /*******************************************************************************
@@ -792,8 +780,8 @@
   for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) {
     if (p_port->rfc.p_mcb == p_mcb) {
       port_rfc_closed(p_port, PORT_PEER_CONNECTION_FAILED);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_PEER_CONNECTION_FAILED, 1);
+      bluetooth::metrics::Counter(
+              bluetooth::metrics::CounterKey::RFCOMM_PORT_PEER_CONNECTION_FAILED);
     }
   }
   rfc_release_multiplexer_channel(p_mcb);
@@ -817,8 +805,7 @@
   for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) {
     if (p_port->rfc.p_mcb == p_mcb) {
       port_rfc_closed(p_port, PORT_PEER_TIMEOUT);
-      bluetooth::metrics::CountCounterMetrics(
-              android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_PEER_TIMEOUT, 1);
+      bluetooth::metrics::Counter(bluetooth::metrics::CounterKey::RFCOMM_PORT_PEER_TIMEOUT);
     }
   }
 }
@@ -978,7 +965,7 @@
  * Description      This function is when forward data can be sent to the peer
  *
  ******************************************************************************/
-uint32_t port_rfc_send_tx_data(tPORT* p_port) {
+static uint32_t port_rfc_send_tx_data(tPORT* p_port) {
   uint32_t events = 0;
   BT_HDR* p_buf;
 
@@ -1119,7 +1106,7 @@
  *                  should be less then 255
  *
  ******************************************************************************/
-void port_get_credits(tPORT* p_port, uint8_t k) {
+static void port_get_credits(tPORT* p_port, uint8_t k) {
   p_port->credit_tx = k;
   if (p_port->credit_tx == 0) {
     p_port->tx.peer_fc = true;
diff --git a/system/stack/rfcomm/rfc_port_fsm.cc b/system/stack/rfcomm/rfc_port_fsm.cc
index dec82b6..c2e32f6 100644
--- a/system/stack/rfcomm/rfc_port_fsm.cc
+++ b/system/stack/rfcomm/rfc_port_fsm.cc
@@ -576,17 +576,15 @@
 
     case RFC_PORT_EVENT_DM:
       log::warn("RFC_EVENT_DM|RFC_EVENT_UA[{}], port_handle:{}", event, p_port->handle);
-      if (com::android::bluetooth::flags::rfcomm_always_disc_initiator_in_disc_wait_ua()) {
-        // If we got a DM in RFC_STATE_DISC_WAIT_UA, it's likely that both ends
-        // attempt to DISC at the same time and both get a DM.
-        // Without setting this flag the both ends would start the same timers,
-        // wait, and still DISC the multiplexer at the same time eventually.
-        // The wait is meaningless and would block all other services that rely
-        // on RFCOMM such as HFP.
-        // Thus, setting this flag here to save us a timeout and doesn't
-        // introduce further RFCOMM event changes.
-        p_port->rfc.p_mcb->is_disc_initiator = true;
-      }
+      // If we got a DM in RFC_STATE_DISC_WAIT_UA, it's likely that both ends
+      // attempt to DISC at the same time and both get a DM.
+      // Without setting this flag the both ends would start the same timers,
+      // wait, and still DISC the multiplexer at the same time eventually.
+      // The wait is meaningless and would block all other services that rely
+      // on RFCOMM such as HFP.
+      // Thus, setting this flag here to save us a timeout and doesn't
+      // introduce further RFCOMM event changes.
+      p_port->rfc.p_mcb->is_disc_initiator = true;
       rfc_port_closed(p_port);
       return;
 
diff --git a/system/stack/rnr/remote_name_request.cc b/system/stack/rnr/remote_name_request.cc
index 989a77b..f10c829 100644
--- a/system/stack/rnr/remote_name_request.cc
+++ b/system/stack/rnr/remote_name_request.cc
@@ -356,8 +356,7 @@
   ::btm_process_remote_name(bda, bdn, evt_len, hci_status);
 }
 
-bluetooth::stack::rnr::Impl default_interface;
-
-bluetooth::stack::rnr::Interface* interface_ = &default_interface;
+static bluetooth::stack::rnr::Impl default_interface;
+static bluetooth::stack::rnr::Interface* interface_ = &default_interface;
 
 bluetooth::stack::rnr::Interface& get_stack_rnr_interface() { return *interface_; }
diff --git a/system/stack/smp/smp_act.cc b/system/stack/smp/smp_act.cc
index 797daff..8686b2c 100644
--- a/system/stack/smp/smp_act.cc
+++ b/system/stack/smp/smp_act.cc
@@ -1100,9 +1100,7 @@
 
   smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_CSRK, true);
 
-  if (com::android::bluetooth::flags::save_peer_csrk_after_ltk_gen()) {
-    smp_key_distribution_by_transport(p_cb, NULL);
-  }
+  smp_key_distribution_by_transport(p_cb, NULL);
 
   /* save CSRK to security record */
   tBTM_LE_KEY_VALUE le_key = {
@@ -1121,10 +1119,6 @@
   if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) {
     btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PCSRK, &le_key, true);
   }
-
-  if (!com::android::bluetooth::flags::save_peer_csrk_after_ltk_gen()) {
-    smp_key_distribution_by_transport(p_cb, NULL);
-  }
 }
 
 /*******************************************************************************
@@ -1550,9 +1544,6 @@
       switch (p_cb->loc_oob_flag) {
         case SMP_OOB_NONE:
           log::info("SMP_MODEL_SEC_CONN_OOB with SMP_OOB_NONE");
-          if (!com::android::bluetooth::flags::remove_dup_pairing_response_in_oob_pairing()) {
-            smp_send_pair_rsp(p_cb, NULL);
-          }
           break;
         case SMP_OOB_PRESENT:
           log::info("SMP_MODEL_SEC_CONN_OOB with SMP_OOB_PRESENT");
diff --git a/system/stack/smp/smp_br_main.cc b/system/stack/smp/smp_br_main.cc
index 20e6459..bb45937 100644
--- a/system/stack/smp/smp_br_main.cc
+++ b/system/stack/smp/smp_br_main.cc
@@ -44,8 +44,8 @@
         "BR_ENC_REQ_EVT",         "BR_BOND_REQ_EVT",
         "BR_DISCARD_SEC_REQ_EVT", "BR_OUT_OF_RANGE_EVT"};
 
-const char* smp_get_br_event_name(tSMP_BR_EVENT event);
-const char* smp_get_br_state_name(tSMP_BR_STATE state);
+static const char* smp_get_br_event_name(tSMP_BR_EVENT event);
+static const char* smp_get_br_state_name(tSMP_BR_STATE state);
 
 #define SMP_BR_SM_IGNORE 0
 #define SMP_BR_NUM_ACTIONS 2
@@ -258,7 +258,7 @@
  * Function     smp_get_br_state_name
  * Returns      The smp_br state name.
  ******************************************************************************/
-const char* smp_get_br_state_name(tSMP_BR_STATE br_state) {
+static const char* smp_get_br_state_name(tSMP_BR_STATE br_state) {
   const char* p_str = smp_br_state_name[SMP_BR_STATE_MAX];
 
   if (br_state < SMP_BR_STATE_MAX) {
@@ -271,7 +271,7 @@
  * Function     smp_get_br_event_name
  * Returns      The smp_br event name.
  ******************************************************************************/
-const char* smp_get_br_event_name(tSMP_BR_EVENT event) {
+static const char* smp_get_br_event_name(tSMP_BR_EVENT event) {
   const char* p_str = smp_br_event_name[SMP_BR_MAX_EVT - 1];
 
   if (event < SMP_BR_MAX_EVT) {
diff --git a/system/stack/smp/smp_main.cc b/system/stack/smp/smp_main.cc
index cfc8df3..d1abbf1 100644
--- a/system/stack/smp/smp_main.cc
+++ b/system/stack/smp/smp_main.cc
@@ -93,8 +93,8 @@
                                       "SIRK_DEVICE_VALID_EVT",
                                       "OUT_OF_RANGE_EVT"};
 
-const char* smp_get_event_name(tSMP_EVENT event);
-const char* smp_get_state_name(tSMP_STATE state);
+static const char* smp_get_event_name(tSMP_EVENT event);
+static const char* smp_get_state_name(tSMP_STATE state);
 
 #define SMP_SM_IGNORE 0
 #define SMP_NUM_ACTIONS 2
@@ -1011,7 +1011,7 @@
  * Function     smp_get_state_name
  * Returns      The smp state name.
  ******************************************************************************/
-const char* smp_get_state_name(tSMP_STATE state) {
+static const char* smp_get_state_name(tSMP_STATE state) {
   const char* p_str = smp_state_name[SMP_STATE_MAX];
 
   if (state < SMP_STATE_MAX) {
@@ -1024,7 +1024,7 @@
  * Function     smp_get_event_name
  * Returns      The smp event name.
  ******************************************************************************/
-const char* smp_get_event_name(tSMP_EVENT event) {
+static const char* smp_get_event_name(tSMP_EVENT event) {
   const char* p_str = smp_event_name[SMP_MAX_EVT];
 
   if (event <= SMP_MAX_EVT) {
diff --git a/tools/rootcanal/model/controller/dual_mode_controller.cc b/tools/rootcanal/model/controller/dual_mode_controller.cc
index c7b5d0b..37cd049 100644
--- a/tools/rootcanal/model/controller/dual_mode_controller.cc
+++ b/tools/rootcanal/model/controller/dual_mode_controller.cc
@@ -917,6 +917,18 @@
   link_layer_controller_.ReadLocalOobExtendedData();
 }
 
+void DualModeController::SetMinEncryptionKeySize(CommandView command) {
+  auto command_view = bluetooth::hci::SetMinEncryptionKeySizeView::Create(command);
+  CHECK_PACKET_VIEW(command_view);
+
+  DEBUG(id_, "<< Set Min Encryption Key Size");
+  DEBUG(id_, "   min_encryption_key_size={}", command_view.GetMinEncryptionKeySize());
+
+  link_layer_controller_.SetMinEncryptionKeySize(command_view.GetMinEncryptionKeySize());
+  send_event_(bluetooth::hci::SetMinEncryptionKeySizeCompleteBuilder::Create(kNumCommandPackets,
+                                                                             ErrorCode::SUCCESS));
+}
+
 void DualModeController::WriteSimplePairingMode(CommandView command) {
   auto command_view = bluetooth::hci::WriteSimplePairingModeView::Create(command);
   CHECK_PACKET_VIEW(command_view);
@@ -3290,9 +3302,58 @@
                                                                        ErrorCode::SUCCESS));
 }
 
-void DualModeController::IntelDdcConfigWrite(CommandView /*command*/) {
-  send_event_(bluetooth::hci::CommandCompleteBuilder::Create(kNumCommandPackets, OpCode::INTEL_DDC_CONFIG_WRITE,
-                                                             std::vector<uint8_t> { static_cast<uint8_t>(ErrorCode::SUCCESS) }));
+void DualModeController::IntelDdcConfigRead(CommandView command) {
+  std::vector<uint8_t> parameters(command.GetPayload());
+  ASSERT(parameters.size() == 2);
+  uint16_t id = parameters[0] | (parameters[1] << 8);
+
+  DEBUG(id_, "<< Intel DDC Config Read");
+  DEBUG(id_, "   id=0x{:04x}", id);
+
+  switch (id) {
+    case 0x0204:
+      send_event_(bluetooth::hci::CommandCompleteBuilder::Create(
+              kNumCommandPackets, OpCode::INTEL_DDC_CONFIG_READ,
+              std::vector<uint8_t>{static_cast<uint8_t>(ErrorCode::SUCCESS), 0x04, 0x02, 0x01,
+                                   0x10}));
+      break;
+    default:
+      send_event_(bluetooth::hci::CommandCompleteBuilder::Create(
+              kNumCommandPackets, OpCode::INTEL_DDC_CONFIG_READ,
+              std::vector<uint8_t>{static_cast<uint8_t>(ErrorCode::INVALID_HCI_COMMAND_PARAMETERS),
+                                   0x00, 0x00}));
+      break;
+  }
+}
+
+void DualModeController::IntelDdcConfigWrite(CommandView command) {
+  std::vector<uint8_t> parameters(command.GetPayload());
+  size_t offset = 0;
+
+  DEBUG(id_, "<< Intel DDC Config Write");
+
+  while (offset < parameters.size()) {
+    uint8_t len = parameters[offset];
+    ASSERT(len >= 2 && offset + len + 1 <= parameters.size());
+
+    uint16_t id = parameters[offset + 1] | (parameters[offset + 2] << 8);
+    uint8_t const* value = &parameters[offset + 3];
+    offset += 1 + len;
+
+    DEBUG(id_, "   id=0x{:04x} len={}", id, len);
+
+    if (id == 0x0126 && len == 10) {
+      INFO(id_, "Intel updating the LE Local Supported Features");
+      properties_.le_features = ((uint64_t)value[0] << 0) | ((uint64_t)value[1] << 8) |
+                                ((uint64_t)value[2] << 16) | ((uint64_t)value[3] << 24) |
+                                ((uint64_t)value[4] << 32) | ((uint64_t)value[5] << 40) |
+                                ((uint64_t)value[6] << 48) | ((uint64_t)value[7] << 56);
+    }
+  }
+
+  send_event_(bluetooth::hci::CommandCompleteBuilder::Create(
+          kNumCommandPackets, OpCode::INTEL_DDC_CONFIG_WRITE,
+          std::vector<uint8_t>{static_cast<uint8_t>(ErrorCode::SUCCESS), 0x00, 0x00}));
 }
 
 // Note: the list does not contain all defined opcodes.
@@ -3965,8 +4026,7 @@
                 //{OpCode::SET_ECOSYSTEM_BASE_INTERVAL,
                 //&DualModeController::SetEcosystemBaseInterval},
                 //{OpCode::CONFIGURE_DATA_PATH, &DualModeController::ConfigureDataPath},
-                //{OpCode::SET_MIN_ENCRYPTION_KEY_SIZE,
-                //&DualModeController::SetMinEncryptionKeySize},
+                {OpCode::SET_MIN_ENCRYPTION_KEY_SIZE, &DualModeController::SetMinEncryptionKeySize},
 
                 // INFORMATIONAL_PARAMETERS
                 {OpCode::READ_LOCAL_VERSION_INFORMATION,
@@ -4280,6 +4340,7 @@
                  &DualModeController::LeGetControllerActivityEnergyInfo},
                 {OpCode::LE_EX_SET_SCAN_PARAMETERS, &DualModeController::LeExSetScanParameters},
                 {OpCode::GET_CONTROLLER_DEBUG_INFO, &DualModeController::GetControllerDebugInfo},
+                {OpCode::INTEL_DDC_CONFIG_READ, &DualModeController::IntelDdcConfigRead},
                 {OpCode::INTEL_DDC_CONFIG_WRITE, &DualModeController::IntelDdcConfigWrite},
         };
 
diff --git a/tools/rootcanal/model/controller/dual_mode_controller.h b/tools/rootcanal/model/controller/dual_mode_controller.h
index c5574bd..50edbe8 100644
--- a/tools/rootcanal/model/controller/dual_mode_controller.h
+++ b/tools/rootcanal/model/controller/dual_mode_controller.h
@@ -337,6 +337,9 @@
   // 7.3.95
   void ReadLocalOobExtendedData(CommandView command);
 
+  // 7.3.102
+  void SetMinEncryptionKeySize(CommandView command);
+
   // Informational Parameters Commands
   // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4
 
@@ -525,6 +528,7 @@
   void LeGetControllerActivityEnergyInfo(CommandView command);
   void LeExSetScanParameters(CommandView command);
   void GetControllerDebugInfo(CommandView command);
+  void IntelDdcConfigRead(CommandView command);
   void IntelDdcConfigWrite(CommandView command);
 
   // CSR vendor command.
diff --git a/tools/rootcanal/model/controller/link_layer_controller.h b/tools/rootcanal/model/controller/link_layer_controller.h
index 75a8fd3..a02e9fe 100644
--- a/tools/rootcanal/model/controller/link_layer_controller.h
+++ b/tools/rootcanal/model/controller/link_layer_controller.h
@@ -693,7 +693,10 @@
 
   // TODO
   // The Encryption Key Size should be specific to an ACL connection.
-  uint8_t GetEncryptionKeySize() const { return min_encryption_key_size_; }
+  uint8_t GetEncryptionKeySize() const { return 16; }
+  void SetMinEncryptionKeySize(uint8_t min_encryption_key_size) {
+    min_encryption_key_size_ = min_encryption_key_size;
+  }
 
   bool GetScoFlowControlEnable() const { return sco_flow_control_enable_; }
 
diff --git a/tools/rootcanal/packets/hci_packets.pdl b/tools/rootcanal/packets/hci_packets.pdl
index 8f3d3c1..1143d60 100644
--- a/tools/rootcanal/packets/hci_packets.pdl
+++ b/tools/rootcanal/packets/hci_packets.pdl
@@ -400,6 +400,7 @@
   // VENDOR_SPECIFIC
   // MSFT_OPCODE_xxxx below is needed for the tests.
   MSFT_OPCODE_INTEL = 0xFC1E,
+  INTEL_DDC_CONFIG_READ = 0xFC8C,
   INTEL_DDC_CONFIG_WRITE = 0xFC8B,
   LE_GET_VENDOR_CAPABILITIES = 0xFD53,
   LE_BATCH_SCAN = 0xFD56,