blob: 6bcd4b0c61ad0afa938e33f2251f00703b9c428e [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 Wasilczykd2e74592021-11-02 12:14:52 -070023#include <libradiocompat/RadioData.h>
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070024#include <libradiocompat/RadioIndication.h>
25#include <libradiocompat/RadioMessaging.h>
Tomasz Wasilczyk535f30c2021-11-08 16:10:28 -080026#include <libradiocompat/RadioModem.h>
Tomasz Wasilczyk61213fe2021-11-03 15:15:48 -070027#include <libradiocompat/RadioNetwork.h>
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070028#include <libradiocompat/RadioResponse.h>
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -070029#include <libradiocompat/RadioSim.h>
Tomasz Wasilczyk9375f3a2021-11-05 10:53:55 -070030#include <libradiocompat/RadioVoice.h>
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070031
32namespace android::hardware::radio::service {
33
34using namespace std::string_literals;
35
36static std::vector<std::shared_ptr<ndk::ICInterface>> gPublishedHals;
37
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070038template <typename T>
Sarah Chinba427352021-12-09 00:33:37 -080039static void publishRadioHal(std::shared_ptr<compat::DriverContext> context,
40 sp<V1_5::IRadio> hidlHal, sp<compat::RadioResponse> responseCb,
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070041 sp<compat::RadioIndication> indicationCb, const std::string& slot) {
42 const auto instance = T::descriptor + "/"s + slot;
43 if (!AServiceManager_isDeclared(instance.c_str())) {
44 LOG(INFO) << instance << " is not declared in VINTF (this may be intentional)";
45 return;
46 }
47 LOG(DEBUG) << "Publishing " << instance;
48
Sarah Chinba427352021-12-09 00:33:37 -080049 auto aidlHal = ndk::SharedRefBase::make<T>(context, hidlHal, responseCb, indicationCb);
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070050 gPublishedHals.push_back(aidlHal);
51 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
52 CHECK_EQ(status, STATUS_OK);
53}
54
55static void publishRadio(std::string slot) {
56 auto radioHidl = V1_5::IRadio::getService(slot);
57 CHECK(radioHidl) << "HIDL IRadio not present in VINTF";
58
59 hidl_utils::linkDeathToDeath(radioHidl);
60
Sarah Chinba427352021-12-09 00:33:37 -080061 auto context = std::make_shared<compat::DriverContext>();
62
63 auto responseCb = sp<compat::RadioResponse>::make(context);
64 auto indicationCb = sp<compat::RadioIndication>::make(context);
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070065 radioHidl->setResponseFunctions(responseCb, indicationCb).assertOk();
66
Sarah Chinba427352021-12-09 00:33:37 -080067 publishRadioHal<compat::RadioData>(context, radioHidl, responseCb, indicationCb, slot);
68 publishRadioHal<compat::RadioMessaging>(context, radioHidl, responseCb, indicationCb, slot);
69 publishRadioHal<compat::RadioModem>(context, radioHidl, responseCb, indicationCb, slot);
70 publishRadioHal<compat::RadioNetwork>(context, radioHidl, responseCb, indicationCb, slot);
71 publishRadioHal<compat::RadioSim>(context, radioHidl, responseCb, indicationCb, slot);
72 publishRadioHal<compat::RadioVoice>(context, radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070073}
74
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070075static void publishRadioConfig() {
76 auto hidlHal = config::V1_1::IRadioConfig::getService();
77 CHECK(hidlHal) << "HIDL IRadioConfig not present in VINTF";
78
79 hidl_utils::linkDeathToDeath(hidlHal);
80
81 auto aidlHal = ndk::SharedRefBase::make<compat::RadioConfig>(hidlHal);
82 gPublishedHals.push_back(aidlHal);
83 const auto instance = compat::RadioConfig::descriptor + "/default"s;
84 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
85 CHECK_EQ(status, STATUS_OK);
86}
87
88static void main() {
89 base::SetDefaultTag("radiocompat");
90 base::SetMinimumLogSeverity(base::VERBOSE);
91 LOG(DEBUG) << "Radio HAL compat service starting...";
92
93 publishRadioConfig();
94
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070095 const auto slots = hidl_utils::listManifestByInterface(V1_0::IRadio::descriptor);
96 LOG(INFO) << "Found " << slots.size() << " slot(s)";
97 for (const auto& slot : slots) {
98 publishRadio(slot);
99 }
100
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -0700101 LOG(DEBUG) << "Radio HAL compat service is operational";
102 ABinderProcess_joinThreadPool();
103 LOG(FATAL) << "Radio HAL compat service has stopped";
104}
105
106} // namespace android::hardware::radio::service
107
108int main() {
109 android::hardware::radio::service::main();
110 return EXIT_FAILURE; // should not reach
111}