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

Commit 9873c06f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix HidlUtils::deviceAddressToHalImpl for HAL V4--6" am: eb4b2202 am:...

Merge "Fix HidlUtils::deviceAddressToHalImpl for HAL V4--6" am: eb4b2202 am: 7fa6d5b8 am: 6d7fb03f am: 64fbbe88

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ie0ccd7b6b4c222680454f78703d7fe8ec6c949b8
parents abb33c9b 64fbbe88
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ cc_library_shared {
    ],
}

cc_library_shared {
cc_library {
    name: "android.hardware.audio.common@6.0-util",
    defaults: ["android.hardware.audio.common-util_default"],
    srcs: [":android.hardware.audio.common-util@2-6"],
@@ -149,6 +149,32 @@ cc_library {
    ],
}

// Note: this isn't a VTS test, but rather a unit test
// to verify correctness of conversion utilities.
cc_test {
    name: "android.hardware.audio.common@6.0-util_tests",
    defaults: ["android.hardware.audio.common-util_default"],

    srcs: ["tests/hidlutils6_tests.cpp"],

    // Use static linking to allow running in presubmit on
    // targets that don't have HAL V6.
    static_libs: [
        "android.hardware.audio.common@6.0",
        "android.hardware.audio.common@6.0-util",
    ],

    cflags: [
        "-Werror",
        "-Wall",
        "-DMAJOR_VERSION=6",
        "-DMINOR_VERSION=0",
        "-include common/all-versions/VersionMacro.h",
    ],

    test_suites: ["device-tests"],
}

// Note: this isn't a VTS test, but rather a unit test
// to verify correctness of conversion utilities.
cc_test {
+4 −0
Original line number Diff line number Diff line
@@ -210,6 +210,9 @@ status_t HidlUtils::deviceAddressToHalImpl(const DA& device, audio_devices_t* ha
               *halDeviceType == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
        snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "%s",
                 device.rSubmixAddress.c_str());
    } else {
        // Fall back to bus address for other device types, e.g. for microphones.
        snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "%s", device.busAddress.c_str());
    }
    return NO_ERROR;
}
@@ -249,6 +252,7 @@ status_t HidlUtils::deviceAddressFromHalImpl(audio_devices_t halDeviceType,
        device->rSubmixAddress = halDeviceAddress;
        return OK;
    }
    // Fall back to bus address for other device types, e.g. for microphones.
    device->busAddress = halDeviceAddress;
    return NO_ERROR;
}
+3 −0
Original line number Diff line number Diff line
{
  "presubmit": [
    {
      "name": "android.hardware.audio.common@6.0-util_tests"
    },
    {
      "name": "android.hardware.audio.common@7.0-util_tests"
    }
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#define LOG_TAG "HidlUtils_Test"
#include <log/log.h>

#include <HidlUtils.h>
#include <system/audio.h>

using namespace android;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;

// Not generated automatically because DeviceAddress contains
// an union.
//
// operator== must be defined in the same namespace as the data type.
namespace android::hardware::audio::common::CPP_VERSION {

inline bool operator==(const DeviceAddress& lhs, const DeviceAddress& rhs) {
    if (lhs.device != rhs.device) return false;
    audio_devices_t halDeviceType = static_cast<audio_devices_t>(lhs.device);
    if (audio_is_a2dp_out_device(halDeviceType) || audio_is_a2dp_in_device(halDeviceType)) {
        return lhs.address.mac == rhs.address.mac;
    } else if (halDeviceType == AUDIO_DEVICE_OUT_IP || halDeviceType == AUDIO_DEVICE_IN_IP) {
        return lhs.address.ipv4 == rhs.address.ipv4;
    } else if (audio_is_usb_out_device(halDeviceType) || audio_is_usb_in_device(halDeviceType)) {
        return lhs.address.alsa == rhs.address.alsa;
    } else if (halDeviceType == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
               halDeviceType == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
        return lhs.rSubmixAddress == rhs.rSubmixAddress;
    }
    // busAddress field can be used for types other than bus, e.g. for microphones.
    return lhs.busAddress == rhs.busAddress;
}

}  // namespace android::hardware::audio::common::CPP_VERSION

static void ConvertDeviceAddress(const DeviceAddress& device) {
    audio_devices_t halDeviceType;
    char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN] = {};
    EXPECT_EQ(NO_ERROR, HidlUtils::deviceAddressToHal(device, &halDeviceType, halDeviceAddress));
    DeviceAddress deviceBack;
    EXPECT_EQ(NO_ERROR,
              HidlUtils::deviceAddressFromHal(halDeviceType, halDeviceAddress, &deviceBack));
    EXPECT_EQ(device, deviceBack);
}

TEST(HidlUtils6, ConvertUniqueDeviceAddress) {
    DeviceAddress speaker;
    speaker.device = AudioDevice::OUT_SPEAKER;
    ConvertDeviceAddress(speaker);

    DeviceAddress micWithAddress;
    micWithAddress.device = AudioDevice::IN_BUILTIN_MIC;
    micWithAddress.busAddress = "bottom";
    ConvertDeviceAddress(micWithAddress);
}

TEST(HidlUtils6, ConvertA2dpDeviceAddress) {
    DeviceAddress a2dpSpeaker;
    a2dpSpeaker.device = AudioDevice::OUT_BLUETOOTH_A2DP_SPEAKER;
    a2dpSpeaker.address.mac = std::array<uint8_t, 6>{1, 2, 3, 4, 5, 6};
    ConvertDeviceAddress(a2dpSpeaker);
}

TEST(HidlUtils6, ConvertIpv4DeviceAddress) {
    DeviceAddress ipv4;
    ipv4.device = AudioDevice::OUT_IP;
    ipv4.address.ipv4 = std::array<uint8_t, 4>{1, 2, 3, 4};
    ConvertDeviceAddress(ipv4);
}

TEST(HidlUtils6, ConvertUsbDeviceAddress) {
    DeviceAddress usbHeadset;
    usbHeadset.device = AudioDevice::OUT_USB_HEADSET;
    usbHeadset.address.alsa = {1, 2};
    ConvertDeviceAddress(usbHeadset);
}

TEST(HidlUtils6, ConvertBusDeviceAddress) {
    DeviceAddress bus;
    bus.device = AudioDevice::OUT_BUS;
    bus.busAddress = "bus_device";
    ConvertDeviceAddress(bus);
}

TEST(HidlUtils6, ConvertRSubmixDeviceAddress) {
    DeviceAddress rSubmix;
    rSubmix.device = AudioDevice::OUT_REMOTE_SUBMIX;
    rSubmix.rSubmixAddress = AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS;
    ConvertDeviceAddress(rSubmix);
}
+5 −0
Original line number Diff line number Diff line
@@ -476,6 +476,11 @@ TEST(HidlUtils, ConvertUniqueDeviceAddress) {
    DeviceAddress speaker;
    speaker.deviceType = toString(xsd::AudioDevice::AUDIO_DEVICE_OUT_SPEAKER);
    ConvertDeviceAddress(speaker);

    DeviceAddress micWithAddress;
    micWithAddress.deviceType = toString(xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC);
    micWithAddress.address.id("bottom");
    ConvertDeviceAddress(micWithAddress);
}

TEST(HidlUtils, ConvertA2dpDeviceAddress) {