Merge "More canonicalization checks and canonicalize before signing" am: cf02e97946 am: 8daddefc18 am: 59624afdce am: c8d296af83 am: b28fc6af9c

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2029343

Change-Id: I14350c17079cdb480559e89ace7ab01ee22f8f3f
diff --git a/automotive/audiocontrol/aidl/default/Android.bp b/automotive/audiocontrol/aidl/default/Android.bp
index 1439cce..6bf4b9d 100644
--- a/automotive/audiocontrol/aidl/default/Android.bp
+++ b/automotive/audiocontrol/aidl/default/Android.bp
@@ -29,8 +29,9 @@
     vendor: true,
     shared_libs: [
         "android.hardware.audio.common@7.0-enums",
+        "android.hardware.audio.common-V1-ndk",
         "android.frameworks.automotive.powerpolicy-V1-ndk",
-        "android.hardware.automotive.audiocontrol-V1-ndk",
+        "android.hardware.automotive.audiocontrol-V2-ndk",
         "libbase",
         "libbinder_ndk",
         "libcutils",
diff --git a/automotive/audiocontrol/aidl/default/AudioControl.cpp b/automotive/audiocontrol/aidl/default/AudioControl.cpp
index c0bc796..a121f8b 100644
--- a/automotive/audiocontrol/aidl/default/AudioControl.cpp
+++ b/automotive/audiocontrol/aidl/default/AudioControl.cpp
@@ -30,6 +30,8 @@
 #include <android_audio_policy_configuration_V7_0-enums.h>
 #include <private/android_filesystem_config.h>
 
+#include <numeric>
+
 #include <stdio.h>
 
 namespace aidl::android::hardware::automotive::audiocontrol {
@@ -147,6 +149,47 @@
     return ndk::ScopedAStatus::ok();
 }
 
+template <typename aidl_type>
+static inline std::string toString(const std::vector<aidl_type>& in_values) {
+    return std::accumulate(std::begin(in_values), std::end(in_values), std::string{},
+                           [](std::string& ls, const aidl_type& rs) {
+                               return ls += (ls.empty() ? "" : ",") + rs.toString();
+                           });
+}
+template <typename aidl_enum_type>
+static inline std::string toEnumString(const std::vector<aidl_enum_type>& in_values) {
+    return std::accumulate(std::begin(in_values), std::end(in_values), std::string{},
+                           [](std::string& ls, const aidl_enum_type& rs) {
+                               return ls += (ls.empty() ? "" : ",") + toString(rs);
+                           });
+}
+
+ndk::ScopedAStatus AudioControl::onAudioFocusChangeWithMetaData(
+        const audiohalcommon::PlaybackTrackMetadata& in_playbackMetaData, int32_t in_zoneId,
+        AudioFocusChange in_focusChange) {
+    LOG(INFO) << "Focus changed: " << toString(in_focusChange).c_str() << " for metadata "
+              << in_playbackMetaData.toString().c_str() << " in zone " << in_zoneId;
+    return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus AudioControl::setAudioDeviceGainsChanged(
+        const std::vector<Reasons>& in_reasons, const std::vector<AudioGainConfigInfo>& in_gains) {
+    LOG(INFO) << "Audio Device Gains changed: resons:" << toEnumString(in_reasons).c_str()
+              << " for devices: " << toString(in_gains).c_str();
+    return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus AudioControl::registerGainCallback(
+        const std::shared_ptr<IAudioGainCallback>& in_callback) {
+    LOG(DEBUG) << ": " << __func__;
+    if (in_callback) {
+        std::atomic_store(&mAudioGainCallback, in_callback);
+    } else {
+        LOG(ERROR) << "Unexpected nullptr for audio gain callback resulting in no-op.";
+    }
+    return ndk::ScopedAStatus::ok();
+}
+
 binder_status_t AudioControl::dump(int fd, const char** args, uint32_t numArgs) {
     if (numArgs == 0) {
         return dumpsys(fd);
@@ -159,6 +202,12 @@
         return cmdRequestFocus(fd, args, numArgs);
     } else if (EqualsIgnoreCase(option, "--abandon")) {
         return cmdAbandonFocus(fd, args, numArgs);
+    } else if (EqualsIgnoreCase(option, "--requestFocusWithMetaData")) {
+        return cmdRequestFocusWithMetaData(fd, args, numArgs);
+    } else if (EqualsIgnoreCase(option, "--abandonFocusWithMetaData")) {
+        return cmdAbandonFocusWithMetaData(fd, args, numArgs);
+    } else if (EqualsIgnoreCase(option, "--audioGainCallback")) {
+        return cmdOnAudioDeviceGainsChanged(fd, args, numArgs);
     } else {
         dprintf(fd, "Invalid option: %s\n", option.c_str());
         return STATUS_BAD_VALUE;
@@ -171,20 +220,49 @@
     } else {
         dprintf(fd, "Focus listener registered\n");
     }
+    dprintf(fd, "AudioGainCallback %sregistered\n", (mAudioGainCallback == nullptr ? "NOT " : ""));
     return STATUS_OK;
 }
 
 binder_status_t AudioControl::cmdHelp(int fd) const {
     dprintf(fd, "Usage: \n\n");
-    dprintf(fd, "[no args]: dumps focus listener status\n");
+    dprintf(fd, "[no args]: dumps focus listener / gain callback registered status\n");
     dprintf(fd, "--help: shows this help\n");
     dprintf(fd,
             "--request <USAGE> <ZONE_ID> <FOCUS_GAIN>: requests audio focus for specified "
-            "usage (string), audio zone ID (int), and focus gain type (int)\n");
+            "usage (string), audio zone ID (int), and focus gain type (int)\n"
+            "Deprecated, use MetaData instead\n");
     dprintf(fd,
             "--abandon <USAGE> <ZONE_ID>: abandons audio focus for specified usage (string) and "
-            "audio zone ID (int)\n");
+            "audio zone ID (int)\n"
+            "Deprecated, use MetaData instead\n");
     dprintf(fd, "See audio_policy_configuration.xsd for valid AudioUsage values.\n");
+
+    dprintf(fd,
+            "--requestFocusWithMetaData <METADATA> <ZONE_ID> <FOCUS_GAIN>: "
+            "requests audio focus for specified metadata, audio zone ID (int), "
+            "and focus gain type (int)\n");
+    dprintf(fd,
+            "--abandonFocusWithMetaData <METADATA> <ZONE_ID>: "
+            "abandons audio focus for specified metadata and audio zone ID (int)\n");
+    dprintf(fd,
+            "--audioGainCallback <ZONE_ID> <REASON_1>[,<REASON_N> ...]"
+            "<DEVICE_ADDRESS_1> <GAIN_INDEX_1> [<DEVICE_ADDRESS_N> <GAIN_INDEX_N> ...]: fire audio "
+            "gain callback for audio zone ID (int), the given reasons (csv int) for given pairs "
+            "of device address (string) and gain index (int) \n");
+
+    dprintf(fd,
+            "Note on <METADATA>: <USAGE,CONTENT_TYPE[,TAGS]>  specified as where (int)usage, "
+            "(int)content type and tags (string)string)\n");
+    dprintf(fd,
+            "See android/media/audio/common/AudioUsageType.aidl for valid AudioUsage values.\n");
+    dprintf(fd,
+            "See android/media/audio/common/AudioContentType.aidl for valid AudioContentType "
+            "values.\n");
+    dprintf(fd,
+            "Tags are optional. If provided, it must follow the <key>=<value> pattern, where the "
+            "value is namespaced (for example com.google.strategy=VR).\n");
+
     return STATUS_OK;
 }
 
@@ -266,4 +344,174 @@
     return STATUS_OK;
 }
 
