blob: d684c271a39daf7a9b1cbc7177212ae6003efb41 [file] [log] [blame]
Kevin Rocard4bcd67f2018-02-28 14:33:38 -08001/*
2 * Copyright (C) 2017 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#define LOG_TAG "DevicesFactoryHalHybrid"
18//#define LOG_NDEBUG 0
19
Kevin Rocard00538f12019-06-25 14:26:29 -070020#include "DevicesFactoryHalHidl.h"
Kevin Rocarddf9b4202018-05-10 19:56:08 -070021#include "DevicesFactoryHalHybrid.h"
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080022#include "DevicesFactoryHalLocal.h"
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080023
24namespace android {
25
Kevin Rocarda8f13932019-06-25 16:08:29 -070026DevicesFactoryHalHybrid::DevicesFactoryHalHybrid(sp<IDevicesFactory> hidlFactory)
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080027 : mLocalFactory(new DevicesFactoryHalLocal()),
Kevin Rocarda8f13932019-06-25 16:08:29 -070028 mHidlFactory(new DevicesFactoryHalHidl(hidlFactory)) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080029}
30
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080031status_t DevicesFactoryHalHybrid::openDevice(const char *name, sp<DeviceHalInterface> *device) {
Eric Laurent58a73fc2018-02-21 18:46:13 -080032 if (mHidlFactory != 0 && strcmp(AUDIO_HARDWARE_MODULE_ID_A2DP, name) != 0 &&
33 strcmp(AUDIO_HARDWARE_MODULE_ID_HEARING_AID, name) != 0) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080034 return mHidlFactory->openDevice(name, device);
35 }
36 return mLocalFactory->openDevice(name, device);
37}
Eric Laurentb680e952019-09-27 15:40:33 -070038
39status_t DevicesFactoryHalHybrid::getHalPids(std::vector<pid_t> *pids) {
40 if (mHidlFactory != 0) {
41 return mHidlFactory->getHalPids(pids);
42 }
43 return INVALID_OPERATION;
44}
45
Mikhail Naganovfb9c73b2020-03-06 10:55:34 -080046status_t DevicesFactoryHalHybrid::setCallbackOnce(sp<DevicesFactoryHalCallback> callback) {
47 if (mHidlFactory) {
48 return mHidlFactory->setCallbackOnce(callback);
49 }
50 return INVALID_OPERATION;
51}
52
Mikhail Naganovd7b2ff02020-02-07 13:51:04 -080053extern "C" __attribute__((visibility("default"))) void* createIDevicesFactory() {
Kevin Rocard00538f12019-06-25 14:26:29 -070054 auto service = hardware::audio::CPP_VERSION::IDevicesFactory::getService();
Mikhail Naganovea1f19d2022-01-27 22:17:21 +000055 return service ? new DevicesFactoryHalHybrid(service) : nullptr;
Kevin Rocard00538f12019-06-25 14:26:29 -070056}
57
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080058} // namespace android