1 /*
2 * Copyright (C) 2023 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 "impl/RadioConfig.h"
18 #include "impl/RadioData.h"
19 #include "impl/RadioModem.h"
20 #include "impl/RadioNetwork.h"
21 #include "impl/RadioSim.h"
22
23 #include <android-base/logging.h>
24 #include <android/binder_manager.h>
25 #include <android/binder_process.h>
26
27 namespace android::hardware::radio::service {
28
29 using namespace std::string_literals;
30
31 static std::vector<std::shared_ptr<ndk::ICInterface>> gPublishedHals;
32
publishRadioConfig()33 static void publishRadioConfig() {
34 const auto instance = RadioConfig::descriptor + "/default"s;
35 LOG(DEBUG) << "Publishing " << instance;
36 auto aidlHal = ndk::SharedRefBase::make<RadioConfig>();
37 gPublishedHals.push_back(aidlHal);
38 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
39 CHECK_EQ(status, STATUS_OK);
40 }
41
42 template <typename T>
publishRadioHal(const std::string & slot,std::shared_ptr<minimal::SlotContext> context)43 static void publishRadioHal(const std::string& slot,
44 std::shared_ptr<minimal::SlotContext> context) {
45 const auto instance = T::descriptor + "/"s + slot;
46 if (!AServiceManager_isDeclared(instance.c_str())) {
47 LOG(INFO) << instance << " is not declared in VINTF (this may be intentional)";
48 return;
49 }
50 LOG(DEBUG) << "Publishing " << instance;
51 auto aidlHal = ndk::SharedRefBase::make<T>(context);
52 gPublishedHals.push_back(aidlHal);
53 context->addHal(aidlHal);
54 const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
55 CHECK_EQ(status, STATUS_OK);
56 }
57
main()58 void main() {
59 base::InitLogging(nullptr, base::LogdLogger(base::RADIO));
60 base::SetDefaultTag("minradio");
61 base::SetMinimumLogSeverity(base::VERBOSE);
62 LOG(DEBUG) << "Minimal Radio HAL service starting...";
63 ABinderProcess_setThreadPoolMaxThreadCount(1);
64 ABinderProcess_startThreadPool();
65
66 auto slot1Context = std::make_shared<minimal::SlotContext>(1);
67 publishRadioConfig();
68 publishRadioHal<RadioData>("slot1", slot1Context);
69 publishRadioHal<RadioModem>("slot1", slot1Context);
70 publishRadioHal<RadioNetwork>("slot1", slot1Context);
71 publishRadioHal<RadioSim>("slot1", slot1Context);
72
73 // Non-virtual implementation would set up and initialize connection to the modem here
74
75 slot1Context->setConnected();
76 LOG(DEBUG) << "Minimal Radio HAL service is operational";
77 ABinderProcess_joinThreadPool();
78 LOG(FATAL) << "Minimal Radio HAL service has stopped";
79 }
80
81 } // namespace android::hardware::radio::service
82
main()83 int main() {
84 android::hardware::radio::service::main();
85 return EXIT_FAILURE; // should not reach
86 }
87