+binder_status_t AudioControl::parseMetaData(int fd, const std::string& metadataLiteral,
+                                            audiohalcommon::PlaybackTrackMetadata& trackMetadata) {
+    std::stringstream csvMetaData(metadataLiteral);
+    std::vector<std::string> splitMetaData;
+    std::string attribute;
+    while (getline(csvMetaData, attribute, ',')) {
+        splitMetaData.push_back(attribute);
+    }
+    if (splitMetaData.size() != 2 && splitMetaData.size() != 3) {
+        dprintf(fd,
+                "Invalid metadata: %s, please provide <METADATA> as <USAGE,CONTENT_TYPE[,TAGS]> "
+                "where (int)usage, (int)content type and tags (string)string)\n",
+                metadataLiteral.c_str());
+        return STATUS_BAD_VALUE;
+    }
+    int usage;
+    if (!safelyParseInt(splitMetaData[0], &usage)) {
+        dprintf(fd, "Non-integer usage provided with request: %s\n", splitMetaData[0].c_str());
+        return STATUS_BAD_VALUE;
+    }
+    int contentType;
+    if (!safelyParseInt(splitMetaData[1], &contentType)) {
+        dprintf(fd, "Non-integer content type provided with request: %s\n",
+                splitMetaData[1].c_str());
+        return STATUS_BAD_VALUE;
+    }
+    const std::string tags = (splitMetaData.size() == 3 ? splitMetaData[2] : "");
+
+    trackMetadata = {.usage = static_cast<audiomediacommon::AudioUsage>(usage),
+                     .contentType = static_cast<audiomediacommon::AudioContentType>(contentType),
+                     .tags = {tags}};
+    return STATUS_OK;
+}
+
+binder_status_t AudioControl::cmdRequestFocusWithMetaData(int fd, const char** args,
+                                                          uint32_t numArgs) {
+    if (!checkCallerHasWritePermissions(fd)) {
+        return STATUS_PERMISSION_DENIED;
+    }
+    if (numArgs != 4) {
+        dprintf(fd,
+                "Invalid number of arguments: please provide:\n"
+                "--requestFocusWithMetaData <METADATA> <ZONE_ID> <FOCUS_GAIN>: "
+                "requests audio focus for specified metadata, audio zone ID (int), "
+                "and focus gain type (int)\n");
+        return STATUS_BAD_VALUE;
+    }
+    std::string metadataLiteral = std::string(args[1]);
+    audiohalcommon::PlaybackTrackMetadata trackMetadata{};
+    auto status = parseMetaData(fd, metadataLiteral, trackMetadata);
+    if (status != STATUS_OK) {
+        return status;
+    }
+
+    int zoneId;
+    if (!safelyParseInt(std::string(args[2]), &zoneId)) {
+        dprintf(fd, "Non-integer zoneId provided with request: %s\n", std::string(args[2]).c_str());
+        return STATUS_BAD_VALUE;
+    }
+
+    int focusGainValue;
+    if (!safelyParseInt(std::string(args[3]), &focusGainValue)) {
+        dprintf(fd, "Non-integer focusGain provided with request: %s\n",
+                std::string(args[3]).c_str());
+        return STATUS_BAD_VALUE;
+    }
+    AudioFocusChange focusGain = AudioFocusChange(focusGainValue);
+
+    if (mFocusListener == nullptr) {
+        dprintf(fd, "Unable to request focus - no focus listener registered\n");
+        return STATUS_BAD_VALUE;
+    }
+    mFocusListener->requestAudioFocusWithMetaData(trackMetadata, zoneId, focusGain);
+    dprintf(fd, "Requested focus for metadata %s, zoneId %d, and focusGain %d\n",
+            trackMetadata.toString().c_str(), zoneId, focusGain);
+    return STATUS_OK;
+}
+
+binder_status_t AudioControl::cmdAbandonFocusWithMetaData(int fd, const char** args,
+                                                          uint32_t numArgs) {
+    if (!checkCallerHasWritePermissions(fd)) {
+        return STATUS_PERMISSION_DENIED;
+    }
+    if (numArgs != 3) {
+        dprintf(fd,
+                "Invalid number of arguments: please provide:\n"
+                "--abandonFocusWithMetaData <METADATA> <ZONE_ID>: "
+                "abandons audio focus for specified metadata and audio zone ID (int)\n");
+        return STATUS_BAD_VALUE;
+    }
+    std::string metadataLiteral = std::string(args[1]);
+    audiohalcommon::PlaybackTrackMetadata trackMetadata{};
+    auto status = parseMetaData(fd, metadataLiteral, trackMetadata);
+    if (status != STATUS_OK) {
+        return status;
+    }
+    int zoneId;
+    if (!safelyParseInt(std::string(args[2]), &zoneId)) {
+        dprintf(fd, "Non-integer zoneId provided with request: %s\n", std::string(args[2]).c_str());
+        return STATUS_BAD_VALUE;
+    }
+    if (mFocusListener == nullptr) {
+        dprintf(fd, "Unable to abandon focus - no focus listener registered\n");
+        return STATUS_BAD_VALUE;
+    }
+
+    mFocusListener->abandonAudioFocusWithMetaData(trackMetadata, zoneId);
+    dprintf(fd, "Abandoned focus for metadata %s and zoneId %d\n", trackMetadata.toString().c_str(),
+            zoneId);
+    return STATUS_OK;
+}
+
+binder_status_t AudioControl::cmdOnAudioDeviceGainsChanged(int fd, const char** args,
+                                                           uint32_t numArgs) {
+    if (!checkCallerHasWritePermissions(fd)) {
+        return STATUS_PERMISSION_DENIED;
+    }
+    if ((numArgs + 1) % 2 != 0) {
+        dprintf(fd,
+                "Invalid number of arguments: please provide\n"
+                "--audioGainCallback <ZONE_ID> <REASON_1>[,<REASON_N> ...]"
+                "<DEVICE_ADDRESS_1> <GAIN_INDEX_1> [<DEVICE_ADDRESS_N> <GAIN_INDEX_N> ...]: "
+                "fire audio gain callback for audio zone ID (int), "
+                "with the given reasons (csv int) for given pairs of device address (string) "
+                "and gain index (int) \n");
+        return STATUS_BAD_VALUE;
+    }
+    int zoneId;
+    if (!safelyParseInt(string(args[1]), &zoneId)) {
+        dprintf(fd, "Non-integer zoneId provided with request: %s\n", std::string(args[1]).c_str());
+        return STATUS_BAD_VALUE;
+    }
+    std::string reasonsLiteral = std::string(args[2]);
+    std::stringstream csvReasonsLiteral(reasonsLiteral);
+    std::vector<Reasons> reasons;
+    std::string reasonLiteral;
+    while (getline(csvReasonsLiteral, reasonLiteral, ',')) {
+        int reason;
+        if (!safelyParseInt(reasonLiteral, &reason)) {
+            dprintf(fd, "Invalid Reason(s) provided %s\n", reasonLiteral.c_str());
+            return STATUS_BAD_VALUE;
+        }
+        reasons.push_back(static_cast<Reasons>(reason));
+    }
+
+    std::vector<AudioGainConfigInfo> agcis{};
+    for (uint32_t i = 3; i < numArgs; i += 2) {
+        std::string deviceAddress = std::string(args[i]);
+        int32_t index;
+        if (!safelyParseInt(std::string(args[i + 1]), &index)) {
+            dprintf(fd, "Non-integer index provided with request: %s\n",
+                    std::string(args[i + 1]).c_str());
+            return STATUS_BAD_VALUE;
+        }
+        AudioGainConfigInfo agci{zoneId, deviceAddress, index};
+        agcis.push_back(agci);
+    }
+    if (mAudioGainCallback == nullptr) {
+        dprintf(fd,
+                "Unable to trig audio gain callback for reasons=%s and gains=%s\n"
+                " - no audio gain callback registered\n",
+                toEnumString(reasons).c_str(), toString(agcis).c_str());
+        return STATUS_BAD_VALUE;
+    }
+
+    mAudioGainCallback->onAudioDeviceGainsChanged(reasons, agcis);
+    dprintf(fd, "Fired audio gain callback for reasons=%s and gains=%s\n",
+            toEnumString(reasons).c_str(), toString(agcis).c_str());
+    return STATUS_OK;
+}
 }  // namespace aidl::android::hardware::automotive::audiocontrol
