Files
hardware_interfaces/audio/aidl/default/include/effectFactory-impl/EffectFactory.h
Mikhail Naganov df5feba141 audio: Retain IBinder for instances with MinSchedulerPolicy
The binder passed to AIBinder_setMinSchedulerPolicy must also be
returned to the client, otherwise setting the policy for it does
not make any sense. However, server side interface instance
classes only hold a weak binder reference. It's the caller of the
'asBinder' method who must retain a strong reference. This
reference must be retained past exiting from the method which
returns the instance to the client.

To solve this issue, add storing of binders along with server
object references. These binders get released after the client
calls a 'close'/'destroy'-type method to release instance
resources.

Bug: 205884982
Test: run `atest VtsHalAudioCoreTargetTest` and effect VTS,
      and grep logcat for
     'destroyed after setMinSchedulerPolicy before being parceled'
Change-Id: I8b905b85cb8263c85edae8839a126ffe4e4d1e69
2022-12-16 15:27:10 +00:00

116 lines
4.5 KiB
C++

/*
* Copyright (C) 2022 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.
*/
#pragma once
#include <any>
#include <map>
#include <optional>
#include <set>
#include <tuple>
#include <vector>
#include <aidl/android/hardware/audio/effect/BnFactory.h>
#include "EffectConfig.h"
namespace aidl::android::hardware::audio::effect {
class Factory : public BnFactory {
public:
explicit Factory(const std::string& file);
/**
* @brief Get identity of all effects supported by the device, with the optional filter by type
* and/or by instance UUID.
*
* @param in_type Type UUID.
* @param in_instance Instance UUID.
* @param in_proxy Proxy UUID.
* @param out_descriptor List of Descriptors.
* @return ndk::ScopedAStatus
*/
ndk::ScopedAStatus queryEffects(
const std::optional<::aidl::android::media::audio::common::AudioUuid>& in_type,
const std::optional<::aidl::android::media::audio::common::AudioUuid>& in_instance,
const std::optional<::aidl::android::media::audio::common::AudioUuid>& in_proxy,
std::vector<Descriptor>* out_descriptor) override;
/**
* @brief Query list of defined processing, with the optional filter by AudioStreamType
*
* @param in_type Type of processing, could be AudioStreamType or AudioSource. Optional.
* @param _aidl_return List of processing filtered by in_type.
* @return ndk::ScopedAStatus
*/
ndk::ScopedAStatus queryProcessing(const std::optional<Processing::Type>& in_type,
std::vector<Processing>* _aidl_return) override;
/**
* @brief Create an effect instance for a certain implementation (identified by UUID).
*
* @param in_impl_uuid Effect implementation UUID.
* @param _aidl_return A pointer to created effect instance.
* @return ndk::ScopedAStatus
*/
ndk::ScopedAStatus createEffect(
const ::aidl::android::media::audio::common::AudioUuid& in_impl_uuid,
std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>* _aidl_return)
override;
/**
* @brief Destroy an effect instance.
*
* @param in_handle Effect instance handle.
* @return ndk::ScopedAStatus
*/
ndk::ScopedAStatus destroyEffect(
const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_handle)
override;
private:
const EffectConfig mConfig;
~Factory();
// Set of effect descriptors supported by the devices.
std::set<Descriptor> mDescSet;
std::set<Descriptor::Identity> mIdentitySet;
static constexpr int kMapEntryHandleIndex = 0;
static constexpr int kMapEntryInterfaceIndex = 1;
static constexpr int kMapEntryLibNameIndex = 2;
typedef std::tuple<std::unique_ptr<void, std::function<void(void*)>> /* dlHandle */,
std::unique_ptr<struct effect_dl_interface_s> /* interfaces */,
std::string /* library name */>
DlEntry;
std::map<aidl::android::media::audio::common::AudioUuid /* implUUID */, DlEntry> mEffectLibMap;
typedef std::pair<aidl::android::media::audio::common::AudioUuid, ndk::SpAIBinder> EffectEntry;
std::map<std::weak_ptr<IEffect>, EffectEntry, std::owner_less<>> mEffectMap;
ndk::ScopedAStatus destroyEffectImpl(const std::shared_ptr<IEffect>& in_handle);
void cleanupEffectMap();
void openEffectLibrary(const ::aidl::android::media::audio::common::AudioUuid& impl,
const std::string& libName);
void createIdentityWithConfig(
const EffectConfig::LibraryUuid& configLib,
const ::aidl::android::media::audio::common::AudioUuid& typeUuid,
const std::optional<::aidl::android::media::audio::common::AudioUuid> proxyUuid);
void loadEffectLibs();
/* Get effect_dl_interface_s from library handle */
void getDlSyms(DlEntry& entry);
};
} // namespace aidl::android::hardware::audio::effect