blob: 2a6756945218d0241f2d872e6e3afa7442c33246 [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>
39static void publishRadioHal(sp<V1_5::IRadio> hidlHal, sp<compat::RadioResponse> responseCb,
40 sp<compat::RadioIndication> indicationCb, const std::string& slot) {
41 const auto instance = T::descriptor + "/"s + slot;
42 if (!AServiceManager_isDeclared(instance.c_str())) {
43 LOG(INFO) << instance << " is not declared in VINTF (this may be intentional)";
44 return;
45 }
46 LOG(DEBUG) << "Publishing " << instance;
47
48 auto aidlHal = ndk::SharedRefBase::make<T>(hidlHal, responseCb, indicationCb);
49 gPublishedHals.push_back(aidlHal);
50 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
51 CHECK_EQ(status, STATUS_OK);
52}
53
54static void publishRadio(std::string slot) {
55 auto radioHidl = V1_5::IRadio::getService(slot);
56 CHECK(radioHidl) << "HIDL IRadio not present in VINTF";
57
58 hidl_utils::linkDeathToDeath(radioHidl);
59
60 auto responseCb = sp<compat::RadioResponse>::make();
61 auto indicationCb = sp<compat::RadioIndication>::make();
62 radioHidl->setResponseFunctions(responseCb, indicationCb).assertOk();
63
Tomasz Wasilczykd2e74592021-11-02 12:14:52 -070064 publishRadioHal<compat::RadioData>(radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070065 publishRadioHal<compat::RadioMessaging>(radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczyk535f30c2021-11-08 16:10:28 -080066 publishRadioHal<compat::RadioModem>(radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczyk61213fe2021-11-03 15:15:48 -070067 publishRadioHal<compat::RadioNetwork>(radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -070068 publishRadioHal<compat::RadioSim>(radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczyk9375f3a2021-11-05 10:53:55 -070069 publishRadioHal<compat::RadioVoice>(radioHidl, responseCb, indicationCb, slot);
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070070}
71
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070072static void publishRadioConfig() {
73 auto hidlHal = config::V1_1::IRadioConfig::getService();
74 CHECK(hidlHal) << "HIDL IRadioConfig not present in VINTF";
75
76 hidl_utils::linkDeathToDeath(hidlHal);
77
78 auto aidlHal = ndk::SharedRefBase::make<compat::RadioConfig>(hidlHal);
79 gPublishedHals.push_back(aidlHal);
80 const auto instance = compat::RadioConfig::descriptor + "/default"s;
81 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
82 CHECK_EQ(status, STATUS_OK);
83}
84
85static void main() {
86 base::SetDefaultTag("radiocompat");
87 base::SetMinimumLogSeverity(base::VERBOSE);
88 LOG(DEBUG) << "Radio HAL compat service starting...";
89
90 publishRadioConfig();
91
Tomasz Wasilczyk1f16d3a2021-10-25 20:20:49 -070092 const auto slots = hidl_utils::listManifestByInterface(V1_0::IRadio::descriptor);
93 LOG(INFO) << "Found " << slots.size() << " slot(s)";
94 for (const auto& slot : slots) {
95 publishRadio(slot);
96 }
97
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -070098 LOG(DEBUG) << "Radio HAL compat service is operational";
99 ABinderProcess_joinThreadPool();
100 LOG(FATAL) << "Radio HAL compat service has stopped";
101}
102
103} // namespace android::hardware::radio::service
104
105int main() {
106 android::hardware::radio::service::main();
107 return EXIT_FAILURE; // should not reach
108}