diff --git a/automotive/audiocontrol/aidl/default/AudioControl.h b/automotive/audiocontrol/aidl/default/AudioControl.h
index cca9c44..16b80e8 100644
--- a/automotive/audiocontrol/aidl/default/AudioControl.h
+++ b/automotive/audiocontrol/aidl/default/AudioControl.h
@@ -17,12 +17,20 @@
 #define ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H
 
 #include <aidl/android/hardware/automotive/audiocontrol/AudioFocusChange.h>
+#include <aidl/android/hardware/automotive/audiocontrol/AudioGainConfigInfo.h>
 #include <aidl/android/hardware/automotive/audiocontrol/BnAudioControl.h>
 #include <aidl/android/hardware/automotive/audiocontrol/DuckingInfo.h>
+#include <aidl/android/hardware/automotive/audiocontrol/IAudioGainCallback.h>
 #include <aidl/android/hardware/automotive/audiocontrol/MutingInfo.h>
+#include <aidl/android/hardware/automotive/audiocontrol/Reasons.h>
+
+#include <aidl/android/hardware/audio/common/PlaybackTrackMetadata.h>
 
 namespace aidl::android::hardware::automotive::audiocontrol {
 
+namespace audiohalcommon = ::aidl::android::hardware::audio::common;
+namespace audiomediacommon = ::aidl::android::media::audio::common;
+
 class AudioControl : public BnAudioControl {
   public:
     ndk::ScopedAStatus onAudioFocusChange(const std::string& in_usage, int32_t in_zoneId,
@@ -35,6 +43,15 @@
             const std::shared_ptr<IFocusListener>& in_listener) override;
     ndk::ScopedAStatus setBalanceTowardRight(float in_value) override;
     ndk::ScopedAStatus setFadeTowardFront(float in_value) override;
+    ndk::ScopedAStatus onAudioFocusChangeWithMetaData(
+            const audiohalcommon::PlaybackTrackMetadata& in_playbackMetaData, int32_t in_zoneId,
+            AudioFocusChange in_focusChange) override;
+    ndk::ScopedAStatus setAudioDeviceGainsChanged(
+            const std::vector<Reasons>& in_reasons,
+            const std::vector<AudioGainConfigInfo>& in_gains) override;
+    ndk::ScopedAStatus registerGainCallback(
+            const std::shared_ptr<IAudioGainCallback>& in_callback) override;
+
     binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
 
   private:
@@ -44,9 +61,22 @@
     // listener, then it should also include mutexes or make the listener atomic.
     std::shared_ptr<IFocusListener> mFocusListener;
 
+    /**
+     * @brief mAudioGainCallback will be used by this HAL instance to communicate e.g. with a single
+     * instance of CarAudioService to report unexpected gain changed.
+     */
+    std::shared_ptr<IAudioGainCallback> mAudioGainCallback = nullptr;
+
     binder_status_t cmdHelp(int fd) const;
     binder_status_t cmdRequestFocus(int fd, const char** args, uint32_t numArgs);
     binder_status_t cmdAbandonFocus(int fd, const char** args, uint32_t numArgs);
+    binder_status_t cmdRequestFocusWithMetaData(int fd, const char** args, uint32_t numArgs);
+    binder_status_t cmdAbandonFocusWithMetaData(int fd, const char** args, uint32_t numArgs);
+    binder_status_t cmdOnAudioDeviceGainsChanged(int fd, const char** args, uint32_t numArgs);
+
+    binder_status_t parseMetaData(int fd, const std::string& metadataLiteral,
+                                  audiohalcommon::PlaybackTrackMetadata& trackMetadata);
+
     binder_status_t dumpsys(int fd);
 };
 
diff --git a/automotive/audiocontrol/aidl/default/audiocontrol-default.xml b/automotive/audiocontrol/aidl/default/audiocontrol-default.xml
index f95d05f..e82f6fa 100644
--- a/automotive/audiocontrol/aidl/default/audiocontrol-default.xml
+++ b/automotive/audiocontrol/aidl/default/audiocontrol-default.xml
@@ -1,4 +1,4 @@
-<manifest version="1.0" type="device">
+<manifest version="2.0" type="device">
     <hal format="aidl">
         <name>android.hardware.automotive.audiocontrol</name>
         <fqname>IAudioControl/default</fqname>
diff --git a/automotive/audiocontrol/aidl/vts/Android.bp b/automotive/audiocontrol/aidl/vts/Android.bp
index 6856b91..3d4be48 100644
--- a/automotive/audiocontrol/aidl/vts/Android.bp
+++ b/automotive/audiocontrol/aidl/vts/Android.bp
@@ -37,11 +37,16 @@
         "libxml2",
     ],
     static_libs: [
-        "android.hardware.automotive.audiocontrol-V1-cpp",
+        "android.hardware.automotive.audiocontrol-V2-cpp",
+        "android.hardware.audio.common-V1-cpp",
+        "android.media.audio.common.types-V1-cpp",
         "libgmock",
     ],
     test_suites: [
         "general-tests",
         "vts",
     ],
