1 /*
2 * Copyright (C) 2022-2023 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 "ims_sms_callback_stub.h"
17
18 #include "ims_sms_client.h"
19 #include "radio_event.h"
20 #include "telephony_errors.h"
21 #include "telephony_log_wrapper.h"
22
23 namespace OHOS {
24 namespace Telephony {
ImsSmsCallbackStub()25 ImsSmsCallbackStub::ImsSmsCallbackStub()
26 {
27 TELEPHONY_LOGI("ImsSmsCallbackStub");
28 InitFuncMap();
29 }
30
InitFuncMap()31 void ImsSmsCallbackStub::InitFuncMap()
32 {
33 InitSmsBasicFuncMap();
34 }
35
InitSmsBasicFuncMap()36 void ImsSmsCallbackStub::InitSmsBasicFuncMap()
37 {
38 /****************** sms basic ******************/
39 requestFuncMap_[static_cast<uint32_t>(ImsSmsCallbackInterfaceCode::IMS_SEND_MESSAGE)] =
40 [this](MessageParcel &data, MessageParcel &reply) { return OnImsSendMessageResponseInner(data, reply); };
41 requestFuncMap_[static_cast<uint32_t>(ImsSmsCallbackInterfaceCode::IMS_SET_SMS_CONFIG)] =
42 [this](MessageParcel &data, MessageParcel &reply) { return OnImsSetSmsConfigResponseInner(data, reply); };
43 requestFuncMap_[static_cast<uint32_t>(ImsSmsCallbackInterfaceCode::IMS_GET_SMS_CONFIG)] =
44 [this](MessageParcel &data, MessageParcel &reply) { return OnImsGetSmsConfigResponseInner(data, reply); };
45 }
46
~ImsSmsCallbackStub()47 ImsSmsCallbackStub::~ImsSmsCallbackStub()
48 {
49 requestFuncMap_.clear();
50 }
51
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int32_t ImsSmsCallbackStub::OnRemoteRequest(
53 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
54 {
55 std::u16string myDescriptor = ImsSmsCallbackStub::GetDescriptor();
56 std::u16string remoteDescriptor = data.ReadInterfaceToken();
57 if (myDescriptor != remoteDescriptor) {
58 TELEPHONY_LOGE("Descriptor check failed, return");
59 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
60 }
61 auto itFunc = requestFuncMap_.find(code);
62 if (itFunc != requestFuncMap_.end()) {
63 auto requestFunc = itFunc->second;
64 if (requestFunc != nullptr) {
65 return requestFunc(data, reply);
66 }
67 }
68 TELEPHONY_LOGE("Do not found the requestFunc of code=%{public}d, need to check", code);
69 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
70 }
71
OnImsSendMessageResponseInner(MessageParcel & data,MessageParcel & reply)72 int32_t ImsSmsCallbackStub::OnImsSendMessageResponseInner(MessageParcel &data, MessageParcel &reply)
73 {
74 int32_t slotId = data.ReadInt32();
75 RadioResponseInfo hRilRadioResponseInfo;
76 SendSmsResultInfo sendSmsResultInfo;
77 if (data.GetRawDataSize() == sizeof(RadioResponseInfo)) {
78 hRilRadioResponseInfo.flag = data.ReadInt32();
79 hRilRadioResponseInfo.serial = data.ReadInt32();
80 hRilRadioResponseInfo.error = static_cast<const ErrType>(data.ReadInt32());
81 hRilRadioResponseInfo.type = static_cast<const ResponseTypes>(data.ReadInt32());
82 reply.WriteInt32(ImsSendMessageResponse(slotId, hRilRadioResponseInfo));
83 return TELEPHONY_SUCCESS;
84 } else {
85 sendSmsResultInfo.msgRef = data.ReadInt32();
86 sendSmsResultInfo.pdu = data.ReadString();
87 sendSmsResultInfo.errCode = data.ReadInt32();
88 sendSmsResultInfo.flag = data.ReadInt64();
89 reply.WriteInt32(ImsSendMessageResponse(slotId, sendSmsResultInfo));
90 return TELEPHONY_SUCCESS;
91 }
92 }
93
OnImsSetSmsConfigResponseInner(MessageParcel & data,MessageParcel & reply)94 int32_t ImsSmsCallbackStub::OnImsSetSmsConfigResponseInner(MessageParcel &data, MessageParcel &reply)
95 {
96 int32_t slotId = data.ReadInt32();
97 RadioResponseInfo hRilRadioResponseInfo;
98 hRilRadioResponseInfo.flag = data.ReadInt32();
99 hRilRadioResponseInfo.serial = data.ReadInt32();
100 hRilRadioResponseInfo.error = static_cast<const ErrType>(data.ReadInt32());
101 hRilRadioResponseInfo.type = static_cast<const ResponseTypes>(data.ReadInt32());
102 reply.WriteInt32(ImsSetSmsConfigResponse(slotId, hRilRadioResponseInfo));
103 return TELEPHONY_SUCCESS;
104 }
105
OnImsGetSmsConfigResponseInner(MessageParcel & data,MessageParcel & reply)106 int32_t ImsSmsCallbackStub::OnImsGetSmsConfigResponseInner(MessageParcel &data, MessageParcel &reply)
107 {
108 int32_t slotId = data.ReadInt32();
109 int32_t imsSmsConfig = data.ReadInt32();
110 reply.WriteInt32(ImsGetSmsConfigResponse(slotId, imsSmsConfig));
111 return TELEPHONY_SUCCESS;
112 }
113
ImsSendMessageResponse(int32_t slotId,const SendSmsResultInfo & result)114 int32_t ImsSmsCallbackStub::ImsSendMessageResponse(int32_t slotId, const SendSmsResultInfo &result)
115 {
116 TELEPHONY_LOGI("[slot%{public}d]Entry with SendSmsResultInfo", slotId);
117 std::shared_ptr<SendSmsResultInfo> sendSmsResultInfo = std::make_shared<SendSmsResultInfo>();
118 if (sendSmsResultInfo == nullptr) {
119 TELEPHONY_LOGE("[slot%{public}d]make_shared SendSmsResultInfo failed", slotId);
120 return TELEPHONY_ERR_LOCAL_PTR_NULL;
121 }
122 *sendSmsResultInfo = result;
123 uint32_t item = RadioEvent::RADIO_SEND_IMS_GSM_SMS;
124 auto eventHandler = DelayedSingleton<ImsSmsClient>::GetInstance()->GetHandler(slotId);
125 if (eventHandler == nullptr) {
126 TELEPHONY_LOGE("eventHandler is nullptr");
127 return TELEPHONY_ERR_LOCAL_PTR_NULL;
128 }
129 TelEventHandler::SendTelEvent(eventHandler, item, sendSmsResultInfo);
130 return TELEPHONY_SUCCESS;
131 }
132
ImsSendMessageResponse(int32_t slotId,const RadioResponseInfo & info)133 int32_t ImsSmsCallbackStub::ImsSendMessageResponse(int32_t slotId, const RadioResponseInfo &info)
134 {
135 return SendHRilRadioResponseInfo(slotId, static_cast<uint32_t>(RadioEvent::RADIO_SEND_IMS_GSM_SMS), info);
136 }
137
ImsSetSmsConfigResponse(int32_t slotId,const RadioResponseInfo & info)138 int32_t ImsSmsCallbackStub::ImsSetSmsConfigResponse(int32_t slotId, const RadioResponseInfo &info)
139 {
140 return SendHRilRadioResponseInfo(slotId, static_cast<uint32_t>(RadioEvent::RADIO_SET_IMS_SMS), info);
141 }
142
ImsGetSmsConfigResponse(int32_t slotId,int32_t imsSmsConfig)143 int32_t ImsSmsCallbackStub::ImsGetSmsConfigResponse(int32_t slotId, int32_t imsSmsConfig)
144 {
145 TELEPHONY_LOGI("[slot%{public}d]Entry", slotId);
146 std::shared_ptr<int32_t> imsSmsCfg = std::make_shared<int32_t>();
147 if (imsSmsCfg == nullptr) {
148 TELEPHONY_LOGE("[slot%{public}d]make_shared imsSmsConfig failed", slotId);
149 return TELEPHONY_ERR_LOCAL_PTR_NULL;
150 }
151 *imsSmsCfg = imsSmsConfig;
152 uint32_t item = RadioEvent::RADIO_GET_IMS_SMS;
153 auto eventHandler = DelayedSingleton<ImsSmsClient>::GetInstance()->GetHandler(slotId);
154 if (eventHandler == nullptr) {
155 TELEPHONY_LOGE("eventHandler is nullptr");
156 return TELEPHONY_ERR_LOCAL_PTR_NULL;
157 }
158 TelEventHandler::SendTelEvent(eventHandler, item, imsSmsCfg);
159 return TELEPHONY_SUCCESS;
160 }
161
ImsGetSmsConfigResponse(int32_t slotId,const RadioResponseInfo & info)162 int32_t ImsSmsCallbackStub::ImsGetSmsConfigResponse(int32_t slotId, const RadioResponseInfo &info)
163 {
164 return SendHRilRadioResponseInfo(slotId, static_cast<uint32_t>(RadioEvent::RADIO_GET_IMS_SMS), info);
165 }
166
SendHRilRadioResponseInfo(int32_t slotId,uint32_t eventId,const RadioResponseInfo & info)167 int32_t ImsSmsCallbackStub::SendHRilRadioResponseInfo(
168 int32_t slotId, uint32_t eventId, const RadioResponseInfo &info)
169 {
170 TELEPHONY_LOGI("[slot%{public}d]eventId=%{public}d response error:%{public}d", slotId, eventId, info.error);
171 std::shared_ptr<RadioResponseInfo> hRilRadioResponseInfo = std::make_shared<RadioResponseInfo>();
172 if (hRilRadioResponseInfo == nullptr) {
173 TELEPHONY_LOGE("[slot%{public}d]make_shared RadioResponseInfo failed", slotId);
174 return TELEPHONY_ERR_LOCAL_PTR_NULL;
175 }
176 *hRilRadioResponseInfo = info;
177 auto eventHandler = DelayedSingleton<ImsSmsClient>::GetInstance()->GetHandler(slotId);
178 if (eventHandler == nullptr) {
179 TELEPHONY_LOGE("eventHandler is nullptr");
180 return TELEPHONY_ERR_LOCAL_PTR_NULL;
181 }
182 TelEventHandler::SendTelEvent(eventHandler, eventId, hRilRadioResponseInfo);
183 return TELEPHONY_SUCCESS;
184 }
185 } // namespace Telephony
186 } // namespace OHOS
187