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

Commit c0199978 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8171414 from 477f865b to tm-d1-release

Change-Id: I99f154afb3c7ed4708d5998fea842b1d9c11768c
parents 3709592e 477f865b
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -41,7 +41,12 @@ aidl_interface {
            enabled: true,
        },
        java: {
            platform_apis: true,
            sdk_version: "module_current",
            min_sdk_version: "31",
            apex_available: [
                "//apex_available:platform",
                "com.android.car.framework",
            ],
        },
        ndk: {
            vndk: {
+1 −2
Original line number Diff line number Diff line
@@ -28,8 +28,7 @@ TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
    if (getDeviceName() != DeviceManager::kPrimaryDevice) {
        GTEST_SKIP() << "No primary device on this factory";  // returns
    }
    EXPECT_TRUE(
            DeviceManager::getInstance().reset(getFactoryName(), DeviceManager::kPrimaryDevice));
    EXPECT_TRUE(DeviceManager::getInstance().resetPrimary(getFactoryName()));

    // Must use IDevicesFactory directly because DeviceManager always uses
    // the latest interfaces version and corresponding methods for opening
+117 −64
Original line number Diff line number Diff line
@@ -96,40 +96,83 @@ class DevicesFactoryManager
    }
};

using FactoryAndDevice = std::tuple<std::string, std::string>;
class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, IDevice> {
namespace impl {

class PrimaryDeviceManager
    : public InterfaceManager<PrimaryDeviceManager, std::string, IPrimaryDevice> {
  public:
    static DeviceManager& getInstance() {
        static DeviceManager instance;
        return instance;
    static sp<IPrimaryDevice> createInterfaceInstance(const std::string& factoryName) {
        sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
        return openPrimaryDevice(factory);
    }

    bool reset(const std::string& factoryName) __attribute__((warn_unused_result)) {
#if MAJOR_VERSION <= 5
        return InterfaceManager::reset(factoryName, true);
#elif MAJOR_VERSION >= 6
        {
            sp<IPrimaryDevice> device = getExisting(factoryName);
            if (device != nullptr) {
                auto ret = device->close();
                ALOGE_IF(!ret.isOk(), "PrimaryDevice %s close failed: %s", factoryName.c_str(),
                         ret.description().c_str());
            }
        }
        return InterfaceManager::reset(factoryName, false);
#endif
    }

  private:
    static sp<IPrimaryDevice> openPrimaryDevice(const sp<IDevicesFactory>& factory) {
        if (factory == nullptr) return {};
        Result result;
        sp<IPrimaryDevice> primaryDevice;
#if !(MAJOR_VERSION == 7 && MINOR_VERSION == 1)
        sp<IDevice> device;
#if MAJOR_VERSION == 2
        auto ret = factory->openDevice(IDevicesFactory::Device::PRIMARY, returnIn(result, device));
        if (ret.isOk() && result == Result::OK && device != nullptr) {
            primaryDevice = IPrimaryDevice::castFrom(device);
        }
#elif MAJOR_VERSION >= 4
        auto ret = factory->openPrimaryDevice(returnIn(result, device));
        if (ret.isOk() && result == Result::OK && device != nullptr) {
            primaryDevice = IPrimaryDevice::castFrom(device);
        }
#endif
        if (!ret.isOk() || result != Result::OK || primaryDevice == nullptr) {
            ALOGW("Primary device can not be opened, transaction: %s, result %d, device %p",
                  ret.description().c_str(), result, device.get());
            return nullptr;
        }
#else  // V7.1
        auto ret = factory->openPrimaryDevice_7_1(returnIn(result, primaryDevice));
        if (!ret.isOk() || result != Result::OK) {
            ALOGW("Primary device can not be opened, transaction: %s, result %d",
                  ret.description().c_str(), result);
            return nullptr;
        }
#endif
        return primaryDevice;
    }
};

using FactoryAndDevice = std::tuple<std::string, std::string>;
class RegularDeviceManager
    : public InterfaceManager<RegularDeviceManager, FactoryAndDevice, IDevice> {
  public:
    static sp<IDevice> createInterfaceInstance(const FactoryAndDevice& factoryAndDevice) {
        auto [factoryName, name] = factoryAndDevice;
        sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
        return openDevice(factory, name);
    }
    using InterfaceManager::reset;

    static constexpr const char* kPrimaryDevice = "primary";

    sp<IDevice> get(const std::string& factoryName, const std::string& name) {
        if (name == kPrimaryDevice) {
            (void)getPrimary(factoryName);  // for initializing primaryDevice if needed.
        }
        return InterfaceManager::get(std::make_tuple(factoryName, name));
    }
    sp<IPrimaryDevice> getPrimary(const std::string& factoryName) {
        if (primaryDevice == nullptr) {
            sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
            primaryDevice = openPrimaryDevice(factory);
        }
        return primaryDevice;
    }

    bool reset(const std::string& factoryName, const std::string& name)
            __attribute__((warn_unused_result)) {
        if (name == kPrimaryDevice) {
            primaryDevice.clear();
        }
#if MAJOR_VERSION <= 5
        return InterfaceManager::reset(std::make_tuple(factoryName, name), true);
#elif MAJOR_VERSION >= 6
@@ -144,9 +187,6 @@ class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, I
        return InterfaceManager::reset(std::make_tuple(factoryName, name), false);
#endif
    }
    bool resetPrimary(const std::string& factoryName) __attribute__((warn_unused_result)) {
        return reset(factoryName, kPrimaryDevice);
    }

  private:
    static sp<IDevice> openDevice(const sp<IDevicesFactory>& factory, const std::string& name) {
@@ -155,9 +195,7 @@ class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, I
        sp<IDevice> device;
#if MAJOR_VERSION == 2
        IDevicesFactory::Device dev = IDevicesFactory::IDevicesFactory::Device(-1);
        if (name == AUDIO_HARDWARE_MODULE_ID_PRIMARY) {
            dev = IDevicesFactory::Device::PRIMARY;
        } else if (name == AUDIO_HARDWARE_MODULE_ID_A2DP) {
        if (name == AUDIO_HARDWARE_MODULE_ID_A2DP) {
            dev = IDevicesFactory::Device::A2DP;
        } else if (name == AUDIO_HARDWARE_MODULE_ID_USB) {
            dev = IDevicesFactory::Device::USB;
@@ -179,47 +217,62 @@ class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, I
        }
        return device;
    }
};

    static sp<IPrimaryDevice> openPrimaryDevice(const sp<IDevicesFactory>& factory) {
        if (factory == nullptr) return {};
        Result result;
        sp<IDevice> device;
        sp<IPrimaryDevice> primaryDevice;
#if MAJOR_VERSION == 2
        auto ret = factory->openDevice(IDevicesFactory::Device::PRIMARY, returnIn(result, device));
        if (ret.isOk() && result == Result::OK && device != nullptr) {
            primaryDevice = IPrimaryDevice::castFrom(device);
}  // namespace impl

class DeviceManager {
  public:
    static DeviceManager& getInstance() {
        static DeviceManager instance;
        return instance;
    }
#elif MAJOR_VERSION >= 4 && (MAJOR_VERSION < 7 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0))
        auto ret = factory->openPrimaryDevice(returnIn(result, device));
        if (ret.isOk() && result == Result::OK && device != nullptr) {
            primaryDevice = IPrimaryDevice::castFrom(device);

    static constexpr const char* kPrimaryDevice = "primary";

    sp<IDevice> get(const std::string& factoryName, const std::string& name) {
        if (name == kPrimaryDevice) {
            auto primary = getPrimary(factoryName);
            return primary ? deviceFromPrimary(primary) : nullptr;
        }
#elif MAJOR_VERSION == 7 && MINOR_VERSION == 1
        auto ret = factory->openPrimaryDevice_7_1(returnIn(result, primaryDevice));
        if (ret.isOk() && result == Result::OK && primaryDevice != nullptr) {
            auto getDeviceRet = primaryDevice->getDevice();
            if (getDeviceRet.isOk()) {
                device = getDeviceRet;
            } else {
                primaryDevice.clear();
                ALOGW("Primary device can not downcast, transaction: %s, primary %p",
                      getDeviceRet.description().c_str(), primaryDevice.get());
                return {};
        return mDevices.get(factoryName, name);
    }

    sp<IPrimaryDevice> getPrimary(const std::string& factoryName) {
        return mPrimary.get(factoryName);
    }
#endif
        if (!ret.isOk() || result != Result::OK || device == nullptr) {
            ALOGW("Primary device can not be opened, transaction: %s, result %d, device %p",
                  ret.description().c_str(), result, device.get());
            return {};

    bool reset(const std::string& factoryName, const std::string& name)
            __attribute__((warn_unused_result)) {
        return name == kPrimaryDevice ? resetPrimary(factoryName)
                                      : mDevices.reset(factoryName, name);
    }
        return primaryDevice;

    bool resetPrimary(const std::string& factoryName) __attribute__((warn_unused_result)) {
        return mPrimary.reset(factoryName);
    }

    static void waitForInstanceDestruction() {
        // Does not matter which device manager to use.
        impl::RegularDeviceManager::waitForInstanceDestruction();
    }

  private:
    // There can only be one primary device across all HAL modules.
    // A reference to a complete interface is used because in V7.1 IDevice can not
    // be upcasted to IPrimaryDevice.
    sp<IPrimaryDevice> primaryDevice;
    sp<IDevice> deviceFromPrimary(const sp<IPrimaryDevice>& primary) {
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
        auto ret = primary->getDevice();
        if (ret.isOk()) {
            return ret;
        } else {
            ALOGW("Error retrieving IDevice from primary: transaction: %s, primary %p",
                  ret.description().c_str(), primary.get());
            return nullptr;
        }
#else
        return primary;
#endif
    }

    impl::PrimaryDeviceManager mPrimary;
    impl::RegularDeviceManager mDevices;
};
+7 −1
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ aidl_interface {
    name: "android.hardware.automotive.audiocontrol",
    vendor_available: true,
    srcs: ["android/hardware/automotive/audiocontrol/*.aidl"],
    imports: [
        "android.hardware.audio.common",
        "android.media.audio.common.types",
    ],
    stability: "vintf",
    backend: {
        java: {
@@ -24,5 +28,7 @@ aidl_interface {
            ],
        },
    },
    versions: ["1"],
    versions: [
        "1",
    ],
}
+22 −6
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
///////////////////////////////////////////////////////////////////////////////

// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
// edit this file. It looks like you are doing that because you have modified
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
// from an interface or a field from a parcelable and it broke the build. That
// breakage is intended.
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
//     the interface (from the latest frozen version), the build system will
//     prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible changes to the AIDL files built
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
Loading