+    cflags: [
+        "-Wno-deprecated-declarations",
+    ],
 }
diff --git a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
index ae53c68..f4f5eef 100644
--- a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
+++ b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
@@ -19,6 +19,7 @@
 #include <aidl/Vintf.h>
 #include <gmock/gmock.h>
 
+#include <android/hardware/automotive/audiocontrol/BnAudioGainCallback.h>
 #include <android/hardware/automotive/audiocontrol/BnFocusListener.h>
 #include <android/hardware/automotive/audiocontrol/IAudioControl.h>
 #include <android/log.h>
@@ -30,10 +31,13 @@
 using android::String16;
 using android::binder::Status;
 using android::hardware::automotive::audiocontrol::AudioFocusChange;
+using android::hardware::automotive::audiocontrol::AudioGainConfigInfo;
+using android::hardware::automotive::audiocontrol::BnAudioGainCallback;
 using android::hardware::automotive::audiocontrol::BnFocusListener;
 using android::hardware::automotive::audiocontrol::DuckingInfo;
 using android::hardware::automotive::audiocontrol::IAudioControl;
 using android::hardware::automotive::audiocontrol::MutingInfo;
+using android::hardware::automotive::audiocontrol::Reasons;
 
 #include "android_audio_policy_configuration_V7_0.h"
 
