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