Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2022 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 "DevicesFactoryHalAidl" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <android/binder_manager.h> |
| 21 | #include <utils/Log.h> |
| 22 | |
| 23 | #include "DevicesFactoryHalAidl.h" |
| 24 | |
| 25 | using ::android::detail::AudioHalVersionInfo; |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | DevicesFactoryHalAidl::DevicesFactoryHalAidl(std::shared_ptr<IConfig> iconfig) { |
| 30 | ALOG_ASSERT(iconfig != nullptr, "Provided default IConfig service is NULL"); |
| 31 | mIConfig = std::move(iconfig); |
| 32 | } |
| 33 | |
| 34 | void DevicesFactoryHalAidl::onFirstRef() { |
| 35 | ALOGE("%s not implemented yet", __func__); |
| 36 | } |
| 37 | |
| 38 | // Opens a device with the specified name. To close the device, it is |
| 39 | // necessary to release references to the returned object. |
| 40 | status_t DevicesFactoryHalAidl::openDevice(const char *name, sp<DeviceHalInterface> *device) { |
| 41 | if (name == nullptr || device == nullptr) { |
| 42 | return BAD_VALUE; |
| 43 | } |
| 44 | ALOGE("%s not implemented yet", __func__); |
| 45 | return INVALID_OPERATION; |
| 46 | } |
| 47 | |
| 48 | status_t DevicesFactoryHalAidl::getHalPids(std::vector<pid_t> *pids) { |
| 49 | if (pids == nullptr) { |
| 50 | return BAD_VALUE; |
| 51 | } |
| 52 | ALOGE("%s not implemented yet", __func__); |
| 53 | return INVALID_OPERATION; |
| 54 | } |
| 55 | |
| 56 | status_t DevicesFactoryHalAidl::setCallbackOnce(sp<DevicesFactoryHalCallback> callback) { |
| 57 | if (callback == nullptr) { |
| 58 | return BAD_VALUE; |
| 59 | } |
| 60 | ALOGE("%s not implemented yet", __func__); |
| 61 | return INVALID_OPERATION; |
| 62 | } |
| 63 | |
| 64 | AudioHalVersionInfo DevicesFactoryHalAidl::getHalVersion() const { |
| 65 | int32_t versionNumber = 0; |
| 66 | if (mIConfig) { |
| 67 | if (!mIConfig->getInterfaceVersion(&versionNumber).isOk()) { |
| 68 | ALOGE("%s getInterfaceVersion failed", __func__); |
| 69 | } else { |
| 70 | ALOGI("%s getInterfaceVersion %d", __func__, versionNumber); |
| 71 | } |
| 72 | } |
| 73 | // AIDL does not have minor version, fill 0 for all versions |
| 74 | return AudioHalVersionInfo(AudioHalVersionInfo::Type::AIDL, versionNumber); |
| 75 | } |
| 76 | |
| 77 | // Main entry-point to the shared library. |
| 78 | extern "C" __attribute__((visibility("default"))) void* createIDevicesFactoryImpl() { |
| 79 | auto service = IConfig::fromBinder( |
| 80 | ndk::SpAIBinder(AServiceManager_waitForService(IConfig::descriptor))); |
| 81 | return service ? new DevicesFactoryHalAidl(service) : nullptr; |
| 82 | } |
| 83 | |
| 84 | } // namespace android |