@@ -41,6 +45,9 @@
 using namespace android::audio::policy::configuration::V7_0;
 }
 
+namespace audiohalcommon = android::hardware::audio::common;
+namespace audiomediacommon = android::media::audio::common;
+
 class AudioControlAidl : public testing::TestWithParam<std::string> {
   public:
     virtual void SetUp() override {
@@ -103,6 +110,11 @@
     MOCK_METHOD(Status, requestAudioFocus,
                 (const String16& usage, int32_t zoneId, AudioFocusChange focusGain));
     MOCK_METHOD(Status, abandonAudioFocus, (const String16& usage, int32_t zoneId));
+    MOCK_METHOD(Status, requestAudioFocusWithMetaData,
+                (const audiohalcommon::PlaybackTrackMetadata& metaData, int32_t zoneId,
+                 AudioFocusChange focusGain));
+    MOCK_METHOD(Status, abandonAudioFocusWithMetaData,
+                (const audiohalcommon::PlaybackTrackMetadata& metaData, int32_t zoneId));
 };
 
 /*
@@ -159,6 +171,61 @@
     ASSERT_TRUE(audioControl->onDevicesToDuckChange(duckingInfos).isOk());
 }
 
+TEST_P(AudioControlAidl, FocusChangeWithMetaDataExercise) {
+    ALOGI("Focus Change test");
+
+    audiohalcommon::PlaybackTrackMetadata metadata;
+    metadata.usage = audiomediacommon::AudioUsage::MEDIA;
+    metadata.contentType = audiomediacommon::AudioContentType::MUSIC;
+    metadata.tags = {"com.google.android=VR"};
+    ASSERT_TRUE(
+            audioControl
+                    ->onAudioFocusChangeWithMetaData(metadata, 0, AudioFocusChange::GAIN_TRANSIENT)
+                    .isOk());
+};
+
+TEST_P(AudioControlAidl, SetAudioDeviceGainsChangedExercise) {
+    ALOGI("Set Audio Gains Changed test");
+
+    const std::vector<Reasons> reasons{Reasons::FORCED_MASTER_MUTE, Reasons::NAV_DUCKING};
+    AudioGainConfigInfo agci1;
+    agci1.zoneId = 0;
+    agci1.devicePortAddress = String16("address 1");
+    agci1.volumeIndex = 8;
+
+    AudioGainConfigInfo agci2;
+    agci1.zoneId = 0;
+    agci1.devicePortAddress = String16("address 2");
+    agci1.volumeIndex = 1;
+
+    std::vector<AudioGainConfigInfo> gains{agci1, agci2};
+    ASSERT_TRUE(audioControl->setAudioDeviceGainsChanged(reasons, gains).isOk());
+}
+
+/*
+ * Test Audio Gain Callback registration.
+ *
+ * Verifies that:
+ * - registerGainCallback succeeds;
+ * - registering a second callback succeeds in replacing the first;
+ * - closing handle does not crash;
+ */
+struct AudioGainCallbackMock : BnAudioGainCallback {
+    MOCK_METHOD(Status, onAudioDeviceGainsChanged,
+                (const std::vector<Reasons>& reasons,
+                 const std::vector<AudioGainConfigInfo>& gains));
+};
+
+TEST_P(AudioControlAidl, AudioGainCallbackRegistration) {
+    ALOGI("Focus listener test");
+
+    sp<AudioGainCallbackMock> gainCallback = new AudioGainCallbackMock();
+    ASSERT_TRUE(audioControl->registerGainCallback(gainCallback).isOk());
+
+    sp<AudioGainCallbackMock> gainCallback2 = new AudioGainCallbackMock();
+    ASSERT_TRUE(audioControl->registerGainCallback(gainCallback2).isOk());
+}
+
 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioControlAidl);
 INSTANTIATE_TEST_SUITE_P(
         Audiocontrol, AudioControlAidl,
diff --git a/automotive/can/1.0/default/libnl++/Socket.cpp b/automotive/can/1.0/default/libnl++/Socket.cpp
index cc1d839..32110fe 100644
--- a/automotive/can/1.0/default/libnl++/Socket.cpp
+++ b/automotive/can/1.0/default/libnl++/Socket.cpp
@@ -47,6 +47,17 @@
     }
 }
 
