1 /*
2 * Copyright (C) 2020 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 #include <system/audio.h>
18 #include <log/log.h>
19 #include "device_factory.h"
20 #include "primary_device.h"
21 #include "debug.h"
22
23 namespace android {
24 namespace hardware {
25 namespace audio {
26 namespace V6_0 {
27 namespace implementation {
28
29 using ::android::hardware::Void;
30
31 #ifdef __LP64__
32 #define LIB_PATH_PREFIX "vendor/lib64/hw/"
33 #else
34 #define LIB_PATH_PREFIX "vendor/lib/hw/"
35 #endif
36
DevicesFactory()37 DevicesFactory::DevicesFactory() {
38 mLegacyLib.reset(dlopen(
39 LIB_PATH_PREFIX "android.hardware.audio.legacy@6.0-impl.ranchu.so", RTLD_NOW));
40 LOG_ALWAYS_FATAL_IF(!mLegacyLib);
41
42 typedef IDevicesFactory *(*Func)(const char *);
43 const auto func = reinterpret_cast<Func>(
44 dlsym(mLegacyLib.get(), "HIDL_FETCH_IDevicesFactory"));
45 LOG_ALWAYS_FATAL_IF(!func);
46
47 mLegacyFactory.reset((*func)("default"));
48 LOG_ALWAYS_FATAL_IF(!mLegacyFactory);
49 }
50
openDevice(const hidl_string & device,openDevice_cb _hidl_cb)51 Return<void> DevicesFactory::openDevice(const hidl_string& device,
52 openDevice_cb _hidl_cb) {
53 if (device == AUDIO_HARDWARE_MODULE_ID_PRIMARY)
54 _hidl_cb(Result::OK, new PrimaryDevice);
55 else {
56 mLegacyFactory->openDevice(device, _hidl_cb);
57 }
58
59 return Void();
60 }
61
openPrimaryDevice(openPrimaryDevice_cb _hidl_cb)62 Return<void> DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) {
63 _hidl_cb(Result::OK, new PrimaryDevice);
64 return Void();
65 }
66
67 } // namespace implementation
68 } // namespace V6_0
69 } // namespace audio
70 } // namespace hardware
71 } // namespace android
72