1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "tel_ril_modem.h"
17 
18 #include "common_event_manager.h"
19 #include "common_event_support.h"
20 #include "radio_event.h"
21 #include "want.h"
22 
23 namespace OHOS {
24 namespace Telephony {
TelRilModem(int32_t slotId,sptr<HDI::Ril::V1_3::IRil> rilInterface,std::shared_ptr<ObserverHandler> observerHandler,std::shared_ptr<TelRilHandler> handler)25 TelRilModem::TelRilModem(int32_t slotId, sptr<HDI::Ril::V1_3::IRil> rilInterface,
26     std::shared_ptr<ObserverHandler> observerHandler, std::shared_ptr<TelRilHandler> handler)
27     : TelRilBase(slotId, rilInterface, observerHandler, handler)
28 {}
29 
SetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)30 int32_t TelRilModem::SetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
31 {
32     auto getDataFunc = [&responseInfo](std::shared_ptr<TelRilRequest> telRilRequest) {
33         std::unique_ptr<RadioStateInfo> radioState = std::make_unique<RadioStateInfo>();
34         radioState->flag = telRilRequest->pointer_->GetParam();
35         radioState->state = static_cast<int32_t>(responseInfo.error);
36         return radioState;
37     };
38     return Response<std::unique_ptr<RadioStateInfo>>(TELEPHONY_LOG_FUNC_NAME, responseInfo, getDataFunc);
39 }
40 
GetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,int32_t state)41 int32_t TelRilModem::GetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, int32_t state)
42 {
43     auto getDataFunc = [state](std::shared_ptr<TelRilRequest> telRilRequest) {
44         std::unique_ptr<RadioStateInfo> radioState = std::make_unique<RadioStateInfo>();
45         radioState->flag = telRilRequest->pointer_->GetParam();
46         radioState->state = state;
47         return radioState;
48     };
49     return Response<std::unique_ptr<RadioStateInfo>>(TELEPHONY_LOG_FUNC_NAME, responseInfo, getDataFunc);
50 }
51 
ShutDown(const AppExecFwk::InnerEvent::Pointer & response)52 int32_t TelRilModem::ShutDown(const AppExecFwk::InnerEvent::Pointer &response)
53 {
54     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::ShutDown);
55 }
56 
SetRadioState(int32_t fun,int32_t rst,const AppExecFwk::InnerEvent::Pointer & response)57 int32_t TelRilModem::SetRadioState(int32_t fun, int32_t rst, const AppExecFwk::InnerEvent::Pointer &response)
58 {
59     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SetRadioState, fun, rst);
60 }
61 
GetRadioState(const AppExecFwk::InnerEvent::Pointer & response)62 int32_t TelRilModem::GetRadioState(const AppExecFwk::InnerEvent::Pointer &response)
63 {
64     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetRadioState);
65 }
66 
GetImei(const AppExecFwk::InnerEvent::Pointer & response)67 int32_t TelRilModem::GetImei(const AppExecFwk::InnerEvent::Pointer &response)
68 {
69     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetImei);
70 }
71 
GetImeiSv(const AppExecFwk::InnerEvent::Pointer & response)72 int32_t TelRilModem::GetImeiSv(const AppExecFwk::InnerEvent::Pointer &response)
73 {
74     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_3::IRil::GetImeiSv);
75 }
76 
GetMeid(const AppExecFwk::InnerEvent::Pointer & response)77 int32_t TelRilModem::GetMeid(const AppExecFwk::InnerEvent::Pointer &response)
78 {
79     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetMeid);
80 }
81 
GetVoiceRadioTechnology(const AppExecFwk::InnerEvent::Pointer & response)82 int32_t TelRilModem::GetVoiceRadioTechnology(const AppExecFwk::InnerEvent::Pointer &response)
83 {
84     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetVoiceRadioTechnology);
85 }
86 
GetBasebandVersion(const AppExecFwk::InnerEvent::Pointer & response)87 int32_t TelRilModem::GetBasebandVersion(const AppExecFwk::InnerEvent::Pointer &response)
88 {
89     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetBasebandVersion);
90 }
91 
ShutDownResponse(const HDI::Ril::V1_1::RilRadioResponseInfo responseInfo)92 int32_t TelRilModem::ShutDownResponse(const HDI::Ril::V1_1::RilRadioResponseInfo responseInfo)
93 {
94     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
95 }
96 
GetImeiResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & imei)97 int32_t TelRilModem::GetImeiResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &imei)
98 {
99     return Response<StringParcel>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<StringParcel>(imei));
100 }
101 
GetImeiSvResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & imeiSv)102 int32_t TelRilModem::GetImeiSvResponse(
103     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &imeiSv)
104 {
105     return Response<StringParcel>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<StringParcel>(imeiSv));
106 }
107 
GetMeidResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & meid)108 int32_t TelRilModem::GetMeidResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &meid)
109 {
110     return Response<StringParcel>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<StringParcel>(meid));
111 }
112 
GetVoiceRadioTechnologyResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::VoiceRadioTechnology & voiceRadioTechnology)113 int32_t TelRilModem::GetVoiceRadioTechnologyResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo,
114     const HDI::Ril::V1_1::VoiceRadioTechnology &voiceRadioTechnology)
115 {
116     std::shared_ptr<VoiceRadioTechnology> mVoiceRadioTechnology = std::make_shared<VoiceRadioTechnology>();
117     BuildVoiceRadioTechnology(voiceRadioTechnology, mVoiceRadioTechnology);
118     return Response<VoiceRadioTechnology>(TELEPHONY_LOG_FUNC_NAME, responseInfo, mVoiceRadioTechnology);
119 }
120 
GetBasebandVersionResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & basebandVersion)121 int32_t TelRilModem::GetBasebandVersionResponse(
122     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &basebandVersion)
123 {
124     return Response<StringParcel>(
125         TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<StringParcel>(basebandVersion));
126 }
127 
OnRilAdapterHostDied()128 int32_t TelRilModem::OnRilAdapterHostDied()
129 {
130     int32_t result = Notify(TELEPHONY_LOG_FUNC_NAME, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED);
131     if (result == TELEPHONY_ERR_SUCCESS) {
132         TELEPHONY_LOGI("Notify RIL died successfully.");
133         result = RadioStateUpdated(ModemPowerState::CORE_SERVICE_POWER_NOT_AVAILABLE);
134     }
135     return result;
136 }
137 
RadioStateUpdated(int32_t state)138 int32_t TelRilModem::RadioStateUpdated(int32_t state)
139 {
140     AAFwk::Want want;
141     want.SetParam("slotId", slotId_);
142     want.SetParam("radioState", state);
143     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_RADIO_STATE_CHANGE);
144     EventFwk::CommonEventData commonEventData;
145     commonEventData.SetWant(want);
146     EventFwk::CommonEventPublishInfo publishInfo;
147     bool result = EventFwk::CommonEventManager::PublishCommonEvent(commonEventData, publishInfo, nullptr);
148     TELEPHONY_LOGD("publish modem subscribed event result : %{public}d", result);
149     return Notify<Int32Parcel>(
150         TELEPHONY_LOG_FUNC_NAME, std::make_shared<Int32Parcel>(state), RadioEvent::RADIO_STATE_CHANGED);
151 }
152 
VoiceRadioTechUpdated(const HDI::Ril::V1_1::VoiceRadioTechnology & voiceRadioTechnology)153 int32_t TelRilModem::VoiceRadioTechUpdated(const HDI::Ril::V1_1::VoiceRadioTechnology &voiceRadioTechnology)
154 {
155     std::shared_ptr<VoiceRadioTechnology> mVoiceRadioTechnology = std::make_shared<VoiceRadioTechnology>();
156     BuildVoiceRadioTechnology(voiceRadioTechnology, mVoiceRadioTechnology);
157     return Notify<VoiceRadioTechnology>(
158         TELEPHONY_LOG_FUNC_NAME, mVoiceRadioTechnology, RadioEvent::RADIO_VOICE_TECH_CHANGED);
159 }
160 
DsdsModeUpdated(int32_t mode)161 int32_t TelRilModem::DsdsModeUpdated(int32_t mode)
162 {
163     return Notify<Int32Parcel>(
164         TELEPHONY_LOG_FUNC_NAME, std::make_shared<Int32Parcel>(mode), RadioEvent::RADIO_DSDS_MODE_CHANGED);
165 }
166 
BuildVoiceRadioTechnology(const HDI::Ril::V1_1::VoiceRadioTechnology & voiceRadioTechnology,std::shared_ptr<VoiceRadioTechnology> & mVoiceRadioTechnology)167 void TelRilModem::BuildVoiceRadioTechnology(const HDI::Ril::V1_1::VoiceRadioTechnology &voiceRadioTechnology,
168     std::shared_ptr<VoiceRadioTechnology> &mVoiceRadioTechnology)
169 {
170     if (mVoiceRadioTechnology == nullptr) {
171         return;
172     }
173     mVoiceRadioTechnology->srvStatus = static_cast<SrvStatus>(voiceRadioTechnology.srvStatus);
174     mVoiceRadioTechnology->srvDomain = static_cast<SrvDomain>(voiceRadioTechnology.srvDomain);
175     mVoiceRadioTechnology->roamStatus = static_cast<RoamStatus>(voiceRadioTechnology.roamStatus);
176     mVoiceRadioTechnology->simStatus = static_cast<SimStatus>(voiceRadioTechnology.simStatus);
177     mVoiceRadioTechnology->lockStatus = static_cast<SimLockStatus>(voiceRadioTechnology.lockStatus);
178     mVoiceRadioTechnology->sysMode = static_cast<SysMode>(voiceRadioTechnology.sysMode);
179     mVoiceRadioTechnology->sysModeName = voiceRadioTechnology.sysModeName;
180     mVoiceRadioTechnology->actType = static_cast<TelRilRadioTech>(voiceRadioTechnology.actType);
181     mVoiceRadioTechnology->actName = voiceRadioTechnology.actName;
182 }
183 } // namespace Telephony
184 } // namespace OHOS
185