+void Socket::clearPollErr() {
+    sockaddr_nl sa = {};
+    socklen_t saLen = sizeof(sa);
+    const auto bytesReceived = recvfrom(mFd.get(), mReceiveBuffer.data(), mReceiveBuffer.size(), 0,
+                                        reinterpret_cast<sockaddr*>(&sa), &saLen);
+    if (errno != EINVAL) {
+        PLOG(WARNING) << "clearPollError() caught unexpected error: ";
+    }
+    CHECK_EQ(bytesReceived, 0) << "clearPollError() recvd " << bytesReceived << " instead of zero!";
+}
+
 bool Socket::send(const Buffer<nlmsghdr>& msg, const sockaddr_nl& sa) {
     if constexpr (kSuperVerbose) {
         LOG(VERBOSE) << (mFailed ? "(not) " : "") << "sending to " << sa.nl_pid << ": "
@@ -110,6 +121,13 @@
     if constexpr (kSuperVerbose) {
         LOG(VERBOSE) << "received from " << sa.nl_pid << ": " << toString(msg, mProtocol);
     }
+    long headerByteTotal = 0;
+    for (const auto hdr : msg) {
+        headerByteTotal += hdr->nlmsg_len;
+    }
+    if (bytesReceived != headerByteTotal) {
+        LOG(ERROR) << "received " << bytesReceived << " bytes, header claims " << headerByteTotal;
+    }
     return {msg, sa};
 }
 
@@ -159,6 +177,7 @@
 }
 
 pollfd Socket::preparePoll(short events) {
+    CHECK(mFd.get() > 0) << "Netlink socket fd is invalid!";
     return {mFd.get(), events, 0};
 }
 
