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