1 /*
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 <libradiocompat/RadioConfig.h>
18 
19 #include "commonStructs.h"
20 #include "debug.h"
21 #include "structs.h"
22 
23 #include "collections.h"
24 
25 #define RADIO_MODULE "Config"
26 
27 namespace android::hardware::radio::compat {
28 
29 using ::ndk::ScopedAStatus;
30 namespace aidl = ::aidl::android::hardware::radio::config;
31 constexpr auto ok = &ScopedAStatus::ok;
32 
RadioConfig(sp<config::V1_1::IRadioConfig> hidlHal)33 RadioConfig::RadioConfig(sp<config::V1_1::IRadioConfig> hidlHal)
34     : mHal1_1(hidlHal),
35       mHal1_3(config::V1_3::IRadioConfig::castFrom(hidlHal)),
36       mRadioConfigResponse(sp<RadioConfigResponse>::make()),
37       mRadioConfigIndication(sp<RadioConfigIndication>::make()) {}
38 
respond()39 std::shared_ptr<aidl::IRadioConfigResponse> RadioConfig::respond() {
40     return mRadioConfigResponse->respond();
41 }
42 
getHalDeviceCapabilities(int32_t serial)43 ScopedAStatus RadioConfig::getHalDeviceCapabilities(int32_t serial) {
44     LOG_CALL << serial;
45     if (mHal1_3) {
46         mHal1_3->getHalDeviceCapabilities(serial);
47     } else {
48         respond()->getHalDeviceCapabilitiesResponse(notSupported(serial), false);
49     }
50     return ok();
51 }
52 
getNumOfLiveModems(int32_t serial)53 ScopedAStatus RadioConfig::getNumOfLiveModems(int32_t serial) {
54     LOG_CALL << serial;
55     mHal1_1->getModemsConfig(serial);
56     return ok();
57 }
58 
getPhoneCapability(int32_t serial)59 ScopedAStatus RadioConfig::getPhoneCapability(int32_t serial) {
60     LOG_CALL << serial;
61     mHal1_1->getPhoneCapability(serial);
62     return ok();
63 }
64 
getSimultaneousCallingSupport(int32_t serial)65 ScopedAStatus RadioConfig::getSimultaneousCallingSupport(int32_t serial) {
66     LOG_CALL << serial;
67     LOG(ERROR) << " getSimultaneousCallingSupport is unsupported by HIDL HALs";
68     respond()->getSimultaneousCallingSupportResponse(notSupported(serial), {});
69     return ok();
70 }
71 
getSimSlotsStatus(int32_t serial)72 ScopedAStatus RadioConfig::getSimSlotsStatus(int32_t serial) {
73     LOG_CALL << serial;
74     mHal1_1->getSimSlotsStatus(serial);
75     return ok();
76 }
77 
setNumOfLiveModems(int32_t serial,int8_t numOfLiveModems)78 ScopedAStatus RadioConfig::setNumOfLiveModems(int32_t serial, int8_t numOfLiveModems) {
79     LOG_CALL << serial;
80     mHal1_1->setModemsConfig(serial, {static_cast<uint8_t>(numOfLiveModems)});
81     return ok();
82 }
83 
setPreferredDataModem(int32_t serial,int8_t modemId)84 ScopedAStatus RadioConfig::setPreferredDataModem(int32_t serial, int8_t modemId) {
85     LOG_CALL << serial;
86     mHal1_1->setPreferredDataModem(serial, modemId);
87     return ok();
88 }
89 
setResponseFunctions(const std::shared_ptr<aidl::IRadioConfigResponse> & radioConfigResponse,const std::shared_ptr<aidl::IRadioConfigIndication> & radioConfigIndication)90 ScopedAStatus RadioConfig::setResponseFunctions(
91         const std::shared_ptr<aidl::IRadioConfigResponse>& radioConfigResponse,
92         const std::shared_ptr<aidl::IRadioConfigIndication>& radioConfigIndication) {
93     LOG_CALL << radioConfigResponse << ' ' << radioConfigIndication;
94 
95     CHECK(radioConfigResponse);
96     CHECK(radioConfigIndication);
97 
98     mRadioConfigResponse->setResponseFunction(radioConfigResponse);
99     mRadioConfigIndication->setResponseFunction(radioConfigIndication);
100     mHal1_1->setResponseFunctions(mRadioConfigResponse, mRadioConfigIndication).assertOk();
101 
102     return ok();
103 }
104 
setSimSlotsMapping(int32_t serial,const std::vector<aidl::SlotPortMapping> & slotMap)105 ScopedAStatus RadioConfig::setSimSlotsMapping(  //
106         int32_t serial, const std::vector<aidl::SlotPortMapping>& slotMap) {
107     LOG_CALL << serial;
108     mHal1_1->setSimSlotsMapping(serial, toHidl(slotMap));
109     return ok();
110 }
111 
112 }  // namespace android::hardware::radio::compat
113