blob: 4d34cf120e5f818b597a486a5f78b397620bb2f4 [file] [log] [blame]
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -07001/*
2 * Copyright (C) 2021 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 "hidl-utils.h"
18
19#include <android-base/logging.h>
20#include <android/binder_manager.h>
21#include <android/binder_process.h>
22#include <libradiocompat/RadioConfig.h>
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070023#include <libradiocompat/RadioIndication.h>
24#include <libradiocompat/RadioMessaging.h>
25#include <libradiocompat/RadioResponse.h>
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070026
27namespace android::hardware::radio::service {
28
29using namespace std::string_literals;
30
31static std::vector<std::shared_ptr<ndk::ICInterface>> gPublishedHals;
32
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070033template <typename T>
34static void publishRadioHal(sp<V1_5::IRadio> hidlHal, sp<compat::RadioResponse> responseCb,
35 sp<compat::RadioIndication> indicationCb, const std::string& slot) {
36 const auto instance = T::descriptor + "/"s + slot;
37 if (!AServiceManager_isDeclared(instance.c_str())) {
38 LOG(INFO) << instance << " is not declared in VINTF (this may be intentional)";
39 return;
40 }
41 LOG(DEBUG) << "Publishing " << instance;
42
43 auto aidlHal = ndk::SharedRefBase::make<T>(hidlHal, responseCb, indicationCb);
44 gPublishedHals.push_back(aidlHal);
45 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
46 CHECK_EQ(status, STATUS_OK);
47}
48
49static void publishRadio(std::string slot) {
50 auto radioHidl = V1_5::IRadio::getService(slot);
51 CHECK(radioHidl) << "HIDL IRadio not present in VINTF";
52
53 hidl_utils::linkDeathToDeath(radioHidl);
54
55 auto responseCb = sp<compat::RadioResponse>::make();
56 auto indicationCb = sp<compat::RadioIndication>::make();
57 radioHidl->setResponseFunctions(responseCb, indicationCb).assertOk();
58
59 publishRadioHal<compat::RadioMessaging>(radioHidl, responseCb, indicationCb, slot);
60}
61
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070062static void publishRadioConfig() {
63 auto hidlHal = config::V1_1::IRadioConfig::getService();
64 CHECK(hidlHal) << "HIDL IRadioConfig not present in VINTF";
65
66 hidl_utils::linkDeathToDeath(hidlHal);
67
68 auto aidlHal = ndk::SharedRefBase::make<compat::RadioConfig>(hidlHal);
69 gPublishedHals.push_back(aidlHal);
70 const auto instance = compat::RadioConfig::descriptor + "/default"s;
71 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
72 CHECK_EQ(status, STATUS_OK);
73}
74
75static void main() {
76 base::SetDefaultTag("radiocompat");
77 base::SetMinimumLogSeverity(base::VERBOSE);
78 LOG(DEBUG) << "Radio HAL compat service starting...";
79
80 publishRadioConfig();
81
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070082 const auto slots = hidl_utils::listManifestByInterface(V1_0::IRadio::descriptor);
83 LOG(INFO) << "Found " << slots.size() << " slot(s)";
84 for (const auto& slot : slots) {
85 publishRadio(slot);
86 }
87
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070088 LOG(DEBUG) << "Radio HAL compat service is operational";
89 ABinderProcess_joinThreadPool();
90 LOG(FATAL) << "Radio HAL compat service has stopped";
91}
92
93} // namespace android::hardware::radio::service
94
95int main() {
96 android::hardware::radio::service::main();
97 return EXIT_FAILURE; // should not reach
98}