diff --git a/automotive/can/1.0/default/libnl++/include/libnl++/Socket.h b/automotive/can/1.0/default/libnl++/include/libnl++/Socket.h
index 7ec0f7b..996a350 100644
--- a/automotive/can/1.0/default/libnl++/include/libnl++/Socket.h
+++ b/automotive/can/1.0/default/libnl++/include/libnl++/Socket.h
@@ -55,6 +55,12 @@
     Socket(int protocol, unsigned pid = 0, uint32_t groups = 0);
 
     /**
+     * Attempt to clear POLLERR by recv-ing.
+     * TODO(224850481): determine if this is necessary, or if the socket is locked up anyway.
+     */
+    void clearPollErr();
+
+    /**
      * Send Netlink message with incremented sequence number to the Kernel.
      *
      * \param msg Message to send. Its sequence number will be updated.
diff --git a/automotive/can/1.0/default/libnl++/protocols/generic/FamilyTracker.cpp b/automotive/can/1.0/default/libnl++/protocols/generic/FamilyTracker.cpp
index 900560e..3ad101e 100644
--- a/automotive/can/1.0/default/libnl++/protocols/generic/FamilyTracker.cpp
+++ b/automotive/can/1.0/default/libnl++/protocols/generic/FamilyTracker.cpp
@@ -30,6 +30,7 @@
     const auto familyName = msg.attributes.get<std::string>(CTRL_ATTR_FAMILY_NAME);
     const auto familyId = msg.attributes.get<uint16_t>(CTRL_ATTR_FAMILY_ID);
 
+    // TODO(224845900): NETLINK_GENERIC == 16, and (erroneously?) sets off this warning
     if (familyId < GENL_START_ALLOC) {
         LOG(WARNING) << "Invalid family ID: " << familyId;
         return true;
diff --git a/uwb/aidl/android/hardware/uwb/IUwbChip.aidl b/uwb/aidl/android/hardware/uwb/IUwbChip.aidl
index 00cb8e0..6ee5799 100644
--- a/uwb/aidl/android/hardware/uwb/IUwbChip.aidl
+++ b/uwb/aidl/android/hardware/uwb/IUwbChip.aidl
@@ -71,8 +71,8 @@
      * The UCI message format is as per UCI  protocol and it is
      * defined in "FiRa Consortium - UCI Generic Specification_v1.0" specification at FiRa
      * consortium.
-     * WIP doc link: https://groups.firaconsortium.org/wg/Technical/document/folder/127.
-     * TODO(b/196004116): Link to the published specification.
+     *
+     * UCI 1.1 specification: https://groups.firaconsortium.org/wg/members/document/1949.
      *
      * This method may queue writes and return immediately, or it may block until data is written.
      * Implementation must guarantee that writes are executed in order.
diff --git a/uwb/aidl/android/hardware/uwb/IUwbClientCallback.aidl b/uwb/aidl/android/hardware/uwb/IUwbClientCallback.aidl
index 75853cd..f31aeba 100755
--- a/uwb/aidl/android/hardware/uwb/IUwbClientCallback.aidl
+++ b/uwb/aidl/android/hardware/uwb/IUwbClientCallback.aidl
@@ -28,8 +28,7 @@
      * can use to pass incoming data to the stack.  These include UCI
      * responses and notifications from the UWB subsystem.
      *
-     * WIP doc link: https://groups.firaconsortium.org/wg/Technical/document/folder/127.
-     * TODO(b/196004116): Link to the published specification.
+     * UCI 1.1 specification: https://groups.firaconsortium.org/wg/members/document/1949.
      *
      * @param data UCI packet sent.
      */
