blob: 3285af7733e0e72319c8c9f2e37e2083070e0c13 [file] [log] [blame]
Mikhail Naganovf558e022016-11-14 17:45:17 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H
18#define ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H
19
Mikhail Naganov88de22f2020-03-06 10:55:34 -080020#include <mutex>
21#include <vector>
22
Kevin Rocard95213bf2018-11-08 17:16:57 -080023#include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h)
Mikhail Naganovf558e022016-11-14 17:45:17 -080024#include <media/audiohal/DevicesFactoryHalInterface.h>
25#include <utils/Errors.h>
26#include <utils/RefBase.h>
27
28#include "DeviceHalHidl.h"
29
Kevin Rocard070e7512018-05-22 09:29:13 -070030using ::android::hardware::audio::CPP_VERSION::IDevicesFactory;
Mikhail Naganovf558e022016-11-14 17:45:17 -080031
32namespace android {
33
34class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
35{
36 public:
Mikhail Naganov88de22f2020-03-06 10:55:34 -080037 explicit DevicesFactoryHalHidl(sp<IDevicesFactory> devicesFactory);
38 void onFirstRef() override;
Kevin Rocardb9448c72019-06-25 16:08:29 -070039
Mikhail Naganovf83b9742023-04-24 13:06:04 -070040 status_t getDeviceNames(std::vector<std::string> *names) override;
41
Mikhail Naganovf558e022016-11-14 17:45:17 -080042 // Opens a device with the specified name. To close the device, it is
43 // necessary to release references to the returned object.
Mikhail Naganov88de22f2020-03-06 10:55:34 -080044 status_t openDevice(const char *name, sp<DeviceHalInterface> *device) override;
Eric Laurent42896a02019-09-27 15:40:33 -070045
Mikhail Naganov88de22f2020-03-06 10:55:34 -080046 status_t getHalPids(std::vector<pid_t> *pids) override;
47
48 status_t setCallbackOnce(sp<DevicesFactoryHalCallback> callback) override;
Eric Laurent42896a02019-09-27 15:40:33 -070049
Shunkai Yaodca65ce2022-12-02 05:35:41 +000050 android::detail::AudioHalVersionInfo getHalVersion() const override;
Jiabin Huangebe64102021-09-07 20:01:07 +000051
Mikhail Naganovf83b9742023-04-24 13:06:04 -070052 status_t getSurroundSoundConfig(media::SurroundSoundConfig *config) override;
53
54 status_t getEngineConfig(media::audio::common::AudioHalEngineConfig *config) override;
55
Mikhail Naganovf558e022016-11-14 17:45:17 -080056 private:
Mikhail Naganov88de22f2020-03-06 10:55:34 -080057 friend class ServiceNotificationListener;
58 void addDeviceFactory(sp<IDevicesFactory> factory, bool needToNotify);
59 std::vector<sp<IDevicesFactory>> copyDeviceFactories();
60
61 std::mutex mLock;
62 std::vector<sp<IDevicesFactory>> mDeviceFactories; // GUARDED_BY(mLock)
63 wp<DevicesFactoryHalCallback> mCallback; // GUARDED_BY(mLock)
64 bool mHaveUndeliveredNotifications = false; // GUARDED_BY(mLock)
Mikhail Naganovf558e022016-11-14 17:45:17 -080065
Kevin Rocarddf9b4202018-05-10 19:56:08 -070066 virtual ~DevicesFactoryHalHidl() = default;
Mikhail Naganovf558e022016-11-14 17:45:17 -080067};
68
Mikhail Naganovf558e022016-11-14 17:45:17 -080069} // namespace android
70
71#endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H