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 "hril_notification.h"
19 #include "hril_request.h"
20 #include "radio_event.h"
21 #include "want.h"
22 #include "common_event_manager.h"
23 #include "common_event_support.h"
24
25 namespace OHOS {
26 namespace Telephony {
TelRilModem(int32_t slotId,sptr<HDI::Ril::V1_2::IRil> rilInterface,std::shared_ptr<ObserverHandler> observerHandler,std::shared_ptr<TelRilHandler> handler)27 TelRilModem::TelRilModem(int32_t slotId, sptr<HDI::Ril::V1_2::IRil> rilInterface,
28 std::shared_ptr<ObserverHandler> observerHandler, std::shared_ptr<TelRilHandler> handler)
29 : TelRilBase(slotId, rilInterface, observerHandler, handler)
30 {}
31
SetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)32 int32_t TelRilModem::SetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
33 {
34 auto getDataFunc = [&responseInfo](std::shared_ptr<TelRilRequest> telRilRequest) {
35 std::unique_ptr<HRilRadioStateInfo> radioState = std::make_unique<HRilRadioStateInfo>();
36 radioState->flag = telRilRequest->pointer_->GetParam();
37 radioState->state = static_cast<int32_t>(responseInfo.error);
38 return radioState;
39 };
40 return Response<std::unique_ptr<HRilRadioStateInfo>>(TELEPHONY_LOG_FUNC_NAME, responseInfo, getDataFunc);
41 }
42
GetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,int32_t state)43 int32_t TelRilModem::GetRadioStateResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, int32_t state)
44 {
45 auto getDataFunc = [state](std::shared_ptr<TelRilRequest> telRilRequest) {
46 std::unique_ptr<HRilRadioStateInfo> radioState = std::make_unique<HRilRadioStateInfo>();
47 radioState->flag = telRilRequest->pointer_->GetParam();
48 radioState->state = state;
49 return radioState;
50 };
51 return Response<std::unique_ptr<HRilRadioStateInfo>>(TELEPHONY_LOG_FUNC_NAME, responseInfo, getDataFunc);
52 }
53
ShutDown(const AppExecFwk::InnerEvent::Pointer & response)54 int32_t TelRilModem::ShutDown(const AppExecFwk::InnerEvent::Pointer &response)
55 {
56 return Request(TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_SHUT_DOWN, &HDI::Ril::V1_1::IRil::ShutDown);
57 }
58
SetRadioState(int32_t fun,int32_t rst,const AppExecFwk::InnerEvent::Pointer & response)59 int32_t TelRilModem::SetRadioState(int32_t fun, int32_t rst, const AppExecFwk::InnerEvent::Pointer &response)
60 {
61 return Request(
62 TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_SET_RADIO_STATUS, &HDI::Ril::V1_1::IRil::SetRadioState, fun, rst);
63 }
64
GetRadioState(const AppExecFwk::InnerEvent::Pointer & response)65 int32_t TelRilModem::GetRadioState(const AppExecFwk::InnerEvent::Pointer &response)
66 {
67 return Request(
68 TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_GET_RADIO_STATUS, &HDI::Ril::V1_1::IRil::GetRadioState);
69 }
70
GetImei(const AppExecFwk::InnerEvent::Pointer & response)71 int32_t TelRilModem::GetImei(const AppExecFwk::InnerEvent::Pointer &response)
72 {
73 return Request(TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_GET_IMEI, &HDI::Ril::V1_1::IRil::GetImei);
74 }
75
GetMeid(const AppExecFwk::InnerEvent::Pointer & response)76 int32_t TelRilModem::GetMeid(const AppExecFwk::InnerEvent::Pointer &response)
77 {
78 return Request(TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_GET_MEID, &HDI::Ril::V1_1::IRil::GetMeid);
79 }
80
GetVoiceRadioTechnology(const AppExecFwk::InnerEvent::Pointer & response)81 int32_t TelRilModem::GetVoiceRadioTechnology(const AppExecFwk::InnerEvent::Pointer &response)
82 {
83 return Request(
84 TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_GET_VOICE_RADIO, &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(
90 TELEPHONY_LOG_FUNC_NAME, response, HREQ_MODEM_GET_BASEBAND_VERSION, &HDI::Ril::V1_1::IRil::GetBasebandVersion);
91 }
92
ShutDownResponse(const HDI::Ril::V1_1::RilRadioResponseInfo responseInfo)93 int32_t TelRilModem::ShutDownResponse(const HDI::Ril::V1_1::RilRadioResponseInfo responseInfo)
94 {
95 return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
96 }
97
GetImeiResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & imei)98 int32_t TelRilModem::GetImeiResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &imei)
99 {
100 return Response<HRilStringParcel>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<HRilStringParcel>(imei));
101 }
102
GetMeidResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & meid)103 int32_t TelRilModem::GetMeidResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &meid)
104 {
105 return Response<HRilStringParcel>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<HRilStringParcel>(meid));
106 }
107
GetVoiceRadioTechnologyResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::VoiceRadioTechnology & voiceRadioTechnology)108 int32_t TelRilModem::GetVoiceRadioTechnologyResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo,
109 const HDI::Ril::V1_1::VoiceRadioTechnology &voiceRadioTechnology)
110 {
111 std::shared_ptr<VoiceRadioTechnology> mVoiceRadioTechnology = std::make_shared<VoiceRadioTechnology>();
112 BuildVoiceRadioTechnology(voiceRadioTechnology, mVoiceRadioTechnology);
113 return Response<VoiceRadioTechnology>(TELEPHONY_LOG_FUNC_NAME, responseInfo, mVoiceRadioTechnology);
114 }
115
GetBasebandVersionResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & basebandVersion)116 int32_t TelRilModem::GetBasebandVersionResponse(
117 const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &basebandVersion)
118 {
119 return Response<HRilStringParcel>(
120 TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<HRilStringParcel>(basebandVersion));
121 }
122
OnRilAdapterHostDied()123 int32_t TelRilModem::OnRilAdapterHostDied()
124 {
125 int32_t result = Notify(TELEPHONY_LOG_FUNC_NAME, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED);
126 if (result == TELEPHONY_ERR_SUCCESS) {
127 TELEPHONY_LOGI("Notify RIL died successfully.");
128 result = RadioStateUpdated(ModemPowerState::CORE_SERVICE_POWER_NOT_AVAILABLE);
129 }
130 return result;
131 }
132
RadioStateUpdated(int32_t state)133 int32_t TelRilModem::RadioStateUpdated(int32_t state)
134 {
135 AAFwk::Want want;
136 want.SetParam("slotId", slotId_);
137 want.SetParam("radioState", state);
138 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_RADIO_STATE_CHANGE);
139 EventFwk::CommonEventData commonEventData;
140 commonEventData.SetWant(want);
141 EventFwk::CommonEventPublishInfo publishInfo;
142 bool result = EventFwk::CommonEventManager::PublishCommonEvent(commonEventData, publishInfo, nullptr);
143 TELEPHONY_LOGD("publish modem subscribed event result : %{public}d", result);
144 return Notify<HRilInt32Parcel>(
145 TELEPHONY_LOG_FUNC_NAME, std::make_shared<HRilInt32Parcel>(state), RadioEvent::RADIO_STATE_CHANGED);
146 }
147
VoiceRadioTechUpdated(const HDI::Ril::V1_1::VoiceRadioTechnology & voiceRadioTechnology)148 int32_t TelRilModem::VoiceRadioTechUpdated(const HDI::Ril::V1_1::VoiceRadioTechnology &voiceRadioTechnology)
149 {
150 std::shared_ptr<VoiceRadioTechnology> mVoiceRadioTechnology = std::make_shared<VoiceRadioTechnology>();
151 BuildVoiceRadioTechnology(voiceRadioTechnology, mVoiceRadioTechnology);
152 return Notify<VoiceRadioTechnology>(
153 TELEPHONY_LOG_FUNC_NAME, mVoiceRadioTechnology, RadioEvent::RADIO_VOICE_TECH_CHANGED);
154 }
155
DsdsModeUpdated(int32_t mode)156 int32_t TelRilModem::DsdsModeUpdated(int32_t mode)
157 {
158 return Notify<HRilInt32Parcel>(
159 TELEPHONY_LOG_FUNC_NAME, std::make_shared<HRilInt32Parcel>(mode), RadioEvent::RADIO_DSDS_MODE_CHANGED);
160 }
161
BuildVoiceRadioTechnology(const HDI::Ril::V1_1::VoiceRadioTechnology & voiceRadioTechnology,std::shared_ptr<VoiceRadioTechnology> & mVoiceRadioTechnology)162 void TelRilModem::BuildVoiceRadioTechnology(const HDI::Ril::V1_1::VoiceRadioTechnology &voiceRadioTechnology,
163 std::shared_ptr<VoiceRadioTechnology> &mVoiceRadioTechnology)
164 {
165 if (mVoiceRadioTechnology == nullptr) {
166 return;
167 }
168 mVoiceRadioTechnology->srvStatus = static_cast<HRilSrvStatus>(voiceRadioTechnology.srvStatus);
169 mVoiceRadioTechnology->srvDomain = static_cast<HRilSrvDomain>(voiceRadioTechnology.srvDomain);
170 mVoiceRadioTechnology->roamStatus = static_cast<HRilRoamStatus>(voiceRadioTechnology.roamStatus);
171 mVoiceRadioTechnology->simStatus = static_cast<HRilSimStatus>(voiceRadioTechnology.simStatus);
172 mVoiceRadioTechnology->lockStatus = static_cast<HRilSimLockStatus>(voiceRadioTechnology.lockStatus);
173 mVoiceRadioTechnology->sysMode = static_cast<HRilSysMode>(voiceRadioTechnology.sysMode);
174 mVoiceRadioTechnology->sysModeName = voiceRadioTechnology.sysModeName;
175 mVoiceRadioTechnology->actType = static_cast<HRilRadioTech>(voiceRadioTechnology.actType);
176 mVoiceRadioTechnology->actName = voiceRadioTechnology.actName;
177 }
178 } // namespace Telephony
179 } // namespace OHOS
180