diff --git a/wifi/netlinkinterceptor/libnlinterceptor/include/libnlinterceptor/libnlinterceptor.h b/wifi/netlinkinterceptor/libnlinterceptor/include/libnlinterceptor/libnlinterceptor.h
index ac8653e..32e5a6e 100644
--- a/wifi/netlinkinterceptor/libnlinterceptor/include/libnlinterceptor/libnlinterceptor.h
+++ b/wifi/netlinkinterceptor/libnlinterceptor/include/libnlinterceptor/libnlinterceptor.h
@@ -117,14 +117,13 @@
     int clientSocketFd, const char* clientName,
     struct android_nlinterceptor_InterceptedSocket* interceptedSocket);
 
-void android_nlinterceptor_closeSocket(
-    const struct android_nlinterceptor_InterceptedSocket* sock);
+void android_nlinterceptor_closeSocket(struct android_nlinterceptor_InterceptedSocket sock);
 
-bool android_nlinterceptor_subscribe(
-    const struct android_nlinterceptor_InterceptedSocket* sock, uint32_t group);
+bool android_nlinterceptor_subscribe(struct android_nlinterceptor_InterceptedSocket sock,
+                                     uint32_t group);
 
-bool android_nlinterceptor_unsubscribe(
-    const struct android_nlinterceptor_InterceptedSocket* sock, uint32_t group);
+bool android_nlinterceptor_unsubscribe(struct android_nlinterceptor_InterceptedSocket sock,
+                                       uint32_t group);
 
 #ifdef __cplusplus
 }
diff --git a/wifi/netlinkinterceptor/libnlinterceptor/libnlinterceptor.cpp b/wifi/netlinkinterceptor/libnlinterceptor/libnlinterceptor.cpp
index 575f900..aae7a3a 100644
--- a/wifi/netlinkinterceptor/libnlinterceptor/libnlinterceptor.cpp
+++ b/wifi/netlinkinterceptor/libnlinterceptor/libnlinterceptor.cpp
@@ -150,25 +150,18 @@
     return true;
 }
 
-extern "C" void android_nlinterceptor_closeSocket(
-    const android_nlinterceptor_InterceptedSocket* sock) {
-    if (!sock) {
-        LOG(ERROR) << "Can't close socket identified by a null pointer!";
-        return;
-    }
-    closeSocket({sock->nlFamily, sock->portId});
+extern "C" void android_nlinterceptor_closeSocket(android_nlinterceptor_InterceptedSocket sock) {
+    closeSocket({sock.nlFamily, sock.portId});
 }
 
-extern "C" bool android_nlinterceptor_subscribe(
-    const android_nlinterceptor_InterceptedSocket* sock, uint32_t group) {
-    if (!sock) return false;
-    return subscribe({sock->nlFamily, sock->portId}, group);
+extern "C" bool android_nlinterceptor_subscribe(android_nlinterceptor_InterceptedSocket sock,
+                                                uint32_t group) {
+    return subscribe({sock.nlFamily, sock.portId}, group);
 }
 
-extern "C" bool android_nlinterceptor_unsubscribe(
-    const android_nlinterceptor_InterceptedSocket* sock, uint32_t group) {
-    if (!sock) return false;
-    return unsubscribe({sock->nlFamily, sock->portId}, group);
+extern "C" bool android_nlinterceptor_unsubscribe(android_nlinterceptor_InterceptedSocket sock,
+                                                  uint32_t group) {
+    return unsubscribe({sock.nlFamily, sock.portId}, group);
 }
 
 }  // namespace android::nlinterceptor