1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "DevicesFactoryImpl.h"
16
17 #include <android-base/logging.h>
18
19 using android::hardware::Void;
20 using namespace android::hardware::audio::CPP_VERSION;
21
22 namespace audio_proxy {
23 namespace service {
24
DevicesFactoryImpl(BusStreamProvider & busStreamProvider,const ServiceConfig & config)25 DevicesFactoryImpl::DevicesFactoryImpl(BusStreamProvider& busStreamProvider,
26 const ServiceConfig& config)
27 : mBusStreamProvider(busStreamProvider), mConfig(config) {}
28
29 // Methods from android::hardware::audio::CPP_VERSION::IDevicesFactory follow.
openDevice(const hidl_string & device,openDevice_cb _hidl_cb)30 Return<void> DevicesFactoryImpl::openDevice(const hidl_string& device,
31 openDevice_cb _hidl_cb) {
32 if (device == mConfig.name) {
33 LOG(INFO) << "Audio Device was opened: " << device;
34 _hidl_cb(Result::OK, new DeviceImpl(mBusStreamProvider, mConfig));
35 } else {
36 _hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
37 }
38
39 return Void();
40 }
41
openPrimaryDevice(openPrimaryDevice_cb _hidl_cb)42 Return<void> DevicesFactoryImpl::openPrimaryDevice(
43 openPrimaryDevice_cb _hidl_cb) {
44 // The AudioProxy HAL does not support a primary device.
45 _hidl_cb(Result::NOT_SUPPORTED, nullptr);
46 return Void();
47 }
48
49 #if MAJOR_VERSION == 7 && MINOR_VERSION == 1
openDevice_7_1(const hidl_string & device,openDevice_7_1_cb _hidl_cb)50 Return<void> DevicesFactoryImpl::openDevice_7_1(const hidl_string& device,
51 openDevice_7_1_cb _hidl_cb) {
52 if (device == mConfig.name) {
53 LOG(INFO) << "Audio Device was opened: " << device;
54 _hidl_cb(Result::OK, new DeviceImpl(mBusStreamProvider, mConfig));
55 } else {
56 _hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
57 }
58
59 return Void();
60 }
61
openPrimaryDevice_7_1(openPrimaryDevice_7_1_cb _hidl_cb)62 Return<void> DevicesFactoryImpl::openPrimaryDevice_7_1(
63 openPrimaryDevice_7_1_cb _hidl_cb) {
64 // The AudioProxy HAL does not support a primary device.
65 _hidl_cb(Result::NOT_SUPPORTED, nullptr);
66 return Void();
67 }
68 #endif
69
70 } // namespace service
71 } // namespace audio_proxy
72