blob: 5294728d8219d9b252f05f19fa27e249c99dc618 [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 Naganovf558e022016-11-14 17:45:17 -080040 // Opens a device with the specified name. To close the device, it is
41 // necessary to release references to the returned object.
Mikhail Naganov88de22f2020-03-06 10:55:34 -080042 status_t openDevice(const char *name, sp<DeviceHalInterface> *device) override;
Eric Laurent42896a02019-09-27 15:40:33 -070043
Mikhail Naganov88de22f2020-03-06 10:55:34 -080044 status_t getHalPids(std::vector<pid_t> *pids) override;
45
46 status_t setCallbackOnce(sp<DevicesFactoryHalCallback> callback) override;
Eric Laurent42896a02019-09-27 15:40:33 -070047
Shunkai Yao489c5a92022-12-02 05:35:41 +000048 android::detail::AudioHalVersionInfo getHalVersion() const override;
Jiabin Huangebe64102021-09-07 20:01:07 +000049
Mikhail Naganovf558e022016-11-14 17:45:17 -080050 private:
Mikhail Naganov88de22f2020-03-06 10:55:34 -080051 friend class ServiceNotificationListener;
52 void addDeviceFactory(sp<IDevicesFactory> factory, bool needToNotify);
53 std::vector<sp<IDevicesFactory>> copyDeviceFactories();
54
55 std::mutex mLock;
56 std::vector<sp<IDevicesFactory>> mDeviceFactories; // GUARDED_BY(mLock)
57 wp<DevicesFactoryHalCallback> mCallback; // GUARDED_BY(mLock)
58 bool mHaveUndeliveredNotifications = false; // GUARDED_BY(mLock)
Mikhail Naganovf558e022016-11-14 17:45:17 -080059
Kevin Rocarddf9b4202018-05-10 19:56:08 -070060 virtual ~DevicesFactoryHalHidl() = default;
Mikhail Naganovf558e022016-11-14 17:45:17 -080061};
62
Mikhail Naganovf558e022016-11-14 17:45:17 -080063} // namespace android
64
65#endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H