• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 "sms_interface_stub.h"
17 
18 #include "sms_interface_manager.h"
19 #include "sms_receive_reliability_handler.h"
20 #include "sms_service.h"
21 #include "string_utils.h"
22 #include "telephony_errors.h"
23 #include "telephony_log_wrapper.h"
24 #include "telephony_types.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 using namespace std;
29 
IsValidSlotId(int32_t slotId)30 static inline bool IsValidSlotId(int32_t slotId)
31 {
32     return ((slotId >= DEFAULT_SIM_SLOT_ID) && (slotId < SIM_SLOT_COUNT));
33 }
34 
SmsInterfaceStub()35 SmsInterfaceStub::SmsInterfaceStub()
36 {
37     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::TEXT_BASED_SMS_DELIVERY)] =
38         &SmsInterfaceStub::OnSendSmsTextRequest;
39     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::DATA_BASED_SMS_DELIVERY)] =
40         &SmsInterfaceStub::OnSendSmsDataRequest;
41     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::SET_SMSC_ADDRESS)] = &SmsInterfaceStub::OnSetSmscAddr;
42     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_SMSC_ADDRESS)] = &SmsInterfaceStub::OnGetSmscAddr;
43     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::ADD_SIM_MESSAGE)] =
44         &SmsInterfaceStub::OnAddSimMessage;
45     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::DEL_SIM_MESSAGE)] =
46         &SmsInterfaceStub::OnDelSimMessage;
47     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::UPDATE_SIM_MESSAGE)] =
48         &SmsInterfaceStub::OnUpdateSimMessage;
49     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_ALL_SIM_MESSAGE)] =
50         &SmsInterfaceStub::OnGetAllSimMessages;
51     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::SET_CB_CONFIG)] = &SmsInterfaceStub::OnSetCBConfig;
52     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::SET_IMS_SMS_CONFIG)] =
53         &SmsInterfaceStub::OnSetImsSmsConfig;
54     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::SET_DEFAULT_SMS_SLOT_ID)] =
55         &SmsInterfaceStub::OnSetDefaultSmsSlotId;
56     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_DEFAULT_SMS_SLOT_ID)] =
57         &SmsInterfaceStub::OnGetDefaultSmsSlotId;
58     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_DEFAULT_SMS_SIM_ID)] =
59         &SmsInterfaceStub::OnGetDefaultSmsSimId;
60     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::SPLIT_MESSAGE)] = &SmsInterfaceStub::OnSplitMessage;
61     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_SMS_SEGMENTS_INFO)] =
62         &SmsInterfaceStub::OnGetSmsSegmentsInfo;
63     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_IMS_SHORT_MESSAGE_FORMAT)] =
64         &SmsInterfaceStub::OnGetImsShortMessageFormat;
65     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::IS_IMS_SMS_SUPPORTED)] =
66         &SmsInterfaceStub::OnIsImsSmsSupported;
67     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::HAS_SMS_CAPABILITY)] =
68         &SmsInterfaceStub::OnHasSmsCapability;
69     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::CREATE_MESSAGE)] = &SmsInterfaceStub::OnCreateMessage;
70     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::MMS_BASE64_ENCODE)] =
71         &SmsInterfaceStub::OnGetBase64Encode;
72     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::MMS_BASE64_DECODE)] =
73         &SmsInterfaceStub::OnGetBase64Decode;
74     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::GET_ENCODE_STRING)] =
75         &SmsInterfaceStub::OnGetEncodeStringFunc;
76     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::SEND_MMS)] = &SmsInterfaceStub::OnSendMms;
77     memberFuncMap_[static_cast<uint32_t>(SmsServiceInterfaceCode::DOWNLOAD_MMS)] = &SmsInterfaceStub::OnDownloadMms;
78 }
79 
~SmsInterfaceStub()80 SmsInterfaceStub::~SmsInterfaceStub()
81 {
82     slotSmsInterfaceManagerMap_.clear();
83     memberFuncMap_.clear();
84 }
85 
InitModule()86 void SmsInterfaceStub::InitModule()
87 {
88     static bool bInitModule = false;
89     if (bInitModule) {
90         return;
91     }
92     bInitModule = true;
93     std::lock_guard<std::mutex> lock(mutex_);
94     for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; ++slotId) {
95         slotSmsInterfaceManagerMap_[slotId] = std::make_shared<SmsInterfaceManager>(slotId);
96         if (slotSmsInterfaceManagerMap_[slotId] == nullptr) {
97             TELEPHONY_LOGE("SmsInterfaceStub InitModule slotSmsInterfaceManagerMap_[%{public}d] is nullptr", slotId);
98             return;
99         }
100         slotSmsInterfaceManagerMap_[slotId]->InitInterfaceManager();
101 
102         TelFFRTUtils::Submit([slotId]() {
103             auto reliabilityHandler = std::make_shared<SmsReceiveReliabilityHandler>(slotId);
104             if (reliabilityHandler == nullptr) {
105                 TELEPHONY_LOGE("reliabilityHandler nullptr");
106                 return;
107             }
108             if (!reliabilityHandler->DeleteExpireSmsFromDB()) {
109                 TELEPHONY_LOGE("DeleteExpireSmsFromDB fail");
110                 return;
111             }
112             if (!reliabilityHandler->CheckSmsCapable()) {
113                 TELEPHONY_LOGE("sms receive capable unSupport");
114                 return;
115             }
116             reliabilityHandler->SmsReceiveReliabilityProcessing();
117         });
118     }
119 }
120 
GetSmsInterfaceManager(int32_t slotId)121 std::shared_ptr<SmsInterfaceManager> SmsInterfaceStub::GetSmsInterfaceManager(int32_t slotId)
122 {
123     std::lock_guard<std::mutex> lock(mutex_);
124     std::map<uint32_t, std::shared_ptr<SmsInterfaceManager>>::iterator iter =
125         slotSmsInterfaceManagerMap_.find(slotId);
126     if (iter != slotSmsInterfaceManagerMap_.end()) {
127         return iter->second;
128     }
129     return nullptr;
130 }
131 
GetSmsInterfaceManager()132 std::shared_ptr<SmsInterfaceManager> SmsInterfaceStub::GetSmsInterfaceManager()
133 {
134     std::lock_guard<std::mutex> lock(mutex_);
135     for (const auto &iter : slotSmsInterfaceManagerMap_) {
136         if (iter.second != nullptr) {
137             return iter.second;
138         }
139     }
140     return nullptr;
141 }
142 
OnSendSmsTextRequest(MessageParcel & data,MessageParcel & reply,MessageOption & option)143 void SmsInterfaceStub::OnSendSmsTextRequest(MessageParcel &data, MessageParcel &reply, MessageOption &option)
144 {
145     sptr<ISendShortMessageCallback> sendCallback = nullptr;
146     sptr<IDeliveryShortMessageCallback> deliveryCallback = nullptr;
147     int32_t slotId = data.ReadInt32();
148     u16string desAddr = data.ReadString16();
149     u16string scAddr = data.ReadString16();
150     u16string text = data.ReadString16();
151     if (!IsValidSlotId(slotId)) {
152         TELEPHONY_LOGE("invalid slotId:%{public}d", slotId);
153         return;
154     }
155 
156     sptr<IRemoteObject> remoteSendCallback = data.ReadRemoteObject();
157     sptr<IRemoteObject> remoteDeliveryCallback = data.ReadRemoteObject();
158     if (remoteSendCallback != nullptr) {
159         sendCallback = iface_cast<ISendShortMessageCallback>(remoteSendCallback);
160     }
161     if (remoteDeliveryCallback != nullptr) {
162         deliveryCallback = iface_cast<IDeliveryShortMessageCallback>(remoteDeliveryCallback);
163     }
164     TELEPHONY_LOGI("MessageID::TEXT_BASED_SMS_DELIVERY %{public}d", slotId);
165     RemoveSpacesInDesAddr(desAddr);
166     std::string bundleName = data.ReadString();
167     TELEPHONY_LOGI("bundleName = %{public}s", bundleName.c_str());
168     int32_t result = SendMessage(slotId, desAddr, scAddr, text, sendCallback, deliveryCallback);
169     if (bundleName != MMS_APP && result == TELEPHONY_ERR_SUCCESS) {
170         DelayedSingleton<SmsService>::GetInstance()->InsertSessionAndDetail(slotId, StringUtils::ToUtf8(desAddr),
171             StringUtils::ToUtf8(text));
172     }
173     reply.WriteInt32(result);
174 }
175 
OnSendSmsDataRequest(MessageParcel & data,MessageParcel & reply,MessageOption & option)176 void SmsInterfaceStub::OnSendSmsDataRequest(MessageParcel &data, MessageParcel &reply, MessageOption &option)
177 {
178     sptr<ISendShortMessageCallback> sendCallback = nullptr;
179     sptr<IDeliveryShortMessageCallback> deliveryCallback = nullptr;
180     int32_t slotId = data.ReadInt32();
181     u16string desAddr = data.ReadString16();
182     u16string scAddr = data.ReadString16();
183     int16_t port = data.ReadInt16();
184     if (!IsValidSlotId(slotId)) {
185         TELEPHONY_LOGE("invalid slotId:%{public}d", slotId);
186         return;
187     }
188 
189     sptr<IRemoteObject> remoteSendCallback = data.ReadRemoteObject();
190     sptr<IRemoteObject> remoteDeliveryCallback = data.ReadRemoteObject();
191     if (remoteSendCallback != nullptr) {
192         sendCallback = iface_cast<ISendShortMessageCallback>(remoteSendCallback);
193     }
194     if (remoteDeliveryCallback != nullptr) {
195         deliveryCallback = iface_cast<IDeliveryShortMessageCallback>(remoteDeliveryCallback);
196     }
197     int16_t dataLen = data.ReadInt16();
198     const uint8_t *buffer = reinterpret_cast<const uint8_t *>(data.ReadRawData(dataLen));
199     RemoveSpacesInDesAddr(desAddr);
200     int32_t result = SendMessage(slotId, desAddr, scAddr, port, buffer, dataLen, sendCallback, deliveryCallback);
201     reply.WriteInt32(result);
202 }
203 
RemoveSpacesInDesAddr(std::u16string & desAddr)204 void SmsInterfaceStub::RemoveSpacesInDesAddr(std::u16string &desAddr)
205 {
206     // Remove spaces in desAddr
207     if (desAddr.empty() || desAddr.size() >= MAX_ADDRESS_LEN) {
208         TELEPHONY_LOGE("RemoveSpacesInDesAddr desAddr is invalid");
209         return;
210     }
211 
212     std::u16string storeAddr = desAddr;
213     int32_t count = static_cast<int32_t>(desAddr.size());
214     int32_t indexDes = 0;
215     int32_t indexResult = 0;
216     while (indexDes < count) {
217         if (desAddr[indexDes] != ' ') {
218             storeAddr[indexResult] = desAddr[indexDes];
219             indexResult++;
220         }
221         indexDes++;
222     }
223     desAddr = storeAddr.substr(0, indexResult);
224 }
225 
OnSetSmscAddr(MessageParcel & data,MessageParcel & reply,MessageOption & option)226 void SmsInterfaceStub::OnSetSmscAddr(MessageParcel &data, MessageParcel &reply, MessageOption &option)
227 {
228     int32_t slotId = data.ReadInt32();
229     std::u16string scAddr = data.ReadString16();
230     int32_t result = SetSmscAddr(slotId, scAddr);
231     TELEPHONY_LOGI("set smsc result:%{public}d", result == TELEPHONY_ERR_SUCCESS);
232     reply.WriteInt32(result);
233 }
234 
OnGetSmscAddr(MessageParcel & data,MessageParcel & reply,MessageOption & option)235 void SmsInterfaceStub::OnGetSmscAddr(MessageParcel &data, MessageParcel &reply, MessageOption &option)
236 {
237     std::u16string smscAddress;
238     int32_t slotId = data.ReadInt32();
239     int32_t result = GetSmscAddr(slotId, smscAddress);
240     if (!reply.WriteInt32(result)) {
241         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr write reply failed.");
242         return;
243     }
244     if (result != TELEPHONY_ERR_SUCCESS) {
245         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr result is not TELEPHONY_ERR_SUCCESS.");
246         return;
247     }
248 
249     if (!reply.WriteString16(smscAddress)) {
250         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr write reply failed.");
251         return;
252     }
253 }
254 
OnAddSimMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)255 void SmsInterfaceStub::OnAddSimMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
256 {
257     int32_t slotId = data.ReadInt32();
258     std::u16string smsc = data.ReadString16();
259     std::u16string pdu = data.ReadString16();
260     uint32_t status = data.ReadUint32();
261     if (status > SIM_MESSAGE_STATUS_SENT || status < SIM_MESSAGE_STATUS_UNREAD) {
262         return;
263     }
264     int32_t result = AddSimMessage(slotId, smsc, pdu, static_cast<SimMessageStatus>(status));
265     TELEPHONY_LOGI("AddSimMessage result %{public}d", result);
266     reply.WriteInt32(result);
267 }
268 
OnDelSimMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)269 void SmsInterfaceStub::OnDelSimMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
270 {
271     int32_t slotId = data.ReadInt32();
272     uint32_t msgIndex = data.ReadUint32();
273     int32_t result = DelSimMessage(slotId, msgIndex);
274     TELEPHONY_LOGI("DelSimMessage result %{public}d", result);
275     reply.WriteInt32(result);
276 }
277 
OnUpdateSimMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)278 void SmsInterfaceStub::OnUpdateSimMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
279 {
280     int32_t slotId = data.ReadInt32();
281     uint32_t msgIndex = data.ReadUint32();
282     uint32_t newStatus = data.ReadUint32();
283     std::u16string pdu = data.ReadString16();
284     std::u16string smsc = data.ReadString16();
285     if (newStatus > SIM_MESSAGE_STATUS_SENT || newStatus < SIM_MESSAGE_STATUS_UNREAD) {
286         return;
287     }
288     int32_t result = UpdateSimMessage(slotId, msgIndex, static_cast<SimMessageStatus>(newStatus), pdu, smsc);
289     TELEPHONY_LOGI("UpdateSimMessage result %{public}d", result);
290     reply.WriteInt32(result);
291 }
292 
OnGetAllSimMessages(MessageParcel & data,MessageParcel & reply,MessageOption & option)293 void SmsInterfaceStub::OnGetAllSimMessages(MessageParcel &data, MessageParcel &reply, MessageOption &option)
294 {
295     std::vector<ShortMessage> message;
296     int32_t slotId = data.ReadInt32();
297     int32_t result = GetAllSimMessages(slotId, message);
298     TELEPHONY_LOGI("GetAllSimMessages result %{public}d size %{public}zu", result, message.size());
299     reply.WriteInt32(result);
300     if (result != TELEPHONY_ERR_SUCCESS) {
301         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr result is not TELEPHONY_ERR_SUCCESS.");
302         return;
303     }
304     int32_t resultLen = static_cast<int32_t>(message.size());
305     reply.WriteInt32(resultLen);
306     for (const auto &v : message) {
307         v.Marshalling(reply);
308     }
309 }
310 
OnSetCBConfig(MessageParcel & data,MessageParcel & reply,MessageOption & option)311 void SmsInterfaceStub::OnSetCBConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option)
312 {
313     int32_t slotId = data.ReadInt32();
314     TELEPHONY_LOGI("set cb config slotId:%{public}d", slotId);
315     bool enable = data.ReadBool();
316     uint32_t fromMsgId = data.ReadUint32();
317     uint32_t toMsgId = data.ReadUint32();
318     uint8_t ranType = data.ReadUint8();
319     int32_t result = SetCBConfig(slotId, enable, fromMsgId, toMsgId, ranType);
320     TELEPHONY_LOGI("OnSetCBConfig result %{public}d", result);
321     reply.WriteInt32(result);
322 }
323 
OnSetImsSmsConfig(MessageParcel & data,MessageParcel & reply,MessageOption & option)324 void SmsInterfaceStub::OnSetImsSmsConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option)
325 {
326     bool result = false;
327     int32_t slotId = data.ReadInt32();
328     int32_t enable = data.ReadInt32();
329     result = SetImsSmsConfig(slotId, enable);
330     TELEPHONY_LOGI("SetImsSmsConfig result %{public}d", result);
331     reply.WriteBool(result);
332 }
333 
OnSetDefaultSmsSlotId(MessageParcel & data,MessageParcel & reply,MessageOption & option)334 void SmsInterfaceStub::OnSetDefaultSmsSlotId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
335 {
336     int32_t slotId = data.ReadInt32();
337     int32_t result = SetDefaultSmsSlotId(slotId);
338     TELEPHONY_LOGI("SetDefaultSmsSlotId result %{public}d", result);
339     reply.WriteInt32(result);
340 }
341 
OnGetDefaultSmsSlotId(MessageParcel & data,MessageParcel & reply,MessageOption & option)342 void SmsInterfaceStub::OnGetDefaultSmsSlotId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
343 {
344     int32_t result = 0;
345     result = GetDefaultSmsSlotId();
346     TELEPHONY_LOGI("SetDefaultSmsSlotId result %{public}d", result);
347     reply.WriteInt32(result);
348 }
349 
OnGetDefaultSmsSimId(MessageParcel & data,MessageParcel & reply,MessageOption & option)350 void SmsInterfaceStub::OnGetDefaultSmsSimId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
351 {
352     int32_t result = 0;
353     int32_t simId = 0;
354     result = GetDefaultSmsSimId(simId);
355     if (!reply.WriteInt32(result)) {
356         TELEPHONY_LOGE("write int32 reply failed.");
357         return;
358     }
359     if (result != TELEPHONY_ERR_SUCCESS) {
360         TELEPHONY_LOGE("result %{public}d", result);
361         return;
362     }
363     if (!reply.WriteInt32(simId)) {
364         TELEPHONY_LOGE("write int32 reply failed.");
365         return;
366     }
367 }
368 
OnSplitMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)369 void SmsInterfaceStub::OnSplitMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
370 {
371     std::vector<std::u16string> splitMessage;
372     std::u16string message = data.ReadString16();
373     int32_t result = SplitMessage(message, splitMessage);
374     reply.WriteInt32(result);
375     if (result != TELEPHONY_ERR_SUCCESS) {
376         TELEPHONY_LOGE("SmsInterfaceStub::OnSplitMessage result is not TELEPHONY_ERR_SUCCESS.");
377         return;
378     }
379     int32_t resultLen = static_cast<int32_t>(splitMessage.size());
380     TELEPHONY_LOGI("SplitMessage size %{public}d", resultLen);
381     reply.WriteInt32(resultLen);
382     for (const auto &item : splitMessage) {
383         reply.WriteString16(item);
384     }
385 }
386 
OnGetSmsSegmentsInfo(MessageParcel & data,MessageParcel & reply,MessageOption & option)387 void SmsInterfaceStub::OnGetSmsSegmentsInfo(MessageParcel &data, MessageParcel &reply, MessageOption &option)
388 {
389     int32_t slotId = data.ReadInt32();
390     std::u16string message = data.ReadString16();
391     bool force7BitCode = data.ReadBool();
392 
393     SmsSegmentsInfo segInfo;
394     int32_t result = GetSmsSegmentsInfo(slotId, message, force7BitCode, segInfo);
395     reply.WriteInt32(result);
396 
397     if (result == TELEPHONY_ERR_SUCCESS) {
398         reply.WriteInt32(segInfo.msgSegCount);
399         reply.WriteInt32(segInfo.msgEncodingCount);
400         reply.WriteInt32(segInfo.msgRemainCount);
401         reply.WriteInt32(static_cast<int32_t>(segInfo.msgCodeScheme));
402     }
403 }
404 
OnIsImsSmsSupported(MessageParcel & data,MessageParcel & reply,MessageOption & option)405 void SmsInterfaceStub::OnIsImsSmsSupported(MessageParcel &data, MessageParcel &reply, MessageOption &option)
406 {
407     int32_t slotId = data.ReadInt32();
408     bool isSupported = false;
409     int32_t result = IsImsSmsSupported(slotId, isSupported);
410     if (!reply.WriteInt32(result)) {
411         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported write reply failed.");
412         return;
413     }
414     if (result != TELEPHONY_ERR_SUCCESS) {
415         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported result is not TELEPHONY_ERR_SUCCESS.");
416         return;
417     }
418     if (!reply.WriteBool(isSupported)) {
419         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported write reply failed.");
420         return;
421     }
422 }
423 
OnGetImsShortMessageFormat(MessageParcel & data,MessageParcel & reply,MessageOption & option)424 void SmsInterfaceStub::OnGetImsShortMessageFormat(MessageParcel &data, MessageParcel &reply, MessageOption &option)
425 {
426     std::u16string format;
427     int32_t result = GetImsShortMessageFormat(format);
428     reply.WriteInt32(result);
429     if (result != TELEPHONY_ERR_SUCCESS) {
430         TELEPHONY_LOGE("SmsInterfaceStub::OnGetImsShortMessageFormat result is not TELEPHONY_ERR_SUCCESS.");
431         return;
432     }
433     reply.WriteString16(format);
434 }
435 
OnHasSmsCapability(MessageParcel & data,MessageParcel & reply,MessageOption & option)436 void SmsInterfaceStub::OnHasSmsCapability(MessageParcel &data, MessageParcel &reply, MessageOption &option)
437 {
438     reply.WriteBool(HasSmsCapability());
439 }
440 
OnCreateMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)441 void SmsInterfaceStub::OnCreateMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
442 {
443     std::string pdu = data.ReadString();
444     std::string specification = data.ReadString();
445     ShortMessage message;
446     int32_t result = CreateMessage(pdu, specification, message);
447 
448     reply.WriteInt32(result);
449     if (result != TELEPHONY_ERR_SUCCESS) {
450         return;
451     }
452     if (!message.Marshalling(reply)) {
453         TELEPHONY_LOGE("SmsInterfaceStub::OnCreateMessage fail");
454     }
455 }
456 
OnGetBase64Encode(MessageParcel & data,MessageParcel & reply,MessageOption & option)457 void SmsInterfaceStub::OnGetBase64Encode(MessageParcel &data, MessageParcel &reply, MessageOption &option)
458 {
459     bool result = false;
460 
461     u16string src = data.ReadString16();
462     std::string dest;
463     result = GetBase64Encode(StringUtils::ToUtf8(src), dest);
464     reply.WriteBool(result);
465     if (!result) {
466         return;
467     }
468     reply.WriteString16(StringUtils::ToUtf16(dest));
469 }
470 
OnGetBase64Decode(MessageParcel & data,MessageParcel & reply,MessageOption & option)471 void SmsInterfaceStub::OnGetBase64Decode(MessageParcel &data, MessageParcel &reply, MessageOption &option)
472 {
473     bool result = false;
474     u16string src = data.ReadString16();
475     std::string dest;
476     result = GetBase64Decode(StringUtils::ToUtf8(src), dest);
477     reply.WriteBool(result);
478     if (!result) {
479         return;
480     }
481     reply.WriteString16(StringUtils::ToUtf16(dest));
482 }
483 
OnGetEncodeStringFunc(MessageParcel & data,MessageParcel & reply,MessageOption & option)484 void SmsInterfaceStub::OnGetEncodeStringFunc(MessageParcel &data, MessageParcel &reply, MessageOption &option)
485 {
486     bool result = false;
487     uint32_t charset = data.ReadUint32();
488     uint32_t valLength = data.ReadUint32();
489     u16string strEncodeString = data.ReadString16();
490     std::string str = StringUtils::ToUtf8(strEncodeString);
491     std::string encodeString;
492 
493     if (valLength != str.length()) {
494         TELEPHONY_LOGE("invalid valLength!");
495         return;
496     }
497     result = GetEncodeStringFunc(encodeString, charset, valLength, str);
498     reply.WriteBool(result);
499     if (!result) {
500         return;
501     }
502     reply.WriteString16(StringUtils::ToUtf16(encodeString));
503 }
504 
OnSendMms(MessageParcel & data,MessageParcel & reply,MessageOption & option)505 void SmsInterfaceStub::OnSendMms(MessageParcel &data, MessageParcel &reply, MessageOption &option)
506 {
507     int32_t slotId = data.ReadInt32();
508     TELEPHONY_LOGI("send mms slotId:%{public}d", slotId);
509     u16string mmsc = data.ReadString16();
510     u16string mmsData = data.ReadString16();
511     u16string ua = data.ReadString16();
512     u16string uaprof = data.ReadString16();
513     int32_t result = SendMms(slotId, mmsc, mmsData, ua, uaprof);
514     if (!reply.WriteInt32(result)) {
515         TELEPHONY_LOGE("SmsInterfaceStub::OnSendMms write reply failed");
516         return;
517     }
518 }
519 
OnDownloadMms(MessageParcel & data,MessageParcel & reply,MessageOption & option)520 void SmsInterfaceStub::OnDownloadMms(MessageParcel &data, MessageParcel &reply, MessageOption &option)
521 {
522     int32_t slotId = data.ReadInt32();
523     TELEPHONY_LOGI("download mms slotId:%{public}d", slotId);
524     u16string mmsc = data.ReadString16();
525     u16string mmsData = data.ReadString16();
526     u16string ua = data.ReadString16();
527     u16string uaprof = data.ReadString16();
528     int32_t result = DownloadMms(slotId, mmsc, mmsData, ua, uaprof);
529     if (!reply.WriteInt32(result)) {
530         TELEPHONY_LOGE("SmsInterfaceStub::OnDownloadMms write reply failed");
531         return;
532     }
533     reply.WriteString16(mmsData);
534     TELEPHONY_LOGI("SmsInterfaceStub::OnDownloadMms dbUrls:%{public}s", StringUtils::ToUtf8(mmsData).c_str());
535 }
536 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)537 int SmsInterfaceStub::OnRemoteRequest(
538     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
539 {
540     TELEPHONY_LOGI("SmsInterfaceStub::OnRemoteRequest code:%{public}d", code);
541     std::u16string myDescripter = SmsInterfaceStub::GetDescriptor();
542     std::u16string remoteDescripter = data.ReadInterfaceToken();
543     if (myDescripter != remoteDescripter) {
544         TELEPHONY_LOGE("descriptor checked fail");
545         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
546     }
547 
548     auto itFunc = memberFuncMap_.find(code);
549     if (itFunc != memberFuncMap_.end()) {
550         auto memberFunc = itFunc->second;
551         if (memberFunc != nullptr) {
552             (this->*memberFunc)(data, reply, option);
553             return TELEPHONY_ERR_SUCCESS;
554         }
555     }
556     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
557 }
558 } // namespace Telephony
559 } // namespace OHOS
560